blob: e5c04593d360f78be44ff8295d342054a43320e0 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e42006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Takashi Iwaic14c95f2012-02-16 16:38:07 +010083#define MAX_VOL_NIDS 0x40
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085struct alc_spec {
86 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020089 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010090 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Takashi Iwai2d9c6482009-10-13 08:06:55 +020092 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020093 * don't forget NULL
94 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020095 */
96 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Takashi Iwaiaa563af2009-07-31 10:05:11 +020098 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020099 const struct hda_pcm_stream *stream_analog_playback;
100 const struct hda_pcm_stream *stream_analog_capture;
101 const struct hda_pcm_stream *stream_analog_alt_playback;
102 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200104 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200105 const struct hda_pcm_stream *stream_digital_playback;
106 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200109 struct hda_multi_out multiout; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
112 */
Takashi Iwai63300792008-01-24 15:31:36 +0100113 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100114 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100115 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 /* capture */
118 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200119 const hda_nid_t *adc_nids;
120 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200121 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200122 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwaic14c95f2012-02-16 16:38:07 +0100123 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
124 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Takashi Iwai840b64c2010-07-13 22:49:01 +0200126 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200127 hda_nid_t cur_adc;
128 unsigned int cur_adc_stream_tag;
129 unsigned int cur_adc_format;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200132 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 const struct hda_input_mux *input_mux;
134 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200135 hda_nid_t ext_mic_pin;
136 hda_nid_t dock_mic_pin;
137 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100140 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200142 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200143 int const_channel_count;
144 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100147 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200148
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100151 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200152 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200153 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200154 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai49535502009-06-30 15:28:30 +0200155 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
156 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200157 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
158 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
159 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100160
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100161 /* hooks */
162 void (*init_hook)(struct hda_codec *codec);
163 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500165 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100166#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200167 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200168 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100169
Takashi Iwai834be882006-03-01 14:16:17 +0100170 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200171 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200172 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200173 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200174 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200175 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200176 unsigned int automute_speaker:1; /* automute speaker outputs */
177 unsigned int automute_lo:1; /* automute LO outputs */
178 unsigned int detect_hp:1; /* Headphone detection enabled */
179 unsigned int detect_lo:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100182 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200183
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100184 /* other flags */
185 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200186 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100187 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200188 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200189 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100190 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200191
192 /* auto-mute control */
193 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200194 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200195
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200196 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200197 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100198
Takashi Iwai2134ea42008-01-10 16:53:55 +0100199 /* for virtual master */
200 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200201#ifdef CONFIG_SND_HDA_POWER_SAVE
202 struct hda_loopback_check loopback;
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 Iwaia9fd4f32009-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 Iwaia9fd4f32009-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 Iwaia9fd4f32009-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 Iwaia9fd4f32009-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 Iwai1c716152011-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 Iwaic8b6bf9b2005-11-17 14:57:47 +01002140 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
2142 struct alc_spec *spec = codec->spec;
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 Iwaic8b6bf9b2005-11-17 14:57:47 +01002151 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152{
2153 struct alc_spec *spec = codec->spec;
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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwaic8b6bf9b2005-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 Iwai1c716152011-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 Iwai1c716152011-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 Iwaic8b6bf9b2005-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 */
3356 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, 1);
3357 if (err < 0)
3358 return err;
3359 badness += err;
3360 }
3361
3362 if (spec->multi_ios == 2) {
3363 for (i = 0; i < 2; i++)
3364 spec->private_dac_nids[spec->multiout.num_dacs++] =
3365 spec->multi_io[i].dac;
3366 spec->ext_channel_count = 2;
3367 } else if (spec->multi_ios) {
3368 spec->multi_ios = 0;
3369 badness += BAD_MULTI_IO;
3370 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003371
3372 return badness;
3373}
3374
3375#define DEBUG_BADNESS
3376
3377#ifdef DEBUG_BADNESS
3378#define debug_badness snd_printdd
3379#else
3380#define debug_badness(...)
3381#endif
3382
3383static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3384{
3385 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3386 cfg->line_out_pins[0], cfg->line_out_pins[1],
3387 cfg->line_out_pins[2], cfg->line_out_pins[2],
3388 spec->multiout.dac_nids[0],
3389 spec->multiout.dac_nids[1],
3390 spec->multiout.dac_nids[2],
3391 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003392 if (spec->multi_ios > 0)
3393 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3394 spec->multi_ios,
3395 spec->multi_io[0].pin, spec->multi_io[1].pin,
3396 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003397 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3398 cfg->hp_pins[0], cfg->hp_pins[1],
3399 cfg->hp_pins[2], cfg->hp_pins[2],
3400 spec->multiout.hp_out_nid[0],
3401 spec->multiout.hp_out_nid[1],
3402 spec->multiout.hp_out_nid[2],
3403 spec->multiout.hp_out_nid[3]);
3404 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3405 cfg->speaker_pins[0], cfg->speaker_pins[1],
3406 cfg->speaker_pins[2], cfg->speaker_pins[3],
3407 spec->multiout.extra_out_nid[0],
3408 spec->multiout.extra_out_nid[1],
3409 spec->multiout.extra_out_nid[2],
3410 spec->multiout.extra_out_nid[3]);
3411}
3412
3413static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3414{
3415 struct alc_spec *spec = codec->spec;
3416 struct auto_pin_cfg *cfg = &spec->autocfg;
3417 struct auto_pin_cfg *best_cfg;
3418 int best_badness = INT_MAX;
3419 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003420 bool fill_hardwired = true, fill_mio_first = true;
3421 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003422 bool hp_spk_swapped = false;
3423
3424 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3425 if (!best_cfg)
3426 return -ENOMEM;
3427 *best_cfg = *cfg;
3428
3429 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003430 badness = fill_and_eval_dacs(codec, fill_hardwired,
3431 fill_mio_first);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003432 if (badness < 0)
3433 return badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003434 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3435 cfg->line_out_type, fill_hardwired, fill_mio_first,
3436 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003437 debug_show_configs(spec, cfg);
3438 if (badness < best_badness) {
3439 best_badness = badness;
3440 *best_cfg = *cfg;
3441 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003442 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003443 }
3444 if (!badness)
3445 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003446 fill_mio_first = !fill_mio_first;
3447 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003448 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003449 fill_hardwired = !fill_hardwired;
3450 if (!fill_hardwired)
3451 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003452 if (hp_spk_swapped)
3453 break;
3454 hp_spk_swapped = true;
3455 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003456 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3457 cfg->hp_outs = cfg->line_outs;
3458 memcpy(cfg->hp_pins, cfg->line_out_pins,
3459 sizeof(cfg->hp_pins));
3460 cfg->line_outs = cfg->speaker_outs;
3461 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3462 sizeof(cfg->speaker_pins));
3463 cfg->speaker_outs = 0;
3464 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3465 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003466 fill_hardwired = true;
3467 continue;
3468 }
3469 if (cfg->hp_outs > 0 &&
3470 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3471 cfg->speaker_outs = cfg->line_outs;
3472 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3473 sizeof(cfg->speaker_pins));
3474 cfg->line_outs = cfg->hp_outs;
3475 memcpy(cfg->line_out_pins, cfg->hp_pins,
3476 sizeof(cfg->hp_pins));
3477 cfg->hp_outs = 0;
3478 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3479 cfg->line_out_type = AUTO_PIN_HP_OUT;
3480 fill_hardwired = true;
3481 continue;
3482 }
3483 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003484 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003485
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003486 if (badness) {
3487 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003488 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003489 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003490 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3491 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003492 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003493
David Henningssonfde48a12011-12-09 18:27:42 +08003494 if (cfg->line_out_pins[0])
3495 spec->vmaster_nid =
3496 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3497 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003498
3499 /* clear the bitmap flags for creating controls */
3500 clear_vol_marks(codec);
3501 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003502 return 0;
3503}
3504
Takashi Iwai343a04b2011-07-06 14:28:39 +02003505static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003506 const char *pfx, int cidx,
3507 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003508{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003509 struct alc_spec *spec = codec->spec;
3510 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003511 if (!nid)
3512 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003513 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3514 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3515 return 0;
3516 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003517 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003518 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003519}
3520
Takashi Iwaie29d3772011-11-14 17:13:23 +01003521static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3522 const char *pfx, int cidx,
3523 hda_nid_t nid)
3524{
3525 int chs = 1;
3526 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3527 chs = 3;
3528 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3529}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003530
3531/* create a mute-switch for the given mixer widget;
3532 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3533 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003534static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003535 const char *pfx, int cidx,
3536 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003537{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003538 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003539 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003540 int type;
3541 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003542 if (!nid)
3543 return 0;
3544 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3545 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3546 type = ALC_CTL_WIDGET_MUTE;
3547 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3548 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003549 type = ALC_CTL_WIDGET_MUTE;
3550 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3551 } else {
3552 type = ALC_CTL_BIND_MUTE;
3553 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3554 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003555 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3556 return 0;
3557 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003558 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003559}
3560
Takashi Iwaie29d3772011-11-14 17:13:23 +01003561static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3562 int cidx, hda_nid_t nid)
3563{
3564 int chs = 1;
3565 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3566 chs = 3;
3567 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3568}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003569
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003570static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3571 hda_nid_t pin, hda_nid_t dac)
3572{
3573 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3574 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3575 return pin;
3576 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3577 return mix;
3578 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3579 return dac;
3580 return 0;
3581}
3582
3583static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3584 hda_nid_t pin, hda_nid_t dac)
3585{
3586 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3587 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3588 return dac;
3589 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3590 return mix;
3591 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3592 return pin;
3593 return 0;
3594}
3595
Takashi Iwai7085ec12009-10-02 09:03:58 +02003596/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003597static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003598 const struct auto_pin_cfg *cfg)
3599{
3600 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003601 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003602
Takashi Iwaice764ab2011-04-27 16:35:23 +02003603 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003604 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003605 noutputs += spec->multi_ios;
3606
3607 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003608 const char *name;
3609 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003610 hda_nid_t dac, pin;
3611 hda_nid_t sw, vol;
3612
3613 dac = spec->multiout.dac_nids[i];
3614 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003615 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003616 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003617 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003618 index = 0;
3619 name = channel_name[i];
3620 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003621 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003622 name = alc_get_line_out_pfx(spec, i, true, &index);
3623 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003624
3625 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3626 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003627 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003628 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003629 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003630 if (err < 0)
3631 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003632 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003633 if (err < 0)
3634 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003635 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003636 if (err < 0)
3637 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003638 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003639 if (err < 0)
3640 return err;
3641 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003642 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003643 if (err < 0)
3644 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003645 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003646 if (err < 0)
3647 return err;
3648 }
3649 }
3650 return 0;
3651}
3652
Takashi Iwai343a04b2011-07-06 14:28:39 +02003653static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003654 hda_nid_t dac, const char *pfx,
3655 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003656{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003657 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003658 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003659 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003660
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003661 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003662 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003663 /* the corresponding DAC is already occupied */
3664 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3665 return 0; /* no way */
3666 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003667 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3668 if (is_ctl_used(spec->sw_ctls, val))
3669 return 0; /* already created */
3670 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003671 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003672 }
3673
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003674 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3675 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003676 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003677 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003678 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003679 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003680 if (err < 0)
3681 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003682 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003683}
3684
Takashi Iwai23c09b02011-08-19 09:05:35 +02003685static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3686 unsigned int nums,
3687 struct hda_ctl_ops *ops)
3688{
3689 struct alc_spec *spec = codec->spec;
3690 struct hda_bind_ctls **ctlp, *ctl;
3691 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3692 ctlp = snd_array_new(&spec->bind_ctls);
3693 if (!ctlp)
3694 return NULL;
3695 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3696 *ctlp = ctl;
3697 if (ctl)
3698 ctl->ops = ops;
3699 return ctl;
3700}
3701
3702/* add playback controls for speaker and HP outputs */
3703static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3704 const hda_nid_t *pins,
3705 const hda_nid_t *dacs,
3706 const char *pfx)
3707{
3708 struct alc_spec *spec = codec->spec;
3709 struct hda_bind_ctls *ctl;
3710 char name[32];
3711 int i, n, err;
3712
3713 if (!num_pins || !pins[0])
3714 return 0;
3715
Takashi Iwai527e4d72011-10-27 16:33:27 +02003716 if (num_pins == 1) {
3717 hda_nid_t dac = *dacs;
3718 if (!dac)
3719 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003720 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003721 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003722
Takashi Iwai23c09b02011-08-19 09:05:35 +02003723 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003724 hda_nid_t dac;
3725 if (dacs[num_pins - 1])
3726 dac = dacs[i]; /* with individual volumes */
3727 else
3728 dac = 0;
3729 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3730 err = alc_auto_create_extra_out(codec, pins[i], dac,
3731 "Bass Speaker", 0);
3732 } else if (num_pins >= 3) {
3733 snprintf(name, sizeof(name), "%s %s",
3734 pfx, channel_name[i]);
3735 err = alc_auto_create_extra_out(codec, pins[i], dac,
3736 name, 0);
3737 } else {
3738 err = alc_auto_create_extra_out(codec, pins[i], dac,
3739 pfx, i);
3740 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003741 if (err < 0)
3742 return err;
3743 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003744 if (dacs[num_pins - 1])
3745 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003746
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003747 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003748 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3749 if (!ctl)
3750 return -ENOMEM;
3751 n = 0;
3752 for (i = 0; i < num_pins; i++) {
3753 hda_nid_t vol;
3754 if (!pins[i] || !dacs[i])
3755 continue;
3756 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3757 if (vol)
3758 ctl->values[n++] =
3759 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3760 }
3761 if (n) {
3762 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3763 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3764 if (err < 0)
3765 return err;
3766 }
3767 return 0;
3768}
3769
Takashi Iwai343a04b2011-07-06 14:28:39 +02003770static int alc_auto_create_hp_out(struct hda_codec *codec)
3771{
3772 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003773 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3774 spec->autocfg.hp_pins,
3775 spec->multiout.hp_out_nid,
3776 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003777}
3778
3779static int alc_auto_create_speaker_out(struct hda_codec *codec)
3780{
3781 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003782 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3783 spec->autocfg.speaker_pins,
3784 spec->multiout.extra_out_nid,
3785 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003786}
3787
Takashi Iwai343a04b2011-07-06 14:28:39 +02003788static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003789 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003790 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003791{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003792 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003793 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003794 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003795
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003796 alc_set_pin_output(codec, pin, pin_type);
3797 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003798 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003799 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003800 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003801 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003802 mix = srcs[i];
3803 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003804 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003805 if (!mix)
3806 return;
3807
3808 /* need the manual connection? */
3809 if (num > 1)
3810 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3811 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003812 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3813 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003814 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003815 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003816 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003817 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003818 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003819 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3820 if (nid)
3821 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3822 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003823
3824 /* unmute DAC if it's not assigned to a mixer */
3825 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3826 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3827 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3828 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003829}
3830
Takashi Iwai343a04b2011-07-06 14:28:39 +02003831static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003832{
3833 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003834 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003835 int i;
3836
3837 for (i = 0; i <= HDA_SIDE; i++) {
3838 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3839 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003840 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003841 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003842 }
3843}
3844
Takashi Iwai343a04b2011-07-06 14:28:39 +02003845static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003846{
3847 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003848 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003849 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003850
David Henningsson636030e2011-10-12 19:26:03 +02003851 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003852 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3853 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003854 pin = spec->autocfg.hp_pins[i];
3855 if (!pin)
3856 break;
3857 dac = spec->multiout.hp_out_nid[i];
3858 if (!dac) {
3859 if (i > 0 && spec->multiout.hp_out_nid[0])
3860 dac = spec->multiout.hp_out_nid[0];
3861 else
3862 dac = spec->multiout.dac_nids[0];
3863 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003864 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3865 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003866 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003867 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3868 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003869 pin = spec->autocfg.speaker_pins[i];
3870 if (!pin)
3871 break;
3872 dac = spec->multiout.extra_out_nid[i];
3873 if (!dac) {
3874 if (i > 0 && spec->multiout.extra_out_nid[0])
3875 dac = spec->multiout.extra_out_nid[0];
3876 else
3877 dac = spec->multiout.dac_nids[0];
3878 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003879 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3880 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003881}
3882
Takashi Iwai276dd702012-02-17 16:17:03 +01003883/* check whether the given pin can be a multi-io pin */
3884static bool can_be_multiio_pin(struct hda_codec *codec,
3885 unsigned int location, hda_nid_t nid)
3886{
3887 unsigned int defcfg, caps;
3888
3889 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3890 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3891 return false;
3892 if (location && get_defcfg_location(defcfg) != location)
3893 return false;
3894 caps = snd_hda_query_pin_caps(codec, nid);
3895 if (!(caps & AC_PINCAP_OUT))
3896 return false;
3897 return true;
3898}
3899
Takashi Iwaice764ab2011-04-27 16:35:23 +02003900/*
3901 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003902 *
3903 * When hardwired is set, try to fill ony hardwired pins, and returns
3904 * zero if any pins are filled, non-zero if nothing found.
3905 * When hardwired is off, try to fill possible input pins, and returns
3906 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003907 */
3908static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003909 hda_nid_t reference_pin,
3910 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003911{
3912 struct alc_spec *spec = codec->spec;
3913 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003914 int type, i, j, dacs, num_pins, old_pins;
3915 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3916 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003917 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003918
Takashi Iwai276dd702012-02-17 16:17:03 +01003919 old_pins = spec->multi_ios;
3920 if (old_pins >= 2)
3921 goto end_fill;
3922
3923 num_pins = 0;
3924 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3925 for (i = 0; i < cfg->num_inputs; i++) {
3926 if (cfg->inputs[i].type != type)
3927 continue;
3928 if (can_be_multiio_pin(codec, location,
3929 cfg->inputs[i].pin))
3930 num_pins++;
3931 }
3932 }
3933 if (num_pins < 2)
3934 goto end_fill;
3935
Takashi Iwai07b18f62011-11-10 15:42:54 +01003936 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003937 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3938 for (i = 0; i < cfg->num_inputs; i++) {
3939 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003940 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003941
Takashi Iwaice764ab2011-04-27 16:35:23 +02003942 if (cfg->inputs[i].type != type)
3943 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003944 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003945 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003946 for (j = 0; j < spec->multi_ios; j++) {
3947 if (nid == spec->multi_io[j].pin)
3948 break;
3949 }
3950 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003951 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003952
3953 if (offset && offset + spec->multi_ios < dacs) {
3954 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003955 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3956 dac = 0;
3957 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003958 if (hardwired)
3959 dac = get_dac_if_single(codec, nid);
3960 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003961 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003962 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003963 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003964 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003965 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003966 spec->multi_io[spec->multi_ios].pin = nid;
3967 spec->multi_io[spec->multi_ios].dac = dac;
3968 spec->multi_ios++;
3969 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003970 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003971 }
3972 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003973 end_fill:
3974 if (badness)
3975 badness = BAD_MULTI_IO;
3976 if (old_pins == spec->multi_ios) {
3977 if (hardwired)
3978 return 1; /* nothing found */
3979 else
3980 return badness; /* no badness if nothing found */
3981 }
3982 if (!hardwired && spec->multi_ios < 2) {
3983 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003984 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003985 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003986
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003987 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003988}
3989
3990static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3991 struct snd_ctl_elem_info *uinfo)
3992{
3993 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3994 struct alc_spec *spec = codec->spec;
3995
3996 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3997 uinfo->count = 1;
3998 uinfo->value.enumerated.items = spec->multi_ios + 1;
3999 if (uinfo->value.enumerated.item > spec->multi_ios)
4000 uinfo->value.enumerated.item = spec->multi_ios;
4001 sprintf(uinfo->value.enumerated.name, "%dch",
4002 (uinfo->value.enumerated.item + 1) * 2);
4003 return 0;
4004}
4005
4006static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4007 struct snd_ctl_elem_value *ucontrol)
4008{
4009 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4010 struct alc_spec *spec = codec->spec;
4011 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4012 return 0;
4013}
4014
4015static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4016{
4017 struct alc_spec *spec = codec->spec;
4018 hda_nid_t nid = spec->multi_io[idx].pin;
4019
4020 if (!spec->multi_io[idx].ctl_in)
4021 spec->multi_io[idx].ctl_in =
4022 snd_hda_codec_read(codec, nid, 0,
4023 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4024 if (output) {
4025 snd_hda_codec_update_cache(codec, nid, 0,
4026 AC_VERB_SET_PIN_WIDGET_CONTROL,
4027 PIN_OUT);
4028 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4029 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4030 HDA_AMP_MUTE, 0);
4031 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
4032 } else {
4033 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4034 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4035 HDA_AMP_MUTE, HDA_AMP_MUTE);
4036 snd_hda_codec_update_cache(codec, nid, 0,
4037 AC_VERB_SET_PIN_WIDGET_CONTROL,
4038 spec->multi_io[idx].ctl_in);
4039 }
4040 return 0;
4041}
4042
4043static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4044 struct snd_ctl_elem_value *ucontrol)
4045{
4046 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4047 struct alc_spec *spec = codec->spec;
4048 int i, ch;
4049
4050 ch = ucontrol->value.enumerated.item[0];
4051 if (ch < 0 || ch > spec->multi_ios)
4052 return -EINVAL;
4053 if (ch == (spec->ext_channel_count - 1) / 2)
4054 return 0;
4055 spec->ext_channel_count = (ch + 1) * 2;
4056 for (i = 0; i < spec->multi_ios; i++)
4057 alc_set_multi_io(codec, i, i < ch);
4058 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004059 if (spec->need_dac_fix && !spec->const_channel_count)
4060 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004061 return 1;
4062}
4063
Takashi Iwaia9111322011-05-02 11:30:18 +02004064static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004065 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4066 .name = "Channel Mode",
4067 .info = alc_auto_ch_mode_info,
4068 .get = alc_auto_ch_mode_get,
4069 .put = alc_auto_ch_mode_put,
4070};
4071
Takashi Iwai23c09b02011-08-19 09:05:35 +02004072static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004073{
4074 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004075
Takashi Iwaic2674682011-08-24 17:57:44 +02004076 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004077 struct snd_kcontrol_new *knew;
4078
4079 knew = alc_kcontrol_new(spec);
4080 if (!knew)
4081 return -ENOMEM;
4082 *knew = alc_auto_channel_mode_enum;
4083 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4084 if (!knew->name)
4085 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004086 }
4087 return 0;
4088}
4089
Takashi Iwai1d045db2011-07-07 18:23:21 +02004090/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4091 * active input pins
4092 */
4093static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4094{
4095 struct alc_spec *spec = codec->spec;
4096 const struct hda_input_mux *imux;
4097 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4098 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4099 int i, n, nums;
4100
4101 imux = spec->input_mux;
4102 if (!imux)
4103 return;
4104 if (spec->dyn_adc_switch)
4105 return;
4106
4107 nums = 0;
4108 for (n = 0; n < spec->num_adc_nids; n++) {
4109 hda_nid_t cap = spec->private_capsrc_nids[n];
4110 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4111 for (i = 0; i < imux->num_items; i++) {
4112 hda_nid_t pin = spec->imux_pins[i];
4113 if (pin) {
4114 if (get_connection_index(codec, cap, pin) < 0)
4115 break;
4116 } else if (num_conns <= imux->items[i].index)
4117 break;
4118 }
4119 if (i >= imux->num_items) {
4120 adc_nids[nums] = spec->private_adc_nids[n];
4121 capsrc_nids[nums++] = cap;
4122 }
4123 }
4124 if (!nums) {
4125 /* check whether ADC-switch is possible */
4126 if (!alc_check_dyn_adc_switch(codec)) {
4127 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4128 " using fallback 0x%x\n",
4129 codec->chip_name, spec->private_adc_nids[0]);
4130 spec->num_adc_nids = 1;
4131 spec->auto_mic = 0;
4132 return;
4133 }
4134 } else if (nums != spec->num_adc_nids) {
4135 memcpy(spec->private_adc_nids, adc_nids,
4136 nums * sizeof(hda_nid_t));
4137 memcpy(spec->private_capsrc_nids, capsrc_nids,
4138 nums * sizeof(hda_nid_t));
4139 spec->num_adc_nids = nums;
4140 }
4141
4142 if (spec->auto_mic)
4143 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4144 else if (spec->input_mux->num_items == 1)
4145 spec->num_adc_nids = 1; /* reduce to a single ADC */
4146}
4147
4148/*
4149 * initialize ADC paths
4150 */
4151static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4152{
4153 struct alc_spec *spec = codec->spec;
4154 hda_nid_t nid;
4155
4156 nid = spec->adc_nids[adc_idx];
4157 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004158 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004159 snd_hda_codec_write(codec, nid, 0,
4160 AC_VERB_SET_AMP_GAIN_MUTE,
4161 AMP_IN_MUTE(0));
4162 return;
4163 }
4164 if (!spec->capsrc_nids)
4165 return;
4166 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004167 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004168 snd_hda_codec_write(codec, nid, 0,
4169 AC_VERB_SET_AMP_GAIN_MUTE,
4170 AMP_OUT_MUTE);
4171}
4172
4173static void alc_auto_init_input_src(struct hda_codec *codec)
4174{
4175 struct alc_spec *spec = codec->spec;
4176 int c, nums;
4177
4178 for (c = 0; c < spec->num_adc_nids; c++)
4179 alc_auto_init_adc(codec, c);
4180 if (spec->dyn_adc_switch)
4181 nums = 1;
4182 else
4183 nums = spec->num_adc_nids;
4184 for (c = 0; c < nums; c++)
4185 alc_mux_select(codec, 0, spec->cur_mux[c], true);
4186}
4187
4188/* add mic boosts if needed */
4189static int alc_auto_add_mic_boost(struct hda_codec *codec)
4190{
4191 struct alc_spec *spec = codec->spec;
4192 struct auto_pin_cfg *cfg = &spec->autocfg;
4193 int i, err;
4194 int type_idx = 0;
4195 hda_nid_t nid;
4196 const char *prev_label = NULL;
4197
4198 for (i = 0; i < cfg->num_inputs; i++) {
4199 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4200 break;
4201 nid = cfg->inputs[i].pin;
4202 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4203 const char *label;
4204 char boost_label[32];
4205
4206 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004207 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4208 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004209 if (prev_label && !strcmp(label, prev_label))
4210 type_idx++;
4211 else
4212 type_idx = 0;
4213 prev_label = label;
4214
4215 snprintf(boost_label, sizeof(boost_label),
4216 "%s Boost Volume", label);
4217 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4218 boost_label, type_idx,
4219 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4220 if (err < 0)
4221 return err;
4222 }
4223 }
4224 return 0;
4225}
4226
4227/* select or unmute the given capsrc route */
4228static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4229 int idx)
4230{
4231 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4232 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4233 HDA_AMP_MUTE, 0);
4234 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4235 snd_hda_codec_write_cache(codec, cap, 0,
4236 AC_VERB_SET_CONNECT_SEL, idx);
4237 }
4238}
4239
4240/* set the default connection to that pin */
4241static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4242{
4243 struct alc_spec *spec = codec->spec;
4244 int i;
4245
4246 if (!pin)
4247 return 0;
4248 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004249 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004250 int idx;
4251
4252 idx = get_connection_index(codec, cap, pin);
4253 if (idx < 0)
4254 continue;
4255 select_or_unmute_capsrc(codec, cap, idx);
4256 return i; /* return the found index */
4257 }
4258 return -1; /* not found */
4259}
4260
4261/* initialize some special cases for input sources */
4262static void alc_init_special_input_src(struct hda_codec *codec)
4263{
4264 struct alc_spec *spec = codec->spec;
4265 int i;
4266
4267 for (i = 0; i < spec->autocfg.num_inputs; i++)
4268 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4269}
4270
4271/* assign appropriate capture mixers */
4272static void set_capture_mixer(struct hda_codec *codec)
4273{
4274 struct alc_spec *spec = codec->spec;
4275 static const struct snd_kcontrol_new *caps[2][3] = {
4276 { alc_capture_mixer_nosrc1,
4277 alc_capture_mixer_nosrc2,
4278 alc_capture_mixer_nosrc3 },
4279 { alc_capture_mixer1,
4280 alc_capture_mixer2,
4281 alc_capture_mixer3 },
4282 };
4283
4284 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004285 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004286 if (!spec->capsrc_nids)
4287 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004288 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004289 return; /* no volume in capsrc, too */
4290 spec->vol_in_capsrc = 1;
4291 }
4292
4293 if (spec->num_adc_nids > 0) {
4294 int mux = 0;
4295 int num_adcs = 0;
4296
4297 if (spec->input_mux && spec->input_mux->num_items > 1)
4298 mux = 1;
4299 if (spec->auto_mic) {
4300 num_adcs = 1;
4301 mux = 0;
4302 } else if (spec->dyn_adc_switch)
4303 num_adcs = 1;
4304 if (!num_adcs) {
4305 if (spec->num_adc_nids > 3)
4306 spec->num_adc_nids = 3;
4307 else if (!spec->num_adc_nids)
4308 return;
4309 num_adcs = spec->num_adc_nids;
4310 }
4311 spec->cap_mixer = caps[mux][num_adcs - 1];
4312 }
4313}
4314
4315/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004316 * standard auto-parser initializations
4317 */
4318static void alc_auto_init_std(struct hda_codec *codec)
4319{
4320 struct alc_spec *spec = codec->spec;
4321 alc_auto_init_multi_out(codec);
4322 alc_auto_init_extra_out(codec);
4323 alc_auto_init_analog_input(codec);
4324 alc_auto_init_input_src(codec);
4325 alc_auto_init_digital(codec);
4326 if (spec->unsol_event)
4327 alc_inithook(codec);
4328}
4329
4330/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004331 * Digital-beep handlers
4332 */
4333#ifdef CONFIG_SND_HDA_INPUT_BEEP
4334#define set_beep_amp(spec, nid, idx, dir) \
4335 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4336
4337static const struct snd_pci_quirk beep_white_list[] = {
4338 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4339 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4340 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4341 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4342 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4343 {}
4344};
4345
4346static inline int has_cdefine_beep(struct hda_codec *codec)
4347{
4348 struct alc_spec *spec = codec->spec;
4349 const struct snd_pci_quirk *q;
4350 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4351 if (q)
4352 return q->value;
4353 return spec->cdefine.enable_pcbeep;
4354}
4355#else
4356#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4357#define has_cdefine_beep(codec) 0
4358#endif
4359
4360/* parse the BIOS configuration and set up the alc_spec */
4361/* return 1 if successful, 0 if the proper config is not found,
4362 * or a negative error code
4363 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004364static int alc_parse_auto_config(struct hda_codec *codec,
4365 const hda_nid_t *ignore_nids,
4366 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004367{
4368 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004369 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004370 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004371
Takashi Iwai53c334a2011-08-23 18:27:14 +02004372 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4373 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004374 if (err < 0)
4375 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004376 if (!cfg->line_outs) {
4377 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004378 spec->multiout.max_channels = 2;
4379 spec->no_analog = 1;
4380 goto dig_only;
4381 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004382 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004383 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004384
Takashi Iwai06503672011-10-06 08:27:19 +02004385 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4386 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004387 /* use HP as primary out */
4388 cfg->speaker_outs = cfg->line_outs;
4389 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4390 sizeof(cfg->speaker_pins));
4391 cfg->line_outs = cfg->hp_outs;
4392 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4393 cfg->hp_outs = 0;
4394 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4395 cfg->line_out_type = AUTO_PIN_HP_OUT;
4396 }
4397
Takashi Iwai1d045db2011-07-07 18:23:21 +02004398 err = alc_auto_fill_dac_nids(codec);
4399 if (err < 0)
4400 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004401 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004402 if (err < 0)
4403 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004404 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004405 if (err < 0)
4406 return err;
4407 err = alc_auto_create_hp_out(codec);
4408 if (err < 0)
4409 return err;
4410 err = alc_auto_create_speaker_out(codec);
4411 if (err < 0)
4412 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004413 err = alc_auto_create_shared_input(codec);
4414 if (err < 0)
4415 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004416 err = alc_auto_create_input_ctls(codec);
4417 if (err < 0)
4418 return err;
4419
4420 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4421
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004422 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004423 alc_auto_parse_digital(codec);
4424
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004425 if (!spec->no_analog)
4426 alc_remove_invalid_adc_nids(codec);
4427
4428 if (ssid_nids)
4429 alc_ssid_check(codec, ssid_nids);
4430
4431 if (!spec->no_analog) {
4432 alc_auto_check_switches(codec);
4433 err = alc_auto_add_mic_boost(codec);
4434 if (err < 0)
4435 return err;
4436 }
4437
Takashi Iwai1d045db2011-07-07 18:23:21 +02004438 if (spec->kctls.list)
4439 add_mixer(spec, spec->kctls.list);
4440
Takashi Iwai1d045db2011-07-07 18:23:21 +02004441 return 1;
4442}
4443
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004444static int alc880_parse_auto_config(struct hda_codec *codec)
4445{
4446 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4447 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4448 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4449}
4450
Takashi Iwai1d045db2011-07-07 18:23:21 +02004451/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004452 * ALC880 fix-ups
4453 */
4454enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004455 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004456 ALC880_FIXUP_GPIO2,
4457 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004458 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004459 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004460 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004461 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004462 ALC880_FIXUP_VOL_KNOB,
4463 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004464 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004465 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004466 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004467 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004468 ALC880_FIXUP_3ST_BASE,
4469 ALC880_FIXUP_3ST,
4470 ALC880_FIXUP_3ST_DIG,
4471 ALC880_FIXUP_5ST_BASE,
4472 ALC880_FIXUP_5ST,
4473 ALC880_FIXUP_5ST_DIG,
4474 ALC880_FIXUP_6ST_BASE,
4475 ALC880_FIXUP_6ST,
4476 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004477};
4478
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004479/* enable the volume-knob widget support on NID 0x21 */
4480static void alc880_fixup_vol_knob(struct hda_codec *codec,
4481 const struct alc_fixup *fix, int action)
4482{
4483 if (action == ALC_FIXUP_ACT_PROBE)
4484 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4485}
4486
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004487static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004488 [ALC880_FIXUP_GPIO1] = {
4489 .type = ALC_FIXUP_VERBS,
4490 .v.verbs = alc_gpio1_init_verbs,
4491 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004492 [ALC880_FIXUP_GPIO2] = {
4493 .type = ALC_FIXUP_VERBS,
4494 .v.verbs = alc_gpio2_init_verbs,
4495 },
4496 [ALC880_FIXUP_MEDION_RIM] = {
4497 .type = ALC_FIXUP_VERBS,
4498 .v.verbs = (const struct hda_verb[]) {
4499 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4500 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4501 { }
4502 },
4503 .chained = true,
4504 .chain_id = ALC880_FIXUP_GPIO2,
4505 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004506 [ALC880_FIXUP_LG] = {
4507 .type = ALC_FIXUP_PINS,
4508 .v.pins = (const struct alc_pincfg[]) {
4509 /* disable bogus unused pins */
4510 { 0x16, 0x411111f0 },
4511 { 0x18, 0x411111f0 },
4512 { 0x1a, 0x411111f0 },
4513 { }
4514 }
4515 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004516 [ALC880_FIXUP_W810] = {
4517 .type = ALC_FIXUP_PINS,
4518 .v.pins = (const struct alc_pincfg[]) {
4519 /* disable bogus unused pins */
4520 { 0x17, 0x411111f0 },
4521 { }
4522 },
4523 .chained = true,
4524 .chain_id = ALC880_FIXUP_GPIO2,
4525 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004526 [ALC880_FIXUP_EAPD_COEF] = {
4527 .type = ALC_FIXUP_VERBS,
4528 .v.verbs = (const struct hda_verb[]) {
4529 /* change to EAPD mode */
4530 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4531 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4532 {}
4533 },
4534 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004535 [ALC880_FIXUP_TCL_S700] = {
4536 .type = ALC_FIXUP_VERBS,
4537 .v.verbs = (const struct hda_verb[]) {
4538 /* change to EAPD mode */
4539 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4540 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4541 {}
4542 },
4543 .chained = true,
4544 .chain_id = ALC880_FIXUP_GPIO2,
4545 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004546 [ALC880_FIXUP_VOL_KNOB] = {
4547 .type = ALC_FIXUP_FUNC,
4548 .v.func = alc880_fixup_vol_knob,
4549 },
4550 [ALC880_FIXUP_FUJITSU] = {
4551 /* override all pins as BIOS on old Amilo is broken */
4552 .type = ALC_FIXUP_PINS,
4553 .v.pins = (const struct alc_pincfg[]) {
4554 { 0x14, 0x0121411f }, /* HP */
4555 { 0x15, 0x99030120 }, /* speaker */
4556 { 0x16, 0x99030130 }, /* bass speaker */
4557 { 0x17, 0x411111f0 }, /* N/A */
4558 { 0x18, 0x411111f0 }, /* N/A */
4559 { 0x19, 0x01a19950 }, /* mic-in */
4560 { 0x1a, 0x411111f0 }, /* N/A */
4561 { 0x1b, 0x411111f0 }, /* N/A */
4562 { 0x1c, 0x411111f0 }, /* N/A */
4563 { 0x1d, 0x411111f0 }, /* N/A */
4564 { 0x1e, 0x01454140 }, /* SPDIF out */
4565 { }
4566 },
4567 .chained = true,
4568 .chain_id = ALC880_FIXUP_VOL_KNOB,
4569 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004570 [ALC880_FIXUP_F1734] = {
4571 /* almost compatible with FUJITSU, but no bass and SPDIF */
4572 .type = ALC_FIXUP_PINS,
4573 .v.pins = (const struct alc_pincfg[]) {
4574 { 0x14, 0x0121411f }, /* HP */
4575 { 0x15, 0x99030120 }, /* speaker */
4576 { 0x16, 0x411111f0 }, /* N/A */
4577 { 0x17, 0x411111f0 }, /* N/A */
4578 { 0x18, 0x411111f0 }, /* N/A */
4579 { 0x19, 0x01a19950 }, /* mic-in */
4580 { 0x1a, 0x411111f0 }, /* N/A */
4581 { 0x1b, 0x411111f0 }, /* N/A */
4582 { 0x1c, 0x411111f0 }, /* N/A */
4583 { 0x1d, 0x411111f0 }, /* N/A */
4584 { 0x1e, 0x411111f0 }, /* N/A */
4585 { }
4586 },
4587 .chained = true,
4588 .chain_id = ALC880_FIXUP_VOL_KNOB,
4589 },
Takashi Iwai817de922012-02-20 17:20:48 +01004590 [ALC880_FIXUP_UNIWILL] = {
4591 /* need to fix HP and speaker pins to be parsed correctly */
4592 .type = ALC_FIXUP_PINS,
4593 .v.pins = (const struct alc_pincfg[]) {
4594 { 0x14, 0x0121411f }, /* HP */
4595 { 0x15, 0x99030120 }, /* speaker */
4596 { 0x16, 0x99030130 }, /* bass speaker */
4597 { }
4598 },
4599 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004600 [ALC880_FIXUP_UNIWILL_DIG] = {
4601 .type = ALC_FIXUP_PINS,
4602 .v.pins = (const struct alc_pincfg[]) {
4603 /* disable bogus unused pins */
4604 { 0x17, 0x411111f0 },
4605 { 0x19, 0x411111f0 },
4606 { 0x1b, 0x411111f0 },
4607 { 0x1f, 0x411111f0 },
4608 { }
4609 }
4610 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004611 [ALC880_FIXUP_Z71V] = {
4612 .type = ALC_FIXUP_PINS,
4613 .v.pins = (const struct alc_pincfg[]) {
4614 /* set up the whole pins as BIOS is utterly broken */
4615 { 0x14, 0x99030120 }, /* speaker */
4616 { 0x15, 0x0121411f }, /* HP */
4617 { 0x16, 0x411111f0 }, /* N/A */
4618 { 0x17, 0x411111f0 }, /* N/A */
4619 { 0x18, 0x01a19950 }, /* mic-in */
4620 { 0x19, 0x411111f0 }, /* N/A */
4621 { 0x1a, 0x01813031 }, /* line-in */
4622 { 0x1b, 0x411111f0 }, /* N/A */
4623 { 0x1c, 0x411111f0 }, /* N/A */
4624 { 0x1d, 0x411111f0 }, /* N/A */
4625 { 0x1e, 0x0144111e }, /* SPDIF */
4626 { }
4627 }
4628 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004629 [ALC880_FIXUP_3ST_BASE] = {
4630 .type = ALC_FIXUP_PINS,
4631 .v.pins = (const struct alc_pincfg[]) {
4632 { 0x14, 0x01014010 }, /* line-out */
4633 { 0x15, 0x411111f0 }, /* N/A */
4634 { 0x16, 0x411111f0 }, /* N/A */
4635 { 0x17, 0x411111f0 }, /* N/A */
4636 { 0x18, 0x01a19c30 }, /* mic-in */
4637 { 0x19, 0x0121411f }, /* HP */
4638 { 0x1a, 0x01813031 }, /* line-in */
4639 { 0x1b, 0x02a19c40 }, /* front-mic */
4640 { 0x1c, 0x411111f0 }, /* N/A */
4641 { 0x1d, 0x411111f0 }, /* N/A */
4642 /* 0x1e is filled in below */
4643 { 0x1f, 0x411111f0 }, /* N/A */
4644 { }
4645 }
4646 },
4647 [ALC880_FIXUP_3ST] = {
4648 .type = ALC_FIXUP_PINS,
4649 .v.pins = (const struct alc_pincfg[]) {
4650 { 0x1e, 0x411111f0 }, /* N/A */
4651 { }
4652 },
4653 .chained = true,
4654 .chain_id = ALC880_FIXUP_3ST_BASE,
4655 },
4656 [ALC880_FIXUP_3ST_DIG] = {
4657 .type = ALC_FIXUP_PINS,
4658 .v.pins = (const struct alc_pincfg[]) {
4659 { 0x1e, 0x0144111e }, /* SPDIF */
4660 { }
4661 },
4662 .chained = true,
4663 .chain_id = ALC880_FIXUP_3ST_BASE,
4664 },
4665 [ALC880_FIXUP_5ST_BASE] = {
4666 .type = ALC_FIXUP_PINS,
4667 .v.pins = (const struct alc_pincfg[]) {
4668 { 0x14, 0x01014010 }, /* front */
4669 { 0x15, 0x411111f0 }, /* N/A */
4670 { 0x16, 0x01011411 }, /* CLFE */
4671 { 0x17, 0x01016412 }, /* surr */
4672 { 0x18, 0x01a19c30 }, /* mic-in */
4673 { 0x19, 0x0121411f }, /* HP */
4674 { 0x1a, 0x01813031 }, /* line-in */
4675 { 0x1b, 0x02a19c40 }, /* front-mic */
4676 { 0x1c, 0x411111f0 }, /* N/A */
4677 { 0x1d, 0x411111f0 }, /* N/A */
4678 /* 0x1e is filled in below */
4679 { 0x1f, 0x411111f0 }, /* N/A */
4680 { }
4681 }
4682 },
4683 [ALC880_FIXUP_5ST] = {
4684 .type = ALC_FIXUP_PINS,
4685 .v.pins = (const struct alc_pincfg[]) {
4686 { 0x1e, 0x411111f0 }, /* N/A */
4687 { }
4688 },
4689 .chained = true,
4690 .chain_id = ALC880_FIXUP_5ST_BASE,
4691 },
4692 [ALC880_FIXUP_5ST_DIG] = {
4693 .type = ALC_FIXUP_PINS,
4694 .v.pins = (const struct alc_pincfg[]) {
4695 { 0x1e, 0x0144111e }, /* SPDIF */
4696 { }
4697 },
4698 .chained = true,
4699 .chain_id = ALC880_FIXUP_5ST_BASE,
4700 },
4701 [ALC880_FIXUP_6ST_BASE] = {
4702 .type = ALC_FIXUP_PINS,
4703 .v.pins = (const struct alc_pincfg[]) {
4704 { 0x14, 0x01014010 }, /* front */
4705 { 0x15, 0x01016412 }, /* surr */
4706 { 0x16, 0x01011411 }, /* CLFE */
4707 { 0x17, 0x01012414 }, /* side */
4708 { 0x18, 0x01a19c30 }, /* mic-in */
4709 { 0x19, 0x02a19c40 }, /* front-mic */
4710 { 0x1a, 0x01813031 }, /* line-in */
4711 { 0x1b, 0x0121411f }, /* HP */
4712 { 0x1c, 0x411111f0 }, /* N/A */
4713 { 0x1d, 0x411111f0 }, /* N/A */
4714 /* 0x1e is filled in below */
4715 { 0x1f, 0x411111f0 }, /* N/A */
4716 { }
4717 }
4718 },
4719 [ALC880_FIXUP_6ST] = {
4720 .type = ALC_FIXUP_PINS,
4721 .v.pins = (const struct alc_pincfg[]) {
4722 { 0x1e, 0x411111f0 }, /* N/A */
4723 { }
4724 },
4725 .chained = true,
4726 .chain_id = ALC880_FIXUP_6ST_BASE,
4727 },
4728 [ALC880_FIXUP_6ST_DIG] = {
4729 .type = ALC_FIXUP_PINS,
4730 .v.pins = (const struct alc_pincfg[]) {
4731 { 0x1e, 0x0144111e }, /* SPDIF */
4732 { }
4733 },
4734 .chained = true,
4735 .chain_id = ALC880_FIXUP_6ST_BASE,
4736 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004737};
4738
4739static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004740 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004741 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004742 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4743 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004744 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004745 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004746 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004747 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004748 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004749 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004750 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004751 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004752 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004753 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004754 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004755 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4756 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4757 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004758 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004759
4760 /* Below is the copied entries from alc880_quirks.c.
4761 * It's not quite sure whether BIOS sets the correct pin-config table
4762 * on these machines, thus they are kept to be compatible with
4763 * the old static quirks. Once when it's confirmed to work without
4764 * these overrides, it'd be better to remove.
4765 */
4766 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4767 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4768 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4769 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4770 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4771 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4772 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4773 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4774 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4775 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4776 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4777 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4778 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4779 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4780 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4781 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4782 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4783 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4784 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4785 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4786 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4787 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4788 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4789 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4790 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4791 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4792 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4793 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4794 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4795 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4796 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4797 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4798 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4799 /* default Intel */
4800 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4801 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4802 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4803 {}
4804};
4805
4806static const struct alc_model_fixup alc880_fixup_models[] = {
4807 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4808 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4809 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4810 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4811 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4812 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004813 {}
4814};
4815
4816
4817/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004818 * OK, here we have finally the patch for ALC880
4819 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004820static int patch_alc880(struct hda_codec *codec)
4821{
4822 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004823 int err;
4824
4825 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4826 if (spec == NULL)
4827 return -ENOMEM;
4828
4829 codec->spec = spec;
4830
4831 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004832 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004833
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004834 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4835 alc880_fixups);
4836 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004837
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004838 /* automatic parse from the BIOS config */
4839 err = alc880_parse_auto_config(codec);
4840 if (err < 0)
4841 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004842
Takashi Iwai60a6a842011-07-27 14:01:24 +02004843 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004844 alc_auto_fill_adc_caps(codec);
4845 alc_rebuild_imux_for_auto_mic(codec);
4846 alc_remove_invalid_adc_nids(codec);
4847 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004848
4849 if (!spec->no_analog && !spec->cap_mixer)
4850 set_capture_mixer(codec);
4851
4852 if (!spec->no_analog) {
4853 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004854 if (err < 0)
4855 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004856 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4857 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004858
Takashi Iwai1d045db2011-07-07 18:23:21 +02004859 codec->patch_ops = alc_patch_ops;
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004860 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004861
Takashi Iwai589876e2012-02-20 15:47:55 +01004862 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4863
Takashi Iwai1d045db2011-07-07 18:23:21 +02004864 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004865
4866 error:
4867 alc_free(codec);
4868 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004869}
4870
4871
4872/*
4873 * ALC260 support
4874 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004875static int alc260_parse_auto_config(struct hda_codec *codec)
4876{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004877 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004878 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4879 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004880}
4881
Takashi Iwai1d045db2011-07-07 18:23:21 +02004882/*
4883 * Pin config fixes
4884 */
4885enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004886 ALC260_FIXUP_HP_DC5750,
4887 ALC260_FIXUP_HP_PIN_0F,
4888 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004889 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004890 ALC260_FIXUP_GPIO1_TOGGLE,
4891 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004892 ALC260_FIXUP_HP_B1900,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004893};
4894
Takashi Iwai20f7d922012-02-16 12:35:16 +01004895static void alc260_gpio1_automute(struct hda_codec *codec)
4896{
4897 struct alc_spec *spec = codec->spec;
4898 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4899 spec->hp_jack_present);
4900}
4901
4902static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4903 const struct alc_fixup *fix, int action)
4904{
4905 struct alc_spec *spec = codec->spec;
4906 if (action == ALC_FIXUP_ACT_PROBE) {
4907 /* although the machine has only one output pin, we need to
4908 * toggle GPIO1 according to the jack state
4909 */
4910 spec->automute_hook = alc260_gpio1_automute;
4911 spec->detect_hp = 1;
4912 spec->automute_speaker = 1;
4913 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4914 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4915 spec->unsol_event = alc_sku_unsol_event;
4916 add_verb(codec->spec, alc_gpio1_init_verbs);
4917 }
4918}
4919
Takashi Iwai1d045db2011-07-07 18:23:21 +02004920static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004921 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004922 .type = ALC_FIXUP_PINS,
4923 .v.pins = (const struct alc_pincfg[]) {
4924 { 0x11, 0x90130110 }, /* speaker */
4925 { }
4926 }
4927 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004928 [ALC260_FIXUP_HP_PIN_0F] = {
4929 .type = ALC_FIXUP_PINS,
4930 .v.pins = (const struct alc_pincfg[]) {
4931 { 0x0f, 0x01214000 }, /* HP */
4932 { }
4933 }
4934 },
4935 [ALC260_FIXUP_COEF] = {
4936 .type = ALC_FIXUP_VERBS,
4937 .v.verbs = (const struct hda_verb[]) {
4938 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4939 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4940 { }
4941 },
4942 .chained = true,
4943 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4944 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004945 [ALC260_FIXUP_GPIO1] = {
4946 .type = ALC_FIXUP_VERBS,
4947 .v.verbs = alc_gpio1_init_verbs,
4948 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004949 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4950 .type = ALC_FIXUP_FUNC,
4951 .v.func = alc260_fixup_gpio1_toggle,
4952 .chained = true,
4953 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4954 },
4955 [ALC260_FIXUP_REPLACER] = {
4956 .type = ALC_FIXUP_VERBS,
4957 .v.verbs = (const struct hda_verb[]) {
4958 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4959 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4960 { }
4961 },
4962 .chained = true,
4963 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4964 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004965 [ALC260_FIXUP_HP_B1900] = {
4966 .type = ALC_FIXUP_FUNC,
4967 .v.func = alc260_fixup_gpio1_toggle,
4968 .chained = true,
4969 .chain_id = ALC260_FIXUP_COEF,
4970 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004971};
4972
4973static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004974 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004975 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004976 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004977 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004978 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004979 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004980 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004981 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004982 {}
4983};
4984
4985/*
4986 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004987static int patch_alc260(struct hda_codec *codec)
4988{
4989 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004990 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004991
4992 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4993 if (spec == NULL)
4994 return -ENOMEM;
4995
4996 codec->spec = spec;
4997
4998 spec->mixer_nid = 0x07;
4999
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005000 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5001 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005002
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005003 /* automatic parse from the BIOS config */
5004 err = alc260_parse_auto_config(codec);
5005 if (err < 0)
5006 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005007
Takashi Iwai60a6a842011-07-27 14:01:24 +02005008 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005009 alc_auto_fill_adc_caps(codec);
5010 alc_rebuild_imux_for_auto_mic(codec);
5011 alc_remove_invalid_adc_nids(codec);
5012 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005013
5014 if (!spec->no_analog && !spec->cap_mixer)
5015 set_capture_mixer(codec);
5016
5017 if (!spec->no_analog) {
5018 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005019 if (err < 0)
5020 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005021 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5022 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005023
Takashi Iwai1d045db2011-07-07 18:23:21 +02005024 codec->patch_ops = alc_patch_ops;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005025 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005026 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005027
Takashi Iwai589876e2012-02-20 15:47:55 +01005028 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5029
Takashi Iwai1d045db2011-07-07 18:23:21 +02005030 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005031
5032 error:
5033 alc_free(codec);
5034 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005035}
5036
5037
5038/*
5039 * ALC882/883/885/888/889 support
5040 *
5041 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5042 * configuration. Each pin widget can choose any input DACs and a mixer.
5043 * Each ADC is connected from a mixer of all inputs. This makes possible
5044 * 6-channel independent captures.
5045 *
5046 * In addition, an independent DAC for the multi-playback (not used in this
5047 * driver yet).
5048 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005049
5050/*
5051 * Pin config fixes
5052 */
5053enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005054 ALC882_FIXUP_ABIT_AW9D_MAX,
5055 ALC882_FIXUP_LENOVO_Y530,
5056 ALC882_FIXUP_PB_M5210,
5057 ALC882_FIXUP_ACER_ASPIRE_7736,
5058 ALC882_FIXUP_ASUS_W90V,
5059 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005060 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005061 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005062 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005063 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005064 ALC882_FIXUP_GPIO1,
5065 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005066 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005067 ALC889_FIXUP_COEF,
5068 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005069 ALC882_FIXUP_ACER_ASPIRE_4930G,
5070 ALC882_FIXUP_ACER_ASPIRE_8930G,
5071 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005072 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005073 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005074 ALC889_FIXUP_MBP_VREF,
5075 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005076};
5077
Takashi Iwai68ef0562011-11-09 18:24:44 +01005078static void alc889_fixup_coef(struct hda_codec *codec,
5079 const struct alc_fixup *fix, int action)
5080{
5081 if (action != ALC_FIXUP_ACT_INIT)
5082 return;
5083 alc889_coef_init(codec);
5084}
5085
Takashi Iwai56710872011-11-14 17:42:11 +01005086/* toggle speaker-output according to the hp-jack state */
5087static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5088{
5089 unsigned int gpiostate, gpiomask, gpiodir;
5090
5091 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5092 AC_VERB_GET_GPIO_DATA, 0);
5093
5094 if (!muted)
5095 gpiostate |= (1 << pin);
5096 else
5097 gpiostate &= ~(1 << pin);
5098
5099 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5100 AC_VERB_GET_GPIO_MASK, 0);
5101 gpiomask |= (1 << pin);
5102
5103 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5104 AC_VERB_GET_GPIO_DIRECTION, 0);
5105 gpiodir |= (1 << pin);
5106
5107
5108 snd_hda_codec_write(codec, codec->afg, 0,
5109 AC_VERB_SET_GPIO_MASK, gpiomask);
5110 snd_hda_codec_write(codec, codec->afg, 0,
5111 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5112
5113 msleep(1);
5114
5115 snd_hda_codec_write(codec, codec->afg, 0,
5116 AC_VERB_SET_GPIO_DATA, gpiostate);
5117}
5118
5119/* set up GPIO at initialization */
5120static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5121 const struct alc_fixup *fix, int action)
5122{
5123 if (action != ALC_FIXUP_ACT_INIT)
5124 return;
5125 alc882_gpio_mute(codec, 0, 0);
5126 alc882_gpio_mute(codec, 1, 0);
5127}
5128
Takashi Iwai02a237b2012-02-13 15:25:07 +01005129/* Fix the connection of some pins for ALC889:
5130 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5131 * work correctly (bko#42740)
5132 */
5133static void alc889_fixup_dac_route(struct hda_codec *codec,
5134 const struct alc_fixup *fix, int action)
5135{
5136 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5137 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5138 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5139 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5140 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5141 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5142 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5143 }
5144}
5145
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005146/* Set VREF on HP pin */
5147static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5148 const struct alc_fixup *fix, int action)
5149{
5150 struct alc_spec *spec = codec->spec;
5151 static hda_nid_t nids[2] = { 0x14, 0x15 };
5152 int i;
5153
5154 if (action != ALC_FIXUP_ACT_INIT)
5155 return;
5156 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5157 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5158 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5159 continue;
5160 val = snd_hda_codec_read(codec, nids[i], 0,
5161 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5162 val |= AC_PINCTL_VREF_80;
5163 snd_hda_codec_write(codec, nids[i], 0,
5164 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5165 spec->keep_vref_in_automute = 1;
5166 break;
5167 }
5168}
5169
5170/* Set VREF on speaker pins on imac91 */
5171static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5172 const struct alc_fixup *fix, int action)
5173{
5174 struct alc_spec *spec = codec->spec;
5175 static hda_nid_t nids[2] = { 0x18, 0x1a };
5176 int i;
5177
5178 if (action != ALC_FIXUP_ACT_INIT)
5179 return;
5180 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5181 unsigned int val;
5182 val = snd_hda_codec_read(codec, nids[i], 0,
5183 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5184 val |= AC_PINCTL_VREF_50;
5185 snd_hda_codec_write(codec, nids[i], 0,
5186 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5187 }
5188 spec->keep_vref_in_automute = 1;
5189}
5190
Takashi Iwai1d045db2011-07-07 18:23:21 +02005191static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005192 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005193 .type = ALC_FIXUP_PINS,
5194 .v.pins = (const struct alc_pincfg[]) {
5195 { 0x15, 0x01080104 }, /* side */
5196 { 0x16, 0x01011012 }, /* rear */
5197 { 0x17, 0x01016011 }, /* clfe */
5198 { }
5199 }
5200 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005201 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005202 .type = ALC_FIXUP_PINS,
5203 .v.pins = (const struct alc_pincfg[]) {
5204 { 0x15, 0x99130112 }, /* rear int speakers */
5205 { 0x16, 0x99130111 }, /* subwoofer */
5206 { }
5207 }
5208 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005209 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005210 .type = ALC_FIXUP_VERBS,
5211 .v.verbs = (const struct hda_verb[]) {
5212 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5213 {}
5214 }
5215 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005216 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005217 .type = ALC_FIXUP_SKU,
5218 .v.sku = ALC_FIXUP_SKU_IGNORE,
5219 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005220 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005221 .type = ALC_FIXUP_PINS,
5222 .v.pins = (const struct alc_pincfg[]) {
5223 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5224 { }
5225 }
5226 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005227 [ALC889_FIXUP_VAIO_TT] = {
5228 .type = ALC_FIXUP_PINS,
5229 .v.pins = (const struct alc_pincfg[]) {
5230 { 0x17, 0x90170111 }, /* hidden surround speaker */
5231 { }
5232 }
5233 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005234 [ALC888_FIXUP_EEE1601] = {
5235 .type = ALC_FIXUP_VERBS,
5236 .v.verbs = (const struct hda_verb[]) {
5237 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5238 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5239 { }
5240 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005241 },
5242 [ALC882_FIXUP_EAPD] = {
5243 .type = ALC_FIXUP_VERBS,
5244 .v.verbs = (const struct hda_verb[]) {
5245 /* change to EAPD mode */
5246 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5247 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5248 { }
5249 }
5250 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005251 [ALC883_FIXUP_EAPD] = {
5252 .type = ALC_FIXUP_VERBS,
5253 .v.verbs = (const struct hda_verb[]) {
5254 /* change to EAPD mode */
5255 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5256 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5257 { }
5258 }
5259 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005260 [ALC883_FIXUP_ACER_EAPD] = {
5261 .type = ALC_FIXUP_VERBS,
5262 .v.verbs = (const struct hda_verb[]) {
5263 /* eanable EAPD on Acer laptops */
5264 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5265 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5266 { }
5267 }
5268 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005269 [ALC882_FIXUP_GPIO1] = {
5270 .type = ALC_FIXUP_VERBS,
5271 .v.verbs = alc_gpio1_init_verbs,
5272 },
5273 [ALC882_FIXUP_GPIO2] = {
5274 .type = ALC_FIXUP_VERBS,
5275 .v.verbs = alc_gpio2_init_verbs,
5276 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005277 [ALC882_FIXUP_GPIO3] = {
5278 .type = ALC_FIXUP_VERBS,
5279 .v.verbs = alc_gpio3_init_verbs,
5280 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005281 [ALC882_FIXUP_ASUS_W2JC] = {
5282 .type = ALC_FIXUP_VERBS,
5283 .v.verbs = alc_gpio1_init_verbs,
5284 .chained = true,
5285 .chain_id = ALC882_FIXUP_EAPD,
5286 },
5287 [ALC889_FIXUP_COEF] = {
5288 .type = ALC_FIXUP_FUNC,
5289 .v.func = alc889_fixup_coef,
5290 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005291 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5292 .type = ALC_FIXUP_PINS,
5293 .v.pins = (const struct alc_pincfg[]) {
5294 { 0x16, 0x99130111 }, /* CLFE speaker */
5295 { 0x17, 0x99130112 }, /* surround speaker */
5296 { }
5297 }
5298 },
5299 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5300 .type = ALC_FIXUP_PINS,
5301 .v.pins = (const struct alc_pincfg[]) {
5302 { 0x16, 0x99130111 }, /* CLFE speaker */
5303 { 0x1b, 0x99130112 }, /* surround speaker */
5304 { }
5305 },
5306 .chained = true,
5307 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5308 },
5309 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5310 /* additional init verbs for Acer Aspire 8930G */
5311 .type = ALC_FIXUP_VERBS,
5312 .v.verbs = (const struct hda_verb[]) {
5313 /* Enable all DACs */
5314 /* DAC DISABLE/MUTE 1? */
5315 /* setting bits 1-5 disables DAC nids 0x02-0x06
5316 * apparently. Init=0x38 */
5317 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5318 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5319 /* DAC DISABLE/MUTE 2? */
5320 /* some bit here disables the other DACs.
5321 * Init=0x4900 */
5322 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5323 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5324 /* DMIC fix
5325 * This laptop has a stereo digital microphone.
5326 * The mics are only 1cm apart which makes the stereo
5327 * useless. However, either the mic or the ALC889
5328 * makes the signal become a difference/sum signal
5329 * instead of standard stereo, which is annoying.
5330 * So instead we flip this bit which makes the
5331 * codec replicate the sum signal to both channels,
5332 * turning it into a normal mono mic.
5333 */
5334 /* DMIC_CONTROL? Init value = 0x0001 */
5335 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5336 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5337 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5338 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5339 { }
5340 }
5341 },
Takashi Iwai56710872011-11-14 17:42:11 +01005342 [ALC885_FIXUP_MACPRO_GPIO] = {
5343 .type = ALC_FIXUP_FUNC,
5344 .v.func = alc885_fixup_macpro_gpio,
5345 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005346 [ALC889_FIXUP_DAC_ROUTE] = {
5347 .type = ALC_FIXUP_FUNC,
5348 .v.func = alc889_fixup_dac_route,
5349 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005350 [ALC889_FIXUP_MBP_VREF] = {
5351 .type = ALC_FIXUP_FUNC,
5352 .v.func = alc889_fixup_mbp_vref,
5353 .chained = true,
5354 .chain_id = ALC882_FIXUP_GPIO1,
5355 },
5356 [ALC889_FIXUP_IMAC91_VREF] = {
5357 .type = ALC_FIXUP_FUNC,
5358 .v.func = alc889_fixup_imac91_vref,
5359 .chained = true,
5360 .chain_id = ALC882_FIXUP_GPIO1,
5361 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005362};
5363
5364static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005365 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5366 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5367 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5368 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5369 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5370 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005371 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5372 ALC882_FIXUP_ACER_ASPIRE_4930G),
5373 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5374 ALC882_FIXUP_ACER_ASPIRE_4930G),
5375 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5376 ALC882_FIXUP_ACER_ASPIRE_8930G),
5377 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5378 ALC882_FIXUP_ACER_ASPIRE_8930G),
5379 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5380 ALC882_FIXUP_ACER_ASPIRE_4930G),
5381 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5382 ALC882_FIXUP_ACER_ASPIRE_4930G),
5383 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5384 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005385 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005386 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005387 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005388 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005389 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005390 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005391 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005392 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005393
5394 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005395 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5396 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5397 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005398 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5399 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5400 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005401 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5402 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005403 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005404 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5405 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5406 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5407 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005408 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005409 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5410 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5411 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5412 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5413 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5414 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005415
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005416 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005417 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005418 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005419 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5420 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005421 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005422 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005423 {}
5424};
5425
5426/*
5427 * BIOS auto configuration
5428 */
5429/* almost identical with ALC880 parser... */
5430static int alc882_parse_auto_config(struct hda_codec *codec)
5431{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005432 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005433 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5434 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005435}
5436
Takashi Iwai1d045db2011-07-07 18:23:21 +02005437/*
5438 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005439static int patch_alc882(struct hda_codec *codec)
5440{
5441 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005442 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005443
5444 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5445 if (spec == NULL)
5446 return -ENOMEM;
5447
5448 codec->spec = spec;
5449
5450 spec->mixer_nid = 0x0b;
5451
5452 switch (codec->vendor_id) {
5453 case 0x10ec0882:
5454 case 0x10ec0885:
5455 break;
5456 default:
5457 /* ALC883 and variants */
5458 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5459 break;
5460 }
5461
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005462 err = alc_codec_rename_from_preset(codec);
5463 if (err < 0)
5464 goto error;
5465
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005466 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
5467 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005468
5469 alc_auto_parse_customize_define(codec);
5470
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005471 /* automatic parse from the BIOS config */
5472 err = alc882_parse_auto_config(codec);
5473 if (err < 0)
5474 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005475
Takashi Iwai60a6a842011-07-27 14:01:24 +02005476 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005477 alc_auto_fill_adc_caps(codec);
5478 alc_rebuild_imux_for_auto_mic(codec);
5479 alc_remove_invalid_adc_nids(codec);
5480 }
5481
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005482 if (!spec->no_analog && !spec->cap_mixer)
5483 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005484
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005485 if (!spec->no_analog && has_cdefine_beep(codec)) {
5486 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005487 if (err < 0)
5488 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005490 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005491
Takashi Iwai1d045db2011-07-07 18:23:21 +02005492 codec->patch_ops = alc_patch_ops;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005493 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005494
Takashi Iwai589876e2012-02-20 15:47:55 +01005495 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5496
Takashi Iwai1d045db2011-07-07 18:23:21 +02005497 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005498
5499 error:
5500 alc_free(codec);
5501 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005502}
5503
5504
5505/*
5506 * ALC262 support
5507 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508static int alc262_parse_auto_config(struct hda_codec *codec)
5509{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005510 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005511 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5512 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005513}
5514
5515/*
5516 * Pin config fixes
5517 */
5518enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005519 ALC262_FIXUP_FSC_H270,
5520 ALC262_FIXUP_HP_Z200,
5521 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005522 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005523 ALC262_FIXUP_BENQ,
5524 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005525};
5526
5527static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005528 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005529 .type = ALC_FIXUP_PINS,
5530 .v.pins = (const struct alc_pincfg[]) {
5531 { 0x14, 0x99130110 }, /* speaker */
5532 { 0x15, 0x0221142f }, /* front HP */
5533 { 0x1b, 0x0121141f }, /* rear HP */
5534 { }
5535 }
5536 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005537 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005538 .type = ALC_FIXUP_PINS,
5539 .v.pins = (const struct alc_pincfg[]) {
5540 { 0x16, 0x99130120 }, /* internal speaker */
5541 { }
5542 }
5543 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005544 [ALC262_FIXUP_TYAN] = {
5545 .type = ALC_FIXUP_PINS,
5546 .v.pins = (const struct alc_pincfg[]) {
5547 { 0x14, 0x1993e1f0 }, /* int AUX */
5548 { }
5549 }
5550 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005551 [ALC262_FIXUP_LENOVO_3000] = {
5552 .type = ALC_FIXUP_VERBS,
5553 .v.verbs = (const struct hda_verb[]) {
5554 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005555 {}
5556 },
5557 .chained = true,
5558 .chain_id = ALC262_FIXUP_BENQ,
5559 },
5560 [ALC262_FIXUP_BENQ] = {
5561 .type = ALC_FIXUP_VERBS,
5562 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005563 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5564 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5565 {}
5566 }
5567 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005568 [ALC262_FIXUP_BENQ_T31] = {
5569 .type = ALC_FIXUP_VERBS,
5570 .v.verbs = (const struct hda_verb[]) {
5571 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5572 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5573 {}
5574 }
5575 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005576};
5577
5578static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005579 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005580 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5581 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005582 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5583 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005584 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005585 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5586 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005587 {}
5588};
5589
5590
Takashi Iwai1d045db2011-07-07 18:23:21 +02005591/*
5592 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005593static int patch_alc262(struct hda_codec *codec)
5594{
5595 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005596 int err;
5597
5598 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5599 if (spec == NULL)
5600 return -ENOMEM;
5601
5602 codec->spec = spec;
5603
5604 spec->mixer_nid = 0x0b;
5605
5606#if 0
5607 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5608 * under-run
5609 */
5610 {
5611 int tmp;
5612 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5613 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5614 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5615 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5616 }
5617#endif
5618 alc_auto_parse_customize_define(codec);
5619
5620 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5621
Takashi Iwai42399f72011-11-07 17:18:44 +01005622 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5623 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005624
Takashi Iwai42399f72011-11-07 17:18:44 +01005625 /* automatic parse from the BIOS config */
5626 err = alc262_parse_auto_config(codec);
5627 if (err < 0)
5628 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005629
Takashi Iwai60a6a842011-07-27 14:01:24 +02005630 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005631 alc_auto_fill_adc_caps(codec);
5632 alc_rebuild_imux_for_auto_mic(codec);
5633 alc_remove_invalid_adc_nids(codec);
5634 }
5635
5636 if (!spec->no_analog && !spec->cap_mixer)
5637 set_capture_mixer(codec);
5638
Takashi Iwai1d045db2011-07-07 18:23:21 +02005639 if (!spec->no_analog && has_cdefine_beep(codec)) {
5640 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005641 if (err < 0)
5642 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005644 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645
Takashi Iwai1d045db2011-07-07 18:23:21 +02005646 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01005647 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005648 spec->shutup = alc_eapd_shutup;
5649
Takashi Iwai589876e2012-02-20 15:47:55 +01005650 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5651
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005653
5654 error:
5655 alc_free(codec);
5656 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657}
5658
5659/*
5660 * ALC268
5661 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005662/* bind Beep switches of both NID 0x0f and 0x10 */
5663static const struct hda_bind_ctls alc268_bind_beep_sw = {
5664 .ops = &snd_hda_bind_sw,
5665 .values = {
5666 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5667 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5668 0
5669 },
5670};
5671
5672static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5673 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5674 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5675 { }
5676};
5677
5678/* set PCBEEP vol = 0, mute connections */
5679static const struct hda_verb alc268_beep_init_verbs[] = {
5680 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5681 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5682 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5683 { }
5684};
5685
5686/*
5687 * BIOS auto configuration
5688 */
5689static int alc268_parse_auto_config(struct hda_codec *codec)
5690{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005691 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005692 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005693 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5694 if (err > 0) {
5695 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5696 add_mixer(spec, alc268_beep_mixer);
5697 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005698 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005699 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005700 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005701}
5702
Takashi Iwai1d045db2011-07-07 18:23:21 +02005703/*
5704 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005705static int patch_alc268(struct hda_codec *codec)
5706{
5707 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005708 int i, has_beep, err;
5709
5710 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5711 if (spec == NULL)
5712 return -ENOMEM;
5713
5714 codec->spec = spec;
5715
5716 /* ALC268 has no aa-loopback mixer */
5717
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005718 /* automatic parse from the BIOS config */
5719 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005720 if (err < 0)
5721 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005722
Takashi Iwai1d045db2011-07-07 18:23:21 +02005723 has_beep = 0;
5724 for (i = 0; i < spec->num_mixers; i++) {
5725 if (spec->mixers[i] == alc268_beep_mixer) {
5726 has_beep = 1;
5727 break;
5728 }
5729 }
5730
5731 if (has_beep) {
5732 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005733 if (err < 0)
5734 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005735 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5736 /* override the amp caps for beep generator */
5737 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5738 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5739 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5740 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5741 (0 << AC_AMPCAP_MUTE_SHIFT));
5742 }
5743
Takashi Iwai60a6a842011-07-27 14:01:24 +02005744 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745 alc_auto_fill_adc_caps(codec);
5746 alc_rebuild_imux_for_auto_mic(codec);
5747 alc_remove_invalid_adc_nids(codec);
5748 }
5749
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005750 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005751 set_capture_mixer(codec);
5752
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005754 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005755 spec->shutup = alc_eapd_shutup;
5756
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005758
5759 error:
5760 alc_free(codec);
5761 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005762}
5763
5764/*
5765 * ALC269
5766 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005767static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5768 .substreams = 1,
5769 .channels_min = 2,
5770 .channels_max = 8,
5771 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5772 /* NID is set in alc_build_pcms */
5773 .ops = {
5774 .open = alc_playback_pcm_open,
5775 .prepare = alc_playback_pcm_prepare,
5776 .cleanup = alc_playback_pcm_cleanup
5777 },
5778};
5779
5780static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5781 .substreams = 1,
5782 .channels_min = 2,
5783 .channels_max = 2,
5784 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5785 /* NID is set in alc_build_pcms */
5786};
5787
5788#ifdef CONFIG_SND_HDA_POWER_SAVE
5789static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5790{
5791 switch (codec->subsystem_id) {
5792 case 0x103c1586:
5793 return 1;
5794 }
5795 return 0;
5796}
5797
5798static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5799{
5800 /* update mute-LED according to the speaker mute state */
5801 if (nid == 0x01 || nid == 0x14) {
5802 int pinval;
5803 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5804 HDA_AMP_MUTE)
5805 pinval = 0x24;
5806 else
5807 pinval = 0x20;
5808 /* mic2 vref pin is used for mute LED control */
5809 snd_hda_codec_update_cache(codec, 0x19, 0,
5810 AC_VERB_SET_PIN_WIDGET_CONTROL,
5811 pinval);
5812 }
5813 return alc_check_power_status(codec, nid);
5814}
5815#endif /* CONFIG_SND_HDA_POWER_SAVE */
5816
5817/* different alc269-variants */
5818enum {
5819 ALC269_TYPE_ALC269VA,
5820 ALC269_TYPE_ALC269VB,
5821 ALC269_TYPE_ALC269VC,
5822};
5823
5824/*
5825 * BIOS auto configuration
5826 */
5827static int alc269_parse_auto_config(struct hda_codec *codec)
5828{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005829 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005830 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5831 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5832 struct alc_spec *spec = codec->spec;
5833 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5834 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005835
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005836 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005837}
5838
Takashi Iwai1d045db2011-07-07 18:23:21 +02005839static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5840{
5841 int val = alc_read_coef_idx(codec, 0x04);
5842 if (power_up)
5843 val |= 1 << 11;
5844 else
5845 val &= ~(1 << 11);
5846 alc_write_coef_idx(codec, 0x04, val);
5847}
5848
5849static void alc269_shutup(struct hda_codec *codec)
5850{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005851 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005852 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005853 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005854 alc269_toggle_power_output(codec, 0);
5855 msleep(150);
5856 }
5857}
5858
Takashi Iwai2a439522011-07-26 09:52:50 +02005859#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005860static int alc269_resume(struct hda_codec *codec)
5861{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005862 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005863 alc269_toggle_power_output(codec, 0);
5864 msleep(150);
5865 }
5866
5867 codec->patch_ops.init(codec);
5868
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005869 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005870 alc269_toggle_power_output(codec, 1);
5871 msleep(200);
5872 }
5873
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005874 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005875 alc269_toggle_power_output(codec, 1);
5876
5877 snd_hda_codec_resume_amp(codec);
5878 snd_hda_codec_resume_cache(codec);
5879 hda_call_check_power_status(codec, 0x01);
5880 return 0;
5881}
Takashi Iwai2a439522011-07-26 09:52:50 +02005882#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005883
5884static void alc269_fixup_hweq(struct hda_codec *codec,
5885 const struct alc_fixup *fix, int action)
5886{
5887 int coef;
5888
5889 if (action != ALC_FIXUP_ACT_INIT)
5890 return;
5891 coef = alc_read_coef_idx(codec, 0x1e);
5892 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5893}
5894
5895static void alc271_fixup_dmic(struct hda_codec *codec,
5896 const struct alc_fixup *fix, int action)
5897{
5898 static const struct hda_verb verbs[] = {
5899 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5900 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5901 {}
5902 };
5903 unsigned int cfg;
5904
5905 if (strcmp(codec->chip_name, "ALC271X"))
5906 return;
5907 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5908 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5909 snd_hda_sequence_write(codec, verbs);
5910}
5911
Takashi Iwai017f2a12011-07-09 14:42:25 +02005912static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5913 const struct alc_fixup *fix, int action)
5914{
5915 struct alc_spec *spec = codec->spec;
5916
5917 if (action != ALC_FIXUP_ACT_PROBE)
5918 return;
5919
5920 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5921 * fix the sample rate of analog I/O to 44.1kHz
5922 */
5923 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5924 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5925}
5926
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005927static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5928 const struct alc_fixup *fix, int action)
5929{
5930 int coef;
5931
5932 if (action != ALC_FIXUP_ACT_INIT)
5933 return;
5934 /* The digital-mic unit sends PDM (differential signal) instead of
5935 * the standard PCM, thus you can't record a valid mono stream as is.
5936 * Below is a workaround specific to ALC269 to control the dmic
5937 * signal source as mono.
5938 */
5939 coef = alc_read_coef_idx(codec, 0x07);
5940 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5941}
5942
Takashi Iwai24519912011-08-16 15:08:49 +02005943static void alc269_quanta_automute(struct hda_codec *codec)
5944{
David Henningsson42cf0d02011-09-20 12:04:56 +02005945 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005946
5947 snd_hda_codec_write(codec, 0x20, 0,
5948 AC_VERB_SET_COEF_INDEX, 0x0c);
5949 snd_hda_codec_write(codec, 0x20, 0,
5950 AC_VERB_SET_PROC_COEF, 0x680);
5951
5952 snd_hda_codec_write(codec, 0x20, 0,
5953 AC_VERB_SET_COEF_INDEX, 0x0c);
5954 snd_hda_codec_write(codec, 0x20, 0,
5955 AC_VERB_SET_PROC_COEF, 0x480);
5956}
5957
5958static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5959 const struct alc_fixup *fix, int action)
5960{
5961 struct alc_spec *spec = codec->spec;
5962 if (action != ALC_FIXUP_ACT_PROBE)
5963 return;
5964 spec->automute_hook = alc269_quanta_automute;
5965}
5966
Takashi Iwai1d045db2011-07-07 18:23:21 +02005967enum {
5968 ALC269_FIXUP_SONY_VAIO,
5969 ALC275_FIXUP_SONY_VAIO_GPIO2,
5970 ALC269_FIXUP_DELL_M101Z,
5971 ALC269_FIXUP_SKU_IGNORE,
5972 ALC269_FIXUP_ASUS_G73JW,
5973 ALC269_FIXUP_LENOVO_EAPD,
5974 ALC275_FIXUP_SONY_HWEQ,
5975 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005976 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005977 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005978 ALC269_FIXUP_QUANTA_MUTE,
5979 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005980 ALC269_FIXUP_AMIC,
5981 ALC269_FIXUP_DMIC,
5982 ALC269VB_FIXUP_AMIC,
5983 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005984};
5985
5986static const struct alc_fixup alc269_fixups[] = {
5987 [ALC269_FIXUP_SONY_VAIO] = {
5988 .type = ALC_FIXUP_VERBS,
5989 .v.verbs = (const struct hda_verb[]) {
5990 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5991 {}
5992 }
5993 },
5994 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5995 .type = ALC_FIXUP_VERBS,
5996 .v.verbs = (const struct hda_verb[]) {
5997 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5998 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5999 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6000 { }
6001 },
6002 .chained = true,
6003 .chain_id = ALC269_FIXUP_SONY_VAIO
6004 },
6005 [ALC269_FIXUP_DELL_M101Z] = {
6006 .type = ALC_FIXUP_VERBS,
6007 .v.verbs = (const struct hda_verb[]) {
6008 /* Enables internal speaker */
6009 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6010 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6011 {}
6012 }
6013 },
6014 [ALC269_FIXUP_SKU_IGNORE] = {
6015 .type = ALC_FIXUP_SKU,
6016 .v.sku = ALC_FIXUP_SKU_IGNORE,
6017 },
6018 [ALC269_FIXUP_ASUS_G73JW] = {
6019 .type = ALC_FIXUP_PINS,
6020 .v.pins = (const struct alc_pincfg[]) {
6021 { 0x17, 0x99130111 }, /* subwoofer */
6022 { }
6023 }
6024 },
6025 [ALC269_FIXUP_LENOVO_EAPD] = {
6026 .type = ALC_FIXUP_VERBS,
6027 .v.verbs = (const struct hda_verb[]) {
6028 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6029 {}
6030 }
6031 },
6032 [ALC275_FIXUP_SONY_HWEQ] = {
6033 .type = ALC_FIXUP_FUNC,
6034 .v.func = alc269_fixup_hweq,
6035 .chained = true,
6036 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6037 },
6038 [ALC271_FIXUP_DMIC] = {
6039 .type = ALC_FIXUP_FUNC,
6040 .v.func = alc271_fixup_dmic,
6041 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006042 [ALC269_FIXUP_PCM_44K] = {
6043 .type = ALC_FIXUP_FUNC,
6044 .v.func = alc269_fixup_pcm_44k,
6045 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006046 [ALC269_FIXUP_STEREO_DMIC] = {
6047 .type = ALC_FIXUP_FUNC,
6048 .v.func = alc269_fixup_stereo_dmic,
6049 },
Takashi Iwai24519912011-08-16 15:08:49 +02006050 [ALC269_FIXUP_QUANTA_MUTE] = {
6051 .type = ALC_FIXUP_FUNC,
6052 .v.func = alc269_fixup_quanta_mute,
6053 },
6054 [ALC269_FIXUP_LIFEBOOK] = {
6055 .type = ALC_FIXUP_PINS,
6056 .v.pins = (const struct alc_pincfg[]) {
6057 { 0x1a, 0x2101103f }, /* dock line-out */
6058 { 0x1b, 0x23a11040 }, /* dock mic-in */
6059 { }
6060 },
6061 .chained = true,
6062 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6063 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006064 [ALC269_FIXUP_AMIC] = {
6065 .type = ALC_FIXUP_PINS,
6066 .v.pins = (const struct alc_pincfg[]) {
6067 { 0x14, 0x99130110 }, /* speaker */
6068 { 0x15, 0x0121401f }, /* HP out */
6069 { 0x18, 0x01a19c20 }, /* mic */
6070 { 0x19, 0x99a3092f }, /* int-mic */
6071 { }
6072 },
6073 },
6074 [ALC269_FIXUP_DMIC] = {
6075 .type = ALC_FIXUP_PINS,
6076 .v.pins = (const struct alc_pincfg[]) {
6077 { 0x12, 0x99a3092f }, /* int-mic */
6078 { 0x14, 0x99130110 }, /* speaker */
6079 { 0x15, 0x0121401f }, /* HP out */
6080 { 0x18, 0x01a19c20 }, /* mic */
6081 { }
6082 },
6083 },
6084 [ALC269VB_FIXUP_AMIC] = {
6085 .type = ALC_FIXUP_PINS,
6086 .v.pins = (const struct alc_pincfg[]) {
6087 { 0x14, 0x99130110 }, /* speaker */
6088 { 0x18, 0x01a19c20 }, /* mic */
6089 { 0x19, 0x99a3092f }, /* int-mic */
6090 { 0x21, 0x0121401f }, /* HP out */
6091 { }
6092 },
6093 },
David Henningsson2267ea92012-01-03 08:45:56 +01006094 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006095 .type = ALC_FIXUP_PINS,
6096 .v.pins = (const struct alc_pincfg[]) {
6097 { 0x12, 0x99a3092f }, /* int-mic */
6098 { 0x14, 0x99130110 }, /* speaker */
6099 { 0x18, 0x01a19c20 }, /* mic */
6100 { 0x21, 0x0121401f }, /* HP out */
6101 { }
6102 },
6103 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006104};
6105
6106static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02006107 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006108 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6109 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6110 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6111 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6112 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006113 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6114 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6115 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6116 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6117 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6118 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006119 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006120 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6121 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6122 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6123 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6124 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006125 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006126 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006127 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006128
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006129#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006130 /* Below is a quirk table taken from the old code.
6131 * Basically the device should work as is without the fixup table.
6132 * If BIOS doesn't give a proper info, enable the corresponding
6133 * fixup entry.
6134 */
6135 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6136 ALC269_FIXUP_AMIC),
6137 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006138 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6139 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6140 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6141 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6142 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6143 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6144 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6145 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6146 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6147 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6148 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6149 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6150 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6151 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6152 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6153 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6154 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6155 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6156 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6157 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6158 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6159 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6160 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6161 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6162 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6163 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6164 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6165 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6166 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6167 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6168 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6169 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6170 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6171 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6172 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6173 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6174 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6175 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6176#endif
6177 {}
6178};
6179
6180static const struct alc_model_fixup alc269_fixup_models[] = {
6181 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6182 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006183 {}
6184};
6185
6186
6187static int alc269_fill_coef(struct hda_codec *codec)
6188{
6189 int val;
6190
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006191 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006192 alc_write_coef_idx(codec, 0xf, 0x960b);
6193 alc_write_coef_idx(codec, 0xe, 0x8817);
6194 }
6195
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006196 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006197 alc_write_coef_idx(codec, 0xf, 0x960b);
6198 alc_write_coef_idx(codec, 0xe, 0x8814);
6199 }
6200
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006201 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006202 val = alc_read_coef_idx(codec, 0x04);
6203 /* Power up output pin */
6204 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6205 }
6206
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006207 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006208 val = alc_read_coef_idx(codec, 0xd);
6209 if ((val & 0x0c00) >> 10 != 0x1) {
6210 /* Capless ramp up clock control */
6211 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6212 }
6213 val = alc_read_coef_idx(codec, 0x17);
6214 if ((val & 0x01c0) >> 6 != 0x4) {
6215 /* Class D power on reset */
6216 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6217 }
6218 }
6219
6220 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6221 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6222
6223 val = alc_read_coef_idx(codec, 0x4); /* HP */
6224 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6225
6226 return 0;
6227}
6228
6229/*
6230 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006231static int patch_alc269(struct hda_codec *codec)
6232{
6233 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006234 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006235
6236 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6237 if (spec == NULL)
6238 return -ENOMEM;
6239
6240 codec->spec = spec;
6241
6242 spec->mixer_nid = 0x0b;
6243
6244 alc_auto_parse_customize_define(codec);
6245
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006246 err = alc_codec_rename_from_preset(codec);
6247 if (err < 0)
6248 goto error;
6249
Takashi Iwai1d045db2011-07-07 18:23:21 +02006250 if (codec->vendor_id == 0x10ec0269) {
6251 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006252 switch (alc_get_coef0(codec) & 0x00f0) {
6253 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006254 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006255 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006256 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006257 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006258 break;
6259 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006260 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6261 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006262 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006263 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006264 break;
6265 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006266 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006267 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006268 if (err < 0)
6269 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006270 alc269_fill_coef(codec);
6271 }
6272
Takashi Iwaia4297b52011-08-23 18:40:12 +02006273 alc_pick_fixup(codec, alc269_fixup_models,
6274 alc269_fixup_tbl, alc269_fixups);
6275 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006276
Takashi Iwaia4297b52011-08-23 18:40:12 +02006277 /* automatic parse from the BIOS config */
6278 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006279 if (err < 0)
6280 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006281
Takashi Iwai60a6a842011-07-27 14:01:24 +02006282 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006283 alc_auto_fill_adc_caps(codec);
6284 alc_rebuild_imux_for_auto_mic(codec);
6285 alc_remove_invalid_adc_nids(codec);
6286 }
6287
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006288 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006289 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006290
6291 if (!spec->no_analog && has_cdefine_beep(codec)) {
6292 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006293 if (err < 0)
6294 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006295 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006296 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006297
Takashi Iwai1d045db2011-07-07 18:23:21 +02006298 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006299#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006300 codec->patch_ops.resume = alc269_resume;
6301#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02006302 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006303 spec->shutup = alc269_shutup;
6304
Takashi Iwai1d045db2011-07-07 18:23:21 +02006305#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai1d045db2011-07-07 18:23:21 +02006306 if (alc269_mic2_for_mute_led(codec))
6307 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
6308#endif
6309
Takashi Iwai589876e2012-02-20 15:47:55 +01006310 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6311
Takashi Iwai1d045db2011-07-07 18:23:21 +02006312 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006313
6314 error:
6315 alc_free(codec);
6316 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006317}
6318
6319/*
6320 * ALC861
6321 */
6322
Takashi Iwai1d045db2011-07-07 18:23:21 +02006323static int alc861_parse_auto_config(struct hda_codec *codec)
6324{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006325 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006326 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6327 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006328}
6329
Takashi Iwai1d045db2011-07-07 18:23:21 +02006330/* Pin config fixes */
6331enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006332 ALC861_FIXUP_FSC_AMILO_PI1505,
6333 ALC861_FIXUP_AMP_VREF_0F,
6334 ALC861_FIXUP_NO_JACK_DETECT,
6335 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006336};
6337
Takashi Iwai31150f22012-01-30 10:54:08 +01006338/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6339static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6340 const struct alc_fixup *fix, int action)
6341{
6342 struct alc_spec *spec = codec->spec;
6343 unsigned int val;
6344
6345 if (action != ALC_FIXUP_ACT_INIT)
6346 return;
6347 val = snd_hda_codec_read(codec, 0x0f, 0,
6348 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6349 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6350 val |= AC_PINCTL_IN_EN;
6351 val |= AC_PINCTL_VREF_50;
6352 snd_hda_codec_write(codec, 0x0f, 0,
6353 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6354 spec->keep_vref_in_automute = 1;
6355}
6356
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006357/* suppress the jack-detection */
6358static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6359 const struct alc_fixup *fix, int action)
6360{
6361 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6362 codec->no_jack_detect = 1;
6363}
6364
Takashi Iwai1d045db2011-07-07 18:23:21 +02006365static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006366 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006367 .type = ALC_FIXUP_PINS,
6368 .v.pins = (const struct alc_pincfg[]) {
6369 { 0x0b, 0x0221101f }, /* HP */
6370 { 0x0f, 0x90170310 }, /* speaker */
6371 { }
6372 }
6373 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006374 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006375 .type = ALC_FIXUP_FUNC,
6376 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006377 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006378 [ALC861_FIXUP_NO_JACK_DETECT] = {
6379 .type = ALC_FIXUP_FUNC,
6380 .v.func = alc_fixup_no_jack_detect,
6381 },
6382 [ALC861_FIXUP_ASUS_A6RP] = {
6383 .type = ALC_FIXUP_FUNC,
6384 .v.func = alc861_fixup_asus_amp_vref_0f,
6385 .chained = true,
6386 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6387 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006388};
6389
6390static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006391 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6392 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6393 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6394 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6395 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6396 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006397 {}
6398};
6399
6400/*
6401 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006402static int patch_alc861(struct hda_codec *codec)
6403{
6404 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006405 int err;
6406
6407 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6408 if (spec == NULL)
6409 return -ENOMEM;
6410
6411 codec->spec = spec;
6412
6413 spec->mixer_nid = 0x15;
6414
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006415 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6416 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006417
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006418 /* automatic parse from the BIOS config */
6419 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006420 if (err < 0)
6421 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006422
Takashi Iwai60a6a842011-07-27 14:01:24 +02006423 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006424 alc_auto_fill_adc_caps(codec);
6425 alc_rebuild_imux_for_auto_mic(codec);
6426 alc_remove_invalid_adc_nids(codec);
6427 }
6428
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006429 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006430 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006431
6432 if (!spec->no_analog) {
6433 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006434 if (err < 0)
6435 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006436 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6437 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006438
Takashi Iwai1d045db2011-07-07 18:23:21 +02006439 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006440 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006441#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006442 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006443#endif
6444
Takashi Iwai589876e2012-02-20 15:47:55 +01006445 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6446
Takashi Iwai1d045db2011-07-07 18:23:21 +02006447 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006448
6449 error:
6450 alc_free(codec);
6451 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006452}
6453
6454/*
6455 * ALC861-VD support
6456 *
6457 * Based on ALC882
6458 *
6459 * In addition, an independent DAC
6460 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006461static int alc861vd_parse_auto_config(struct hda_codec *codec)
6462{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006463 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006464 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6465 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006466}
6467
Takashi Iwai1d045db2011-07-07 18:23:21 +02006468enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006469 ALC660VD_FIX_ASUS_GPIO1,
6470 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006471};
6472
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006473/* exclude VREF80 */
6474static void alc861vd_fixup_dallas(struct hda_codec *codec,
6475 const struct alc_fixup *fix, int action)
6476{
6477 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6478 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6479 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6480 }
6481}
6482
Takashi Iwai1d045db2011-07-07 18:23:21 +02006483static const struct alc_fixup alc861vd_fixups[] = {
6484 [ALC660VD_FIX_ASUS_GPIO1] = {
6485 .type = ALC_FIXUP_VERBS,
6486 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006487 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006488 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6489 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6490 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6491 { }
6492 }
6493 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006494 [ALC861VD_FIX_DALLAS] = {
6495 .type = ALC_FIXUP_FUNC,
6496 .v.func = alc861vd_fixup_dallas,
6497 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006498};
6499
6500static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006501 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006502 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006503 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006504 {}
6505};
6506
6507static const struct hda_verb alc660vd_eapd_verbs[] = {
6508 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6509 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6510 { }
6511};
6512
6513/*
6514 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006515static int patch_alc861vd(struct hda_codec *codec)
6516{
6517 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006518 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006519
6520 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6521 if (spec == NULL)
6522 return -ENOMEM;
6523
6524 codec->spec = spec;
6525
6526 spec->mixer_nid = 0x0b;
6527
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006528 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6529 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006530
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006531 /* automatic parse from the BIOS config */
6532 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006533 if (err < 0)
6534 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006535
Takashi Iwai1d045db2011-07-07 18:23:21 +02006536 if (codec->vendor_id == 0x10ec0660) {
6537 /* always turn on EAPD */
6538 add_verb(spec, alc660vd_eapd_verbs);
6539 }
6540
Takashi Iwai60a6a842011-07-27 14:01:24 +02006541 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006542 alc_auto_fill_adc_caps(codec);
6543 alc_rebuild_imux_for_auto_mic(codec);
6544 alc_remove_invalid_adc_nids(codec);
6545 }
6546
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006547 if (!spec->no_analog && !spec->cap_mixer)
6548 set_capture_mixer(codec);
6549
6550 if (!spec->no_analog) {
6551 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006552 if (err < 0)
6553 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006554 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6555 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006556
Takashi Iwai1d045db2011-07-07 18:23:21 +02006557 codec->patch_ops = alc_patch_ops;
6558
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006559 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006560 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006561
Takashi Iwai589876e2012-02-20 15:47:55 +01006562 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6563
Takashi Iwai1d045db2011-07-07 18:23:21 +02006564 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006565
6566 error:
6567 alc_free(codec);
6568 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006569}
6570
6571/*
6572 * ALC662 support
6573 *
6574 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6575 * configuration. Each pin widget can choose any input DACs and a mixer.
6576 * Each ADC is connected from a mixer of all inputs. This makes possible
6577 * 6-channel independent captures.
6578 *
6579 * In addition, an independent DAC for the multi-playback (not used in this
6580 * driver yet).
6581 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006582
6583/*
6584 * BIOS auto configuration
6585 */
6586
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006587static int alc662_parse_auto_config(struct hda_codec *codec)
6588{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006589 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006590 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6591 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6592 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006593
Kailang Yang6227cdc2010-02-25 08:36:52 +01006594 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6595 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006596 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006597 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006598 ssids = alc662_ssids;
6599 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006600}
6601
Todd Broch6be79482010-12-07 16:51:05 -08006602static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006603 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006604{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006605 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006606 return;
Todd Broch6be79482010-12-07 16:51:05 -08006607 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6608 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6609 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6610 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6611 (0 << AC_AMPCAP_MUTE_SHIFT)))
6612 printk(KERN_WARNING
6613 "hda_codec: failed to override amp caps for NID 0x2\n");
6614}
6615
David Henningsson6cb3b702010-09-09 08:51:44 +02006616enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006617 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006618 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006619 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006620 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006621 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006622 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006623 ALC662_FIXUP_ASUS_MODE1,
6624 ALC662_FIXUP_ASUS_MODE2,
6625 ALC662_FIXUP_ASUS_MODE3,
6626 ALC662_FIXUP_ASUS_MODE4,
6627 ALC662_FIXUP_ASUS_MODE5,
6628 ALC662_FIXUP_ASUS_MODE6,
6629 ALC662_FIXUP_ASUS_MODE7,
6630 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006631 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006632};
6633
6634static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006635 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006636 .type = ALC_FIXUP_PINS,
6637 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006638 { 0x15, 0x99130112 }, /* subwoofer */
6639 { }
6640 }
6641 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006642 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006643 .type = ALC_FIXUP_PINS,
6644 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006645 { 0x17, 0x99130112 }, /* subwoofer */
6646 { }
6647 }
6648 },
Todd Broch6be79482010-12-07 16:51:05 -08006649 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006650 .type = ALC_FIXUP_FUNC,
6651 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006652 },
6653 [ALC662_FIXUP_CZC_P10T] = {
6654 .type = ALC_FIXUP_VERBS,
6655 .v.verbs = (const struct hda_verb[]) {
6656 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6657 {}
6658 }
6659 },
David Henningsson94024cd2011-04-29 14:10:55 +02006660 [ALC662_FIXUP_SKU_IGNORE] = {
6661 .type = ALC_FIXUP_SKU,
6662 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006663 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006664 [ALC662_FIXUP_HP_RP5800] = {
6665 .type = ALC_FIXUP_PINS,
6666 .v.pins = (const struct alc_pincfg[]) {
6667 { 0x14, 0x0221201f }, /* HP out */
6668 { }
6669 },
6670 .chained = true,
6671 .chain_id = ALC662_FIXUP_SKU_IGNORE
6672 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006673 [ALC662_FIXUP_ASUS_MODE1] = {
6674 .type = ALC_FIXUP_PINS,
6675 .v.pins = (const struct alc_pincfg[]) {
6676 { 0x14, 0x99130110 }, /* speaker */
6677 { 0x18, 0x01a19c20 }, /* mic */
6678 { 0x19, 0x99a3092f }, /* int-mic */
6679 { 0x21, 0x0121401f }, /* HP out */
6680 { }
6681 },
6682 .chained = true,
6683 .chain_id = ALC662_FIXUP_SKU_IGNORE
6684 },
6685 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006686 .type = ALC_FIXUP_PINS,
6687 .v.pins = (const struct alc_pincfg[]) {
6688 { 0x14, 0x99130110 }, /* speaker */
6689 { 0x18, 0x01a19820 }, /* mic */
6690 { 0x19, 0x99a3092f }, /* int-mic */
6691 { 0x1b, 0x0121401f }, /* HP out */
6692 { }
6693 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006694 .chained = true,
6695 .chain_id = ALC662_FIXUP_SKU_IGNORE
6696 },
6697 [ALC662_FIXUP_ASUS_MODE3] = {
6698 .type = ALC_FIXUP_PINS,
6699 .v.pins = (const struct alc_pincfg[]) {
6700 { 0x14, 0x99130110 }, /* speaker */
6701 { 0x15, 0x0121441f }, /* HP */
6702 { 0x18, 0x01a19840 }, /* mic */
6703 { 0x19, 0x99a3094f }, /* int-mic */
6704 { 0x21, 0x01211420 }, /* HP2 */
6705 { }
6706 },
6707 .chained = true,
6708 .chain_id = ALC662_FIXUP_SKU_IGNORE
6709 },
6710 [ALC662_FIXUP_ASUS_MODE4] = {
6711 .type = ALC_FIXUP_PINS,
6712 .v.pins = (const struct alc_pincfg[]) {
6713 { 0x14, 0x99130110 }, /* speaker */
6714 { 0x16, 0x99130111 }, /* speaker */
6715 { 0x18, 0x01a19840 }, /* mic */
6716 { 0x19, 0x99a3094f }, /* int-mic */
6717 { 0x21, 0x0121441f }, /* HP */
6718 { }
6719 },
6720 .chained = true,
6721 .chain_id = ALC662_FIXUP_SKU_IGNORE
6722 },
6723 [ALC662_FIXUP_ASUS_MODE5] = {
6724 .type = ALC_FIXUP_PINS,
6725 .v.pins = (const struct alc_pincfg[]) {
6726 { 0x14, 0x99130110 }, /* speaker */
6727 { 0x15, 0x0121441f }, /* HP */
6728 { 0x16, 0x99130111 }, /* speaker */
6729 { 0x18, 0x01a19840 }, /* mic */
6730 { 0x19, 0x99a3094f }, /* int-mic */
6731 { }
6732 },
6733 .chained = true,
6734 .chain_id = ALC662_FIXUP_SKU_IGNORE
6735 },
6736 [ALC662_FIXUP_ASUS_MODE6] = {
6737 .type = ALC_FIXUP_PINS,
6738 .v.pins = (const struct alc_pincfg[]) {
6739 { 0x14, 0x99130110 }, /* speaker */
6740 { 0x15, 0x01211420 }, /* HP2 */
6741 { 0x18, 0x01a19840 }, /* mic */
6742 { 0x19, 0x99a3094f }, /* int-mic */
6743 { 0x1b, 0x0121441f }, /* HP */
6744 { }
6745 },
6746 .chained = true,
6747 .chain_id = ALC662_FIXUP_SKU_IGNORE
6748 },
6749 [ALC662_FIXUP_ASUS_MODE7] = {
6750 .type = ALC_FIXUP_PINS,
6751 .v.pins = (const struct alc_pincfg[]) {
6752 { 0x14, 0x99130110 }, /* speaker */
6753 { 0x17, 0x99130111 }, /* speaker */
6754 { 0x18, 0x01a19840 }, /* mic */
6755 { 0x19, 0x99a3094f }, /* int-mic */
6756 { 0x1b, 0x01214020 }, /* HP */
6757 { 0x21, 0x0121401f }, /* HP */
6758 { }
6759 },
6760 .chained = true,
6761 .chain_id = ALC662_FIXUP_SKU_IGNORE
6762 },
6763 [ALC662_FIXUP_ASUS_MODE8] = {
6764 .type = ALC_FIXUP_PINS,
6765 .v.pins = (const struct alc_pincfg[]) {
6766 { 0x14, 0x99130110 }, /* speaker */
6767 { 0x12, 0x99a30970 }, /* int-mic */
6768 { 0x15, 0x01214020 }, /* HP */
6769 { 0x17, 0x99130111 }, /* speaker */
6770 { 0x18, 0x01a19840 }, /* mic */
6771 { 0x21, 0x0121401f }, /* HP */
6772 { }
6773 },
6774 .chained = true,
6775 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006776 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006777 [ALC662_FIXUP_NO_JACK_DETECT] = {
6778 .type = ALC_FIXUP_FUNC,
6779 .v.func = alc_fixup_no_jack_detect,
6780 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006781};
6782
Takashi Iwaia9111322011-05-02 11:30:18 +02006783static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006784 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006785 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006786 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006787 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006788 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006789 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006790 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006791 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006792 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006793 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006794 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006795
6796#if 0
6797 /* Below is a quirk table taken from the old code.
6798 * Basically the device should work as is without the fixup table.
6799 * If BIOS doesn't give a proper info, enable the corresponding
6800 * fixup entry.
6801 */
6802 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6803 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6804 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6805 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6806 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6807 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6808 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6809 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6810 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6811 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6812 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6813 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6814 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6815 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6816 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6817 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6818 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6819 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6820 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6821 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6822 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6823 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6824 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6825 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6826 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6827 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6828 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6829 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6830 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6831 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6832 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6833 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6834 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6835 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6836 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6837 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6838 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6839 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6840 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6841 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6842 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6843 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6844 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6845 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6846 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6847 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6848 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6849 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6850 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6851 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6852#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006853 {}
6854};
6855
Todd Broch6be79482010-12-07 16:51:05 -08006856static const struct alc_model_fixup alc662_fixup_models[] = {
6857 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006858 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6859 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6860 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6861 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6862 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6863 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6864 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6865 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006866 {}
6867};
David Henningsson6cb3b702010-09-09 08:51:44 +02006868
6869
Takashi Iwai1d045db2011-07-07 18:23:21 +02006870/*
6871 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006872static int patch_alc662(struct hda_codec *codec)
6873{
6874 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006875 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006876
6877 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6878 if (!spec)
6879 return -ENOMEM;
6880
6881 codec->spec = spec;
6882
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006883 spec->mixer_nid = 0x0b;
6884
Takashi Iwai53c334a2011-08-23 18:27:14 +02006885 /* handle multiple HPs as is */
6886 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6887
Kailang Yangda00c242010-03-19 11:23:45 +01006888 alc_auto_parse_customize_define(codec);
6889
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006890 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6891
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006892 err = alc_codec_rename_from_preset(codec);
6893 if (err < 0)
6894 goto error;
6895
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006896 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006897 codec->bus->pci->subsystem_vendor == 0x1025 &&
6898 spec->cdefine.platform_type == 1) {
6899 if (alc_codec_rename(codec, "ALC272X") < 0)
6900 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006901 }
Kailang Yang274693f2009-12-03 10:07:50 +01006902
Takashi Iwaib9c51062011-08-24 18:08:07 +02006903 alc_pick_fixup(codec, alc662_fixup_models,
6904 alc662_fixup_tbl, alc662_fixups);
6905 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6906 /* automatic parse from the BIOS config */
6907 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006908 if (err < 0)
6909 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006910
Takashi Iwai60a6a842011-07-27 14:01:24 +02006911 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006912 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006913 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006914 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006915 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006916
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006917 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006918 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006919
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006920 if (!spec->no_analog && has_cdefine_beep(codec)) {
6921 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006922 if (err < 0)
6923 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006924 switch (codec->vendor_id) {
6925 case 0x10ec0662:
6926 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6927 break;
6928 case 0x10ec0272:
6929 case 0x10ec0663:
6930 case 0x10ec0665:
6931 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6932 break;
6933 case 0x10ec0273:
6934 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6935 break;
6936 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006937 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006938
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006939 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006940 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006941 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006942
Takashi Iwai589876e2012-02-20 15:47:55 +01006943 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6944
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006945 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006946
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006947 error:
6948 alc_free(codec);
6949 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006950}
6951
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006952/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006953 * ALC680 support
6954 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006955
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006956static int alc680_parse_auto_config(struct hda_codec *codec)
6957{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006958 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006959}
6960
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006961/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006962 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006963static int patch_alc680(struct hda_codec *codec)
6964{
6965 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006966 int err;
6967
6968 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6969 if (spec == NULL)
6970 return -ENOMEM;
6971
6972 codec->spec = spec;
6973
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006974 /* ALC680 has no aa-loopback mixer */
6975
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006976 /* automatic parse from the BIOS config */
6977 err = alc680_parse_auto_config(codec);
6978 if (err < 0) {
6979 alc_free(codec);
6980 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006981 }
6982
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006983 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006984 set_capture_mixer(codec);
6985
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006986 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006987 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006988
6989 return 0;
6990}
6991
6992/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006993 * patch entries
6994 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006995static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006996 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006997 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006998 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006999 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007000 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007001 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007002 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007003 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007004 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007005 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007006 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007007 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007008 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7009 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7010 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007011 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02007012 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007013 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7014 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007015 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7016 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007017 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007018 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007019 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007020 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007021 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007022 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02007023 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007024 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02007025 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007026 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02007027 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007028 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007029 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007030 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02007031 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007032 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02007033 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007034 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007035 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007036 {} /* terminator */
7037};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007038
7039MODULE_ALIAS("snd-hda-codec-id:10ec*");
7040
7041MODULE_LICENSE("GPL");
7042MODULE_DESCRIPTION("Realtek HD-audio codec");
7043
7044static struct hda_codec_preset_list realtek_list = {
7045 .preset = snd_hda_preset_realtek,
7046 .owner = THIS_MODULE,
7047};
7048
7049static int __init patch_realtek_init(void)
7050{
7051 return snd_hda_add_codec_preset(&realtek_list);
7052}
7053
7054static void __exit patch_realtek_exit(void)
7055{
7056 snd_hda_delete_codec_preset(&realtek_list);
7057}
7058
7059module_init(patch_realtek_init)
7060module_exit(patch_realtek_exit)