blob: e82911ab0f8c890abeb876404b44e251a08bd60d [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;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100203 int num_loopbacks;
204 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200205#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200206
207 /* for PLL fix */
208 hda_nid_t pll_nid;
209 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200210 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100211
212 /* fix-up list */
213 int fixup_id;
214 const struct alc_fixup *fixup_list;
215 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200216
217 /* multi-io */
218 int multi_ios;
219 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200220
221 /* bind volumes */
222 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100223};
224
Takashi Iwai1d045db2011-07-07 18:23:21 +0200225#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
Takashi Iwai44c02402011-07-08 15:14:19 +0200227static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
228 int dir, unsigned int bits)
229{
230 if (!nid)
231 return false;
232 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
233 if (query_amp_caps(codec, nid, dir) & bits)
234 return true;
235 return false;
236}
237
238#define nid_has_mute(codec, nid, dir) \
239 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
240#define nid_has_volume(codec, nid, dir) \
241 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
242
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243/*
244 * input MUX handling
245 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200246static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
250 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200251 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
252 if (mux_idx >= spec->num_mux_defs)
253 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100254 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
255 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200256 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200259static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
260 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
262 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
263 struct alc_spec *spec = codec->spec;
264 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
265
266 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
267 return 0;
268}
269
Takashi Iwai21268962011-07-07 15:01:13 +0200270static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
Takashi Iwai21268962011-07-07 15:01:13 +0200272 struct alc_spec *spec = codec->spec;
273 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
274
275 if (spec->cur_adc && spec->cur_adc != new_adc) {
276 /* stream is running, let's swap the current ADC */
277 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
278 spec->cur_adc = new_adc;
279 snd_hda_codec_setup_stream(codec, new_adc,
280 spec->cur_adc_stream_tag, 0,
281 spec->cur_adc_format);
282 return true;
283 }
284 return false;
285}
286
Takashi Iwai61071592011-11-23 07:52:15 +0100287static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
288{
289 return spec->capsrc_nids ?
290 spec->capsrc_nids[idx] : spec->adc_nids[idx];
291}
292
Takashi Iwai24de1832011-11-07 17:13:39 +0100293static void call_update_outputs(struct hda_codec *codec);
294
Takashi Iwai21268962011-07-07 15:01:13 +0200295/* select the given imux item; either unmute exclusively or select the route */
296static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
297 unsigned int idx, bool force)
298{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100300 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100301 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100302 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200303 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304
Takashi Iwai5803a322012-02-21 11:59:45 +0100305 if (!spec->input_mux)
306 return 0;
307
Takashi Iwaicd896c32008-11-18 12:36:33 +0100308 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
309 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100310 if (!imux->num_items && mux_idx > 0)
311 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100312 if (!imux->num_items)
313 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100314
Takashi Iwai21268962011-07-07 15:01:13 +0200315 if (idx >= imux->num_items)
316 idx = imux->num_items - 1;
317 if (spec->cur_mux[adc_idx] == idx && !force)
318 return 0;
319 spec->cur_mux[adc_idx] = idx;
320
Takashi Iwai24de1832011-11-07 17:13:39 +0100321 /* for shared I/O, change the pin-control accordingly */
322 if (spec->shared_mic_hp) {
323 /* NOTE: this assumes that there are only two inputs, the
324 * first is the real internal mic and the second is HP jack.
325 */
326 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
327 AC_VERB_SET_PIN_WIDGET_CONTROL,
328 spec->cur_mux[adc_idx] ?
329 PIN_VREF80 : PIN_HP);
330 spec->automute_speaker = !spec->cur_mux[adc_idx];
331 call_update_outputs(codec);
332 }
333
Takashi Iwai21268962011-07-07 15:01:13 +0200334 if (spec->dyn_adc_switch) {
335 alc_dyn_adc_pcm_resetup(codec, idx);
336 adc_idx = spec->dyn_adc_idx[idx];
337 }
338
Takashi Iwai61071592011-11-23 07:52:15 +0100339 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200340
341 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100342 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
343 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200344 return 1;
345
Takashi Iwaia22d5432009-07-27 12:54:26 +0200346 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200347 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100348 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100349 int active = imux->items[idx].index;
350 for (i = 0; i < num_conns; i++) {
351 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
352 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100353 HDA_AMP_MUTE, v);
354 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100355 } else {
356 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200357 snd_hda_codec_write_cache(codec, nid, 0,
358 AC_VERB_SET_CONNECT_SEL,
359 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100360 }
Takashi Iwai21268962011-07-07 15:01:13 +0200361 return 1;
362}
363
364static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
365 struct snd_ctl_elem_value *ucontrol)
366{
367 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
368 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
369 return alc_mux_select(codec, adc_idx,
370 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100371}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100374 * set up the input pin config (depending on the given auto-pin type)
375 */
376static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
377 int auto_pin_type)
378{
379 unsigned int val = PIN_IN;
380
Takashi Iwai86e29592010-09-09 14:50:17 +0200381 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100382 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200383 unsigned int oldval;
384 oldval = snd_hda_codec_read(codec, nid, 0,
385 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100386 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100387 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200388 /* if the default pin setup is vref50, we give it priority */
389 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100390 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200391 else if (pincap & AC_PINCAP_VREF_50)
392 val = PIN_VREF50;
393 else if (pincap & AC_PINCAP_VREF_100)
394 val = PIN_VREF100;
395 else if (pincap & AC_PINCAP_VREF_GRD)
396 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100397 }
398 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
399}
400
401/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200402 * Append the given mixer and verb elements for the later use
403 * The mixer array is referred in build_controls(), and init_verbs are
404 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100405 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200406static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100407{
408 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
409 return;
410 spec->mixers[spec->num_mixers++] = mix;
411}
412
413static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
414{
415 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
416 return;
417 spec->init_verbs[spec->num_init_verbs++] = verb;
418}
419
420/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200421 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100422 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200423/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200424static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200425 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
427 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
428 { }
429};
430
Takashi Iwaia9111322011-05-02 11:30:18 +0200431static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200432 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
433 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
434 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
435 { }
436};
437
Takashi Iwaia9111322011-05-02 11:30:18 +0200438static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200439 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
440 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
441 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
442 { }
443};
444
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200445/*
446 * Fix hardware PLL issue
447 * On some codecs, the analog PLL gating control must be off while
448 * the default value is 1.
449 */
450static void alc_fix_pll(struct hda_codec *codec)
451{
452 struct alc_spec *spec = codec->spec;
453 unsigned int val;
454
455 if (!spec->pll_nid)
456 return;
457 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
458 spec->pll_coef_idx);
459 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
460 AC_VERB_GET_PROC_COEF, 0);
461 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
462 spec->pll_coef_idx);
463 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
464 val & ~(1 << spec->pll_coef_bit));
465}
466
467static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
468 unsigned int coef_idx, unsigned int coef_bit)
469{
470 struct alc_spec *spec = codec->spec;
471 spec->pll_nid = nid;
472 spec->pll_coef_idx = coef_idx;
473 spec->pll_coef_bit = coef_bit;
474 alc_fix_pll(codec);
475}
476
Takashi Iwai1d045db2011-07-07 18:23:21 +0200477/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200478 * Jack detections for HP auto-mute and mic-switch
479 */
480
481/* check each pin in the given array; returns true if any of them is plugged */
482static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200483{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200484 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200485
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200486 for (i = 0; i < num_pins; i++) {
487 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200488 if (!nid)
489 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200490 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200491 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200492 return present;
493}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200494
Takashi Iwai1d045db2011-07-07 18:23:21 +0200495/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200496static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200497 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200498{
499 struct alc_spec *spec = codec->spec;
500 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200501 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200502 int i;
503
504 for (i = 0; i < num_pins; i++) {
505 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100506 unsigned int val;
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200507 if (!nid)
508 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200509 switch (spec->automute_mode) {
510 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100511 /* don't reset VREF value in case it's controlling
512 * the amp (see alc861_fixup_asus_amp_vref_0f())
513 */
514 if (spec->keep_vref_in_automute) {
515 val = snd_hda_codec_read(codec, nid, 0,
516 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
517 val &= ~PIN_HP;
518 } else
519 val = 0;
520 val |= pin_bits;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200521 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200522 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai31150f22012-01-30 10:54:08 +0100523 val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200524 break;
525 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200526 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200527 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200528 break;
529 case ALC_AUTOMUTE_MIXER:
530 nid = spec->automute_mixer_nid[i];
531 if (!nid)
532 break;
533 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200534 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200535 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200536 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200537 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200538 }
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200539 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200540}
541
David Henningsson42cf0d02011-09-20 12:04:56 +0200542/* Toggle outputs muting */
543static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200544{
545 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200546 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200547
Takashi Iwaic0a20262011-06-10 15:28:15 +0200548 /* Control HP pins/amps depending on master_mute state;
549 * in general, HP pins/amps control should be enabled in all cases,
550 * but currently set only for master_mute, just to be safe
551 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100552 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
553 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200554 spec->autocfg.hp_pins, spec->master_mute, true);
555
David Henningsson42cf0d02011-09-20 12:04:56 +0200556 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200557 on = 0;
558 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200559 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200562 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200563
564 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 /* if LO is a copy of either HP or Speaker, don't need to handle it */
566 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
567 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200568 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200569 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 on = 0;
571 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200572 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200573 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200574 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200575 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200576}
577
David Henningsson42cf0d02011-09-20 12:04:56 +0200578static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200579{
580 struct alc_spec *spec = codec->spec;
581 if (spec->automute_hook)
582 spec->automute_hook(codec);
583 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200584 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200585}
586
Takashi Iwai1d045db2011-07-07 18:23:21 +0200587/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588static void alc_hp_automute(struct hda_codec *codec)
589{
590 struct alc_spec *spec = codec->spec;
591
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200593 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
594 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200595 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200596 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200597 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200598}
599
Takashi Iwai1d045db2011-07-07 18:23:21 +0200600/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200601static void alc_line_automute(struct hda_codec *codec)
602{
603 struct alc_spec *spec = codec->spec;
604
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200605 /* check LO jack only when it's different from HP */
606 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
607 return;
608
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200609 spec->line_jack_present =
610 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
611 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200612 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200613 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200614 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200615}
616
Takashi Iwai8d087c72011-06-28 12:45:47 +0200617#define get_connection_index(codec, mux, nid) \
618 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200619
Takashi Iwai1d045db2011-07-07 18:23:21 +0200620/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200621static void alc_mic_automute(struct hda_codec *codec)
622{
623 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200624 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200625
Takashi Iwai21268962011-07-07 15:01:13 +0200626 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200627 return;
628 if (snd_BUG_ON(!spec->adc_nids))
629 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200630 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200631 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200632
Takashi Iwai21268962011-07-07 15:01:13 +0200633 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
634 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
635 else if (spec->dock_mic_idx >= 0 &&
636 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
637 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
638 else
639 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200640}
641
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100642/* handle the specified unsol action (ALC_XXX_EVENT) */
643static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200644{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100645 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200646 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200647 alc_hp_automute(codec);
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200648 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200649 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200650 alc_line_automute(codec);
651 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200652 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200653 alc_mic_automute(codec);
Takashi Iwaia9fd4f3f2009-05-08 15:57:59 +0200654 break;
655 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200656 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200657}
658
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100659/* update the master volume per volume-knob's unsol event */
660static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
661{
662 unsigned int val;
663 struct snd_kcontrol *kctl;
664 struct snd_ctl_elem_value *uctl;
665
666 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
667 if (!kctl)
668 return;
669 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
670 if (!uctl)
671 return;
672 val = snd_hda_codec_read(codec, nid, 0,
673 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
674 val &= HDA_AMP_VOLMASK;
675 uctl->value.integer.value[0] = val;
676 uctl->value.integer.value[1] = val;
677 kctl->put(kctl, uctl);
678 kfree(uctl);
679}
680
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100681/* unsolicited event for HP jack sensing */
682static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
683{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100684 int action;
685
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100686 if (codec->vendor_id == 0x10ec0880)
687 res >>= 28;
688 else
689 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100690 action = snd_hda_jack_get_action(codec, res);
691 if (res == ALC_DCVOL_EVENT) {
692 /* Execute the dc-vol event here as it requires the NID
693 * but we don't pass NID to alc_exec_unsol_event().
694 * Once when we convert all static quirks to the auto-parser,
695 * this can be integerated into there.
696 */
697 struct hda_jack_tbl *jack;
698 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
699 if (jack)
700 alc_update_knob_master(codec, jack->nid);
701 return;
702 }
703 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100704}
705
Takashi Iwai1d045db2011-07-07 18:23:21 +0200706/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200707static void alc_inithook(struct hda_codec *codec)
708{
Takashi Iwaid922b512011-04-28 12:18:53 +0200709 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200710 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200711 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200712}
713
Kailang Yangf9423e72008-05-27 12:32:25 +0200714/* additional initialization for ALC888 variants */
715static void alc888_coef_init(struct hda_codec *codec)
716{
717 unsigned int tmp;
718
719 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
720 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100722 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200723 /* alc888S-VC */
724 snd_hda_codec_read(codec, 0x20, 0,
725 AC_VERB_SET_PROC_COEF, 0x830);
726 else
727 /* alc888-VB */
728 snd_hda_codec_read(codec, 0x20, 0,
729 AC_VERB_SET_PROC_COEF, 0x3030);
730}
731
Takashi Iwai1d045db2011-07-07 18:23:21 +0200732/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200733static void alc889_coef_init(struct hda_codec *codec)
734{
735 unsigned int tmp;
736
737 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
738 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
739 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
740 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
741}
742
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100743/* turn on/off EAPD control (only if available) */
744static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
745{
746 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
747 return;
748 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
749 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
750 on ? 2 : 0);
751}
752
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200753/* turn on/off EAPD controls of the codec */
754static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
755{
756 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200757 static hda_nid_t pins[] = {
758 0x0f, 0x10, 0x14, 0x15, 0
759 };
760 hda_nid_t *p;
761 for (p = pins; *p; p++)
762 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200763}
764
Takashi Iwai1c7161532011-04-07 10:37:16 +0200765/* generic shutup callback;
766 * just turning off EPAD and a little pause for avoiding pop-noise
767 */
768static void alc_eapd_shutup(struct hda_codec *codec)
769{
770 alc_auto_setup_eapd(codec, false);
771 msleep(200);
772}
773
Takashi Iwai1d045db2011-07-07 18:23:21 +0200774/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200775static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200776{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200778
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200779 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200780 switch (type) {
781 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200782 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
783 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200784 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200785 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
786 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200787 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200788 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
789 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200790 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200791 switch (codec->vendor_id) {
792 case 0x10ec0260:
793 snd_hda_codec_write(codec, 0x1a, 0,
794 AC_VERB_SET_COEF_INDEX, 7);
795 tmp = snd_hda_codec_read(codec, 0x1a, 0,
796 AC_VERB_GET_PROC_COEF, 0);
797 snd_hda_codec_write(codec, 0x1a, 0,
798 AC_VERB_SET_COEF_INDEX, 7);
799 snd_hda_codec_write(codec, 0x1a, 0,
800 AC_VERB_SET_PROC_COEF,
801 tmp | 0x2010);
802 break;
803 case 0x10ec0262:
804 case 0x10ec0880:
805 case 0x10ec0882:
806 case 0x10ec0883:
807 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100808 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100809 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200810 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200811 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200812 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200813 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200814 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100815#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200816 case 0x10ec0267:
817 case 0x10ec0268:
818 snd_hda_codec_write(codec, 0x20, 0,
819 AC_VERB_SET_COEF_INDEX, 7);
820 tmp = snd_hda_codec_read(codec, 0x20, 0,
821 AC_VERB_GET_PROC_COEF, 0);
822 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200823 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200824 snd_hda_codec_write(codec, 0x20, 0,
825 AC_VERB_SET_PROC_COEF,
826 tmp | 0x3000);
827 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100828#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200829 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200830 break;
831 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200832}
Kailang Yangea1fb292008-08-26 12:58:38 +0200833
Takashi Iwai1d045db2011-07-07 18:23:21 +0200834/*
835 * Auto-Mute mode mixer enum support
836 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200837static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
838 struct snd_ctl_elem_info *uinfo)
839{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200840 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
841 struct alc_spec *spec = codec->spec;
842 static const char * const texts2[] = {
843 "Disabled", "Enabled"
844 };
845 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200846 "Disabled", "Speaker Only", "Line-Out+Speaker"
847 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200848 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200849
850 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
851 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200852 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200853 uinfo->value.enumerated.items = 3;
854 texts = texts3;
855 } else {
856 uinfo->value.enumerated.items = 2;
857 texts = texts2;
858 }
859 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
860 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200861 strcpy(uinfo->value.enumerated.name,
862 texts[uinfo->value.enumerated.item]);
863 return 0;
864}
865
866static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
867 struct snd_ctl_elem_value *ucontrol)
868{
869 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
870 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200871 unsigned int val = 0;
872 if (spec->automute_speaker)
873 val++;
874 if (spec->automute_lo)
875 val++;
876
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200877 ucontrol->value.enumerated.item[0] = val;
878 return 0;
879}
880
881static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
882 struct snd_ctl_elem_value *ucontrol)
883{
884 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
885 struct alc_spec *spec = codec->spec;
886
887 switch (ucontrol->value.enumerated.item[0]) {
888 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200889 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200890 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200891 spec->automute_speaker = 0;
892 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200893 break;
894 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200895 if (spec->automute_speaker_possible) {
896 if (!spec->automute_lo && spec->automute_speaker)
897 return 0;
898 spec->automute_speaker = 1;
899 spec->automute_lo = 0;
900 } else if (spec->automute_lo_possible) {
901 if (spec->automute_lo)
902 return 0;
903 spec->automute_lo = 1;
904 } else
905 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200906 break;
907 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200908 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200909 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200910 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200911 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200912 spec->automute_speaker = 1;
913 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200914 break;
915 default:
916 return -EINVAL;
917 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200918 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200919 return 1;
920}
921
Takashi Iwaia9111322011-05-02 11:30:18 +0200922static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200923 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
924 .name = "Auto-Mute Mode",
925 .info = alc_automute_mode_info,
926 .get = alc_automute_mode_get,
927 .put = alc_automute_mode_put,
928};
929
Takashi Iwai1d045db2011-07-07 18:23:21 +0200930static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
931{
932 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
933 return snd_array_new(&spec->kctls);
934}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200935
936static int alc_add_automute_mode_enum(struct hda_codec *codec)
937{
938 struct alc_spec *spec = codec->spec;
939 struct snd_kcontrol_new *knew;
940
941 knew = alc_kcontrol_new(spec);
942 if (!knew)
943 return -ENOMEM;
944 *knew = alc_automute_mode_enum;
945 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
946 if (!knew->name)
947 return -ENOMEM;
948 return 0;
949}
950
Takashi Iwai1d045db2011-07-07 18:23:21 +0200951/*
952 * Check the availability of HP/line-out auto-mute;
953 * Set up appropriately if really supported
954 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200955static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200956{
957 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200958 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200959 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200960 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200961
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200962 if (cfg->hp_pins[0])
963 present++;
964 if (cfg->line_out_pins[0])
965 present++;
966 if (cfg->speaker_pins[0])
967 present++;
968 if (present < 2) /* need two different output types */
969 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200970
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200971 if (!cfg->speaker_pins[0] &&
972 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200973 memcpy(cfg->speaker_pins, cfg->line_out_pins,
974 sizeof(cfg->speaker_pins));
975 cfg->speaker_outs = cfg->line_outs;
976 }
977
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200978 if (!cfg->hp_pins[0] &&
979 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200980 memcpy(cfg->hp_pins, cfg->line_out_pins,
981 sizeof(cfg->hp_pins));
982 cfg->hp_outs = cfg->line_outs;
983 }
984
David Henningsson42cf0d02011-09-20 12:04:56 +0200985 spec->automute_mode = ALC_AUTOMUTE_PIN;
986
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200987 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200988 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200989 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200990 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200991 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200992 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200993 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200994 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200995 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200996
David Henningsson42cf0d02011-09-20 12:04:56 +0200997 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
998 if (cfg->speaker_outs)
999 for (i = 0; i < cfg->line_outs; i++) {
1000 hda_nid_t nid = cfg->line_out_pins[i];
1001 if (!is_jack_detectable(codec, nid))
1002 continue;
1003 snd_printdd("realtek: Enable Line-Out "
1004 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001005 snd_hda_jack_detect_enable(codec, nid,
1006 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001007 spec->detect_lo = 1;
1008 }
1009 spec->automute_lo_possible = spec->detect_hp;
1010 }
1011
1012 spec->automute_speaker_possible = cfg->speaker_outs &&
1013 (spec->detect_hp || spec->detect_lo);
1014
1015 spec->automute_lo = spec->automute_lo_possible;
1016 spec->automute_speaker = spec->automute_speaker_possible;
1017
1018 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001019 /* create a control for automute mode */
1020 alc_add_automute_mode_enum(codec);
1021 spec->unsol_event = alc_sku_unsol_event;
1022 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001023}
1024
Takashi Iwai1d045db2011-07-07 18:23:21 +02001025/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001026static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1027{
1028 int i;
1029 for (i = 0; i < nums; i++)
1030 if (list[i] == nid)
1031 return i;
1032 return -1;
1033}
1034
Takashi Iwai1d045db2011-07-07 18:23:21 +02001035/* check whether dynamic ADC-switching is available */
1036static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1037{
1038 struct alc_spec *spec = codec->spec;
1039 struct hda_input_mux *imux = &spec->private_imux[0];
1040 int i, n, idx;
1041 hda_nid_t cap, pin;
1042
1043 if (imux != spec->input_mux) /* no dynamic imux? */
1044 return false;
1045
1046 for (n = 0; n < spec->num_adc_nids; n++) {
1047 cap = spec->private_capsrc_nids[n];
1048 for (i = 0; i < imux->num_items; i++) {
1049 pin = spec->imux_pins[i];
1050 if (!pin)
1051 return false;
1052 if (get_connection_index(codec, cap, pin) < 0)
1053 break;
1054 }
1055 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001056 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001057 }
1058
1059 for (i = 0; i < imux->num_items; i++) {
1060 pin = spec->imux_pins[i];
1061 for (n = 0; n < spec->num_adc_nids; n++) {
1062 cap = spec->private_capsrc_nids[n];
1063 idx = get_connection_index(codec, cap, pin);
1064 if (idx >= 0) {
1065 imux->items[i].index = idx;
1066 spec->dyn_adc_idx[i] = n;
1067 break;
1068 }
1069 }
1070 }
1071
1072 snd_printdd("realtek: enabling ADC switching\n");
1073 spec->dyn_adc_switch = 1;
1074 return true;
1075}
Takashi Iwai21268962011-07-07 15:01:13 +02001076
1077/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1078static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1079{
1080 struct alc_spec *spec = codec->spec;
1081 struct hda_input_mux *imux;
1082 static char * const texts[3] = {
1083 "Mic", "Internal Mic", "Dock Mic"
1084 };
1085 int i;
1086
1087 if (!spec->auto_mic)
1088 return false;
1089 imux = &spec->private_imux[0];
1090 if (spec->input_mux == imux)
1091 return true;
1092 spec->imux_pins[0] = spec->ext_mic_pin;
1093 spec->imux_pins[1] = spec->int_mic_pin;
1094 spec->imux_pins[2] = spec->dock_mic_pin;
1095 for (i = 0; i < 3; i++) {
1096 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001097 if (spec->imux_pins[i]) {
1098 hda_nid_t pin = spec->imux_pins[i];
1099 int c;
1100 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001101 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001102 int idx = get_connection_index(codec, cap, pin);
1103 if (idx >= 0) {
1104 imux->items[i].index = idx;
1105 break;
1106 }
1107 }
Takashi Iwai21268962011-07-07 15:01:13 +02001108 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001109 }
Takashi Iwai21268962011-07-07 15:01:13 +02001110 }
1111 spec->num_mux_defs = 1;
1112 spec->input_mux = imux;
1113 return true;
1114}
1115
1116/* check whether all auto-mic pins are valid; setup indices if OK */
1117static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1118{
1119 struct alc_spec *spec = codec->spec;
1120 const struct hda_input_mux *imux;
1121
1122 if (!spec->auto_mic)
1123 return false;
1124 if (spec->auto_mic_valid_imux)
1125 return true; /* already checked */
1126
1127 /* fill up imux indices */
1128 if (!alc_check_dyn_adc_switch(codec)) {
1129 spec->auto_mic = 0;
1130 return false;
1131 }
1132
1133 imux = spec->input_mux;
1134 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1135 spec->imux_pins, imux->num_items);
1136 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1137 spec->imux_pins, imux->num_items);
1138 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1139 spec->imux_pins, imux->num_items);
1140 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1141 spec->auto_mic = 0;
1142 return false; /* no corresponding imux */
1143 }
1144
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001145 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001146 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001147 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1148 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001149
1150 spec->auto_mic_valid_imux = 1;
1151 spec->auto_mic = 1;
1152 return true;
1153}
1154
Takashi Iwai1d045db2011-07-07 18:23:21 +02001155/*
1156 * Check the availability of auto-mic switch;
1157 * Set up if really supported
1158 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001159static void alc_init_auto_mic(struct hda_codec *codec)
1160{
1161 struct alc_spec *spec = codec->spec;
1162 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001163 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001164 int i;
1165
Takashi Iwai24de1832011-11-07 17:13:39 +01001166 if (spec->shared_mic_hp)
1167 return; /* no auto-mic for the shared I/O */
1168
Takashi Iwai21268962011-07-07 15:01:13 +02001169 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1170
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001171 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001172 for (i = 0; i < cfg->num_inputs; i++) {
1173 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001174 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001175 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001176 switch (snd_hda_get_input_pin_attr(defcfg)) {
1177 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001178 if (fixed)
1179 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001180 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1181 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001182 fixed = nid;
1183 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001184 case INPUT_PIN_ATTR_UNUSED:
1185 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001186 case INPUT_PIN_ATTR_DOCK:
1187 if (dock)
1188 return; /* already occupied */
1189 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1190 return; /* invalid type */
1191 dock = nid;
1192 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001193 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001194 if (ext)
1195 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001196 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1197 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001198 ext = nid;
1199 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001200 }
1201 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001202 if (!ext && dock) {
1203 ext = dock;
1204 dock = 0;
1205 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001206 if (!ext || !fixed)
1207 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001208 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001209 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001210 if (dock && !is_jack_detectable(codec, dock))
1211 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001212
1213 /* check imux indices */
1214 spec->ext_mic_pin = ext;
1215 spec->int_mic_pin = fixed;
1216 spec->dock_mic_pin = dock;
1217
1218 spec->auto_mic = 1;
1219 if (!alc_auto_mic_check_imux(codec))
1220 return;
1221
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001222 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1223 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001224 spec->unsol_event = alc_sku_unsol_event;
1225}
1226
Takashi Iwai1d045db2011-07-07 18:23:21 +02001227/* check the availabilities of auto-mute and auto-mic switches */
1228static void alc_auto_check_switches(struct hda_codec *codec)
1229{
David Henningsson42cf0d02011-09-20 12:04:56 +02001230 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001231 alc_init_auto_mic(codec);
1232}
1233
1234/*
1235 * Realtek SSID verification
1236 */
1237
David Henningsson90622912010-10-14 14:50:18 +02001238/* Could be any non-zero and even value. When used as fixup, tells
1239 * the driver to ignore any present sku defines.
1240 */
1241#define ALC_FIXUP_SKU_IGNORE (2)
1242
Kailang Yangda00c242010-03-19 11:23:45 +01001243static int alc_auto_parse_customize_define(struct hda_codec *codec)
1244{
1245 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001246 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001247 struct alc_spec *spec = codec->spec;
1248
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001249 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1250
David Henningsson90622912010-10-14 14:50:18 +02001251 if (spec->cdefine.fixup) {
1252 ass = spec->cdefine.sku_cfg;
1253 if (ass == ALC_FIXUP_SKU_IGNORE)
1254 return -1;
1255 goto do_sku;
1256 }
1257
Kailang Yangda00c242010-03-19 11:23:45 +01001258 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001259 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001260 goto do_sku;
1261
1262 nid = 0x1d;
1263 if (codec->vendor_id == 0x10ec0260)
1264 nid = 0x17;
1265 ass = snd_hda_codec_get_pincfg(codec, nid);
1266
1267 if (!(ass & 1)) {
1268 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1269 codec->chip_name, ass);
1270 return -1;
1271 }
1272
1273 /* check sum */
1274 tmp = 0;
1275 for (i = 1; i < 16; i++) {
1276 if ((ass >> i) & 1)
1277 tmp++;
1278 }
1279 if (((ass >> 16) & 0xf) != tmp)
1280 return -1;
1281
1282 spec->cdefine.port_connectivity = ass >> 30;
1283 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1284 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1285 spec->cdefine.customization = ass >> 8;
1286do_sku:
1287 spec->cdefine.sku_cfg = ass;
1288 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1289 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1290 spec->cdefine.swap = (ass & 0x2) >> 1;
1291 spec->cdefine.override = ass & 0x1;
1292
1293 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1294 nid, spec->cdefine.sku_cfg);
1295 snd_printd("SKU: port_connectivity=0x%x\n",
1296 spec->cdefine.port_connectivity);
1297 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1298 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1299 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1300 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1301 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1302 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1303 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1304
1305 return 0;
1306}
1307
Takashi Iwai1d045db2011-07-07 18:23:21 +02001308/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001309static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1310{
Takashi Iwai21268962011-07-07 15:01:13 +02001311 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001312}
1313
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001314/* check subsystem ID and set up device-specific initialization;
1315 * return 1 if initialized, 0 if invalid SSID
1316 */
1317/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1318 * 31 ~ 16 : Manufacture ID
1319 * 15 ~ 8 : SKU ID
1320 * 7 ~ 0 : Assembly ID
1321 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1322 */
1323static int alc_subsystem_id(struct hda_codec *codec,
1324 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001325 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001326{
1327 unsigned int ass, tmp, i;
1328 unsigned nid;
1329 struct alc_spec *spec = codec->spec;
1330
David Henningsson90622912010-10-14 14:50:18 +02001331 if (spec->cdefine.fixup) {
1332 ass = spec->cdefine.sku_cfg;
1333 if (ass == ALC_FIXUP_SKU_IGNORE)
1334 return 0;
1335 goto do_sku;
1336 }
1337
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001338 ass = codec->subsystem_id & 0xffff;
1339 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1340 goto do_sku;
1341
1342 /* invalid SSID, check the special NID pin defcfg instead */
1343 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001344 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001345 * 29~21 : reserve
1346 * 20 : PCBEEP input
1347 * 19~16 : Check sum (15:1)
1348 * 15~1 : Custom
1349 * 0 : override
1350 */
1351 nid = 0x1d;
1352 if (codec->vendor_id == 0x10ec0260)
1353 nid = 0x17;
1354 ass = snd_hda_codec_get_pincfg(codec, nid);
1355 snd_printd("realtek: No valid SSID, "
1356 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001357 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001358 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001359 return 0;
1360 if ((ass >> 30) != 1) /* no physical connection */
1361 return 0;
1362
1363 /* check sum */
1364 tmp = 0;
1365 for (i = 1; i < 16; i++) {
1366 if ((ass >> i) & 1)
1367 tmp++;
1368 }
1369 if (((ass >> 16) & 0xf) != tmp)
1370 return 0;
1371do_sku:
1372 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1373 ass & 0xffff, codec->vendor_id);
1374 /*
1375 * 0 : override
1376 * 1 : Swap Jack
1377 * 2 : 0 --> Desktop, 1 --> Laptop
1378 * 3~5 : External Amplifier control
1379 * 7~6 : Reserved
1380 */
1381 tmp = (ass & 0x38) >> 3; /* external Amp control */
1382 switch (tmp) {
1383 case 1:
1384 spec->init_amp = ALC_INIT_GPIO1;
1385 break;
1386 case 3:
1387 spec->init_amp = ALC_INIT_GPIO2;
1388 break;
1389 case 7:
1390 spec->init_amp = ALC_INIT_GPIO3;
1391 break;
1392 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001393 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001394 spec->init_amp = ALC_INIT_DEFAULT;
1395 break;
1396 }
1397
1398 /* is laptop or Desktop and enable the function "Mute internal speaker
1399 * when the external headphone out jack is plugged"
1400 */
1401 if (!(ass & 0x8000))
1402 return 1;
1403 /*
1404 * 10~8 : Jack location
1405 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1406 * 14~13: Resvered
1407 * 15 : 1 --> enable the function "Mute internal speaker
1408 * when the external headphone out jack is plugged"
1409 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001410 if (!spec->autocfg.hp_pins[0] &&
1411 !(spec->autocfg.line_out_pins[0] &&
1412 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001413 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001414 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1415 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001416 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001417 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001418 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001419 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001420 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001421 else if (tmp == 3)
1422 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001423 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001424 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001425 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1426 spec->autocfg.line_outs))
1427 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001428 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001429 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001430 return 1;
1431}
Kailang Yangea1fb292008-08-26 12:58:38 +02001432
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001433/* Check the validity of ALC subsystem-id
1434 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1435static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001436{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001437 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001438 struct alc_spec *spec = codec->spec;
1439 snd_printd("realtek: "
1440 "Enable default setup for auto mode as fallback\n");
1441 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001442 }
Takashi Iwai21268962011-07-07 15:01:13 +02001443}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001444
Takashi Iwai41e41f12005-06-08 14:48:49 +02001445/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001446 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001447 */
1448
1449struct alc_pincfg {
1450 hda_nid_t nid;
1451 u32 val;
1452};
1453
Todd Broche1eb5f12010-12-06 11:19:51 -08001454struct alc_model_fixup {
1455 const int id;
1456 const char *name;
1457};
1458
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001459struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001460 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001461 bool chained;
1462 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001463 union {
1464 unsigned int sku;
1465 const struct alc_pincfg *pins;
1466 const struct hda_verb *verbs;
1467 void (*func)(struct hda_codec *codec,
1468 const struct alc_fixup *fix,
1469 int action);
1470 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001471};
1472
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001473enum {
1474 ALC_FIXUP_INVALID,
1475 ALC_FIXUP_SKU,
1476 ALC_FIXUP_PINS,
1477 ALC_FIXUP_VERBS,
1478 ALC_FIXUP_FUNC,
1479};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001480
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001481enum {
1482 ALC_FIXUP_ACT_PRE_PROBE,
1483 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001484 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001485};
1486
1487static void alc_apply_fixup(struct hda_codec *codec, int action)
1488{
1489 struct alc_spec *spec = codec->spec;
1490 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001491#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001492 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001493#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001494 int depth = 0;
1495
1496 if (!spec->fixup_list)
1497 return;
1498
1499 while (id >= 0) {
1500 const struct alc_fixup *fix = spec->fixup_list + id;
1501 const struct alc_pincfg *cfg;
1502
1503 switch (fix->type) {
1504 case ALC_FIXUP_SKU:
1505 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001506 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001507 snd_printdd(KERN_INFO "hda_codec: %s: "
1508 "Apply sku override for %s\n",
1509 codec->chip_name, modelname);
1510 spec->cdefine.sku_cfg = fix->v.sku;
1511 spec->cdefine.fixup = 1;
1512 break;
1513 case ALC_FIXUP_PINS:
1514 cfg = fix->v.pins;
1515 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1516 break;
1517 snd_printdd(KERN_INFO "hda_codec: %s: "
1518 "Apply pincfg for %s\n",
1519 codec->chip_name, modelname);
1520 for (; cfg->nid; cfg++)
1521 snd_hda_codec_set_pincfg(codec, cfg->nid,
1522 cfg->val);
1523 break;
1524 case ALC_FIXUP_VERBS:
1525 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1526 break;
1527 snd_printdd(KERN_INFO "hda_codec: %s: "
1528 "Apply fix-verbs for %s\n",
1529 codec->chip_name, modelname);
1530 add_verb(codec->spec, fix->v.verbs);
1531 break;
1532 case ALC_FIXUP_FUNC:
1533 if (!fix->v.func)
1534 break;
1535 snd_printdd(KERN_INFO "hda_codec: %s: "
1536 "Apply fix-func for %s\n",
1537 codec->chip_name, modelname);
1538 fix->v.func(codec, fix, action);
1539 break;
1540 default:
1541 snd_printk(KERN_ERR "hda_codec: %s: "
1542 "Invalid fixup type %d\n",
1543 codec->chip_name, fix->type);
1544 break;
1545 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001546 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001547 break;
1548 if (++depth > 10)
1549 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001550 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001551 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001552}
1553
Todd Broche1eb5f12010-12-06 11:19:51 -08001554static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001555 const struct alc_model_fixup *models,
1556 const struct snd_pci_quirk *quirk,
1557 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001558{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001559 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001560 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001561 int id = -1;
1562 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001563
Takashi Iwai9155f822012-02-20 18:41:02 +01001564 /* when model=nofixup is given, don't pick up any fixups */
1565 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
1566 spec->fixup_list = NULL;
1567 spec->fixup_id = -1;
1568 return;
1569 }
1570
Todd Broche1eb5f12010-12-06 11:19:51 -08001571 if (codec->modelname && models) {
1572 while (models->name) {
1573 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001574 id = models->id;
1575 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001576 break;
1577 }
1578 models++;
1579 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001580 }
1581 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001582 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1583 if (q) {
1584 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001585#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001586 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001587#endif
1588 }
1589 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001590 if (id < 0) {
1591 for (q = quirk; q->subvendor; q++) {
1592 unsigned int vendorid =
1593 q->subdevice | (q->subvendor << 16);
1594 if (vendorid == codec->subsystem_id) {
1595 id = q->value;
1596#ifdef CONFIG_SND_DEBUG_VERBOSE
1597 name = q->name;
1598#endif
1599 break;
1600 }
1601 }
1602 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001603
1604 spec->fixup_id = id;
1605 if (id >= 0) {
1606 spec->fixup_list = fixlist;
1607 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001608 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001609}
1610
Takashi Iwai1d045db2011-07-07 18:23:21 +02001611/*
1612 * COEF access helper functions
1613 */
Kailang Yang274693f2009-12-03 10:07:50 +01001614static int alc_read_coef_idx(struct hda_codec *codec,
1615 unsigned int coef_idx)
1616{
1617 unsigned int val;
1618 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1619 coef_idx);
1620 val = snd_hda_codec_read(codec, 0x20, 0,
1621 AC_VERB_GET_PROC_COEF, 0);
1622 return val;
1623}
1624
Kailang Yang977ddd62010-09-15 10:02:29 +02001625static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1626 unsigned int coef_val)
1627{
1628 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1629 coef_idx);
1630 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1631 coef_val);
1632}
1633
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001634/* a special bypass for COEF 0; read the cached value at the second time */
1635static unsigned int alc_get_coef0(struct hda_codec *codec)
1636{
1637 struct alc_spec *spec = codec->spec;
1638 if (!spec->coef0)
1639 spec->coef0 = alc_read_coef_idx(codec, 0);
1640 return spec->coef0;
1641}
1642
Takashi Iwai1d045db2011-07-07 18:23:21 +02001643/*
1644 * Digital I/O handling
1645 */
1646
Takashi Iwai757899a2010-07-30 10:48:14 +02001647/* set right pin controls for digital I/O */
1648static void alc_auto_init_digital(struct hda_codec *codec)
1649{
1650 struct alc_spec *spec = codec->spec;
1651 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001652 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001653
1654 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1655 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001656 if (!pin)
1657 continue;
1658 snd_hda_codec_write(codec, pin, 0,
1659 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1660 if (!i)
1661 dac = spec->multiout.dig_out_nid;
1662 else
1663 dac = spec->slave_dig_outs[i - 1];
1664 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1665 continue;
1666 snd_hda_codec_write(codec, dac, 0,
1667 AC_VERB_SET_AMP_GAIN_MUTE,
1668 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001669 }
1670 pin = spec->autocfg.dig_in_pin;
1671 if (pin)
1672 snd_hda_codec_write(codec, pin, 0,
1673 AC_VERB_SET_PIN_WIDGET_CONTROL,
1674 PIN_IN);
1675}
1676
1677/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1678static void alc_auto_parse_digital(struct hda_codec *codec)
1679{
1680 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001681 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001682 hda_nid_t dig_nid;
1683
1684 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001685 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001686 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001687 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001688 err = snd_hda_get_connections(codec,
1689 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001690 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001691 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001692 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001693 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001694 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001695 spec->multiout.dig_out_nid = dig_nid;
1696 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1697 } else {
1698 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001699 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001700 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001701 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001702 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001703 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001704 }
1705
1706 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001707 dig_nid = codec->start_nid;
1708 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1709 unsigned int wcaps = get_wcaps(codec, dig_nid);
1710 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1711 continue;
1712 if (!(wcaps & AC_WCAP_DIGITAL))
1713 continue;
1714 if (!(wcaps & AC_WCAP_CONN_LIST))
1715 continue;
1716 err = get_connection_index(codec, dig_nid,
1717 spec->autocfg.dig_in_pin);
1718 if (err >= 0) {
1719 spec->dig_in_nid = dig_nid;
1720 break;
1721 }
1722 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001723 }
1724}
1725
Takashi Iwaif95474e2007-07-10 00:47:43 +02001726/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001727 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001728 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001729static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_info *uinfo)
1731{
1732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1733 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001734 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001735 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001736
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001737 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001738 if (spec->vol_in_capsrc)
1739 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1740 else
1741 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1742 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001743 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001744 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001745 return err;
1746}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001748static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1749 unsigned int size, unsigned int __user *tlv)
1750{
1751 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1752 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001753 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001754 int err;
1755
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001756 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001757 if (spec->vol_in_capsrc)
1758 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1759 else
1760 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1761 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001762 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001763 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001764 return err;
1765}
1766
1767typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1768 struct snd_ctl_elem_value *ucontrol);
1769
1770static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1771 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001772 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001773{
1774 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1775 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001776 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001777
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001778 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001779 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001780 for (i = 0; i < spec->num_adc_nids; i++) {
1781 kcontrol->private_value =
1782 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1783 3, 0, HDA_INPUT);
1784 err = func(kcontrol, ucontrol);
1785 if (err < 0)
1786 goto error;
1787 }
1788 } else {
1789 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001790 if (spec->vol_in_capsrc)
1791 kcontrol->private_value =
1792 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1793 3, 0, HDA_OUTPUT);
1794 else
1795 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001796 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1797 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001798 err = func(kcontrol, ucontrol);
1799 }
1800 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001801 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001802 return err;
1803}
1804
1805static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1806 struct snd_ctl_elem_value *ucontrol)
1807{
1808 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001809 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001810}
1811
1812static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1813 struct snd_ctl_elem_value *ucontrol)
1814{
1815 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001816 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001817}
1818
1819/* capture mixer elements */
1820#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1821
1822static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1823 struct snd_ctl_elem_value *ucontrol)
1824{
1825 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001826 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001827}
1828
1829static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1830 struct snd_ctl_elem_value *ucontrol)
1831{
1832 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001833 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001834}
1835
Takashi Iwaia23b6882009-03-23 15:21:36 +01001836#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001837 { \
1838 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1839 .name = "Capture Switch", \
1840 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1841 .count = num, \
1842 .info = alc_cap_sw_info, \
1843 .get = alc_cap_sw_get, \
1844 .put = alc_cap_sw_put, \
1845 }, \
1846 { \
1847 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1848 .name = "Capture Volume", \
1849 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1850 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1851 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1852 .count = num, \
1853 .info = alc_cap_vol_info, \
1854 .get = alc_cap_vol_get, \
1855 .put = alc_cap_vol_put, \
1856 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001857 }
1858
1859#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001860 { \
1861 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1862 /* .name = "Capture Source", */ \
1863 .name = "Input Source", \
1864 .count = num, \
1865 .info = alc_mux_enum_info, \
1866 .get = alc_mux_enum_get, \
1867 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001868 }
1869
1870#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001871static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001872 _DEFINE_CAPMIX(num), \
1873 _DEFINE_CAPSRC(num), \
1874 { } /* end */ \
1875}
1876
1877#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001878static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001879 _DEFINE_CAPMIX(num), \
1880 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001881}
1882
1883/* up to three ADCs */
1884DEFINE_CAPMIX(1);
1885DEFINE_CAPMIX(2);
1886DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001887DEFINE_CAPMIX_NOSRC(1);
1888DEFINE_CAPMIX_NOSRC(2);
1889DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001890
1891/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001892 * virtual master controls
1893 */
1894
1895/*
1896 * slave controls for virtual master
1897 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001898static const char * const alc_slave_pfxs[] = {
1899 "Front", "Surround", "Center", "LFE", "Side",
1900 "Headphone", "Speaker", "Mono", "Line-Out",
1901 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001902 NULL,
1903};
1904
1905/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001906 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001908
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001909#define NID_MAPPING (-1)
1910
1911#define SUBDEV_SPEAKER_ (0 << 6)
1912#define SUBDEV_HP_ (1 << 6)
1913#define SUBDEV_LINE_ (2 << 6)
1914#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1915#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1916#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1917
Takashi Iwai603c4012008-07-30 15:01:44 +02001918static void alc_free_kctls(struct hda_codec *codec);
1919
Takashi Iwai67d634c2009-11-16 15:35:59 +01001920#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001921/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001922static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001923 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001924 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001925 { } /* end */
1926};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001927#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001928
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001929static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930{
1931 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001932 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001933 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001934 int i, j, err;
1935 unsigned int u;
1936 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937
1938 for (i = 0; i < spec->num_mixers; i++) {
1939 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1940 if (err < 0)
1941 return err;
1942 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001943 if (spec->cap_mixer) {
1944 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1945 if (err < 0)
1946 return err;
1947 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001949 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001950 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001951 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 if (err < 0)
1953 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001954 if (!spec->no_analog) {
1955 err = snd_hda_create_spdif_share_sw(codec,
1956 &spec->multiout);
1957 if (err < 0)
1958 return err;
1959 spec->multiout.share_spdif = 1;
1960 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 }
1962 if (spec->dig_in_nid) {
1963 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1964 if (err < 0)
1965 return err;
1966 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001967
Takashi Iwai67d634c2009-11-16 15:35:59 +01001968#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001969 /* create beep controls if needed */
1970 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001971 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001972 for (knew = alc_beep_mixer; knew->name; knew++) {
1973 struct snd_kcontrol *kctl;
1974 kctl = snd_ctl_new1(knew, codec);
1975 if (!kctl)
1976 return -ENOMEM;
1977 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001978 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001979 if (err < 0)
1980 return err;
1981 }
1982 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001983#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001984
Takashi Iwai2134ea42008-01-10 16:53:55 +01001985 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001986 if (!spec->no_analog &&
1987 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001988 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001989 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001990 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001991 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001992 vmaster_tlv, alc_slave_pfxs,
1993 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001994 if (err < 0)
1995 return err;
1996 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001997 if (!spec->no_analog &&
1998 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001999 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01002000 NULL, alc_slave_pfxs,
2001 "Playback Switch");
Takashi Iwai2134ea42008-01-10 16:53:55 +01002002 if (err < 0)
2003 return err;
2004 }
2005
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002006 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02002007 if (spec->capsrc_nids || spec->adc_nids) {
2008 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
2009 if (!kctl)
2010 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
2011 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002012 err = snd_hda_add_nid(codec, kctl, i,
2013 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02002014 if (err < 0)
2015 return err;
2016 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002017 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02002018 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002019 const char *kname = kctl ? kctl->id.name : NULL;
2020 for (knew = spec->cap_mixer; knew->name; knew++) {
2021 if (kname && strcmp(knew->name, kname) == 0)
2022 continue;
2023 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2024 for (i = 0; kctl && i < kctl->count; i++) {
2025 err = snd_hda_add_nid(codec, kctl, i,
2026 spec->adc_nids[i]);
2027 if (err < 0)
2028 return err;
2029 }
2030 }
2031 }
2032
2033 /* other nid->control mapping */
2034 for (i = 0; i < spec->num_mixers; i++) {
2035 for (knew = spec->mixers[i]; knew->name; knew++) {
2036 if (knew->iface != NID_MAPPING)
2037 continue;
2038 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2039 if (kctl == NULL)
2040 continue;
2041 u = knew->subdevice;
2042 for (j = 0; j < 4; j++, u >>= 8) {
2043 nid = u & 0x3f;
2044 if (nid == 0)
2045 continue;
2046 switch (u & 0xc0) {
2047 case SUBDEV_SPEAKER_:
2048 nid = spec->autocfg.speaker_pins[nid];
2049 break;
2050 case SUBDEV_LINE_:
2051 nid = spec->autocfg.line_out_pins[nid];
2052 break;
2053 case SUBDEV_HP_:
2054 nid = spec->autocfg.hp_pins[nid];
2055 break;
2056 default:
2057 continue;
2058 }
2059 err = snd_hda_add_nid(codec, kctl, 0, nid);
2060 if (err < 0)
2061 return err;
2062 }
2063 u = knew->private_value;
2064 for (j = 0; j < 4; j++, u >>= 8) {
2065 nid = u & 0xff;
2066 if (nid == 0)
2067 continue;
2068 err = snd_hda_add_nid(codec, kctl, 0, nid);
2069 if (err < 0)
2070 return err;
2071 }
2072 }
2073 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002074
2075 alc_free_kctls(codec); /* no longer needed */
2076
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002077 return 0;
2078}
2079
2080static int alc_build_controls(struct hda_codec *codec)
2081{
2082 struct alc_spec *spec = codec->spec;
2083 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002084 if (err < 0)
2085 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002086 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087}
2088
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002091 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002092 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002093
Takashi Iwai584c0c42011-03-10 12:51:11 +01002094static void alc_init_special_input_src(struct hda_codec *codec);
2095
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096static int alc_init(struct hda_codec *codec)
2097{
2098 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002099 unsigned int i;
2100
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002101 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002102 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002103
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002104 for (i = 0; i < spec->num_init_verbs; i++)
2105 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002106 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002107
2108 if (spec->init_hook)
2109 spec->init_hook(codec);
2110
Takashi Iwai58701122011-01-13 15:41:45 +01002111 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2112
Takashi Iwai01a61e12011-10-28 00:03:22 +02002113 snd_hda_jack_report_sync(codec);
2114
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002115 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 return 0;
2117}
2118
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002119static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2120{
2121 struct alc_spec *spec = codec->spec;
2122
2123 if (spec->unsol_event)
2124 spec->unsol_event(codec, res);
2125}
2126
Takashi Iwaicb53c622007-08-10 17:21:45 +02002127#ifdef CONFIG_SND_HDA_POWER_SAVE
2128static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2129{
2130 struct alc_spec *spec = codec->spec;
2131 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2132}
2133#endif
2134
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135/*
2136 * Analog playback callbacks
2137 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002138static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002140 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
2142 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002143 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2144 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145}
2146
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002147static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 struct hda_codec *codec,
2149 unsigned int stream_tag,
2150 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002151 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152{
2153 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002154 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2155 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156}
2157
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002158static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002160 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161{
2162 struct alc_spec *spec = codec->spec;
2163 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2164}
2165
2166/*
2167 * Digital out
2168 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002169static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002171 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
2173 struct alc_spec *spec = codec->spec;
2174 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2175}
2176
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002177static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002178 struct hda_codec *codec,
2179 unsigned int stream_tag,
2180 unsigned int format,
2181 struct snd_pcm_substream *substream)
2182{
2183 struct alc_spec *spec = codec->spec;
2184 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2185 stream_tag, format, substream);
2186}
2187
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002188static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002189 struct hda_codec *codec,
2190 struct snd_pcm_substream *substream)
2191{
2192 struct alc_spec *spec = codec->spec;
2193 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2194}
2195
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002196static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002198 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
2200 struct alc_spec *spec = codec->spec;
2201 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2202}
2203
2204/*
2205 * Analog capture
2206 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002207static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 struct hda_codec *codec,
2209 unsigned int stream_tag,
2210 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002211 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212{
2213 struct alc_spec *spec = codec->spec;
2214
Takashi Iwai63300792008-01-24 15:31:36 +01002215 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 stream_tag, 0, format);
2217 return 0;
2218}
2219
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002220static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002222 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223{
2224 struct alc_spec *spec = codec->spec;
2225
Takashi Iwai888afa12008-03-18 09:57:50 +01002226 snd_hda_codec_cleanup_stream(codec,
2227 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 return 0;
2229}
2230
Takashi Iwai840b64c2010-07-13 22:49:01 +02002231/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002232static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002233 struct hda_codec *codec,
2234 unsigned int stream_tag,
2235 unsigned int format,
2236 struct snd_pcm_substream *substream)
2237{
2238 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002239 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002240 spec->cur_adc_stream_tag = stream_tag;
2241 spec->cur_adc_format = format;
2242 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2243 return 0;
2244}
2245
Takashi Iwai21268962011-07-07 15:01:13 +02002246static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002247 struct hda_codec *codec,
2248 struct snd_pcm_substream *substream)
2249{
2250 struct alc_spec *spec = codec->spec;
2251 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2252 spec->cur_adc = 0;
2253 return 0;
2254}
2255
Takashi Iwai21268962011-07-07 15:01:13 +02002256static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002257 .substreams = 1,
2258 .channels_min = 2,
2259 .channels_max = 2,
2260 .nid = 0, /* fill later */
2261 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002262 .prepare = dyn_adc_capture_pcm_prepare,
2263 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002264 },
2265};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
2267/*
2268 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002269static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 .substreams = 1,
2271 .channels_min = 2,
2272 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002273 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002275 .open = alc_playback_pcm_open,
2276 .prepare = alc_playback_pcm_prepare,
2277 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 },
2279};
2280
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002281static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002282 .substreams = 1,
2283 .channels_min = 2,
2284 .channels_max = 2,
2285 /* NID is set in alc_build_pcms */
2286};
2287
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002288static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002289 .substreams = 1,
2290 .channels_min = 2,
2291 .channels_max = 2,
2292 /* NID is set in alc_build_pcms */
2293};
2294
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002295static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002296 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 .channels_min = 2,
2298 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002299 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002301 .prepare = alc_alt_capture_pcm_prepare,
2302 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 },
2304};
2305
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002306static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 .substreams = 1,
2308 .channels_min = 2,
2309 .channels_max = 2,
2310 /* NID is set in alc_build_pcms */
2311 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002312 .open = alc_dig_playback_pcm_open,
2313 .close = alc_dig_playback_pcm_close,
2314 .prepare = alc_dig_playback_pcm_prepare,
2315 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 },
2317};
2318
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002319static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 .substreams = 1,
2321 .channels_min = 2,
2322 .channels_max = 2,
2323 /* NID is set in alc_build_pcms */
2324};
2325
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002326/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002327static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002328 .substreams = 0,
2329 .channels_min = 0,
2330 .channels_max = 0,
2331};
2332
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333static int alc_build_pcms(struct hda_codec *codec)
2334{
2335 struct alc_spec *spec = codec->spec;
2336 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002337 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002338 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 int i;
2340
2341 codec->num_pcms = 1;
2342 codec->pcm_info = info;
2343
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002344 if (spec->no_analog)
2345 goto skip_analog;
2346
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002347 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2348 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002350
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002351 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002352 p = spec->stream_analog_playback;
2353 if (!p)
2354 p = &alc_pcm_analog_playback;
2355 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002356 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2357 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002358 if (spec->adc_nids) {
2359 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002360 if (!p) {
2361 if (spec->dyn_adc_switch)
2362 p = &dyn_adc_pcm_analog_capture;
2363 else
2364 p = &alc_pcm_analog_capture;
2365 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002366 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002367 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2368 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369
Takashi Iwai4a471b72005-12-07 13:56:29 +01002370 if (spec->channel_mode) {
2371 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2372 for (i = 0; i < spec->num_channel_mode; i++) {
2373 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2374 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2375 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 }
2377 }
2378
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002379 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002380 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002382 snprintf(spec->stream_name_digital,
2383 sizeof(spec->stream_name_digital),
2384 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002385 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002386 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002387 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002389 if (spec->dig_out_type)
2390 info->pcm_type = spec->dig_out_type;
2391 else
2392 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002393 if (spec->multiout.dig_out_nid) {
2394 p = spec->stream_digital_playback;
2395 if (!p)
2396 p = &alc_pcm_digital_playback;
2397 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2399 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002400 if (spec->dig_in_nid) {
2401 p = spec->stream_digital_capture;
2402 if (!p)
2403 p = &alc_pcm_digital_capture;
2404 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2406 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002407 /* FIXME: do we need this for all Realtek codec models? */
2408 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 }
2410
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002411 if (spec->no_analog)
2412 return 0;
2413
Takashi Iwaie08a0072006-09-07 17:52:14 +02002414 /* If the use of more than one ADC is requested for the current
2415 * model, configure a second analog capture-only PCM.
2416 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002417 have_multi_adcs = (spec->num_adc_nids > 1) &&
2418 !spec->dyn_adc_switch && !spec->auto_mic &&
2419 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002420 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002421 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002422 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002423 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002424 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002425 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002426 p = spec->stream_analog_alt_playback;
2427 if (!p)
2428 p = &alc_pcm_analog_alt_playback;
2429 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002430 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2431 spec->alt_dac_nid;
2432 } else {
2433 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2434 alc_pcm_null_stream;
2435 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2436 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002437 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002438 p = spec->stream_analog_alt_capture;
2439 if (!p)
2440 p = &alc_pcm_analog_alt_capture;
2441 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002442 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2443 spec->adc_nids[1];
2444 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2445 spec->num_adc_nids - 1;
2446 } else {
2447 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2448 alc_pcm_null_stream;
2449 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002450 }
2451 }
2452
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 return 0;
2454}
2455
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002456static inline void alc_shutup(struct hda_codec *codec)
2457{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002458 struct alc_spec *spec = codec->spec;
2459
2460 if (spec && spec->shutup)
2461 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002462 snd_hda_shutup_pins(codec);
2463}
2464
Takashi Iwai603c4012008-07-30 15:01:44 +02002465static void alc_free_kctls(struct hda_codec *codec)
2466{
2467 struct alc_spec *spec = codec->spec;
2468
2469 if (spec->kctls.list) {
2470 struct snd_kcontrol_new *kctl = spec->kctls.list;
2471 int i;
2472 for (i = 0; i < spec->kctls.used; i++)
2473 kfree(kctl[i].name);
2474 }
2475 snd_array_free(&spec->kctls);
2476}
2477
Takashi Iwai23c09b02011-08-19 09:05:35 +02002478static void alc_free_bind_ctls(struct hda_codec *codec)
2479{
2480 struct alc_spec *spec = codec->spec;
2481 if (spec->bind_ctls.list) {
2482 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2483 int i;
2484 for (i = 0; i < spec->bind_ctls.used; i++)
2485 kfree(ctl[i]);
2486 }
2487 snd_array_free(&spec->bind_ctls);
2488}
2489
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490static void alc_free(struct hda_codec *codec)
2491{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002492 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002493
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002494 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002495 return;
2496
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002497 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002498 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002499 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002500 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002501 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502}
2503
Hector Martinf5de24b2009-12-20 22:51:31 +01002504#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002505static void alc_power_eapd(struct hda_codec *codec)
2506{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002507 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002508}
2509
Hector Martinf5de24b2009-12-20 22:51:31 +01002510static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2511{
2512 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002513 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002514 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002515 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002516 return 0;
2517}
2518#endif
2519
Takashi Iwai2a439522011-07-26 09:52:50 +02002520#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002521static int alc_resume(struct hda_codec *codec)
2522{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002523 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002524 codec->patch_ops.init(codec);
2525 snd_hda_codec_resume_amp(codec);
2526 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002527 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002528 return 0;
2529}
Takashi Iwaie044c392008-10-27 16:56:24 +01002530#endif
2531
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532/*
2533 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002534static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 .build_controls = alc_build_controls,
2536 .build_pcms = alc_build_pcms,
2537 .init = alc_init,
2538 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002539 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002540#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002541 .resume = alc_resume,
2542#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002543#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002544 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002545 .check_power_status = alc_check_power_status,
2546#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002547 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548};
2549
Kailang Yangc027ddc2010-03-19 11:33:06 +01002550/* replace the codec chip_name with the given string */
2551static int alc_codec_rename(struct hda_codec *codec, const char *name)
2552{
2553 kfree(codec->chip_name);
2554 codec->chip_name = kstrdup(name, GFP_KERNEL);
2555 if (!codec->chip_name) {
2556 alc_free(codec);
2557 return -ENOMEM;
2558 }
2559 return 0;
2560}
2561
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002562/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002563 * Rename codecs appropriately from COEF value
2564 */
2565struct alc_codec_rename_table {
2566 unsigned int vendor_id;
2567 unsigned short coef_mask;
2568 unsigned short coef_bits;
2569 const char *name;
2570};
2571
2572static struct alc_codec_rename_table rename_tbl[] = {
2573 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2574 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2575 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2576 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2577 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2578 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2579 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2580 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2581 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2582 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2583 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2584 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2585 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2586 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2587 { } /* terminator */
2588};
2589
2590static int alc_codec_rename_from_preset(struct hda_codec *codec)
2591{
2592 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002593
2594 for (p = rename_tbl; p->vendor_id; p++) {
2595 if (p->vendor_id != codec->vendor_id)
2596 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002597 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002598 return alc_codec_rename(codec, p->name);
2599 }
2600 return 0;
2601}
2602
2603/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002604 * Automatic parse of I/O pins from the BIOS configuration
2605 */
2606
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002607enum {
2608 ALC_CTL_WIDGET_VOL,
2609 ALC_CTL_WIDGET_MUTE,
2610 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002611 ALC_CTL_BIND_VOL,
2612 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002613};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002614static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002615 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2616 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002617 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002618 HDA_BIND_VOL(NULL, 0),
2619 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002620};
2621
2622/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002623static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002624 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002625{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002626 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002627
Takashi Iwaice764ab2011-04-27 16:35:23 +02002628 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002629 if (!knew)
2630 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002631 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002632 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002633 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002634 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002635 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002636 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002637 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002638 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002639 return 0;
2640}
2641
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002642static int add_control_with_pfx(struct alc_spec *spec, int type,
2643 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002644 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002645{
2646 char name[32];
2647 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002648 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002649}
2650
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002651#define add_pb_vol_ctrl(spec, type, pfx, val) \
2652 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2653#define add_pb_sw_ctrl(spec, type, pfx, val) \
2654 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2655#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2656 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2657#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2658 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002659
Takashi Iwai23c09b02011-08-19 09:05:35 +02002660static const char * const channel_name[4] = {
2661 "Front", "Surround", "CLFE", "Side"
2662};
2663
Takashi Iwai6843ca12011-06-24 11:03:58 +02002664static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2665 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002666{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002667 struct auto_pin_cfg *cfg = &spec->autocfg;
2668
Takashi Iwai6843ca12011-06-24 11:03:58 +02002669 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002670 if (cfg->line_outs == 1 && !spec->multi_ios &&
2671 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002672 return "Master";
2673
2674 switch (cfg->line_out_type) {
2675 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002676 if (cfg->line_outs == 1)
2677 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002678 if (cfg->line_outs == 2)
2679 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002680 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002681 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002682 /* for multi-io case, only the primary out */
2683 if (ch && spec->multi_ios)
2684 break;
2685 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002686 return "Headphone";
2687 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002688 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002689 return "PCM";
2690 break;
2691 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002692 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2693 return "PCM";
2694
2695 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002696}
2697
Takashi Iwai164f73e2012-02-21 11:27:09 +01002698#ifdef CONFIG_SND_HDA_POWER_SAVE
2699/* add the powersave loopback-list entry */
2700static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2701{
2702 struct hda_amp_list *list;
2703
2704 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2705 return;
2706 list = spec->loopback_list + spec->num_loopbacks;
2707 list->nid = mix;
2708 list->dir = HDA_INPUT;
2709 list->idx = idx;
2710 spec->num_loopbacks++;
2711 spec->loopback.amplist = spec->loopback_list;
2712}
2713#else
2714#define add_loopback_list(spec, mix, idx) /* NOP */
2715#endif
2716
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002717/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002718static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002719 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002720 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002721{
Kailang Yangdf694da2005-12-05 19:42:22 +01002722 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002723
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002724 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002725 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2726 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002727 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002728 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002729 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2730 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002731 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002732 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002733 return 0;
2734}
2735
Takashi Iwai05f5f472009-08-25 13:10:18 +02002736static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002737{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002738 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2739 return (pincap & AC_PINCAP_IN) != 0;
2740}
2741
Takashi Iwai1d045db2011-07-07 18:23:21 +02002742/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002743static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002744{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002745 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002746 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002747 hda_nid_t *adc_nids = spec->private_adc_nids;
2748 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2749 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002750 int i, nums = 0;
2751
Takashi Iwai24de1832011-11-07 17:13:39 +01002752 if (spec->shared_mic_hp)
2753 max_nums = 1; /* no multi streams with the shared HP/mic */
2754
Takashi Iwaib7821702011-07-06 15:12:46 +02002755 nid = codec->start_nid;
2756 for (i = 0; i < codec->num_nodes; i++, nid++) {
2757 hda_nid_t src;
2758 const hda_nid_t *list;
2759 unsigned int caps = get_wcaps(codec, nid);
2760 int type = get_wcaps_type(caps);
2761
2762 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2763 continue;
2764 adc_nids[nums] = nid;
2765 cap_nids[nums] = nid;
2766 src = nid;
2767 for (;;) {
2768 int n;
2769 type = get_wcaps_type(get_wcaps(codec, src));
2770 if (type == AC_WID_PIN)
2771 break;
2772 if (type == AC_WID_AUD_SEL) {
2773 cap_nids[nums] = src;
2774 break;
2775 }
2776 n = snd_hda_get_conn_list(codec, src, &list);
2777 if (n > 1) {
2778 cap_nids[nums] = src;
2779 break;
2780 } else if (n != 1)
2781 break;
2782 src = *list;
2783 }
2784 if (++nums >= max_nums)
2785 break;
2786 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002787 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002788 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002789 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002790 return nums;
2791}
2792
Takashi Iwai05f5f472009-08-25 13:10:18 +02002793/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002794static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002795{
2796 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002797 const struct auto_pin_cfg *cfg = &spec->autocfg;
2798 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002799 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002800 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002801 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002802 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002803
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002804 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002805 if (num_adcs < 0)
2806 return 0;
2807
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002808 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002809 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002810 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002811
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002812 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002813 if (!alc_is_input_pin(codec, pin))
2814 continue;
2815
David Henningsson5322bf22011-01-05 11:03:56 +01002816 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002817 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2818 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002819 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002820 type_idx++;
2821 else
2822 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002823 prev_label = label;
2824
Takashi Iwai05f5f472009-08-25 13:10:18 +02002825 if (mixer) {
2826 idx = get_connection_index(codec, mixer, pin);
2827 if (idx >= 0) {
2828 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002829 label, type_idx,
2830 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002831 if (err < 0)
2832 return err;
2833 }
2834 }
2835
Takashi Iwaib7821702011-07-06 15:12:46 +02002836 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002837 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002838 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002839 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002840 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002841 snd_hda_add_imux_item(imux, label, idx, NULL);
2842 break;
2843 }
2844 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002845 }
Takashi Iwai21268962011-07-07 15:01:13 +02002846
2847 spec->num_mux_defs = 1;
2848 spec->input_mux = imux;
2849
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002850 return 0;
2851}
2852
Takashi Iwai24de1832011-11-07 17:13:39 +01002853/* create a shared input with the headphone out */
2854static int alc_auto_create_shared_input(struct hda_codec *codec)
2855{
2856 struct alc_spec *spec = codec->spec;
2857 struct auto_pin_cfg *cfg = &spec->autocfg;
2858 unsigned int defcfg;
2859 hda_nid_t nid;
2860
2861 /* only one internal input pin? */
2862 if (cfg->num_inputs != 1)
2863 return 0;
2864 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2865 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2866 return 0;
2867
2868 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2869 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2870 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2871 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2872 else
2873 return 0; /* both not available */
2874
2875 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2876 return 0; /* no input */
2877
2878 cfg->inputs[1].pin = nid;
2879 cfg->inputs[1].type = AUTO_PIN_MIC;
2880 cfg->num_inputs = 2;
2881 spec->shared_mic_hp = 1;
2882 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2883 return 0;
2884}
2885
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002886static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2887 unsigned int pin_type)
2888{
2889 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2890 pin_type);
2891 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002892 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2893 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002894 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002895}
2896
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002897static int get_pin_type(int line_out_type)
2898{
2899 if (line_out_type == AUTO_PIN_HP_OUT)
2900 return PIN_HP;
2901 else
2902 return PIN_OUT;
2903}
2904
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002905static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002906{
2907 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002908 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002909 int i;
2910
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002911 for (i = 0; i < cfg->num_inputs; i++) {
2912 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002913 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002914 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002915 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002916 snd_hda_codec_write(codec, nid, 0,
2917 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002918 AMP_OUT_MUTE);
2919 }
2920 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002921
2922 /* mute all loopback inputs */
2923 if (spec->mixer_nid) {
2924 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2925 for (i = 0; i < nums; i++)
2926 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2927 AC_VERB_SET_AMP_GAIN_MUTE,
2928 AMP_IN_MUTE(i));
2929 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002930}
2931
Takashi Iwai7085ec12009-10-02 09:03:58 +02002932/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002933static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002934{
Takashi Iwai604401a2011-04-27 15:14:23 +02002935 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002936 int i, num;
2937
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002938 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2939 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002940 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2941 for (i = 0; i < num; i++) {
2942 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2943 return list[i];
2944 }
2945 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002946}
2947
Takashi Iwai604401a2011-04-27 15:14:23 +02002948/* go down to the selector widget before the mixer */
2949static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2950{
2951 hda_nid_t srcs[5];
2952 int num = snd_hda_get_connections(codec, pin, srcs,
2953 ARRAY_SIZE(srcs));
2954 if (num != 1 ||
2955 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2956 return pin;
2957 return srcs[0];
2958}
2959
Takashi Iwai7085ec12009-10-02 09:03:58 +02002960/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002961static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002962 hda_nid_t dac)
2963{
David Henningssoncc1c4522010-11-24 14:17:47 +01002964 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002965 int i, num;
2966
Takashi Iwai604401a2011-04-27 15:14:23 +02002967 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002968 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2969 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002970 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002971 return mix[i];
2972 }
2973 return 0;
2974}
2975
Takashi Iwaice764ab2011-04-27 16:35:23 +02002976/* select the connection from pin to DAC if needed */
2977static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2978 hda_nid_t dac)
2979{
2980 hda_nid_t mix[5];
2981 int i, num;
2982
2983 pin = alc_go_down_to_selector(codec, pin);
2984 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2985 if (num < 2)
2986 return 0;
2987 for (i = 0; i < num; i++) {
2988 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2989 snd_hda_codec_update_cache(codec, pin, 0,
2990 AC_VERB_SET_CONNECT_SEL, i);
2991 return 0;
2992 }
2993 }
2994 return 0;
2995}
2996
Takashi Iwai185d99f2012-02-16 18:39:45 +01002997static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2998{
2999 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01003000 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003001 if (found_in_nid_list(nid, spec->multiout.dac_nids,
3002 ARRAY_SIZE(spec->private_dac_nids)) ||
3003 found_in_nid_list(nid, spec->multiout.hp_out_nid,
3004 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
3005 found_in_nid_list(nid, spec->multiout.extra_out_nid,
3006 ARRAY_SIZE(spec->multiout.extra_out_nid)))
3007 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01003008 for (i = 0; i < spec->multi_ios; i++) {
3009 if (spec->multi_io[i].dac == nid)
3010 return true;
3011 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003012 return false;
3013}
3014
Takashi Iwai7085ec12009-10-02 09:03:58 +02003015/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02003016static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003017{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003018 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003019 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003020
Takashi Iwai604401a2011-04-27 15:14:23 +02003021 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003022 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003023 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003024 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003025 if (!nid)
3026 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003027 if (!alc_is_dac_already_used(codec, nid))
3028 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003029 }
3030 return 0;
3031}
3032
Takashi Iwai07b18f62011-11-10 15:42:54 +01003033/* check whether the DAC is reachable from the pin */
3034static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
3035 hda_nid_t pin, hda_nid_t dac)
3036{
3037 hda_nid_t srcs[5];
3038 int i, num;
3039
Takashi Iwaidc31b582012-02-17 17:27:53 +01003040 if (!pin || !dac)
3041 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003042 pin = alc_go_down_to_selector(codec, pin);
3043 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
3044 for (i = 0; i < num; i++) {
3045 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3046 if (nid == dac)
3047 return true;
3048 }
3049 return false;
3050}
3051
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003052static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3053{
Takashi Iwai140547e2012-02-16 17:23:46 +01003054 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003055 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003056 hda_nid_t nid, nid_found, srcs[5];
3057 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01003058 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01003059 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003060 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003061 nid_found = 0;
3062 for (i = 0; i < num; i++) {
3063 if (srcs[i] == spec->mixer_nid)
3064 continue;
3065 nid = alc_auto_mix_to_dac(codec, srcs[i]);
3066 if (nid && !alc_is_dac_already_used(codec, nid)) {
3067 if (nid_found)
3068 return 0;
3069 nid_found = nid;
3070 }
3071 }
3072 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003073}
3074
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003075/* mark up volume and mute control NIDs: used during badness parsing and
3076 * at creating actual controls
3077 */
3078static inline unsigned int get_ctl_pos(unsigned int data)
3079{
3080 hda_nid_t nid = get_amp_nid_(data);
3081 unsigned int dir;
3082 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3083 return 0;
3084 dir = get_amp_direction_(data);
3085 return (nid << 1) | dir;
3086}
3087
3088#define is_ctl_used(bits, data) \
3089 test_bit(get_ctl_pos(data), bits)
3090#define mark_ctl_usage(bits, data) \
3091 set_bit(get_ctl_pos(data), bits)
3092
3093static void clear_vol_marks(struct hda_codec *codec)
3094{
3095 struct alc_spec *spec = codec->spec;
3096 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3097 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3098}
3099
3100/* badness definition */
3101enum {
3102 /* No primary DAC is found for the main output */
3103 BAD_NO_PRIMARY_DAC = 0x10000,
3104 /* No DAC is found for the extra output */
3105 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003106 /* No possible multi-ios */
3107 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003108 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003109 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003110 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003111 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003112 /* Primary DAC shared with main surrounds */
3113 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003114 /* Primary DAC shared with main CLFE */
3115 BAD_SHARED_CLFE = 0x10,
3116 /* Primary DAC shared with extra surrounds */
3117 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003118 /* Volume widget is shared */
3119 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003120};
3121
3122static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3123 hda_nid_t pin, hda_nid_t dac);
3124static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3125 hda_nid_t pin, hda_nid_t dac);
3126
3127static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3128 hda_nid_t dac)
3129{
3130 struct alc_spec *spec = codec->spec;
3131 hda_nid_t nid;
3132 unsigned int val;
3133 int badness = 0;
3134
3135 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3136 if (nid) {
3137 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3138 if (is_ctl_used(spec->vol_ctls, nid))
3139 badness += BAD_SHARED_VOL;
3140 else
3141 mark_ctl_usage(spec->vol_ctls, val);
3142 } else
3143 badness += BAD_SHARED_VOL;
3144 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3145 if (nid) {
3146 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3147 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3148 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3149 else
3150 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3151 if (is_ctl_used(spec->sw_ctls, val))
3152 badness += BAD_SHARED_VOL;
3153 else
3154 mark_ctl_usage(spec->sw_ctls, val);
3155 } else
3156 badness += BAD_SHARED_VOL;
3157 return badness;
3158}
3159
Takashi Iwaidc31b582012-02-17 17:27:53 +01003160struct badness_table {
3161 int no_primary_dac; /* no primary DAC */
3162 int no_dac; /* no secondary DACs */
3163 int shared_primary; /* primary DAC is shared with main output */
3164 int shared_surr; /* secondary DAC shared with main or primary */
3165 int shared_clfe; /* third DAC shared with main or primary */
3166 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3167};
3168
3169static struct badness_table main_out_badness = {
3170 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3171 .no_dac = BAD_NO_DAC,
3172 .shared_primary = BAD_NO_PRIMARY_DAC,
3173 .shared_surr = BAD_SHARED_SURROUND,
3174 .shared_clfe = BAD_SHARED_CLFE,
3175 .shared_surr_main = BAD_SHARED_SURROUND,
3176};
3177
3178static struct badness_table extra_out_badness = {
3179 .no_primary_dac = BAD_NO_DAC,
3180 .no_dac = BAD_NO_DAC,
3181 .shared_primary = BAD_NO_EXTRA_DAC,
3182 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3183 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3184 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3185};
3186
3187/* try to assign DACs to pins and return the resultant badness */
3188static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3189 const hda_nid_t *pins, hda_nid_t *dacs,
3190 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003191{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003192 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003193 struct auto_pin_cfg *cfg = &spec->autocfg;
3194 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003195 int badness = 0;
3196 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003197
Takashi Iwai185d99f2012-02-16 18:39:45 +01003198 if (!num_outs)
3199 return 0;
3200
Takashi Iwaidc31b582012-02-17 17:27:53 +01003201 for (i = 0; i < num_outs; i++) {
3202 hda_nid_t pin = pins[i];
3203 if (!dacs[i])
3204 dacs[i] = alc_auto_look_for_dac(codec, pin);
3205 if (!dacs[i] && !i) {
3206 for (j = 1; j < num_outs; j++) {
3207 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3208 dacs[0] = dacs[j];
3209 dacs[j] = 0;
3210 break;
3211 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003212 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003213 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003214 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003215 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003216 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003217 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003218 else if (cfg->line_outs > i &&
3219 alc_auto_is_dac_reachable(codec, pin,
3220 spec->private_dac_nids[i]))
3221 dac = spec->private_dac_nids[i];
3222 if (dac) {
3223 if (!i)
3224 badness += bad->shared_primary;
3225 else if (i == 1)
3226 badness += bad->shared_surr;
3227 else
3228 badness += bad->shared_clfe;
3229 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003230 spec->private_dac_nids[0])) {
3231 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003232 badness += bad->shared_surr_main;
3233 } else if (!i)
3234 badness += bad->no_primary_dac;
3235 else
3236 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003237 }
3238 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003239 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003240 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003241
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003242 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003243}
3244
3245static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003246 hda_nid_t reference_pin,
3247 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003248
Takashi Iwai185d99f2012-02-16 18:39:45 +01003249static bool alc_map_singles(struct hda_codec *codec, int outs,
3250 const hda_nid_t *pins, hda_nid_t *dacs)
3251{
3252 int i;
3253 bool found = false;
3254 for (i = 0; i < outs; i++) {
3255 if (dacs[i])
3256 continue;
3257 dacs[i] = get_dac_if_single(codec, pins[i]);
3258 if (dacs[i])
3259 found = true;
3260 }
3261 return found;
3262}
3263
Takashi Iwai7085ec12009-10-02 09:03:58 +02003264/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003265static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003266 bool fill_hardwired,
3267 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003268{
3269 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003270 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003271 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003272
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003273 /* set num_dacs once to full for alc_auto_look_for_dac() */
3274 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003275 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003276 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3277 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3278 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003279 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003280 clear_vol_marks(codec);
3281 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003282
3283 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003284 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003285 bool mapped;
3286 do {
3287 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003288 cfg->line_out_pins,
3289 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003290 mapped |= alc_map_singles(codec, cfg->hp_outs,
3291 cfg->hp_pins,
3292 spec->multiout.hp_out_nid);
3293 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3294 cfg->speaker_pins,
3295 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003296 if (fill_mio_first && cfg->line_outs == 1 &&
3297 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3298 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3299 if (!err)
3300 mapped = true;
3301 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003302 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003303 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003304
Takashi Iwaidc31b582012-02-17 17:27:53 +01003305 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3306 spec->private_dac_nids,
3307 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003308
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003309 /* re-count num_dacs and squash invalid entries */
3310 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003311 for (i = 0; i < cfg->line_outs; i++) {
3312 if (spec->private_dac_nids[i])
3313 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003314 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003315 memmove(spec->private_dac_nids + i,
3316 spec->private_dac_nids + i + 1,
3317 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003318 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3319 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003320 }
3321
Takashi Iwai276dd702012-02-17 16:17:03 +01003322 if (fill_mio_first &&
3323 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003324 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003325 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003326 if (err < 0)
3327 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003328 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003329 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003330
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003331 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003332 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3333 spec->multiout.hp_out_nid,
3334 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003335 if (err < 0)
3336 return err;
3337 badness += err;
3338 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003339 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003340 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3341 cfg->speaker_pins,
3342 spec->multiout.extra_out_nid,
3343 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003344 if (err < 0)
3345 return err;
3346 badness += err;
3347 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003348 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3349 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003350 if (err < 0)
3351 return err;
3352 badness += err;
3353 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003354 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3355 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003356 int offset = 0;
3357 if (cfg->line_outs >= 3)
3358 offset = 1;
3359 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3360 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003361 if (err < 0)
3362 return err;
3363 badness += err;
3364 }
3365
3366 if (spec->multi_ios == 2) {
3367 for (i = 0; i < 2; i++)
3368 spec->private_dac_nids[spec->multiout.num_dacs++] =
3369 spec->multi_io[i].dac;
3370 spec->ext_channel_count = 2;
3371 } else if (spec->multi_ios) {
3372 spec->multi_ios = 0;
3373 badness += BAD_MULTI_IO;
3374 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003375
3376 return badness;
3377}
3378
3379#define DEBUG_BADNESS
3380
3381#ifdef DEBUG_BADNESS
3382#define debug_badness snd_printdd
3383#else
3384#define debug_badness(...)
3385#endif
3386
3387static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3388{
3389 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3390 cfg->line_out_pins[0], cfg->line_out_pins[1],
3391 cfg->line_out_pins[2], cfg->line_out_pins[2],
3392 spec->multiout.dac_nids[0],
3393 spec->multiout.dac_nids[1],
3394 spec->multiout.dac_nids[2],
3395 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003396 if (spec->multi_ios > 0)
3397 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3398 spec->multi_ios,
3399 spec->multi_io[0].pin, spec->multi_io[1].pin,
3400 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003401 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3402 cfg->hp_pins[0], cfg->hp_pins[1],
3403 cfg->hp_pins[2], cfg->hp_pins[2],
3404 spec->multiout.hp_out_nid[0],
3405 spec->multiout.hp_out_nid[1],
3406 spec->multiout.hp_out_nid[2],
3407 spec->multiout.hp_out_nid[3]);
3408 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3409 cfg->speaker_pins[0], cfg->speaker_pins[1],
3410 cfg->speaker_pins[2], cfg->speaker_pins[3],
3411 spec->multiout.extra_out_nid[0],
3412 spec->multiout.extra_out_nid[1],
3413 spec->multiout.extra_out_nid[2],
3414 spec->multiout.extra_out_nid[3]);
3415}
3416
3417static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3418{
3419 struct alc_spec *spec = codec->spec;
3420 struct auto_pin_cfg *cfg = &spec->autocfg;
3421 struct auto_pin_cfg *best_cfg;
3422 int best_badness = INT_MAX;
3423 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003424 bool fill_hardwired = true, fill_mio_first = true;
3425 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003426 bool hp_spk_swapped = false;
3427
3428 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3429 if (!best_cfg)
3430 return -ENOMEM;
3431 *best_cfg = *cfg;
3432
3433 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003434 badness = fill_and_eval_dacs(codec, fill_hardwired,
3435 fill_mio_first);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003436 if (badness < 0)
3437 return badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003438 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3439 cfg->line_out_type, fill_hardwired, fill_mio_first,
3440 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003441 debug_show_configs(spec, cfg);
3442 if (badness < best_badness) {
3443 best_badness = badness;
3444 *best_cfg = *cfg;
3445 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003446 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003447 }
3448 if (!badness)
3449 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003450 fill_mio_first = !fill_mio_first;
3451 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003452 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003453 fill_hardwired = !fill_hardwired;
3454 if (!fill_hardwired)
3455 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003456 if (hp_spk_swapped)
3457 break;
3458 hp_spk_swapped = true;
3459 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003460 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3461 cfg->hp_outs = cfg->line_outs;
3462 memcpy(cfg->hp_pins, cfg->line_out_pins,
3463 sizeof(cfg->hp_pins));
3464 cfg->line_outs = cfg->speaker_outs;
3465 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3466 sizeof(cfg->speaker_pins));
3467 cfg->speaker_outs = 0;
3468 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3469 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003470 fill_hardwired = true;
3471 continue;
3472 }
3473 if (cfg->hp_outs > 0 &&
3474 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3475 cfg->speaker_outs = cfg->line_outs;
3476 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3477 sizeof(cfg->speaker_pins));
3478 cfg->line_outs = cfg->hp_outs;
3479 memcpy(cfg->line_out_pins, cfg->hp_pins,
3480 sizeof(cfg->hp_pins));
3481 cfg->hp_outs = 0;
3482 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3483 cfg->line_out_type = AUTO_PIN_HP_OUT;
3484 fill_hardwired = true;
3485 continue;
3486 }
3487 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003488 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003489
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003490 if (badness) {
3491 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003492 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003493 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003494 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3495 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003496 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003497
David Henningssonfde48a12011-12-09 18:27:42 +08003498 if (cfg->line_out_pins[0])
3499 spec->vmaster_nid =
3500 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3501 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003502
3503 /* clear the bitmap flags for creating controls */
3504 clear_vol_marks(codec);
3505 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003506 return 0;
3507}
3508
Takashi Iwai343a04b2011-07-06 14:28:39 +02003509static int alc_auto_add_vol_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)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003512{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003513 struct alc_spec *spec = codec->spec;
3514 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003515 if (!nid)
3516 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003517 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3518 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3519 return 0;
3520 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003521 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003522 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003523}
3524
Takashi Iwaie29d3772011-11-14 17:13:23 +01003525static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3526 const char *pfx, int cidx,
3527 hda_nid_t nid)
3528{
3529 int chs = 1;
3530 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3531 chs = 3;
3532 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3533}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003534
3535/* create a mute-switch for the given mixer widget;
3536 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3537 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003538static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003539 const char *pfx, int cidx,
3540 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003541{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003542 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003543 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003544 int type;
3545 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003546 if (!nid)
3547 return 0;
3548 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3549 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3550 type = ALC_CTL_WIDGET_MUTE;
3551 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3552 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003553 type = ALC_CTL_WIDGET_MUTE;
3554 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3555 } else {
3556 type = ALC_CTL_BIND_MUTE;
3557 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3558 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003559 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3560 return 0;
3561 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003562 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003563}
3564
Takashi Iwaie29d3772011-11-14 17:13:23 +01003565static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3566 int cidx, hda_nid_t nid)
3567{
3568 int chs = 1;
3569 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3570 chs = 3;
3571 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3572}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003573
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003574static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3575 hda_nid_t pin, hda_nid_t dac)
3576{
3577 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3578 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3579 return pin;
3580 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3581 return mix;
3582 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3583 return dac;
3584 return 0;
3585}
3586
3587static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3588 hda_nid_t pin, hda_nid_t dac)
3589{
3590 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3591 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3592 return dac;
3593 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3594 return mix;
3595 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3596 return pin;
3597 return 0;
3598}
3599
Takashi Iwai7085ec12009-10-02 09:03:58 +02003600/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003601static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003602 const struct auto_pin_cfg *cfg)
3603{
3604 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003605 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003606
Takashi Iwaice764ab2011-04-27 16:35:23 +02003607 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003608 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003609 noutputs += spec->multi_ios;
3610
3611 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003612 const char *name;
3613 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003614 hda_nid_t dac, pin;
3615 hda_nid_t sw, vol;
3616
3617 dac = spec->multiout.dac_nids[i];
3618 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003619 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003620 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003621 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003622 index = 0;
3623 name = channel_name[i];
3624 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003625 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003626 name = alc_get_line_out_pfx(spec, i, true, &index);
3627 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003628
3629 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3630 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003631 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003632 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003633 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003634 if (err < 0)
3635 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003636 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003637 if (err < 0)
3638 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003639 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003640 if (err < 0)
3641 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003642 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003643 if (err < 0)
3644 return err;
3645 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003646 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003647 if (err < 0)
3648 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003649 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003650 if (err < 0)
3651 return err;
3652 }
3653 }
3654 return 0;
3655}
3656
Takashi Iwai343a04b2011-07-06 14:28:39 +02003657static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003658 hda_nid_t dac, const char *pfx,
3659 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003660{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003661 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003662 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003663 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003664
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003665 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003666 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003667 /* the corresponding DAC is already occupied */
3668 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3669 return 0; /* no way */
3670 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003671 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3672 if (is_ctl_used(spec->sw_ctls, val))
3673 return 0; /* already created */
3674 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003675 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003676 }
3677
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003678 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3679 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003680 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003681 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003682 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003683 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003684 if (err < 0)
3685 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003686 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003687}
3688
Takashi Iwai23c09b02011-08-19 09:05:35 +02003689static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3690 unsigned int nums,
3691 struct hda_ctl_ops *ops)
3692{
3693 struct alc_spec *spec = codec->spec;
3694 struct hda_bind_ctls **ctlp, *ctl;
3695 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3696 ctlp = snd_array_new(&spec->bind_ctls);
3697 if (!ctlp)
3698 return NULL;
3699 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3700 *ctlp = ctl;
3701 if (ctl)
3702 ctl->ops = ops;
3703 return ctl;
3704}
3705
3706/* add playback controls for speaker and HP outputs */
3707static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3708 const hda_nid_t *pins,
3709 const hda_nid_t *dacs,
3710 const char *pfx)
3711{
3712 struct alc_spec *spec = codec->spec;
3713 struct hda_bind_ctls *ctl;
3714 char name[32];
3715 int i, n, err;
3716
3717 if (!num_pins || !pins[0])
3718 return 0;
3719
Takashi Iwai527e4d72011-10-27 16:33:27 +02003720 if (num_pins == 1) {
3721 hda_nid_t dac = *dacs;
3722 if (!dac)
3723 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003724 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003725 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003726
Takashi Iwai23c09b02011-08-19 09:05:35 +02003727 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003728 hda_nid_t dac;
3729 if (dacs[num_pins - 1])
3730 dac = dacs[i]; /* with individual volumes */
3731 else
3732 dac = 0;
3733 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3734 err = alc_auto_create_extra_out(codec, pins[i], dac,
3735 "Bass Speaker", 0);
3736 } else if (num_pins >= 3) {
3737 snprintf(name, sizeof(name), "%s %s",
3738 pfx, channel_name[i]);
3739 err = alc_auto_create_extra_out(codec, pins[i], dac,
3740 name, 0);
3741 } else {
3742 err = alc_auto_create_extra_out(codec, pins[i], dac,
3743 pfx, i);
3744 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003745 if (err < 0)
3746 return err;
3747 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003748 if (dacs[num_pins - 1])
3749 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003750
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003751 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003752 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3753 if (!ctl)
3754 return -ENOMEM;
3755 n = 0;
3756 for (i = 0; i < num_pins; i++) {
3757 hda_nid_t vol;
3758 if (!pins[i] || !dacs[i])
3759 continue;
3760 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3761 if (vol)
3762 ctl->values[n++] =
3763 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3764 }
3765 if (n) {
3766 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3767 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3768 if (err < 0)
3769 return err;
3770 }
3771 return 0;
3772}
3773
Takashi Iwai343a04b2011-07-06 14:28:39 +02003774static int alc_auto_create_hp_out(struct hda_codec *codec)
3775{
3776 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003777 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3778 spec->autocfg.hp_pins,
3779 spec->multiout.hp_out_nid,
3780 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003781}
3782
3783static int alc_auto_create_speaker_out(struct hda_codec *codec)
3784{
3785 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003786 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3787 spec->autocfg.speaker_pins,
3788 spec->multiout.extra_out_nid,
3789 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003790}
3791
Takashi Iwai343a04b2011-07-06 14:28:39 +02003792static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003793 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003794 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003795{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003796 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003797 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003798 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003799
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003800 alc_set_pin_output(codec, pin, pin_type);
3801 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003802 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003803 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003804 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003805 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003806 mix = srcs[i];
3807 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003808 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003809 if (!mix)
3810 return;
3811
3812 /* need the manual connection? */
3813 if (num > 1)
3814 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3815 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003816 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3817 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003818 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003819 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003820 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003821 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003822 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003823 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3824 if (nid)
3825 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3826 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003827
3828 /* unmute DAC if it's not assigned to a mixer */
3829 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3830 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3831 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3832 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003833}
3834
Takashi Iwai343a04b2011-07-06 14:28:39 +02003835static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003836{
3837 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003838 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003839 int i;
3840
3841 for (i = 0; i <= HDA_SIDE; i++) {
3842 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3843 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003844 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003845 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003846 }
3847}
3848
Takashi Iwai343a04b2011-07-06 14:28:39 +02003849static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003850{
3851 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003852 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003853 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003854
David Henningsson636030e2011-10-12 19:26:03 +02003855 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003856 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3857 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003858 pin = spec->autocfg.hp_pins[i];
3859 if (!pin)
3860 break;
3861 dac = spec->multiout.hp_out_nid[i];
3862 if (!dac) {
3863 if (i > 0 && spec->multiout.hp_out_nid[0])
3864 dac = spec->multiout.hp_out_nid[0];
3865 else
3866 dac = spec->multiout.dac_nids[0];
3867 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003868 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3869 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003870 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003871 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3872 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003873 pin = spec->autocfg.speaker_pins[i];
3874 if (!pin)
3875 break;
3876 dac = spec->multiout.extra_out_nid[i];
3877 if (!dac) {
3878 if (i > 0 && spec->multiout.extra_out_nid[0])
3879 dac = spec->multiout.extra_out_nid[0];
3880 else
3881 dac = spec->multiout.dac_nids[0];
3882 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003883 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3884 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003885}
3886
Takashi Iwai276dd702012-02-17 16:17:03 +01003887/* check whether the given pin can be a multi-io pin */
3888static bool can_be_multiio_pin(struct hda_codec *codec,
3889 unsigned int location, hda_nid_t nid)
3890{
3891 unsigned int defcfg, caps;
3892
3893 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3894 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3895 return false;
3896 if (location && get_defcfg_location(defcfg) != location)
3897 return false;
3898 caps = snd_hda_query_pin_caps(codec, nid);
3899 if (!(caps & AC_PINCAP_OUT))
3900 return false;
3901 return true;
3902}
3903
Takashi Iwaice764ab2011-04-27 16:35:23 +02003904/*
3905 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003906 *
3907 * When hardwired is set, try to fill ony hardwired pins, and returns
3908 * zero if any pins are filled, non-zero if nothing found.
3909 * When hardwired is off, try to fill possible input pins, and returns
3910 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003911 */
3912static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003913 hda_nid_t reference_pin,
3914 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003915{
3916 struct alc_spec *spec = codec->spec;
3917 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003918 int type, i, j, dacs, num_pins, old_pins;
3919 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3920 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003921 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003922
Takashi Iwai276dd702012-02-17 16:17:03 +01003923 old_pins = spec->multi_ios;
3924 if (old_pins >= 2)
3925 goto end_fill;
3926
3927 num_pins = 0;
3928 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3929 for (i = 0; i < cfg->num_inputs; i++) {
3930 if (cfg->inputs[i].type != type)
3931 continue;
3932 if (can_be_multiio_pin(codec, location,
3933 cfg->inputs[i].pin))
3934 num_pins++;
3935 }
3936 }
3937 if (num_pins < 2)
3938 goto end_fill;
3939
Takashi Iwai07b18f62011-11-10 15:42:54 +01003940 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003941 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3942 for (i = 0; i < cfg->num_inputs; i++) {
3943 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003944 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003945
Takashi Iwaice764ab2011-04-27 16:35:23 +02003946 if (cfg->inputs[i].type != type)
3947 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003948 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003949 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003950 for (j = 0; j < spec->multi_ios; j++) {
3951 if (nid == spec->multi_io[j].pin)
3952 break;
3953 }
3954 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003955 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003956
3957 if (offset && offset + spec->multi_ios < dacs) {
3958 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003959 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3960 dac = 0;
3961 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003962 if (hardwired)
3963 dac = get_dac_if_single(codec, nid);
3964 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003965 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003966 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003967 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003968 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003969 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003970 spec->multi_io[spec->multi_ios].pin = nid;
3971 spec->multi_io[spec->multi_ios].dac = dac;
3972 spec->multi_ios++;
3973 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003974 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003975 }
3976 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003977 end_fill:
3978 if (badness)
3979 badness = BAD_MULTI_IO;
3980 if (old_pins == spec->multi_ios) {
3981 if (hardwired)
3982 return 1; /* nothing found */
3983 else
3984 return badness; /* no badness if nothing found */
3985 }
3986 if (!hardwired && spec->multi_ios < 2) {
3987 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003988 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003989 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003990
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003991 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003992}
3993
3994static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3995 struct snd_ctl_elem_info *uinfo)
3996{
3997 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3998 struct alc_spec *spec = codec->spec;
3999
4000 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4001 uinfo->count = 1;
4002 uinfo->value.enumerated.items = spec->multi_ios + 1;
4003 if (uinfo->value.enumerated.item > spec->multi_ios)
4004 uinfo->value.enumerated.item = spec->multi_ios;
4005 sprintf(uinfo->value.enumerated.name, "%dch",
4006 (uinfo->value.enumerated.item + 1) * 2);
4007 return 0;
4008}
4009
4010static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4011 struct snd_ctl_elem_value *ucontrol)
4012{
4013 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4014 struct alc_spec *spec = codec->spec;
4015 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4016 return 0;
4017}
4018
4019static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4020{
4021 struct alc_spec *spec = codec->spec;
4022 hda_nid_t nid = spec->multi_io[idx].pin;
4023
4024 if (!spec->multi_io[idx].ctl_in)
4025 spec->multi_io[idx].ctl_in =
4026 snd_hda_codec_read(codec, nid, 0,
4027 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4028 if (output) {
4029 snd_hda_codec_update_cache(codec, nid, 0,
4030 AC_VERB_SET_PIN_WIDGET_CONTROL,
4031 PIN_OUT);
4032 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4033 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4034 HDA_AMP_MUTE, 0);
4035 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
4036 } else {
4037 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4038 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4039 HDA_AMP_MUTE, HDA_AMP_MUTE);
4040 snd_hda_codec_update_cache(codec, nid, 0,
4041 AC_VERB_SET_PIN_WIDGET_CONTROL,
4042 spec->multi_io[idx].ctl_in);
4043 }
4044 return 0;
4045}
4046
4047static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4048 struct snd_ctl_elem_value *ucontrol)
4049{
4050 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4051 struct alc_spec *spec = codec->spec;
4052 int i, ch;
4053
4054 ch = ucontrol->value.enumerated.item[0];
4055 if (ch < 0 || ch > spec->multi_ios)
4056 return -EINVAL;
4057 if (ch == (spec->ext_channel_count - 1) / 2)
4058 return 0;
4059 spec->ext_channel_count = (ch + 1) * 2;
4060 for (i = 0; i < spec->multi_ios; i++)
4061 alc_set_multi_io(codec, i, i < ch);
4062 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004063 if (spec->need_dac_fix && !spec->const_channel_count)
4064 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004065 return 1;
4066}
4067
Takashi Iwaia9111322011-05-02 11:30:18 +02004068static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004069 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4070 .name = "Channel Mode",
4071 .info = alc_auto_ch_mode_info,
4072 .get = alc_auto_ch_mode_get,
4073 .put = alc_auto_ch_mode_put,
4074};
4075
Takashi Iwai23c09b02011-08-19 09:05:35 +02004076static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004077{
4078 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004079
Takashi Iwaic2674682011-08-24 17:57:44 +02004080 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004081 struct snd_kcontrol_new *knew;
4082
4083 knew = alc_kcontrol_new(spec);
4084 if (!knew)
4085 return -ENOMEM;
4086 *knew = alc_auto_channel_mode_enum;
4087 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4088 if (!knew->name)
4089 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004090 }
4091 return 0;
4092}
4093
Takashi Iwai1d045db2011-07-07 18:23:21 +02004094/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4095 * active input pins
4096 */
4097static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4098{
4099 struct alc_spec *spec = codec->spec;
4100 const struct hda_input_mux *imux;
4101 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4102 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4103 int i, n, nums;
4104
4105 imux = spec->input_mux;
4106 if (!imux)
4107 return;
4108 if (spec->dyn_adc_switch)
4109 return;
4110
4111 nums = 0;
4112 for (n = 0; n < spec->num_adc_nids; n++) {
4113 hda_nid_t cap = spec->private_capsrc_nids[n];
4114 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4115 for (i = 0; i < imux->num_items; i++) {
4116 hda_nid_t pin = spec->imux_pins[i];
4117 if (pin) {
4118 if (get_connection_index(codec, cap, pin) < 0)
4119 break;
4120 } else if (num_conns <= imux->items[i].index)
4121 break;
4122 }
4123 if (i >= imux->num_items) {
4124 adc_nids[nums] = spec->private_adc_nids[n];
4125 capsrc_nids[nums++] = cap;
4126 }
4127 }
4128 if (!nums) {
4129 /* check whether ADC-switch is possible */
4130 if (!alc_check_dyn_adc_switch(codec)) {
4131 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4132 " using fallback 0x%x\n",
4133 codec->chip_name, spec->private_adc_nids[0]);
4134 spec->num_adc_nids = 1;
4135 spec->auto_mic = 0;
4136 return;
4137 }
4138 } else if (nums != spec->num_adc_nids) {
4139 memcpy(spec->private_adc_nids, adc_nids,
4140 nums * sizeof(hda_nid_t));
4141 memcpy(spec->private_capsrc_nids, capsrc_nids,
4142 nums * sizeof(hda_nid_t));
4143 spec->num_adc_nids = nums;
4144 }
4145
4146 if (spec->auto_mic)
4147 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4148 else if (spec->input_mux->num_items == 1)
4149 spec->num_adc_nids = 1; /* reduce to a single ADC */
4150}
4151
4152/*
4153 * initialize ADC paths
4154 */
4155static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4156{
4157 struct alc_spec *spec = codec->spec;
4158 hda_nid_t nid;
4159
4160 nid = spec->adc_nids[adc_idx];
4161 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004162 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004163 snd_hda_codec_write(codec, nid, 0,
4164 AC_VERB_SET_AMP_GAIN_MUTE,
4165 AMP_IN_MUTE(0));
4166 return;
4167 }
4168 if (!spec->capsrc_nids)
4169 return;
4170 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004171 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004172 snd_hda_codec_write(codec, nid, 0,
4173 AC_VERB_SET_AMP_GAIN_MUTE,
4174 AMP_OUT_MUTE);
4175}
4176
4177static void alc_auto_init_input_src(struct hda_codec *codec)
4178{
4179 struct alc_spec *spec = codec->spec;
4180 int c, nums;
4181
4182 for (c = 0; c < spec->num_adc_nids; c++)
4183 alc_auto_init_adc(codec, c);
4184 if (spec->dyn_adc_switch)
4185 nums = 1;
4186 else
4187 nums = spec->num_adc_nids;
4188 for (c = 0; c < nums; c++)
4189 alc_mux_select(codec, 0, spec->cur_mux[c], true);
4190}
4191
4192/* add mic boosts if needed */
4193static int alc_auto_add_mic_boost(struct hda_codec *codec)
4194{
4195 struct alc_spec *spec = codec->spec;
4196 struct auto_pin_cfg *cfg = &spec->autocfg;
4197 int i, err;
4198 int type_idx = 0;
4199 hda_nid_t nid;
4200 const char *prev_label = NULL;
4201
4202 for (i = 0; i < cfg->num_inputs; i++) {
4203 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4204 break;
4205 nid = cfg->inputs[i].pin;
4206 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4207 const char *label;
4208 char boost_label[32];
4209
4210 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004211 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4212 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004213 if (prev_label && !strcmp(label, prev_label))
4214 type_idx++;
4215 else
4216 type_idx = 0;
4217 prev_label = label;
4218
4219 snprintf(boost_label, sizeof(boost_label),
4220 "%s Boost Volume", label);
4221 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4222 boost_label, type_idx,
4223 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4224 if (err < 0)
4225 return err;
4226 }
4227 }
4228 return 0;
4229}
4230
4231/* select or unmute the given capsrc route */
4232static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4233 int idx)
4234{
4235 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4236 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4237 HDA_AMP_MUTE, 0);
4238 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4239 snd_hda_codec_write_cache(codec, cap, 0,
4240 AC_VERB_SET_CONNECT_SEL, idx);
4241 }
4242}
4243
4244/* set the default connection to that pin */
4245static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4246{
4247 struct alc_spec *spec = codec->spec;
4248 int i;
4249
4250 if (!pin)
4251 return 0;
4252 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004253 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004254 int idx;
4255
4256 idx = get_connection_index(codec, cap, pin);
4257 if (idx < 0)
4258 continue;
4259 select_or_unmute_capsrc(codec, cap, idx);
4260 return i; /* return the found index */
4261 }
4262 return -1; /* not found */
4263}
4264
4265/* initialize some special cases for input sources */
4266static void alc_init_special_input_src(struct hda_codec *codec)
4267{
4268 struct alc_spec *spec = codec->spec;
4269 int i;
4270
4271 for (i = 0; i < spec->autocfg.num_inputs; i++)
4272 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4273}
4274
4275/* assign appropriate capture mixers */
4276static void set_capture_mixer(struct hda_codec *codec)
4277{
4278 struct alc_spec *spec = codec->spec;
4279 static const struct snd_kcontrol_new *caps[2][3] = {
4280 { alc_capture_mixer_nosrc1,
4281 alc_capture_mixer_nosrc2,
4282 alc_capture_mixer_nosrc3 },
4283 { alc_capture_mixer1,
4284 alc_capture_mixer2,
4285 alc_capture_mixer3 },
4286 };
4287
4288 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004289 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004290 if (!spec->capsrc_nids)
4291 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004292 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004293 return; /* no volume in capsrc, too */
4294 spec->vol_in_capsrc = 1;
4295 }
4296
4297 if (spec->num_adc_nids > 0) {
4298 int mux = 0;
4299 int num_adcs = 0;
4300
4301 if (spec->input_mux && spec->input_mux->num_items > 1)
4302 mux = 1;
4303 if (spec->auto_mic) {
4304 num_adcs = 1;
4305 mux = 0;
4306 } else if (spec->dyn_adc_switch)
4307 num_adcs = 1;
4308 if (!num_adcs) {
4309 if (spec->num_adc_nids > 3)
4310 spec->num_adc_nids = 3;
4311 else if (!spec->num_adc_nids)
4312 return;
4313 num_adcs = spec->num_adc_nids;
4314 }
4315 spec->cap_mixer = caps[mux][num_adcs - 1];
4316 }
4317}
4318
4319/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004320 * standard auto-parser initializations
4321 */
4322static void alc_auto_init_std(struct hda_codec *codec)
4323{
4324 struct alc_spec *spec = codec->spec;
4325 alc_auto_init_multi_out(codec);
4326 alc_auto_init_extra_out(codec);
4327 alc_auto_init_analog_input(codec);
4328 alc_auto_init_input_src(codec);
4329 alc_auto_init_digital(codec);
4330 if (spec->unsol_event)
4331 alc_inithook(codec);
4332}
4333
4334/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004335 * Digital-beep handlers
4336 */
4337#ifdef CONFIG_SND_HDA_INPUT_BEEP
4338#define set_beep_amp(spec, nid, idx, dir) \
4339 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4340
4341static const struct snd_pci_quirk beep_white_list[] = {
4342 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4343 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4344 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4345 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4346 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4347 {}
4348};
4349
4350static inline int has_cdefine_beep(struct hda_codec *codec)
4351{
4352 struct alc_spec *spec = codec->spec;
4353 const struct snd_pci_quirk *q;
4354 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4355 if (q)
4356 return q->value;
4357 return spec->cdefine.enable_pcbeep;
4358}
4359#else
4360#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4361#define has_cdefine_beep(codec) 0
4362#endif
4363
4364/* parse the BIOS configuration and set up the alc_spec */
4365/* return 1 if successful, 0 if the proper config is not found,
4366 * or a negative error code
4367 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004368static int alc_parse_auto_config(struct hda_codec *codec,
4369 const hda_nid_t *ignore_nids,
4370 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004371{
4372 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004373 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004374 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004375
Takashi Iwai53c334a2011-08-23 18:27:14 +02004376 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4377 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004378 if (err < 0)
4379 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004380 if (!cfg->line_outs) {
4381 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004382 spec->multiout.max_channels = 2;
4383 spec->no_analog = 1;
4384 goto dig_only;
4385 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004386 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004387 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004388
Takashi Iwai06503672011-10-06 08:27:19 +02004389 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4390 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004391 /* use HP as primary out */
4392 cfg->speaker_outs = cfg->line_outs;
4393 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4394 sizeof(cfg->speaker_pins));
4395 cfg->line_outs = cfg->hp_outs;
4396 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4397 cfg->hp_outs = 0;
4398 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4399 cfg->line_out_type = AUTO_PIN_HP_OUT;
4400 }
4401
Takashi Iwai1d045db2011-07-07 18:23:21 +02004402 err = alc_auto_fill_dac_nids(codec);
4403 if (err < 0)
4404 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004405 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004406 if (err < 0)
4407 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004408 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004409 if (err < 0)
4410 return err;
4411 err = alc_auto_create_hp_out(codec);
4412 if (err < 0)
4413 return err;
4414 err = alc_auto_create_speaker_out(codec);
4415 if (err < 0)
4416 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004417 err = alc_auto_create_shared_input(codec);
4418 if (err < 0)
4419 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004420 err = alc_auto_create_input_ctls(codec);
4421 if (err < 0)
4422 return err;
4423
4424 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4425
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004426 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004427 alc_auto_parse_digital(codec);
4428
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004429 if (!spec->no_analog)
4430 alc_remove_invalid_adc_nids(codec);
4431
4432 if (ssid_nids)
4433 alc_ssid_check(codec, ssid_nids);
4434
4435 if (!spec->no_analog) {
4436 alc_auto_check_switches(codec);
4437 err = alc_auto_add_mic_boost(codec);
4438 if (err < 0)
4439 return err;
4440 }
4441
Takashi Iwai1d045db2011-07-07 18:23:21 +02004442 if (spec->kctls.list)
4443 add_mixer(spec, spec->kctls.list);
4444
Takashi Iwai1d045db2011-07-07 18:23:21 +02004445 return 1;
4446}
4447
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004448static int alc880_parse_auto_config(struct hda_codec *codec)
4449{
4450 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4451 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4452 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4453}
4454
Takashi Iwai1d045db2011-07-07 18:23:21 +02004455/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004456 * ALC880 fix-ups
4457 */
4458enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004459 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004460 ALC880_FIXUP_GPIO2,
4461 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004462 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004463 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004464 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004465 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004466 ALC880_FIXUP_VOL_KNOB,
4467 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004468 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004469 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004470 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004471 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004472 ALC880_FIXUP_3ST_BASE,
4473 ALC880_FIXUP_3ST,
4474 ALC880_FIXUP_3ST_DIG,
4475 ALC880_FIXUP_5ST_BASE,
4476 ALC880_FIXUP_5ST,
4477 ALC880_FIXUP_5ST_DIG,
4478 ALC880_FIXUP_6ST_BASE,
4479 ALC880_FIXUP_6ST,
4480 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004481};
4482
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004483/* enable the volume-knob widget support on NID 0x21 */
4484static void alc880_fixup_vol_knob(struct hda_codec *codec,
4485 const struct alc_fixup *fix, int action)
4486{
4487 if (action == ALC_FIXUP_ACT_PROBE)
4488 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4489}
4490
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004491static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004492 [ALC880_FIXUP_GPIO1] = {
4493 .type = ALC_FIXUP_VERBS,
4494 .v.verbs = alc_gpio1_init_verbs,
4495 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004496 [ALC880_FIXUP_GPIO2] = {
4497 .type = ALC_FIXUP_VERBS,
4498 .v.verbs = alc_gpio2_init_verbs,
4499 },
4500 [ALC880_FIXUP_MEDION_RIM] = {
4501 .type = ALC_FIXUP_VERBS,
4502 .v.verbs = (const struct hda_verb[]) {
4503 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4504 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4505 { }
4506 },
4507 .chained = true,
4508 .chain_id = ALC880_FIXUP_GPIO2,
4509 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004510 [ALC880_FIXUP_LG] = {
4511 .type = ALC_FIXUP_PINS,
4512 .v.pins = (const struct alc_pincfg[]) {
4513 /* disable bogus unused pins */
4514 { 0x16, 0x411111f0 },
4515 { 0x18, 0x411111f0 },
4516 { 0x1a, 0x411111f0 },
4517 { }
4518 }
4519 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004520 [ALC880_FIXUP_W810] = {
4521 .type = ALC_FIXUP_PINS,
4522 .v.pins = (const struct alc_pincfg[]) {
4523 /* disable bogus unused pins */
4524 { 0x17, 0x411111f0 },
4525 { }
4526 },
4527 .chained = true,
4528 .chain_id = ALC880_FIXUP_GPIO2,
4529 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004530 [ALC880_FIXUP_EAPD_COEF] = {
4531 .type = ALC_FIXUP_VERBS,
4532 .v.verbs = (const struct hda_verb[]) {
4533 /* change to EAPD mode */
4534 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4535 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4536 {}
4537 },
4538 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004539 [ALC880_FIXUP_TCL_S700] = {
4540 .type = ALC_FIXUP_VERBS,
4541 .v.verbs = (const struct hda_verb[]) {
4542 /* change to EAPD mode */
4543 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4544 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4545 {}
4546 },
4547 .chained = true,
4548 .chain_id = ALC880_FIXUP_GPIO2,
4549 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004550 [ALC880_FIXUP_VOL_KNOB] = {
4551 .type = ALC_FIXUP_FUNC,
4552 .v.func = alc880_fixup_vol_knob,
4553 },
4554 [ALC880_FIXUP_FUJITSU] = {
4555 /* override all pins as BIOS on old Amilo is broken */
4556 .type = ALC_FIXUP_PINS,
4557 .v.pins = (const struct alc_pincfg[]) {
4558 { 0x14, 0x0121411f }, /* HP */
4559 { 0x15, 0x99030120 }, /* speaker */
4560 { 0x16, 0x99030130 }, /* bass speaker */
4561 { 0x17, 0x411111f0 }, /* N/A */
4562 { 0x18, 0x411111f0 }, /* N/A */
4563 { 0x19, 0x01a19950 }, /* mic-in */
4564 { 0x1a, 0x411111f0 }, /* N/A */
4565 { 0x1b, 0x411111f0 }, /* N/A */
4566 { 0x1c, 0x411111f0 }, /* N/A */
4567 { 0x1d, 0x411111f0 }, /* N/A */
4568 { 0x1e, 0x01454140 }, /* SPDIF out */
4569 { }
4570 },
4571 .chained = true,
4572 .chain_id = ALC880_FIXUP_VOL_KNOB,
4573 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004574 [ALC880_FIXUP_F1734] = {
4575 /* almost compatible with FUJITSU, but no bass and SPDIF */
4576 .type = ALC_FIXUP_PINS,
4577 .v.pins = (const struct alc_pincfg[]) {
4578 { 0x14, 0x0121411f }, /* HP */
4579 { 0x15, 0x99030120 }, /* speaker */
4580 { 0x16, 0x411111f0 }, /* N/A */
4581 { 0x17, 0x411111f0 }, /* N/A */
4582 { 0x18, 0x411111f0 }, /* N/A */
4583 { 0x19, 0x01a19950 }, /* mic-in */
4584 { 0x1a, 0x411111f0 }, /* N/A */
4585 { 0x1b, 0x411111f0 }, /* N/A */
4586 { 0x1c, 0x411111f0 }, /* N/A */
4587 { 0x1d, 0x411111f0 }, /* N/A */
4588 { 0x1e, 0x411111f0 }, /* N/A */
4589 { }
4590 },
4591 .chained = true,
4592 .chain_id = ALC880_FIXUP_VOL_KNOB,
4593 },
Takashi Iwai817de922012-02-20 17:20:48 +01004594 [ALC880_FIXUP_UNIWILL] = {
4595 /* need to fix HP and speaker pins to be parsed correctly */
4596 .type = ALC_FIXUP_PINS,
4597 .v.pins = (const struct alc_pincfg[]) {
4598 { 0x14, 0x0121411f }, /* HP */
4599 { 0x15, 0x99030120 }, /* speaker */
4600 { 0x16, 0x99030130 }, /* bass speaker */
4601 { }
4602 },
4603 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004604 [ALC880_FIXUP_UNIWILL_DIG] = {
4605 .type = ALC_FIXUP_PINS,
4606 .v.pins = (const struct alc_pincfg[]) {
4607 /* disable bogus unused pins */
4608 { 0x17, 0x411111f0 },
4609 { 0x19, 0x411111f0 },
4610 { 0x1b, 0x411111f0 },
4611 { 0x1f, 0x411111f0 },
4612 { }
4613 }
4614 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004615 [ALC880_FIXUP_Z71V] = {
4616 .type = ALC_FIXUP_PINS,
4617 .v.pins = (const struct alc_pincfg[]) {
4618 /* set up the whole pins as BIOS is utterly broken */
4619 { 0x14, 0x99030120 }, /* speaker */
4620 { 0x15, 0x0121411f }, /* HP */
4621 { 0x16, 0x411111f0 }, /* N/A */
4622 { 0x17, 0x411111f0 }, /* N/A */
4623 { 0x18, 0x01a19950 }, /* mic-in */
4624 { 0x19, 0x411111f0 }, /* N/A */
4625 { 0x1a, 0x01813031 }, /* line-in */
4626 { 0x1b, 0x411111f0 }, /* N/A */
4627 { 0x1c, 0x411111f0 }, /* N/A */
4628 { 0x1d, 0x411111f0 }, /* N/A */
4629 { 0x1e, 0x0144111e }, /* SPDIF */
4630 { }
4631 }
4632 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004633 [ALC880_FIXUP_3ST_BASE] = {
4634 .type = ALC_FIXUP_PINS,
4635 .v.pins = (const struct alc_pincfg[]) {
4636 { 0x14, 0x01014010 }, /* line-out */
4637 { 0x15, 0x411111f0 }, /* N/A */
4638 { 0x16, 0x411111f0 }, /* N/A */
4639 { 0x17, 0x411111f0 }, /* N/A */
4640 { 0x18, 0x01a19c30 }, /* mic-in */
4641 { 0x19, 0x0121411f }, /* HP */
4642 { 0x1a, 0x01813031 }, /* line-in */
4643 { 0x1b, 0x02a19c40 }, /* front-mic */
4644 { 0x1c, 0x411111f0 }, /* N/A */
4645 { 0x1d, 0x411111f0 }, /* N/A */
4646 /* 0x1e is filled in below */
4647 { 0x1f, 0x411111f0 }, /* N/A */
4648 { }
4649 }
4650 },
4651 [ALC880_FIXUP_3ST] = {
4652 .type = ALC_FIXUP_PINS,
4653 .v.pins = (const struct alc_pincfg[]) {
4654 { 0x1e, 0x411111f0 }, /* N/A */
4655 { }
4656 },
4657 .chained = true,
4658 .chain_id = ALC880_FIXUP_3ST_BASE,
4659 },
4660 [ALC880_FIXUP_3ST_DIG] = {
4661 .type = ALC_FIXUP_PINS,
4662 .v.pins = (const struct alc_pincfg[]) {
4663 { 0x1e, 0x0144111e }, /* SPDIF */
4664 { }
4665 },
4666 .chained = true,
4667 .chain_id = ALC880_FIXUP_3ST_BASE,
4668 },
4669 [ALC880_FIXUP_5ST_BASE] = {
4670 .type = ALC_FIXUP_PINS,
4671 .v.pins = (const struct alc_pincfg[]) {
4672 { 0x14, 0x01014010 }, /* front */
4673 { 0x15, 0x411111f0 }, /* N/A */
4674 { 0x16, 0x01011411 }, /* CLFE */
4675 { 0x17, 0x01016412 }, /* surr */
4676 { 0x18, 0x01a19c30 }, /* mic-in */
4677 { 0x19, 0x0121411f }, /* HP */
4678 { 0x1a, 0x01813031 }, /* line-in */
4679 { 0x1b, 0x02a19c40 }, /* front-mic */
4680 { 0x1c, 0x411111f0 }, /* N/A */
4681 { 0x1d, 0x411111f0 }, /* N/A */
4682 /* 0x1e is filled in below */
4683 { 0x1f, 0x411111f0 }, /* N/A */
4684 { }
4685 }
4686 },
4687 [ALC880_FIXUP_5ST] = {
4688 .type = ALC_FIXUP_PINS,
4689 .v.pins = (const struct alc_pincfg[]) {
4690 { 0x1e, 0x411111f0 }, /* N/A */
4691 { }
4692 },
4693 .chained = true,
4694 .chain_id = ALC880_FIXUP_5ST_BASE,
4695 },
4696 [ALC880_FIXUP_5ST_DIG] = {
4697 .type = ALC_FIXUP_PINS,
4698 .v.pins = (const struct alc_pincfg[]) {
4699 { 0x1e, 0x0144111e }, /* SPDIF */
4700 { }
4701 },
4702 .chained = true,
4703 .chain_id = ALC880_FIXUP_5ST_BASE,
4704 },
4705 [ALC880_FIXUP_6ST_BASE] = {
4706 .type = ALC_FIXUP_PINS,
4707 .v.pins = (const struct alc_pincfg[]) {
4708 { 0x14, 0x01014010 }, /* front */
4709 { 0x15, 0x01016412 }, /* surr */
4710 { 0x16, 0x01011411 }, /* CLFE */
4711 { 0x17, 0x01012414 }, /* side */
4712 { 0x18, 0x01a19c30 }, /* mic-in */
4713 { 0x19, 0x02a19c40 }, /* front-mic */
4714 { 0x1a, 0x01813031 }, /* line-in */
4715 { 0x1b, 0x0121411f }, /* HP */
4716 { 0x1c, 0x411111f0 }, /* N/A */
4717 { 0x1d, 0x411111f0 }, /* N/A */
4718 /* 0x1e is filled in below */
4719 { 0x1f, 0x411111f0 }, /* N/A */
4720 { }
4721 }
4722 },
4723 [ALC880_FIXUP_6ST] = {
4724 .type = ALC_FIXUP_PINS,
4725 .v.pins = (const struct alc_pincfg[]) {
4726 { 0x1e, 0x411111f0 }, /* N/A */
4727 { }
4728 },
4729 .chained = true,
4730 .chain_id = ALC880_FIXUP_6ST_BASE,
4731 },
4732 [ALC880_FIXUP_6ST_DIG] = {
4733 .type = ALC_FIXUP_PINS,
4734 .v.pins = (const struct alc_pincfg[]) {
4735 { 0x1e, 0x0144111e }, /* SPDIF */
4736 { }
4737 },
4738 .chained = true,
4739 .chain_id = ALC880_FIXUP_6ST_BASE,
4740 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004741};
4742
4743static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004744 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004745 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004746 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4747 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004748 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004749 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004750 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004751 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004752 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004753 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004754 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004755 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004756 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004757 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004758 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004759 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4760 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4761 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004762 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004763
4764 /* Below is the copied entries from alc880_quirks.c.
4765 * It's not quite sure whether BIOS sets the correct pin-config table
4766 * on these machines, thus they are kept to be compatible with
4767 * the old static quirks. Once when it's confirmed to work without
4768 * these overrides, it'd be better to remove.
4769 */
4770 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4771 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4772 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4773 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4774 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4775 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4776 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4777 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4778 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4779 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4780 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4781 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4782 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4783 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4784 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4785 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4786 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4787 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4788 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4789 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4790 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4791 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4792 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4793 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4794 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4795 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4796 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4797 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4798 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4799 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4800 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4801 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4802 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4803 /* default Intel */
4804 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4805 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4806 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4807 {}
4808};
4809
4810static const struct alc_model_fixup alc880_fixup_models[] = {
4811 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4812 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4813 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4814 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4815 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4816 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004817 {}
4818};
4819
4820
4821/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004822 * OK, here we have finally the patch for ALC880
4823 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004824static int patch_alc880(struct hda_codec *codec)
4825{
4826 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004827 int err;
4828
4829 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4830 if (spec == NULL)
4831 return -ENOMEM;
4832
4833 codec->spec = spec;
4834
4835 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004836 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004837
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004838 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4839 alc880_fixups);
4840 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004841
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004842 /* automatic parse from the BIOS config */
4843 err = alc880_parse_auto_config(codec);
4844 if (err < 0)
4845 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004846
Takashi Iwai60a6a842011-07-27 14:01:24 +02004847 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004848 alc_auto_fill_adc_caps(codec);
4849 alc_rebuild_imux_for_auto_mic(codec);
4850 alc_remove_invalid_adc_nids(codec);
4851 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004852
4853 if (!spec->no_analog && !spec->cap_mixer)
4854 set_capture_mixer(codec);
4855
4856 if (!spec->no_analog) {
4857 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004858 if (err < 0)
4859 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004860 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4861 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004862
Takashi Iwai1d045db2011-07-07 18:23:21 +02004863 codec->patch_ops = alc_patch_ops;
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004864 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004865
Takashi Iwai589876e2012-02-20 15:47:55 +01004866 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4867
Takashi Iwai1d045db2011-07-07 18:23:21 +02004868 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004869
4870 error:
4871 alc_free(codec);
4872 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004873}
4874
4875
4876/*
4877 * ALC260 support
4878 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004879static int alc260_parse_auto_config(struct hda_codec *codec)
4880{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004882 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4883 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004884}
4885
Takashi Iwai1d045db2011-07-07 18:23:21 +02004886/*
4887 * Pin config fixes
4888 */
4889enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004890 ALC260_FIXUP_HP_DC5750,
4891 ALC260_FIXUP_HP_PIN_0F,
4892 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004893 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004894 ALC260_FIXUP_GPIO1_TOGGLE,
4895 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004896 ALC260_FIXUP_HP_B1900,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004897};
4898
Takashi Iwai20f7d922012-02-16 12:35:16 +01004899static void alc260_gpio1_automute(struct hda_codec *codec)
4900{
4901 struct alc_spec *spec = codec->spec;
4902 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4903 spec->hp_jack_present);
4904}
4905
4906static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4907 const struct alc_fixup *fix, int action)
4908{
4909 struct alc_spec *spec = codec->spec;
4910 if (action == ALC_FIXUP_ACT_PROBE) {
4911 /* although the machine has only one output pin, we need to
4912 * toggle GPIO1 according to the jack state
4913 */
4914 spec->automute_hook = alc260_gpio1_automute;
4915 spec->detect_hp = 1;
4916 spec->automute_speaker = 1;
4917 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4918 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4919 spec->unsol_event = alc_sku_unsol_event;
4920 add_verb(codec->spec, alc_gpio1_init_verbs);
4921 }
4922}
4923
Takashi Iwai1d045db2011-07-07 18:23:21 +02004924static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004925 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004926 .type = ALC_FIXUP_PINS,
4927 .v.pins = (const struct alc_pincfg[]) {
4928 { 0x11, 0x90130110 }, /* speaker */
4929 { }
4930 }
4931 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004932 [ALC260_FIXUP_HP_PIN_0F] = {
4933 .type = ALC_FIXUP_PINS,
4934 .v.pins = (const struct alc_pincfg[]) {
4935 { 0x0f, 0x01214000 }, /* HP */
4936 { }
4937 }
4938 },
4939 [ALC260_FIXUP_COEF] = {
4940 .type = ALC_FIXUP_VERBS,
4941 .v.verbs = (const struct hda_verb[]) {
4942 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4943 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4944 { }
4945 },
4946 .chained = true,
4947 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4948 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004949 [ALC260_FIXUP_GPIO1] = {
4950 .type = ALC_FIXUP_VERBS,
4951 .v.verbs = alc_gpio1_init_verbs,
4952 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004953 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4954 .type = ALC_FIXUP_FUNC,
4955 .v.func = alc260_fixup_gpio1_toggle,
4956 .chained = true,
4957 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4958 },
4959 [ALC260_FIXUP_REPLACER] = {
4960 .type = ALC_FIXUP_VERBS,
4961 .v.verbs = (const struct hda_verb[]) {
4962 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4963 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4964 { }
4965 },
4966 .chained = true,
4967 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4968 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004969 [ALC260_FIXUP_HP_B1900] = {
4970 .type = ALC_FIXUP_FUNC,
4971 .v.func = alc260_fixup_gpio1_toggle,
4972 .chained = true,
4973 .chain_id = ALC260_FIXUP_COEF,
4974 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004975};
4976
4977static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004978 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004979 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004980 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004981 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004982 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004983 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004984 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004985 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004986 {}
4987};
4988
4989/*
4990 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004991static int patch_alc260(struct hda_codec *codec)
4992{
4993 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004994 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995
4996 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4997 if (spec == NULL)
4998 return -ENOMEM;
4999
5000 codec->spec = spec;
5001
5002 spec->mixer_nid = 0x07;
5003
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005004 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5005 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005006
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005007 /* automatic parse from the BIOS config */
5008 err = alc260_parse_auto_config(codec);
5009 if (err < 0)
5010 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005011
Takashi Iwai60a6a842011-07-27 14:01:24 +02005012 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005013 alc_auto_fill_adc_caps(codec);
5014 alc_rebuild_imux_for_auto_mic(codec);
5015 alc_remove_invalid_adc_nids(codec);
5016 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005017
5018 if (!spec->no_analog && !spec->cap_mixer)
5019 set_capture_mixer(codec);
5020
5021 if (!spec->no_analog) {
5022 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005023 if (err < 0)
5024 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005025 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5026 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005027
Takashi Iwai1d045db2011-07-07 18:23:21 +02005028 codec->patch_ops = alc_patch_ops;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005029 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005030 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005031
Takashi Iwai589876e2012-02-20 15:47:55 +01005032 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5033
Takashi Iwai1d045db2011-07-07 18:23:21 +02005034 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005035
5036 error:
5037 alc_free(codec);
5038 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005039}
5040
5041
5042/*
5043 * ALC882/883/885/888/889 support
5044 *
5045 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5046 * configuration. Each pin widget can choose any input DACs and a mixer.
5047 * Each ADC is connected from a mixer of all inputs. This makes possible
5048 * 6-channel independent captures.
5049 *
5050 * In addition, an independent DAC for the multi-playback (not used in this
5051 * driver yet).
5052 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005053
5054/*
5055 * Pin config fixes
5056 */
5057enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005058 ALC882_FIXUP_ABIT_AW9D_MAX,
5059 ALC882_FIXUP_LENOVO_Y530,
5060 ALC882_FIXUP_PB_M5210,
5061 ALC882_FIXUP_ACER_ASPIRE_7736,
5062 ALC882_FIXUP_ASUS_W90V,
5063 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005064 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005065 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005066 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005067 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005068 ALC882_FIXUP_GPIO1,
5069 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005070 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005071 ALC889_FIXUP_COEF,
5072 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005073 ALC882_FIXUP_ACER_ASPIRE_4930G,
5074 ALC882_FIXUP_ACER_ASPIRE_8930G,
5075 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005076 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005077 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005078 ALC889_FIXUP_MBP_VREF,
5079 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005080};
5081
Takashi Iwai68ef0562011-11-09 18:24:44 +01005082static void alc889_fixup_coef(struct hda_codec *codec,
5083 const struct alc_fixup *fix, int action)
5084{
5085 if (action != ALC_FIXUP_ACT_INIT)
5086 return;
5087 alc889_coef_init(codec);
5088}
5089
Takashi Iwai56710872011-11-14 17:42:11 +01005090/* toggle speaker-output according to the hp-jack state */
5091static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5092{
5093 unsigned int gpiostate, gpiomask, gpiodir;
5094
5095 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5096 AC_VERB_GET_GPIO_DATA, 0);
5097
5098 if (!muted)
5099 gpiostate |= (1 << pin);
5100 else
5101 gpiostate &= ~(1 << pin);
5102
5103 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5104 AC_VERB_GET_GPIO_MASK, 0);
5105 gpiomask |= (1 << pin);
5106
5107 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5108 AC_VERB_GET_GPIO_DIRECTION, 0);
5109 gpiodir |= (1 << pin);
5110
5111
5112 snd_hda_codec_write(codec, codec->afg, 0,
5113 AC_VERB_SET_GPIO_MASK, gpiomask);
5114 snd_hda_codec_write(codec, codec->afg, 0,
5115 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5116
5117 msleep(1);
5118
5119 snd_hda_codec_write(codec, codec->afg, 0,
5120 AC_VERB_SET_GPIO_DATA, gpiostate);
5121}
5122
5123/* set up GPIO at initialization */
5124static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5125 const struct alc_fixup *fix, int action)
5126{
5127 if (action != ALC_FIXUP_ACT_INIT)
5128 return;
5129 alc882_gpio_mute(codec, 0, 0);
5130 alc882_gpio_mute(codec, 1, 0);
5131}
5132
Takashi Iwai02a237b2012-02-13 15:25:07 +01005133/* Fix the connection of some pins for ALC889:
5134 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5135 * work correctly (bko#42740)
5136 */
5137static void alc889_fixup_dac_route(struct hda_codec *codec,
5138 const struct alc_fixup *fix, int action)
5139{
5140 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5141 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5142 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5143 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5144 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5145 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5146 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5147 }
5148}
5149
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005150/* Set VREF on HP pin */
5151static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5152 const struct alc_fixup *fix, int action)
5153{
5154 struct alc_spec *spec = codec->spec;
5155 static hda_nid_t nids[2] = { 0x14, 0x15 };
5156 int i;
5157
5158 if (action != ALC_FIXUP_ACT_INIT)
5159 return;
5160 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5161 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5162 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5163 continue;
5164 val = snd_hda_codec_read(codec, nids[i], 0,
5165 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5166 val |= AC_PINCTL_VREF_80;
5167 snd_hda_codec_write(codec, nids[i], 0,
5168 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5169 spec->keep_vref_in_automute = 1;
5170 break;
5171 }
5172}
5173
5174/* Set VREF on speaker pins on imac91 */
5175static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5176 const struct alc_fixup *fix, int action)
5177{
5178 struct alc_spec *spec = codec->spec;
5179 static hda_nid_t nids[2] = { 0x18, 0x1a };
5180 int i;
5181
5182 if (action != ALC_FIXUP_ACT_INIT)
5183 return;
5184 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5185 unsigned int val;
5186 val = snd_hda_codec_read(codec, nids[i], 0,
5187 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5188 val |= AC_PINCTL_VREF_50;
5189 snd_hda_codec_write(codec, nids[i], 0,
5190 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5191 }
5192 spec->keep_vref_in_automute = 1;
5193}
5194
Takashi Iwai1d045db2011-07-07 18:23:21 +02005195static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005196 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005197 .type = ALC_FIXUP_PINS,
5198 .v.pins = (const struct alc_pincfg[]) {
5199 { 0x15, 0x01080104 }, /* side */
5200 { 0x16, 0x01011012 }, /* rear */
5201 { 0x17, 0x01016011 }, /* clfe */
5202 { }
5203 }
5204 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005205 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005206 .type = ALC_FIXUP_PINS,
5207 .v.pins = (const struct alc_pincfg[]) {
5208 { 0x15, 0x99130112 }, /* rear int speakers */
5209 { 0x16, 0x99130111 }, /* subwoofer */
5210 { }
5211 }
5212 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005213 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005214 .type = ALC_FIXUP_VERBS,
5215 .v.verbs = (const struct hda_verb[]) {
5216 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5217 {}
5218 }
5219 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005220 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005221 .type = ALC_FIXUP_SKU,
5222 .v.sku = ALC_FIXUP_SKU_IGNORE,
5223 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005224 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005225 .type = ALC_FIXUP_PINS,
5226 .v.pins = (const struct alc_pincfg[]) {
5227 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5228 { }
5229 }
5230 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005231 [ALC889_FIXUP_VAIO_TT] = {
5232 .type = ALC_FIXUP_PINS,
5233 .v.pins = (const struct alc_pincfg[]) {
5234 { 0x17, 0x90170111 }, /* hidden surround speaker */
5235 { }
5236 }
5237 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005238 [ALC888_FIXUP_EEE1601] = {
5239 .type = ALC_FIXUP_VERBS,
5240 .v.verbs = (const struct hda_verb[]) {
5241 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5242 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5243 { }
5244 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005245 },
5246 [ALC882_FIXUP_EAPD] = {
5247 .type = ALC_FIXUP_VERBS,
5248 .v.verbs = (const struct hda_verb[]) {
5249 /* change to EAPD mode */
5250 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5251 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5252 { }
5253 }
5254 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005255 [ALC883_FIXUP_EAPD] = {
5256 .type = ALC_FIXUP_VERBS,
5257 .v.verbs = (const struct hda_verb[]) {
5258 /* change to EAPD mode */
5259 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5260 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5261 { }
5262 }
5263 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005264 [ALC883_FIXUP_ACER_EAPD] = {
5265 .type = ALC_FIXUP_VERBS,
5266 .v.verbs = (const struct hda_verb[]) {
5267 /* eanable EAPD on Acer laptops */
5268 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5269 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5270 { }
5271 }
5272 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005273 [ALC882_FIXUP_GPIO1] = {
5274 .type = ALC_FIXUP_VERBS,
5275 .v.verbs = alc_gpio1_init_verbs,
5276 },
5277 [ALC882_FIXUP_GPIO2] = {
5278 .type = ALC_FIXUP_VERBS,
5279 .v.verbs = alc_gpio2_init_verbs,
5280 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005281 [ALC882_FIXUP_GPIO3] = {
5282 .type = ALC_FIXUP_VERBS,
5283 .v.verbs = alc_gpio3_init_verbs,
5284 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005285 [ALC882_FIXUP_ASUS_W2JC] = {
5286 .type = ALC_FIXUP_VERBS,
5287 .v.verbs = alc_gpio1_init_verbs,
5288 .chained = true,
5289 .chain_id = ALC882_FIXUP_EAPD,
5290 },
5291 [ALC889_FIXUP_COEF] = {
5292 .type = ALC_FIXUP_FUNC,
5293 .v.func = alc889_fixup_coef,
5294 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005295 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5296 .type = ALC_FIXUP_PINS,
5297 .v.pins = (const struct alc_pincfg[]) {
5298 { 0x16, 0x99130111 }, /* CLFE speaker */
5299 { 0x17, 0x99130112 }, /* surround speaker */
5300 { }
5301 }
5302 },
5303 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5304 .type = ALC_FIXUP_PINS,
5305 .v.pins = (const struct alc_pincfg[]) {
5306 { 0x16, 0x99130111 }, /* CLFE speaker */
5307 { 0x1b, 0x99130112 }, /* surround speaker */
5308 { }
5309 },
5310 .chained = true,
5311 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5312 },
5313 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5314 /* additional init verbs for Acer Aspire 8930G */
5315 .type = ALC_FIXUP_VERBS,
5316 .v.verbs = (const struct hda_verb[]) {
5317 /* Enable all DACs */
5318 /* DAC DISABLE/MUTE 1? */
5319 /* setting bits 1-5 disables DAC nids 0x02-0x06
5320 * apparently. Init=0x38 */
5321 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5322 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5323 /* DAC DISABLE/MUTE 2? */
5324 /* some bit here disables the other DACs.
5325 * Init=0x4900 */
5326 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5327 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5328 /* DMIC fix
5329 * This laptop has a stereo digital microphone.
5330 * The mics are only 1cm apart which makes the stereo
5331 * useless. However, either the mic or the ALC889
5332 * makes the signal become a difference/sum signal
5333 * instead of standard stereo, which is annoying.
5334 * So instead we flip this bit which makes the
5335 * codec replicate the sum signal to both channels,
5336 * turning it into a normal mono mic.
5337 */
5338 /* DMIC_CONTROL? Init value = 0x0001 */
5339 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5340 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5341 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5342 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5343 { }
5344 }
5345 },
Takashi Iwai56710872011-11-14 17:42:11 +01005346 [ALC885_FIXUP_MACPRO_GPIO] = {
5347 .type = ALC_FIXUP_FUNC,
5348 .v.func = alc885_fixup_macpro_gpio,
5349 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005350 [ALC889_FIXUP_DAC_ROUTE] = {
5351 .type = ALC_FIXUP_FUNC,
5352 .v.func = alc889_fixup_dac_route,
5353 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005354 [ALC889_FIXUP_MBP_VREF] = {
5355 .type = ALC_FIXUP_FUNC,
5356 .v.func = alc889_fixup_mbp_vref,
5357 .chained = true,
5358 .chain_id = ALC882_FIXUP_GPIO1,
5359 },
5360 [ALC889_FIXUP_IMAC91_VREF] = {
5361 .type = ALC_FIXUP_FUNC,
5362 .v.func = alc889_fixup_imac91_vref,
5363 .chained = true,
5364 .chain_id = ALC882_FIXUP_GPIO1,
5365 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005366};
5367
5368static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005369 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5370 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5371 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5372 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5373 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5374 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005375 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5376 ALC882_FIXUP_ACER_ASPIRE_4930G),
5377 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5378 ALC882_FIXUP_ACER_ASPIRE_4930G),
5379 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5380 ALC882_FIXUP_ACER_ASPIRE_8930G),
5381 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5382 ALC882_FIXUP_ACER_ASPIRE_8930G),
5383 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5384 ALC882_FIXUP_ACER_ASPIRE_4930G),
5385 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5386 ALC882_FIXUP_ACER_ASPIRE_4930G),
5387 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5388 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005389 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005390 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005391 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005392 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005393 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005394 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005395 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005396 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005397
5398 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005399 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5400 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5401 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005402 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5403 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5404 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005405 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5406 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005407 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005408 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5409 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5410 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5411 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005412 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005413 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5414 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5415 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5416 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5417 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5418 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005419
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005420 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005421 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005422 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005423 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5424 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005425 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005426 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005427 {}
5428};
5429
5430/*
5431 * BIOS auto configuration
5432 */
5433/* almost identical with ALC880 parser... */
5434static int alc882_parse_auto_config(struct hda_codec *codec)
5435{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005436 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005437 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5438 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005439}
5440
Takashi Iwai1d045db2011-07-07 18:23:21 +02005441/*
5442 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005443static int patch_alc882(struct hda_codec *codec)
5444{
5445 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005446 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005447
5448 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5449 if (spec == NULL)
5450 return -ENOMEM;
5451
5452 codec->spec = spec;
5453
5454 spec->mixer_nid = 0x0b;
5455
5456 switch (codec->vendor_id) {
5457 case 0x10ec0882:
5458 case 0x10ec0885:
5459 break;
5460 default:
5461 /* ALC883 and variants */
5462 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5463 break;
5464 }
5465
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005466 err = alc_codec_rename_from_preset(codec);
5467 if (err < 0)
5468 goto error;
5469
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005470 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
5471 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005472
5473 alc_auto_parse_customize_define(codec);
5474
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005475 /* automatic parse from the BIOS config */
5476 err = alc882_parse_auto_config(codec);
5477 if (err < 0)
5478 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005479
Takashi Iwai60a6a842011-07-27 14:01:24 +02005480 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481 alc_auto_fill_adc_caps(codec);
5482 alc_rebuild_imux_for_auto_mic(codec);
5483 alc_remove_invalid_adc_nids(codec);
5484 }
5485
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005486 if (!spec->no_analog && !spec->cap_mixer)
5487 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005488
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005489 if (!spec->no_analog && has_cdefine_beep(codec)) {
5490 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005491 if (err < 0)
5492 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005493 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005494 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005495
Takashi Iwai1d045db2011-07-07 18:23:21 +02005496 codec->patch_ops = alc_patch_ops;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005497 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005498
Takashi Iwai589876e2012-02-20 15:47:55 +01005499 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5500
Takashi Iwai1d045db2011-07-07 18:23:21 +02005501 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005502
5503 error:
5504 alc_free(codec);
5505 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005506}
5507
5508
5509/*
5510 * ALC262 support
5511 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512static int alc262_parse_auto_config(struct hda_codec *codec)
5513{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005514 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005515 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5516 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005517}
5518
5519/*
5520 * Pin config fixes
5521 */
5522enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005523 ALC262_FIXUP_FSC_H270,
5524 ALC262_FIXUP_HP_Z200,
5525 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005526 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005527 ALC262_FIXUP_BENQ,
5528 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005529};
5530
5531static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005532 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005533 .type = ALC_FIXUP_PINS,
5534 .v.pins = (const struct alc_pincfg[]) {
5535 { 0x14, 0x99130110 }, /* speaker */
5536 { 0x15, 0x0221142f }, /* front HP */
5537 { 0x1b, 0x0121141f }, /* rear HP */
5538 { }
5539 }
5540 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005541 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005542 .type = ALC_FIXUP_PINS,
5543 .v.pins = (const struct alc_pincfg[]) {
5544 { 0x16, 0x99130120 }, /* internal speaker */
5545 { }
5546 }
5547 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005548 [ALC262_FIXUP_TYAN] = {
5549 .type = ALC_FIXUP_PINS,
5550 .v.pins = (const struct alc_pincfg[]) {
5551 { 0x14, 0x1993e1f0 }, /* int AUX */
5552 { }
5553 }
5554 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005555 [ALC262_FIXUP_LENOVO_3000] = {
5556 .type = ALC_FIXUP_VERBS,
5557 .v.verbs = (const struct hda_verb[]) {
5558 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005559 {}
5560 },
5561 .chained = true,
5562 .chain_id = ALC262_FIXUP_BENQ,
5563 },
5564 [ALC262_FIXUP_BENQ] = {
5565 .type = ALC_FIXUP_VERBS,
5566 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005567 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5568 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5569 {}
5570 }
5571 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005572 [ALC262_FIXUP_BENQ_T31] = {
5573 .type = ALC_FIXUP_VERBS,
5574 .v.verbs = (const struct hda_verb[]) {
5575 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5576 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5577 {}
5578 }
5579 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005580};
5581
5582static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005583 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005584 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5585 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005586 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5587 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005588 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005589 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5590 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005591 {}
5592};
5593
5594
Takashi Iwai1d045db2011-07-07 18:23:21 +02005595/*
5596 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005597static int patch_alc262(struct hda_codec *codec)
5598{
5599 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005600 int err;
5601
5602 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5603 if (spec == NULL)
5604 return -ENOMEM;
5605
5606 codec->spec = spec;
5607
5608 spec->mixer_nid = 0x0b;
5609
5610#if 0
5611 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5612 * under-run
5613 */
5614 {
5615 int tmp;
5616 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5617 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5618 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5619 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5620 }
5621#endif
5622 alc_auto_parse_customize_define(codec);
5623
5624 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5625
Takashi Iwai42399f72011-11-07 17:18:44 +01005626 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5627 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005628
Takashi Iwai42399f72011-11-07 17:18:44 +01005629 /* automatic parse from the BIOS config */
5630 err = alc262_parse_auto_config(codec);
5631 if (err < 0)
5632 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005633
Takashi Iwai60a6a842011-07-27 14:01:24 +02005634 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005635 alc_auto_fill_adc_caps(codec);
5636 alc_rebuild_imux_for_auto_mic(codec);
5637 alc_remove_invalid_adc_nids(codec);
5638 }
5639
5640 if (!spec->no_analog && !spec->cap_mixer)
5641 set_capture_mixer(codec);
5642
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643 if (!spec->no_analog && has_cdefine_beep(codec)) {
5644 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005645 if (err < 0)
5646 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005647 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005648 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649
Takashi Iwai1d045db2011-07-07 18:23:21 +02005650 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01005651 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652 spec->shutup = alc_eapd_shutup;
5653
Takashi Iwai589876e2012-02-20 15:47:55 +01005654 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5655
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005657
5658 error:
5659 alc_free(codec);
5660 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661}
5662
5663/*
5664 * ALC268
5665 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005666/* bind Beep switches of both NID 0x0f and 0x10 */
5667static const struct hda_bind_ctls alc268_bind_beep_sw = {
5668 .ops = &snd_hda_bind_sw,
5669 .values = {
5670 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5671 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5672 0
5673 },
5674};
5675
5676static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5677 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5678 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5679 { }
5680};
5681
5682/* set PCBEEP vol = 0, mute connections */
5683static const struct hda_verb alc268_beep_init_verbs[] = {
5684 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5685 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5686 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5687 { }
5688};
5689
5690/*
5691 * BIOS auto configuration
5692 */
5693static int alc268_parse_auto_config(struct hda_codec *codec)
5694{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005695 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005696 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005697 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5698 if (err > 0) {
5699 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5700 add_mixer(spec, alc268_beep_mixer);
5701 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005702 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005703 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005704 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005705}
5706
Takashi Iwai1d045db2011-07-07 18:23:21 +02005707/*
5708 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005709static int patch_alc268(struct hda_codec *codec)
5710{
5711 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712 int i, has_beep, err;
5713
5714 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5715 if (spec == NULL)
5716 return -ENOMEM;
5717
5718 codec->spec = spec;
5719
5720 /* ALC268 has no aa-loopback mixer */
5721
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005722 /* automatic parse from the BIOS config */
5723 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005724 if (err < 0)
5725 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005726
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727 has_beep = 0;
5728 for (i = 0; i < spec->num_mixers; i++) {
5729 if (spec->mixers[i] == alc268_beep_mixer) {
5730 has_beep = 1;
5731 break;
5732 }
5733 }
5734
5735 if (has_beep) {
5736 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005737 if (err < 0)
5738 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005739 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5740 /* override the amp caps for beep generator */
5741 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5742 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5743 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5744 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5745 (0 << AC_AMPCAP_MUTE_SHIFT));
5746 }
5747
Takashi Iwai60a6a842011-07-27 14:01:24 +02005748 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005749 alc_auto_fill_adc_caps(codec);
5750 alc_rebuild_imux_for_auto_mic(codec);
5751 alc_remove_invalid_adc_nids(codec);
5752 }
5753
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005754 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005755 set_capture_mixer(codec);
5756
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005758 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005759 spec->shutup = alc_eapd_shutup;
5760
Takashi Iwai1d045db2011-07-07 18:23:21 +02005761 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005762
5763 error:
5764 alc_free(codec);
5765 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005766}
5767
5768/*
5769 * ALC269
5770 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005771static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5772 .substreams = 1,
5773 .channels_min = 2,
5774 .channels_max = 8,
5775 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5776 /* NID is set in alc_build_pcms */
5777 .ops = {
5778 .open = alc_playback_pcm_open,
5779 .prepare = alc_playback_pcm_prepare,
5780 .cleanup = alc_playback_pcm_cleanup
5781 },
5782};
5783
5784static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5785 .substreams = 1,
5786 .channels_min = 2,
5787 .channels_max = 2,
5788 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5789 /* NID is set in alc_build_pcms */
5790};
5791
5792#ifdef CONFIG_SND_HDA_POWER_SAVE
5793static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5794{
5795 switch (codec->subsystem_id) {
5796 case 0x103c1586:
5797 return 1;
5798 }
5799 return 0;
5800}
5801
5802static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5803{
5804 /* update mute-LED according to the speaker mute state */
5805 if (nid == 0x01 || nid == 0x14) {
5806 int pinval;
5807 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5808 HDA_AMP_MUTE)
5809 pinval = 0x24;
5810 else
5811 pinval = 0x20;
5812 /* mic2 vref pin is used for mute LED control */
5813 snd_hda_codec_update_cache(codec, 0x19, 0,
5814 AC_VERB_SET_PIN_WIDGET_CONTROL,
5815 pinval);
5816 }
5817 return alc_check_power_status(codec, nid);
5818}
5819#endif /* CONFIG_SND_HDA_POWER_SAVE */
5820
5821/* different alc269-variants */
5822enum {
5823 ALC269_TYPE_ALC269VA,
5824 ALC269_TYPE_ALC269VB,
5825 ALC269_TYPE_ALC269VC,
5826};
5827
5828/*
5829 * BIOS auto configuration
5830 */
5831static int alc269_parse_auto_config(struct hda_codec *codec)
5832{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005833 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005834 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5835 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5836 struct alc_spec *spec = codec->spec;
5837 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5838 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005839
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005840 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005841}
5842
Takashi Iwai1d045db2011-07-07 18:23:21 +02005843static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5844{
5845 int val = alc_read_coef_idx(codec, 0x04);
5846 if (power_up)
5847 val |= 1 << 11;
5848 else
5849 val &= ~(1 << 11);
5850 alc_write_coef_idx(codec, 0x04, val);
5851}
5852
5853static void alc269_shutup(struct hda_codec *codec)
5854{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005855 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005856 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005857 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005858 alc269_toggle_power_output(codec, 0);
5859 msleep(150);
5860 }
5861}
5862
Takashi Iwai2a439522011-07-26 09:52:50 +02005863#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005864static int alc269_resume(struct hda_codec *codec)
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, 0);
5868 msleep(150);
5869 }
5870
5871 codec->patch_ops.init(codec);
5872
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005873 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005874 alc269_toggle_power_output(codec, 1);
5875 msleep(200);
5876 }
5877
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005878 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005879 alc269_toggle_power_output(codec, 1);
5880
5881 snd_hda_codec_resume_amp(codec);
5882 snd_hda_codec_resume_cache(codec);
5883 hda_call_check_power_status(codec, 0x01);
5884 return 0;
5885}
Takashi Iwai2a439522011-07-26 09:52:50 +02005886#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887
5888static void alc269_fixup_hweq(struct hda_codec *codec,
5889 const struct alc_fixup *fix, int action)
5890{
5891 int coef;
5892
5893 if (action != ALC_FIXUP_ACT_INIT)
5894 return;
5895 coef = alc_read_coef_idx(codec, 0x1e);
5896 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5897}
5898
5899static void alc271_fixup_dmic(struct hda_codec *codec,
5900 const struct alc_fixup *fix, int action)
5901{
5902 static const struct hda_verb verbs[] = {
5903 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5904 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5905 {}
5906 };
5907 unsigned int cfg;
5908
5909 if (strcmp(codec->chip_name, "ALC271X"))
5910 return;
5911 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5912 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5913 snd_hda_sequence_write(codec, verbs);
5914}
5915
Takashi Iwai017f2a12011-07-09 14:42:25 +02005916static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5917 const struct alc_fixup *fix, int action)
5918{
5919 struct alc_spec *spec = codec->spec;
5920
5921 if (action != ALC_FIXUP_ACT_PROBE)
5922 return;
5923
5924 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5925 * fix the sample rate of analog I/O to 44.1kHz
5926 */
5927 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5928 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5929}
5930
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005931static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5932 const struct alc_fixup *fix, int action)
5933{
5934 int coef;
5935
5936 if (action != ALC_FIXUP_ACT_INIT)
5937 return;
5938 /* The digital-mic unit sends PDM (differential signal) instead of
5939 * the standard PCM, thus you can't record a valid mono stream as is.
5940 * Below is a workaround specific to ALC269 to control the dmic
5941 * signal source as mono.
5942 */
5943 coef = alc_read_coef_idx(codec, 0x07);
5944 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5945}
5946
Takashi Iwai24519912011-08-16 15:08:49 +02005947static void alc269_quanta_automute(struct hda_codec *codec)
5948{
David Henningsson42cf0d02011-09-20 12:04:56 +02005949 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005950
5951 snd_hda_codec_write(codec, 0x20, 0,
5952 AC_VERB_SET_COEF_INDEX, 0x0c);
5953 snd_hda_codec_write(codec, 0x20, 0,
5954 AC_VERB_SET_PROC_COEF, 0x680);
5955
5956 snd_hda_codec_write(codec, 0x20, 0,
5957 AC_VERB_SET_COEF_INDEX, 0x0c);
5958 snd_hda_codec_write(codec, 0x20, 0,
5959 AC_VERB_SET_PROC_COEF, 0x480);
5960}
5961
5962static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5963 const struct alc_fixup *fix, int action)
5964{
5965 struct alc_spec *spec = codec->spec;
5966 if (action != ALC_FIXUP_ACT_PROBE)
5967 return;
5968 spec->automute_hook = alc269_quanta_automute;
5969}
5970
Takashi Iwai1d045db2011-07-07 18:23:21 +02005971enum {
5972 ALC269_FIXUP_SONY_VAIO,
5973 ALC275_FIXUP_SONY_VAIO_GPIO2,
5974 ALC269_FIXUP_DELL_M101Z,
5975 ALC269_FIXUP_SKU_IGNORE,
5976 ALC269_FIXUP_ASUS_G73JW,
5977 ALC269_FIXUP_LENOVO_EAPD,
5978 ALC275_FIXUP_SONY_HWEQ,
5979 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005980 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005981 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005982 ALC269_FIXUP_QUANTA_MUTE,
5983 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005984 ALC269_FIXUP_AMIC,
5985 ALC269_FIXUP_DMIC,
5986 ALC269VB_FIXUP_AMIC,
5987 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005988};
5989
5990static const struct alc_fixup alc269_fixups[] = {
5991 [ALC269_FIXUP_SONY_VAIO] = {
5992 .type = ALC_FIXUP_VERBS,
5993 .v.verbs = (const struct hda_verb[]) {
5994 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5995 {}
5996 }
5997 },
5998 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5999 .type = ALC_FIXUP_VERBS,
6000 .v.verbs = (const struct hda_verb[]) {
6001 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6002 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6003 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6004 { }
6005 },
6006 .chained = true,
6007 .chain_id = ALC269_FIXUP_SONY_VAIO
6008 },
6009 [ALC269_FIXUP_DELL_M101Z] = {
6010 .type = ALC_FIXUP_VERBS,
6011 .v.verbs = (const struct hda_verb[]) {
6012 /* Enables internal speaker */
6013 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6014 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6015 {}
6016 }
6017 },
6018 [ALC269_FIXUP_SKU_IGNORE] = {
6019 .type = ALC_FIXUP_SKU,
6020 .v.sku = ALC_FIXUP_SKU_IGNORE,
6021 },
6022 [ALC269_FIXUP_ASUS_G73JW] = {
6023 .type = ALC_FIXUP_PINS,
6024 .v.pins = (const struct alc_pincfg[]) {
6025 { 0x17, 0x99130111 }, /* subwoofer */
6026 { }
6027 }
6028 },
6029 [ALC269_FIXUP_LENOVO_EAPD] = {
6030 .type = ALC_FIXUP_VERBS,
6031 .v.verbs = (const struct hda_verb[]) {
6032 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6033 {}
6034 }
6035 },
6036 [ALC275_FIXUP_SONY_HWEQ] = {
6037 .type = ALC_FIXUP_FUNC,
6038 .v.func = alc269_fixup_hweq,
6039 .chained = true,
6040 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6041 },
6042 [ALC271_FIXUP_DMIC] = {
6043 .type = ALC_FIXUP_FUNC,
6044 .v.func = alc271_fixup_dmic,
6045 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006046 [ALC269_FIXUP_PCM_44K] = {
6047 .type = ALC_FIXUP_FUNC,
6048 .v.func = alc269_fixup_pcm_44k,
6049 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006050 [ALC269_FIXUP_STEREO_DMIC] = {
6051 .type = ALC_FIXUP_FUNC,
6052 .v.func = alc269_fixup_stereo_dmic,
6053 },
Takashi Iwai24519912011-08-16 15:08:49 +02006054 [ALC269_FIXUP_QUANTA_MUTE] = {
6055 .type = ALC_FIXUP_FUNC,
6056 .v.func = alc269_fixup_quanta_mute,
6057 },
6058 [ALC269_FIXUP_LIFEBOOK] = {
6059 .type = ALC_FIXUP_PINS,
6060 .v.pins = (const struct alc_pincfg[]) {
6061 { 0x1a, 0x2101103f }, /* dock line-out */
6062 { 0x1b, 0x23a11040 }, /* dock mic-in */
6063 { }
6064 },
6065 .chained = true,
6066 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6067 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006068 [ALC269_FIXUP_AMIC] = {
6069 .type = ALC_FIXUP_PINS,
6070 .v.pins = (const struct alc_pincfg[]) {
6071 { 0x14, 0x99130110 }, /* speaker */
6072 { 0x15, 0x0121401f }, /* HP out */
6073 { 0x18, 0x01a19c20 }, /* mic */
6074 { 0x19, 0x99a3092f }, /* int-mic */
6075 { }
6076 },
6077 },
6078 [ALC269_FIXUP_DMIC] = {
6079 .type = ALC_FIXUP_PINS,
6080 .v.pins = (const struct alc_pincfg[]) {
6081 { 0x12, 0x99a3092f }, /* int-mic */
6082 { 0x14, 0x99130110 }, /* speaker */
6083 { 0x15, 0x0121401f }, /* HP out */
6084 { 0x18, 0x01a19c20 }, /* mic */
6085 { }
6086 },
6087 },
6088 [ALC269VB_FIXUP_AMIC] = {
6089 .type = ALC_FIXUP_PINS,
6090 .v.pins = (const struct alc_pincfg[]) {
6091 { 0x14, 0x99130110 }, /* speaker */
6092 { 0x18, 0x01a19c20 }, /* mic */
6093 { 0x19, 0x99a3092f }, /* int-mic */
6094 { 0x21, 0x0121401f }, /* HP out */
6095 { }
6096 },
6097 },
David Henningsson2267ea92012-01-03 08:45:56 +01006098 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006099 .type = ALC_FIXUP_PINS,
6100 .v.pins = (const struct alc_pincfg[]) {
6101 { 0x12, 0x99a3092f }, /* int-mic */
6102 { 0x14, 0x99130110 }, /* speaker */
6103 { 0x18, 0x01a19c20 }, /* mic */
6104 { 0x21, 0x0121401f }, /* HP out */
6105 { }
6106 },
6107 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006108};
6109
6110static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02006111 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006112 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6113 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6114 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6115 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6116 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006117 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6118 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6119 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6120 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6121 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6122 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006123 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006124 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6125 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6126 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6127 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6128 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006129 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006130 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006131 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006132
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006133#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006134 /* Below is a quirk table taken from the old code.
6135 * Basically the device should work as is without the fixup table.
6136 * If BIOS doesn't give a proper info, enable the corresponding
6137 * fixup entry.
6138 */
6139 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6140 ALC269_FIXUP_AMIC),
6141 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006142 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6143 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6144 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6145 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6146 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6147 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6148 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6149 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6150 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6151 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6152 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6153 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6154 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6155 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6156 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6157 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6158 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6159 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6160 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6161 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6162 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6163 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6164 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6165 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6166 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6167 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6168 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6169 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6170 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6171 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6172 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6173 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6174 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6175 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6176 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6177 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6178 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6179 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6180#endif
6181 {}
6182};
6183
6184static const struct alc_model_fixup alc269_fixup_models[] = {
6185 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6186 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006187 {}
6188};
6189
6190
6191static int alc269_fill_coef(struct hda_codec *codec)
6192{
6193 int val;
6194
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006195 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006196 alc_write_coef_idx(codec, 0xf, 0x960b);
6197 alc_write_coef_idx(codec, 0xe, 0x8817);
6198 }
6199
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006200 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006201 alc_write_coef_idx(codec, 0xf, 0x960b);
6202 alc_write_coef_idx(codec, 0xe, 0x8814);
6203 }
6204
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006205 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006206 val = alc_read_coef_idx(codec, 0x04);
6207 /* Power up output pin */
6208 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6209 }
6210
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006211 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006212 val = alc_read_coef_idx(codec, 0xd);
6213 if ((val & 0x0c00) >> 10 != 0x1) {
6214 /* Capless ramp up clock control */
6215 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6216 }
6217 val = alc_read_coef_idx(codec, 0x17);
6218 if ((val & 0x01c0) >> 6 != 0x4) {
6219 /* Class D power on reset */
6220 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6221 }
6222 }
6223
6224 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6225 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6226
6227 val = alc_read_coef_idx(codec, 0x4); /* HP */
6228 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6229
6230 return 0;
6231}
6232
6233/*
6234 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006235static int patch_alc269(struct hda_codec *codec)
6236{
6237 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006238 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006239
6240 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6241 if (spec == NULL)
6242 return -ENOMEM;
6243
6244 codec->spec = spec;
6245
6246 spec->mixer_nid = 0x0b;
6247
6248 alc_auto_parse_customize_define(codec);
6249
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006250 err = alc_codec_rename_from_preset(codec);
6251 if (err < 0)
6252 goto error;
6253
Takashi Iwai1d045db2011-07-07 18:23:21 +02006254 if (codec->vendor_id == 0x10ec0269) {
6255 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006256 switch (alc_get_coef0(codec) & 0x00f0) {
6257 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006258 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006259 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006260 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006261 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006262 break;
6263 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006264 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6265 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006266 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006267 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006268 break;
6269 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006270 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006271 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006272 if (err < 0)
6273 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006274 alc269_fill_coef(codec);
6275 }
6276
Takashi Iwaia4297b52011-08-23 18:40:12 +02006277 alc_pick_fixup(codec, alc269_fixup_models,
6278 alc269_fixup_tbl, alc269_fixups);
6279 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006280
Takashi Iwaia4297b52011-08-23 18:40:12 +02006281 /* automatic parse from the BIOS config */
6282 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006283 if (err < 0)
6284 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006285
Takashi Iwai60a6a842011-07-27 14:01:24 +02006286 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006287 alc_auto_fill_adc_caps(codec);
6288 alc_rebuild_imux_for_auto_mic(codec);
6289 alc_remove_invalid_adc_nids(codec);
6290 }
6291
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006292 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006293 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006294
6295 if (!spec->no_analog && has_cdefine_beep(codec)) {
6296 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006297 if (err < 0)
6298 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006300 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006301
Takashi Iwai1d045db2011-07-07 18:23:21 +02006302 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006303#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006304 codec->patch_ops.resume = alc269_resume;
6305#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02006306 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006307 spec->shutup = alc269_shutup;
6308
Takashi Iwai1d045db2011-07-07 18:23:21 +02006309#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai1d045db2011-07-07 18:23:21 +02006310 if (alc269_mic2_for_mute_led(codec))
6311 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
6312#endif
6313
Takashi Iwai589876e2012-02-20 15:47:55 +01006314 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6315
Takashi Iwai1d045db2011-07-07 18:23:21 +02006316 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006317
6318 error:
6319 alc_free(codec);
6320 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006321}
6322
6323/*
6324 * ALC861
6325 */
6326
Takashi Iwai1d045db2011-07-07 18:23:21 +02006327static int alc861_parse_auto_config(struct hda_codec *codec)
6328{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006329 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006330 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6331 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006332}
6333
Takashi Iwai1d045db2011-07-07 18:23:21 +02006334/* Pin config fixes */
6335enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006336 ALC861_FIXUP_FSC_AMILO_PI1505,
6337 ALC861_FIXUP_AMP_VREF_0F,
6338 ALC861_FIXUP_NO_JACK_DETECT,
6339 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006340};
6341
Takashi Iwai31150f22012-01-30 10:54:08 +01006342/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6343static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6344 const struct alc_fixup *fix, int action)
6345{
6346 struct alc_spec *spec = codec->spec;
6347 unsigned int val;
6348
6349 if (action != ALC_FIXUP_ACT_INIT)
6350 return;
6351 val = snd_hda_codec_read(codec, 0x0f, 0,
6352 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6353 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6354 val |= AC_PINCTL_IN_EN;
6355 val |= AC_PINCTL_VREF_50;
6356 snd_hda_codec_write(codec, 0x0f, 0,
6357 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6358 spec->keep_vref_in_automute = 1;
6359}
6360
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006361/* suppress the jack-detection */
6362static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6363 const struct alc_fixup *fix, int action)
6364{
6365 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6366 codec->no_jack_detect = 1;
6367}
6368
Takashi Iwai1d045db2011-07-07 18:23:21 +02006369static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006370 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006371 .type = ALC_FIXUP_PINS,
6372 .v.pins = (const struct alc_pincfg[]) {
6373 { 0x0b, 0x0221101f }, /* HP */
6374 { 0x0f, 0x90170310 }, /* speaker */
6375 { }
6376 }
6377 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006378 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006379 .type = ALC_FIXUP_FUNC,
6380 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006381 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006382 [ALC861_FIXUP_NO_JACK_DETECT] = {
6383 .type = ALC_FIXUP_FUNC,
6384 .v.func = alc_fixup_no_jack_detect,
6385 },
6386 [ALC861_FIXUP_ASUS_A6RP] = {
6387 .type = ALC_FIXUP_FUNC,
6388 .v.func = alc861_fixup_asus_amp_vref_0f,
6389 .chained = true,
6390 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6391 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006392};
6393
6394static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006395 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6396 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6397 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6398 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6399 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6400 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006401 {}
6402};
6403
6404/*
6405 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006406static int patch_alc861(struct hda_codec *codec)
6407{
6408 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006409 int err;
6410
6411 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6412 if (spec == NULL)
6413 return -ENOMEM;
6414
6415 codec->spec = spec;
6416
6417 spec->mixer_nid = 0x15;
6418
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006419 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6420 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006421
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006422 /* automatic parse from the BIOS config */
6423 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006424 if (err < 0)
6425 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006426
Takashi Iwai60a6a842011-07-27 14:01:24 +02006427 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006428 alc_auto_fill_adc_caps(codec);
6429 alc_rebuild_imux_for_auto_mic(codec);
6430 alc_remove_invalid_adc_nids(codec);
6431 }
6432
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006433 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006434 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006435
6436 if (!spec->no_analog) {
6437 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006438 if (err < 0)
6439 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006440 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6441 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006442
Takashi Iwai1d045db2011-07-07 18:23:21 +02006443 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006444 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006445#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006446 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006447#endif
6448
Takashi Iwai589876e2012-02-20 15:47:55 +01006449 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6450
Takashi Iwai1d045db2011-07-07 18:23:21 +02006451 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006452
6453 error:
6454 alc_free(codec);
6455 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006456}
6457
6458/*
6459 * ALC861-VD support
6460 *
6461 * Based on ALC882
6462 *
6463 * In addition, an independent DAC
6464 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006465static int alc861vd_parse_auto_config(struct hda_codec *codec)
6466{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006467 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006468 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6469 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006470}
6471
Takashi Iwai1d045db2011-07-07 18:23:21 +02006472enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006473 ALC660VD_FIX_ASUS_GPIO1,
6474 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006475};
6476
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006477/* exclude VREF80 */
6478static void alc861vd_fixup_dallas(struct hda_codec *codec,
6479 const struct alc_fixup *fix, int action)
6480{
6481 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6482 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6483 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6484 }
6485}
6486
Takashi Iwai1d045db2011-07-07 18:23:21 +02006487static const struct alc_fixup alc861vd_fixups[] = {
6488 [ALC660VD_FIX_ASUS_GPIO1] = {
6489 .type = ALC_FIXUP_VERBS,
6490 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006491 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006492 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6493 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6494 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6495 { }
6496 }
6497 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006498 [ALC861VD_FIX_DALLAS] = {
6499 .type = ALC_FIXUP_FUNC,
6500 .v.func = alc861vd_fixup_dallas,
6501 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006502};
6503
6504static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006505 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006506 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006507 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006508 {}
6509};
6510
6511static const struct hda_verb alc660vd_eapd_verbs[] = {
6512 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6513 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6514 { }
6515};
6516
6517/*
6518 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006519static int patch_alc861vd(struct hda_codec *codec)
6520{
6521 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006522 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006523
6524 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6525 if (spec == NULL)
6526 return -ENOMEM;
6527
6528 codec->spec = spec;
6529
6530 spec->mixer_nid = 0x0b;
6531
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006532 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6533 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006534
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006535 /* automatic parse from the BIOS config */
6536 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006537 if (err < 0)
6538 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006539
Takashi Iwai1d045db2011-07-07 18:23:21 +02006540 if (codec->vendor_id == 0x10ec0660) {
6541 /* always turn on EAPD */
6542 add_verb(spec, alc660vd_eapd_verbs);
6543 }
6544
Takashi Iwai60a6a842011-07-27 14:01:24 +02006545 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006546 alc_auto_fill_adc_caps(codec);
6547 alc_rebuild_imux_for_auto_mic(codec);
6548 alc_remove_invalid_adc_nids(codec);
6549 }
6550
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006551 if (!spec->no_analog && !spec->cap_mixer)
6552 set_capture_mixer(codec);
6553
6554 if (!spec->no_analog) {
6555 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006556 if (err < 0)
6557 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006558 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6559 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006560
Takashi Iwai1d045db2011-07-07 18:23:21 +02006561 codec->patch_ops = alc_patch_ops;
6562
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006563 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006564 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006565
Takashi Iwai589876e2012-02-20 15:47:55 +01006566 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6567
Takashi Iwai1d045db2011-07-07 18:23:21 +02006568 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006569
6570 error:
6571 alc_free(codec);
6572 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006573}
6574
6575/*
6576 * ALC662 support
6577 *
6578 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6579 * configuration. Each pin widget can choose any input DACs and a mixer.
6580 * Each ADC is connected from a mixer of all inputs. This makes possible
6581 * 6-channel independent captures.
6582 *
6583 * In addition, an independent DAC for the multi-playback (not used in this
6584 * driver yet).
6585 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006586
6587/*
6588 * BIOS auto configuration
6589 */
6590
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006591static int alc662_parse_auto_config(struct hda_codec *codec)
6592{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006593 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006594 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6595 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6596 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006597
Kailang Yang6227cdc2010-02-25 08:36:52 +01006598 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6599 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006600 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006601 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006602 ssids = alc662_ssids;
6603 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006604}
6605
Todd Broch6be79482010-12-07 16:51:05 -08006606static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006607 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006608{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006609 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006610 return;
Todd Broch6be79482010-12-07 16:51:05 -08006611 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6612 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6613 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6614 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6615 (0 << AC_AMPCAP_MUTE_SHIFT)))
6616 printk(KERN_WARNING
6617 "hda_codec: failed to override amp caps for NID 0x2\n");
6618}
6619
David Henningsson6cb3b702010-09-09 08:51:44 +02006620enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006621 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006622 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006623 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006624 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006625 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006626 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006627 ALC662_FIXUP_ASUS_MODE1,
6628 ALC662_FIXUP_ASUS_MODE2,
6629 ALC662_FIXUP_ASUS_MODE3,
6630 ALC662_FIXUP_ASUS_MODE4,
6631 ALC662_FIXUP_ASUS_MODE5,
6632 ALC662_FIXUP_ASUS_MODE6,
6633 ALC662_FIXUP_ASUS_MODE7,
6634 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006635 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006636};
6637
6638static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006639 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006640 .type = ALC_FIXUP_PINS,
6641 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006642 { 0x15, 0x99130112 }, /* subwoofer */
6643 { }
6644 }
6645 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006646 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006647 .type = ALC_FIXUP_PINS,
6648 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006649 { 0x17, 0x99130112 }, /* subwoofer */
6650 { }
6651 }
6652 },
Todd Broch6be79482010-12-07 16:51:05 -08006653 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006654 .type = ALC_FIXUP_FUNC,
6655 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006656 },
6657 [ALC662_FIXUP_CZC_P10T] = {
6658 .type = ALC_FIXUP_VERBS,
6659 .v.verbs = (const struct hda_verb[]) {
6660 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6661 {}
6662 }
6663 },
David Henningsson94024cd2011-04-29 14:10:55 +02006664 [ALC662_FIXUP_SKU_IGNORE] = {
6665 .type = ALC_FIXUP_SKU,
6666 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006667 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006668 [ALC662_FIXUP_HP_RP5800] = {
6669 .type = ALC_FIXUP_PINS,
6670 .v.pins = (const struct alc_pincfg[]) {
6671 { 0x14, 0x0221201f }, /* HP out */
6672 { }
6673 },
6674 .chained = true,
6675 .chain_id = ALC662_FIXUP_SKU_IGNORE
6676 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006677 [ALC662_FIXUP_ASUS_MODE1] = {
6678 .type = ALC_FIXUP_PINS,
6679 .v.pins = (const struct alc_pincfg[]) {
6680 { 0x14, 0x99130110 }, /* speaker */
6681 { 0x18, 0x01a19c20 }, /* mic */
6682 { 0x19, 0x99a3092f }, /* int-mic */
6683 { 0x21, 0x0121401f }, /* HP out */
6684 { }
6685 },
6686 .chained = true,
6687 .chain_id = ALC662_FIXUP_SKU_IGNORE
6688 },
6689 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006690 .type = ALC_FIXUP_PINS,
6691 .v.pins = (const struct alc_pincfg[]) {
6692 { 0x14, 0x99130110 }, /* speaker */
6693 { 0x18, 0x01a19820 }, /* mic */
6694 { 0x19, 0x99a3092f }, /* int-mic */
6695 { 0x1b, 0x0121401f }, /* HP out */
6696 { }
6697 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006698 .chained = true,
6699 .chain_id = ALC662_FIXUP_SKU_IGNORE
6700 },
6701 [ALC662_FIXUP_ASUS_MODE3] = {
6702 .type = ALC_FIXUP_PINS,
6703 .v.pins = (const struct alc_pincfg[]) {
6704 { 0x14, 0x99130110 }, /* speaker */
6705 { 0x15, 0x0121441f }, /* HP */
6706 { 0x18, 0x01a19840 }, /* mic */
6707 { 0x19, 0x99a3094f }, /* int-mic */
6708 { 0x21, 0x01211420 }, /* HP2 */
6709 { }
6710 },
6711 .chained = true,
6712 .chain_id = ALC662_FIXUP_SKU_IGNORE
6713 },
6714 [ALC662_FIXUP_ASUS_MODE4] = {
6715 .type = ALC_FIXUP_PINS,
6716 .v.pins = (const struct alc_pincfg[]) {
6717 { 0x14, 0x99130110 }, /* speaker */
6718 { 0x16, 0x99130111 }, /* speaker */
6719 { 0x18, 0x01a19840 }, /* mic */
6720 { 0x19, 0x99a3094f }, /* int-mic */
6721 { 0x21, 0x0121441f }, /* HP */
6722 { }
6723 },
6724 .chained = true,
6725 .chain_id = ALC662_FIXUP_SKU_IGNORE
6726 },
6727 [ALC662_FIXUP_ASUS_MODE5] = {
6728 .type = ALC_FIXUP_PINS,
6729 .v.pins = (const struct alc_pincfg[]) {
6730 { 0x14, 0x99130110 }, /* speaker */
6731 { 0x15, 0x0121441f }, /* HP */
6732 { 0x16, 0x99130111 }, /* speaker */
6733 { 0x18, 0x01a19840 }, /* mic */
6734 { 0x19, 0x99a3094f }, /* int-mic */
6735 { }
6736 },
6737 .chained = true,
6738 .chain_id = ALC662_FIXUP_SKU_IGNORE
6739 },
6740 [ALC662_FIXUP_ASUS_MODE6] = {
6741 .type = ALC_FIXUP_PINS,
6742 .v.pins = (const struct alc_pincfg[]) {
6743 { 0x14, 0x99130110 }, /* speaker */
6744 { 0x15, 0x01211420 }, /* HP2 */
6745 { 0x18, 0x01a19840 }, /* mic */
6746 { 0x19, 0x99a3094f }, /* int-mic */
6747 { 0x1b, 0x0121441f }, /* HP */
6748 { }
6749 },
6750 .chained = true,
6751 .chain_id = ALC662_FIXUP_SKU_IGNORE
6752 },
6753 [ALC662_FIXUP_ASUS_MODE7] = {
6754 .type = ALC_FIXUP_PINS,
6755 .v.pins = (const struct alc_pincfg[]) {
6756 { 0x14, 0x99130110 }, /* speaker */
6757 { 0x17, 0x99130111 }, /* speaker */
6758 { 0x18, 0x01a19840 }, /* mic */
6759 { 0x19, 0x99a3094f }, /* int-mic */
6760 { 0x1b, 0x01214020 }, /* HP */
6761 { 0x21, 0x0121401f }, /* HP */
6762 { }
6763 },
6764 .chained = true,
6765 .chain_id = ALC662_FIXUP_SKU_IGNORE
6766 },
6767 [ALC662_FIXUP_ASUS_MODE8] = {
6768 .type = ALC_FIXUP_PINS,
6769 .v.pins = (const struct alc_pincfg[]) {
6770 { 0x14, 0x99130110 }, /* speaker */
6771 { 0x12, 0x99a30970 }, /* int-mic */
6772 { 0x15, 0x01214020 }, /* HP */
6773 { 0x17, 0x99130111 }, /* speaker */
6774 { 0x18, 0x01a19840 }, /* mic */
6775 { 0x21, 0x0121401f }, /* HP */
6776 { }
6777 },
6778 .chained = true,
6779 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006780 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006781 [ALC662_FIXUP_NO_JACK_DETECT] = {
6782 .type = ALC_FIXUP_FUNC,
6783 .v.func = alc_fixup_no_jack_detect,
6784 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006785};
6786
Takashi Iwaia9111322011-05-02 11:30:18 +02006787static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006788 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006789 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006790 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006791 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006792 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006793 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006794 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006795 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006796 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006797 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006798 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006799
6800#if 0
6801 /* Below is a quirk table taken from the old code.
6802 * Basically the device should work as is without the fixup table.
6803 * If BIOS doesn't give a proper info, enable the corresponding
6804 * fixup entry.
6805 */
6806 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6807 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6808 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6809 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6810 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6811 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6812 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6813 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6814 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6815 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6816 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6817 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6818 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6819 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6820 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6821 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6822 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6823 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6824 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6825 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6826 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6827 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6828 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6829 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6830 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6831 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6832 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6833 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6834 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6835 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6836 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6837 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6838 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6839 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6840 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6841 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6842 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6843 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6844 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6845 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6846 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6847 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6848 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6849 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6850 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6851 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6852 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6853 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6854 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6855 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6856#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006857 {}
6858};
6859
Todd Broch6be79482010-12-07 16:51:05 -08006860static const struct alc_model_fixup alc662_fixup_models[] = {
6861 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006862 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6863 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6864 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6865 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6866 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6867 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6868 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6869 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006870 {}
6871};
David Henningsson6cb3b702010-09-09 08:51:44 +02006872
6873
Takashi Iwai1d045db2011-07-07 18:23:21 +02006874/*
6875 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006876static int patch_alc662(struct hda_codec *codec)
6877{
6878 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006879 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006880
6881 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6882 if (!spec)
6883 return -ENOMEM;
6884
6885 codec->spec = spec;
6886
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006887 spec->mixer_nid = 0x0b;
6888
Takashi Iwai53c334a2011-08-23 18:27:14 +02006889 /* handle multiple HPs as is */
6890 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6891
Kailang Yangda00c242010-03-19 11:23:45 +01006892 alc_auto_parse_customize_define(codec);
6893
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006894 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6895
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006896 err = alc_codec_rename_from_preset(codec);
6897 if (err < 0)
6898 goto error;
6899
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006900 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006901 codec->bus->pci->subsystem_vendor == 0x1025 &&
6902 spec->cdefine.platform_type == 1) {
6903 if (alc_codec_rename(codec, "ALC272X") < 0)
6904 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006905 }
Kailang Yang274693f2009-12-03 10:07:50 +01006906
Takashi Iwaib9c51062011-08-24 18:08:07 +02006907 alc_pick_fixup(codec, alc662_fixup_models,
6908 alc662_fixup_tbl, alc662_fixups);
6909 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6910 /* automatic parse from the BIOS config */
6911 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006912 if (err < 0)
6913 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006914
Takashi Iwai60a6a842011-07-27 14:01:24 +02006915 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006916 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006917 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006918 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006919 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006920
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006921 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006922 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006923
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006924 if (!spec->no_analog && has_cdefine_beep(codec)) {
6925 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006926 if (err < 0)
6927 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006928 switch (codec->vendor_id) {
6929 case 0x10ec0662:
6930 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6931 break;
6932 case 0x10ec0272:
6933 case 0x10ec0663:
6934 case 0x10ec0665:
6935 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6936 break;
6937 case 0x10ec0273:
6938 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6939 break;
6940 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006941 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006942
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006943 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006944 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c7161532011-04-07 10:37:16 +02006945 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006946
Takashi Iwai589876e2012-02-20 15:47:55 +01006947 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6948
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006949 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006950
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006951 error:
6952 alc_free(codec);
6953 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006954}
6955
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006956/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006957 * ALC680 support
6958 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006959
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006960static int alc680_parse_auto_config(struct hda_codec *codec)
6961{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006962 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006963}
6964
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006965/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006966 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006967static int patch_alc680(struct hda_codec *codec)
6968{
6969 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006970 int err;
6971
6972 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6973 if (spec == NULL)
6974 return -ENOMEM;
6975
6976 codec->spec = spec;
6977
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006978 /* ALC680 has no aa-loopback mixer */
6979
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006980 /* automatic parse from the BIOS config */
6981 err = alc680_parse_auto_config(codec);
6982 if (err < 0) {
6983 alc_free(codec);
6984 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006985 }
6986
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006987 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006988 set_capture_mixer(codec);
6989
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006990 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006991 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006992
6993 return 0;
6994}
6995
6996/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006997 * patch entries
6998 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006999static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007000 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007001 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007002 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007003 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007004 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007005 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007006 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007007 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007008 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007009 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007010 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007011 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007012 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7013 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7014 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007015 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007016 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007017 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7018 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007019 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7020 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007021 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007022 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007023 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007024 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007025 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007026 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007027 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007028 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007029 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007030 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007031 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007032 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007033 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007034 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007035 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007036 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007037 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007038 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007039 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040 {} /* terminator */
7041};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007042
7043MODULE_ALIAS("snd-hda-codec-id:10ec*");
7044
7045MODULE_LICENSE("GPL");
7046MODULE_DESCRIPTION("Realtek HD-audio codec");
7047
7048static struct hda_codec_preset_list realtek_list = {
7049 .preset = snd_hda_preset_realtek,
7050 .owner = THIS_MODULE,
7051};
7052
7053static int __init patch_realtek_init(void)
7054{
7055 return snd_hda_add_codec_preset(&realtek_list);
7056}
7057
7058static void __exit patch_realtek_exit(void)
7059{
7060 snd_hda_delete_codec_preset(&realtek_list);
7061}
7062
7063module_init(patch_realtek_init)
7064module_exit(patch_realtek_exit)