blob: eba50dff613047e1d8e7ef9ce7cfe4383b1b9c74 [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 Iwaicd896c32008-11-18 12:36:33 +0100305 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
306 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100307 if (!imux->num_items && mux_idx > 0)
308 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100309 if (!imux->num_items)
310 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100311
Takashi Iwai21268962011-07-07 15:01:13 +0200312 if (idx >= imux->num_items)
313 idx = imux->num_items - 1;
314 if (spec->cur_mux[adc_idx] == idx && !force)
315 return 0;
316 spec->cur_mux[adc_idx] = idx;
317
Takashi Iwai24de1832011-11-07 17:13:39 +0100318 /* for shared I/O, change the pin-control accordingly */
319 if (spec->shared_mic_hp) {
320 /* NOTE: this assumes that there are only two inputs, the
321 * first is the real internal mic and the second is HP jack.
322 */
323 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
324 AC_VERB_SET_PIN_WIDGET_CONTROL,
325 spec->cur_mux[adc_idx] ?
326 PIN_VREF80 : PIN_HP);
327 spec->automute_speaker = !spec->cur_mux[adc_idx];
328 call_update_outputs(codec);
329 }
330
Takashi Iwai21268962011-07-07 15:01:13 +0200331 if (spec->dyn_adc_switch) {
332 alc_dyn_adc_pcm_resetup(codec, idx);
333 adc_idx = spec->dyn_adc_idx[idx];
334 }
335
Takashi Iwai61071592011-11-23 07:52:15 +0100336 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200337
338 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100339 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
340 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200341 return 1;
342
Takashi Iwaia22d5432009-07-27 12:54:26 +0200343 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200344 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100345 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100346 int active = imux->items[idx].index;
347 for (i = 0; i < num_conns; i++) {
348 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
349 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100350 HDA_AMP_MUTE, v);
351 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100352 } else {
353 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200354 snd_hda_codec_write_cache(codec, nid, 0,
355 AC_VERB_SET_CONNECT_SEL,
356 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100357 }
Takashi Iwai21268962011-07-07 15:01:13 +0200358 return 1;
359}
360
361static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
362 struct snd_ctl_elem_value *ucontrol)
363{
364 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
365 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
366 return alc_mux_select(codec, adc_idx,
367 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100368}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100371 * set up the input pin config (depending on the given auto-pin type)
372 */
373static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
374 int auto_pin_type)
375{
376 unsigned int val = PIN_IN;
377
Takashi Iwai86e29592010-09-09 14:50:17 +0200378 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100379 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200380 unsigned int oldval;
381 oldval = snd_hda_codec_read(codec, nid, 0,
382 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100383 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100384 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200385 /* if the default pin setup is vref50, we give it priority */
386 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100387 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200388 else if (pincap & AC_PINCAP_VREF_50)
389 val = PIN_VREF50;
390 else if (pincap & AC_PINCAP_VREF_100)
391 val = PIN_VREF100;
392 else if (pincap & AC_PINCAP_VREF_GRD)
393 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100394 }
395 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
396}
397
398/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200399 * Append the given mixer and verb elements for the later use
400 * The mixer array is referred in build_controls(), and init_verbs are
401 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100402 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200403static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100404{
405 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
406 return;
407 spec->mixers[spec->num_mixers++] = mix;
408}
409
410static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
411{
412 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
413 return;
414 spec->init_verbs[spec->num_init_verbs++] = verb;
415}
416
417/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200418 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100419 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200420/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200421static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200422 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
423 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
424 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
425 { }
426};
427
Takashi Iwaia9111322011-05-02 11:30:18 +0200428static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200429 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
430 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
431 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
432 { }
433};
434
Takashi Iwaia9111322011-05-02 11:30:18 +0200435static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200436 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
437 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
438 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
439 { }
440};
441
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200442/*
443 * Fix hardware PLL issue
444 * On some codecs, the analog PLL gating control must be off while
445 * the default value is 1.
446 */
447static void alc_fix_pll(struct hda_codec *codec)
448{
449 struct alc_spec *spec = codec->spec;
450 unsigned int val;
451
452 if (!spec->pll_nid)
453 return;
454 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
455 spec->pll_coef_idx);
456 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
457 AC_VERB_GET_PROC_COEF, 0);
458 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
459 spec->pll_coef_idx);
460 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
461 val & ~(1 << spec->pll_coef_bit));
462}
463
464static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
465 unsigned int coef_idx, unsigned int coef_bit)
466{
467 struct alc_spec *spec = codec->spec;
468 spec->pll_nid = nid;
469 spec->pll_coef_idx = coef_idx;
470 spec->pll_coef_bit = coef_bit;
471 alc_fix_pll(codec);
472}
473
Takashi Iwai1d045db2011-07-07 18:23:21 +0200474/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200475 * Jack detections for HP auto-mute and mic-switch
476 */
477
478/* check each pin in the given array; returns true if any of them is plugged */
479static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200480{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200481 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200482
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200483 for (i = 0; i < num_pins; i++) {
484 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200485 if (!nid)
486 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200487 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200488 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200489 return present;
490}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200491
Takashi Iwai1d045db2011-07-07 18:23:21 +0200492/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200493static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200494 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495{
496 struct alc_spec *spec = codec->spec;
497 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200498 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200499 int i;
500
501 for (i = 0; i < num_pins; i++) {
502 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100503 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200504 if (!nid)
505 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200506 switch (spec->automute_mode) {
507 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100508 /* don't reset VREF value in case it's controlling
509 * the amp (see alc861_fixup_asus_amp_vref_0f())
510 */
511 if (spec->keep_vref_in_automute) {
512 val = snd_hda_codec_read(codec, nid, 0,
513 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
514 val &= ~PIN_HP;
515 } else
516 val = 0;
517 val |= pin_bits;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200518 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200519 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai31150f22012-01-30 10:54:08 +0100520 val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200521 break;
522 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200523 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200524 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200525 break;
526 case ALC_AUTOMUTE_MIXER:
527 nid = spec->automute_mixer_nid[i];
528 if (!nid)
529 break;
530 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200531 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200532 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200533 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200534 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200535 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200536 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200537}
538
David Henningsson42cf0d02011-09-20 12:04:56 +0200539/* Toggle outputs muting */
540static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200541{
542 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200543 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200544
Takashi Iwaic0a20262011-06-10 15:28:15 +0200545 /* Control HP pins/amps depending on master_mute state;
546 * in general, HP pins/amps control should be enabled in all cases,
547 * but currently set only for master_mute, just to be safe
548 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100549 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
550 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200551 spec->autocfg.hp_pins, spec->master_mute, true);
552
David Henningsson42cf0d02011-09-20 12:04:56 +0200553 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200554 on = 0;
555 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200556 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200557 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200559 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200560
561 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200562 /* if LO is a copy of either HP or Speaker, don't need to handle it */
563 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
564 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200565 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200566 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200567 on = 0;
568 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200569 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200571 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200572 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200573}
574
David Henningsson42cf0d02011-09-20 12:04:56 +0200575static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200576{
577 struct alc_spec *spec = codec->spec;
578 if (spec->automute_hook)
579 spec->automute_hook(codec);
580 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200581 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200582}
583
Takashi Iwai1d045db2011-07-07 18:23:21 +0200584/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200585static void alc_hp_automute(struct hda_codec *codec)
586{
587 struct alc_spec *spec = codec->spec;
588
David Henningsson42cf0d02011-09-20 12:04:56 +0200589 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
591 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200593 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200594 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200595}
596
Takashi Iwai1d045db2011-07-07 18:23:21 +0200597/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200598static void alc_line_automute(struct hda_codec *codec)
599{
600 struct alc_spec *spec = codec->spec;
601
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200602 /* check LO jack only when it's different from HP */
603 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
604 return;
605
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200606 spec->line_jack_present =
607 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
608 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200609 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200610 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200611 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200612}
613
Takashi Iwai8d087c72011-06-28 12:45:47 +0200614#define get_connection_index(codec, mux, nid) \
615 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200616
Takashi Iwai1d045db2011-07-07 18:23:21 +0200617/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200618static void alc_mic_automute(struct hda_codec *codec)
619{
620 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200621 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200622
Takashi Iwai21268962011-07-07 15:01:13 +0200623 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200624 return;
625 if (snd_BUG_ON(!spec->adc_nids))
626 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200627 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200628 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200629
Takashi Iwai21268962011-07-07 15:01:13 +0200630 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
631 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
632 else if (spec->dock_mic_idx >= 0 &&
633 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
634 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
635 else
636 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200637}
638
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100639/* handle the specified unsol action (ALC_XXX_EVENT) */
640static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200641{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100642 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200643 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200644 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200645 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200646 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200647 alc_line_automute(codec);
648 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200649 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200650 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200651 break;
652 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200653 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200654}
655
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100656/* update the master volume per volume-knob's unsol event */
657static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
658{
659 unsigned int val;
660 struct snd_kcontrol *kctl;
661 struct snd_ctl_elem_value *uctl;
662
663 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
664 if (!kctl)
665 return;
666 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
667 if (!uctl)
668 return;
669 val = snd_hda_codec_read(codec, nid, 0,
670 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
671 val &= HDA_AMP_VOLMASK;
672 uctl->value.integer.value[0] = val;
673 uctl->value.integer.value[1] = val;
674 kctl->put(kctl, uctl);
675 kfree(uctl);
676}
677
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100678/* unsolicited event for HP jack sensing */
679static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
680{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100681 int action;
682
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100683 if (codec->vendor_id == 0x10ec0880)
684 res >>= 28;
685 else
686 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100687 action = snd_hda_jack_get_action(codec, res);
688 if (res == ALC_DCVOL_EVENT) {
689 /* Execute the dc-vol event here as it requires the NID
690 * but we don't pass NID to alc_exec_unsol_event().
691 * Once when we convert all static quirks to the auto-parser,
692 * this can be integerated into there.
693 */
694 struct hda_jack_tbl *jack;
695 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
696 if (jack)
697 alc_update_knob_master(codec, jack->nid);
698 return;
699 }
700 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100701}
702
Takashi Iwai1d045db2011-07-07 18:23:21 +0200703/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200704static void alc_inithook(struct hda_codec *codec)
705{
Takashi Iwaid922b512011-04-28 12:18:53 +0200706 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200707 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200708 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200709}
710
Kailang Yangf9423e72008-05-27 12:32:25 +0200711/* additional initialization for ALC888 variants */
712static void alc888_coef_init(struct hda_codec *codec)
713{
714 unsigned int tmp;
715
716 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
717 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
718 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100719 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200720 /* alc888S-VC */
721 snd_hda_codec_read(codec, 0x20, 0,
722 AC_VERB_SET_PROC_COEF, 0x830);
723 else
724 /* alc888-VB */
725 snd_hda_codec_read(codec, 0x20, 0,
726 AC_VERB_SET_PROC_COEF, 0x3030);
727}
728
Takashi Iwai1d045db2011-07-07 18:23:21 +0200729/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200730static void alc889_coef_init(struct hda_codec *codec)
731{
732 unsigned int tmp;
733
734 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
735 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
736 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
737 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
738}
739
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100740/* turn on/off EAPD control (only if available) */
741static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
742{
743 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
744 return;
745 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
746 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
747 on ? 2 : 0);
748}
749
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200750/* turn on/off EAPD controls of the codec */
751static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
752{
753 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200754 static hda_nid_t pins[] = {
755 0x0f, 0x10, 0x14, 0x15, 0
756 };
757 hda_nid_t *p;
758 for (p = pins; *p; p++)
759 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200760}
761
Takashi Iwai1c716152011-04-07 10:37:16 +0200762/* generic shutup callback;
763 * just turning off EPAD and a little pause for avoiding pop-noise
764 */
765static void alc_eapd_shutup(struct hda_codec *codec)
766{
767 alc_auto_setup_eapd(codec, false);
768 msleep(200);
769}
770
Takashi Iwai1d045db2011-07-07 18:23:21 +0200771/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200772static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200773{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200774 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200775
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200776 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777 switch (type) {
778 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200779 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
780 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200781 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200782 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
783 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200784 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200785 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
786 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200787 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200788 switch (codec->vendor_id) {
789 case 0x10ec0260:
790 snd_hda_codec_write(codec, 0x1a, 0,
791 AC_VERB_SET_COEF_INDEX, 7);
792 tmp = snd_hda_codec_read(codec, 0x1a, 0,
793 AC_VERB_GET_PROC_COEF, 0);
794 snd_hda_codec_write(codec, 0x1a, 0,
795 AC_VERB_SET_COEF_INDEX, 7);
796 snd_hda_codec_write(codec, 0x1a, 0,
797 AC_VERB_SET_PROC_COEF,
798 tmp | 0x2010);
799 break;
800 case 0x10ec0262:
801 case 0x10ec0880:
802 case 0x10ec0882:
803 case 0x10ec0883:
804 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100805 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100806 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200807 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200808 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200809 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200810 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200811 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100812#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200813 case 0x10ec0267:
814 case 0x10ec0268:
815 snd_hda_codec_write(codec, 0x20, 0,
816 AC_VERB_SET_COEF_INDEX, 7);
817 tmp = snd_hda_codec_read(codec, 0x20, 0,
818 AC_VERB_GET_PROC_COEF, 0);
819 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200820 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200821 snd_hda_codec_write(codec, 0x20, 0,
822 AC_VERB_SET_PROC_COEF,
823 tmp | 0x3000);
824 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100825#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200826 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200827 break;
828 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200829}
Kailang Yangea1fb292008-08-26 12:58:38 +0200830
Takashi Iwai1d045db2011-07-07 18:23:21 +0200831/*
832 * Auto-Mute mode mixer enum support
833 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200834static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
835 struct snd_ctl_elem_info *uinfo)
836{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200837 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
838 struct alc_spec *spec = codec->spec;
839 static const char * const texts2[] = {
840 "Disabled", "Enabled"
841 };
842 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200843 "Disabled", "Speaker Only", "Line-Out+Speaker"
844 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200845 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200846
847 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
848 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200849 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200850 uinfo->value.enumerated.items = 3;
851 texts = texts3;
852 } else {
853 uinfo->value.enumerated.items = 2;
854 texts = texts2;
855 }
856 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
857 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200858 strcpy(uinfo->value.enumerated.name,
859 texts[uinfo->value.enumerated.item]);
860 return 0;
861}
862
863static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
864 struct snd_ctl_elem_value *ucontrol)
865{
866 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
867 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200868 unsigned int val = 0;
869 if (spec->automute_speaker)
870 val++;
871 if (spec->automute_lo)
872 val++;
873
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200874 ucontrol->value.enumerated.item[0] = val;
875 return 0;
876}
877
878static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
879 struct snd_ctl_elem_value *ucontrol)
880{
881 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
882 struct alc_spec *spec = codec->spec;
883
884 switch (ucontrol->value.enumerated.item[0]) {
885 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200886 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200887 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200888 spec->automute_speaker = 0;
889 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200890 break;
891 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200892 if (spec->automute_speaker_possible) {
893 if (!spec->automute_lo && spec->automute_speaker)
894 return 0;
895 spec->automute_speaker = 1;
896 spec->automute_lo = 0;
897 } else if (spec->automute_lo_possible) {
898 if (spec->automute_lo)
899 return 0;
900 spec->automute_lo = 1;
901 } else
902 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200903 break;
904 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200905 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200906 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200907 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200908 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200909 spec->automute_speaker = 1;
910 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200911 break;
912 default:
913 return -EINVAL;
914 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200915 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200916 return 1;
917}
918
Takashi Iwaia9111322011-05-02 11:30:18 +0200919static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200920 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
921 .name = "Auto-Mute Mode",
922 .info = alc_automute_mode_info,
923 .get = alc_automute_mode_get,
924 .put = alc_automute_mode_put,
925};
926
Takashi Iwai1d045db2011-07-07 18:23:21 +0200927static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
928{
929 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
930 return snd_array_new(&spec->kctls);
931}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200932
933static int alc_add_automute_mode_enum(struct hda_codec *codec)
934{
935 struct alc_spec *spec = codec->spec;
936 struct snd_kcontrol_new *knew;
937
938 knew = alc_kcontrol_new(spec);
939 if (!knew)
940 return -ENOMEM;
941 *knew = alc_automute_mode_enum;
942 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
943 if (!knew->name)
944 return -ENOMEM;
945 return 0;
946}
947
Takashi Iwai1d045db2011-07-07 18:23:21 +0200948/*
949 * Check the availability of HP/line-out auto-mute;
950 * Set up appropriately if really supported
951 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200952static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200953{
954 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200955 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200956 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200957 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200958
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200959 if (cfg->hp_pins[0])
960 present++;
961 if (cfg->line_out_pins[0])
962 present++;
963 if (cfg->speaker_pins[0])
964 present++;
965 if (present < 2) /* need two different output types */
966 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200967
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200968 if (!cfg->speaker_pins[0] &&
969 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200970 memcpy(cfg->speaker_pins, cfg->line_out_pins,
971 sizeof(cfg->speaker_pins));
972 cfg->speaker_outs = cfg->line_outs;
973 }
974
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200975 if (!cfg->hp_pins[0] &&
976 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200977 memcpy(cfg->hp_pins, cfg->line_out_pins,
978 sizeof(cfg->hp_pins));
979 cfg->hp_outs = cfg->line_outs;
980 }
981
David Henningsson42cf0d02011-09-20 12:04:56 +0200982 spec->automute_mode = ALC_AUTOMUTE_PIN;
983
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200984 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200985 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200986 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200987 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200988 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200989 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200990 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200991 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200992 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200993
David Henningsson42cf0d02011-09-20 12:04:56 +0200994 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
995 if (cfg->speaker_outs)
996 for (i = 0; i < cfg->line_outs; i++) {
997 hda_nid_t nid = cfg->line_out_pins[i];
998 if (!is_jack_detectable(codec, nid))
999 continue;
1000 snd_printdd("realtek: Enable Line-Out "
1001 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001002 snd_hda_jack_detect_enable(codec, nid,
1003 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001004 spec->detect_lo = 1;
1005 }
1006 spec->automute_lo_possible = spec->detect_hp;
1007 }
1008
1009 spec->automute_speaker_possible = cfg->speaker_outs &&
1010 (spec->detect_hp || spec->detect_lo);
1011
1012 spec->automute_lo = spec->automute_lo_possible;
1013 spec->automute_speaker = spec->automute_speaker_possible;
1014
1015 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001016 /* create a control for automute mode */
1017 alc_add_automute_mode_enum(codec);
1018 spec->unsol_event = alc_sku_unsol_event;
1019 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001020}
1021
Takashi Iwai1d045db2011-07-07 18:23:21 +02001022/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001023static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1024{
1025 int i;
1026 for (i = 0; i < nums; i++)
1027 if (list[i] == nid)
1028 return i;
1029 return -1;
1030}
1031
Takashi Iwai1d045db2011-07-07 18:23:21 +02001032/* check whether dynamic ADC-switching is available */
1033static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1034{
1035 struct alc_spec *spec = codec->spec;
1036 struct hda_input_mux *imux = &spec->private_imux[0];
1037 int i, n, idx;
1038 hda_nid_t cap, pin;
1039
1040 if (imux != spec->input_mux) /* no dynamic imux? */
1041 return false;
1042
1043 for (n = 0; n < spec->num_adc_nids; n++) {
1044 cap = spec->private_capsrc_nids[n];
1045 for (i = 0; i < imux->num_items; i++) {
1046 pin = spec->imux_pins[i];
1047 if (!pin)
1048 return false;
1049 if (get_connection_index(codec, cap, pin) < 0)
1050 break;
1051 }
1052 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001053 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001054 }
1055
1056 for (i = 0; i < imux->num_items; i++) {
1057 pin = spec->imux_pins[i];
1058 for (n = 0; n < spec->num_adc_nids; n++) {
1059 cap = spec->private_capsrc_nids[n];
1060 idx = get_connection_index(codec, cap, pin);
1061 if (idx >= 0) {
1062 imux->items[i].index = idx;
1063 spec->dyn_adc_idx[i] = n;
1064 break;
1065 }
1066 }
1067 }
1068
1069 snd_printdd("realtek: enabling ADC switching\n");
1070 spec->dyn_adc_switch = 1;
1071 return true;
1072}
Takashi Iwai21268962011-07-07 15:01:13 +02001073
1074/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1075static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1076{
1077 struct alc_spec *spec = codec->spec;
1078 struct hda_input_mux *imux;
1079 static char * const texts[3] = {
1080 "Mic", "Internal Mic", "Dock Mic"
1081 };
1082 int i;
1083
1084 if (!spec->auto_mic)
1085 return false;
1086 imux = &spec->private_imux[0];
1087 if (spec->input_mux == imux)
1088 return true;
1089 spec->imux_pins[0] = spec->ext_mic_pin;
1090 spec->imux_pins[1] = spec->int_mic_pin;
1091 spec->imux_pins[2] = spec->dock_mic_pin;
1092 for (i = 0; i < 3; i++) {
1093 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001094 if (spec->imux_pins[i]) {
1095 hda_nid_t pin = spec->imux_pins[i];
1096 int c;
1097 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001098 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001099 int idx = get_connection_index(codec, cap, pin);
1100 if (idx >= 0) {
1101 imux->items[i].index = idx;
1102 break;
1103 }
1104 }
Takashi Iwai21268962011-07-07 15:01:13 +02001105 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001106 }
Takashi Iwai21268962011-07-07 15:01:13 +02001107 }
1108 spec->num_mux_defs = 1;
1109 spec->input_mux = imux;
1110 return true;
1111}
1112
1113/* check whether all auto-mic pins are valid; setup indices if OK */
1114static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1115{
1116 struct alc_spec *spec = codec->spec;
1117 const struct hda_input_mux *imux;
1118
1119 if (!spec->auto_mic)
1120 return false;
1121 if (spec->auto_mic_valid_imux)
1122 return true; /* already checked */
1123
1124 /* fill up imux indices */
1125 if (!alc_check_dyn_adc_switch(codec)) {
1126 spec->auto_mic = 0;
1127 return false;
1128 }
1129
1130 imux = spec->input_mux;
1131 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1132 spec->imux_pins, imux->num_items);
1133 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1134 spec->imux_pins, imux->num_items);
1135 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1136 spec->imux_pins, imux->num_items);
1137 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1138 spec->auto_mic = 0;
1139 return false; /* no corresponding imux */
1140 }
1141
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001142 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001143 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001144 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1145 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001146
1147 spec->auto_mic_valid_imux = 1;
1148 spec->auto_mic = 1;
1149 return true;
1150}
1151
Takashi Iwai1d045db2011-07-07 18:23:21 +02001152/*
1153 * Check the availability of auto-mic switch;
1154 * Set up if really supported
1155 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001156static void alc_init_auto_mic(struct hda_codec *codec)
1157{
1158 struct alc_spec *spec = codec->spec;
1159 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001160 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001161 int i;
1162
Takashi Iwai24de1832011-11-07 17:13:39 +01001163 if (spec->shared_mic_hp)
1164 return; /* no auto-mic for the shared I/O */
1165
Takashi Iwai21268962011-07-07 15:01:13 +02001166 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1167
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001168 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001169 for (i = 0; i < cfg->num_inputs; i++) {
1170 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001171 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001172 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001173 switch (snd_hda_get_input_pin_attr(defcfg)) {
1174 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001175 if (fixed)
1176 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001177 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1178 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001179 fixed = nid;
1180 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001181 case INPUT_PIN_ATTR_UNUSED:
1182 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001183 case INPUT_PIN_ATTR_DOCK:
1184 if (dock)
1185 return; /* already occupied */
1186 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1187 return; /* invalid type */
1188 dock = nid;
1189 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001190 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001191 if (ext)
1192 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001193 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1194 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001195 ext = nid;
1196 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001197 }
1198 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001199 if (!ext && dock) {
1200 ext = dock;
1201 dock = 0;
1202 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001203 if (!ext || !fixed)
1204 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001205 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001206 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001207 if (dock && !is_jack_detectable(codec, dock))
1208 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001209
1210 /* check imux indices */
1211 spec->ext_mic_pin = ext;
1212 spec->int_mic_pin = fixed;
1213 spec->dock_mic_pin = dock;
1214
1215 spec->auto_mic = 1;
1216 if (!alc_auto_mic_check_imux(codec))
1217 return;
1218
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001219 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1220 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001221 spec->unsol_event = alc_sku_unsol_event;
1222}
1223
Takashi Iwai1d045db2011-07-07 18:23:21 +02001224/* check the availabilities of auto-mute and auto-mic switches */
1225static void alc_auto_check_switches(struct hda_codec *codec)
1226{
David Henningsson42cf0d02011-09-20 12:04:56 +02001227 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001228 alc_init_auto_mic(codec);
1229}
1230
1231/*
1232 * Realtek SSID verification
1233 */
1234
David Henningsson90622912010-10-14 14:50:18 +02001235/* Could be any non-zero and even value. When used as fixup, tells
1236 * the driver to ignore any present sku defines.
1237 */
1238#define ALC_FIXUP_SKU_IGNORE (2)
1239
Kailang Yangda00c242010-03-19 11:23:45 +01001240static int alc_auto_parse_customize_define(struct hda_codec *codec)
1241{
1242 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001243 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001244 struct alc_spec *spec = codec->spec;
1245
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001246 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1247
David Henningsson90622912010-10-14 14:50:18 +02001248 if (spec->cdefine.fixup) {
1249 ass = spec->cdefine.sku_cfg;
1250 if (ass == ALC_FIXUP_SKU_IGNORE)
1251 return -1;
1252 goto do_sku;
1253 }
1254
Kailang Yangda00c242010-03-19 11:23:45 +01001255 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001256 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001257 goto do_sku;
1258
1259 nid = 0x1d;
1260 if (codec->vendor_id == 0x10ec0260)
1261 nid = 0x17;
1262 ass = snd_hda_codec_get_pincfg(codec, nid);
1263
1264 if (!(ass & 1)) {
1265 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1266 codec->chip_name, ass);
1267 return -1;
1268 }
1269
1270 /* check sum */
1271 tmp = 0;
1272 for (i = 1; i < 16; i++) {
1273 if ((ass >> i) & 1)
1274 tmp++;
1275 }
1276 if (((ass >> 16) & 0xf) != tmp)
1277 return -1;
1278
1279 spec->cdefine.port_connectivity = ass >> 30;
1280 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1281 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1282 spec->cdefine.customization = ass >> 8;
1283do_sku:
1284 spec->cdefine.sku_cfg = ass;
1285 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1286 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1287 spec->cdefine.swap = (ass & 0x2) >> 1;
1288 spec->cdefine.override = ass & 0x1;
1289
1290 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1291 nid, spec->cdefine.sku_cfg);
1292 snd_printd("SKU: port_connectivity=0x%x\n",
1293 spec->cdefine.port_connectivity);
1294 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1295 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1296 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1297 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1298 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1299 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1300 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1301
1302 return 0;
1303}
1304
Takashi Iwai1d045db2011-07-07 18:23:21 +02001305/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001306static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1307{
Takashi Iwai21268962011-07-07 15:01:13 +02001308 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001309}
1310
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001311/* check subsystem ID and set up device-specific initialization;
1312 * return 1 if initialized, 0 if invalid SSID
1313 */
1314/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1315 * 31 ~ 16 : Manufacture ID
1316 * 15 ~ 8 : SKU ID
1317 * 7 ~ 0 : Assembly ID
1318 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1319 */
1320static int alc_subsystem_id(struct hda_codec *codec,
1321 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001322 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001323{
1324 unsigned int ass, tmp, i;
1325 unsigned nid;
1326 struct alc_spec *spec = codec->spec;
1327
David Henningsson90622912010-10-14 14:50:18 +02001328 if (spec->cdefine.fixup) {
1329 ass = spec->cdefine.sku_cfg;
1330 if (ass == ALC_FIXUP_SKU_IGNORE)
1331 return 0;
1332 goto do_sku;
1333 }
1334
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001335 ass = codec->subsystem_id & 0xffff;
1336 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1337 goto do_sku;
1338
1339 /* invalid SSID, check the special NID pin defcfg instead */
1340 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001341 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001342 * 29~21 : reserve
1343 * 20 : PCBEEP input
1344 * 19~16 : Check sum (15:1)
1345 * 15~1 : Custom
1346 * 0 : override
1347 */
1348 nid = 0x1d;
1349 if (codec->vendor_id == 0x10ec0260)
1350 nid = 0x17;
1351 ass = snd_hda_codec_get_pincfg(codec, nid);
1352 snd_printd("realtek: No valid SSID, "
1353 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001354 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001355 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001356 return 0;
1357 if ((ass >> 30) != 1) /* no physical connection */
1358 return 0;
1359
1360 /* check sum */
1361 tmp = 0;
1362 for (i = 1; i < 16; i++) {
1363 if ((ass >> i) & 1)
1364 tmp++;
1365 }
1366 if (((ass >> 16) & 0xf) != tmp)
1367 return 0;
1368do_sku:
1369 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1370 ass & 0xffff, codec->vendor_id);
1371 /*
1372 * 0 : override
1373 * 1 : Swap Jack
1374 * 2 : 0 --> Desktop, 1 --> Laptop
1375 * 3~5 : External Amplifier control
1376 * 7~6 : Reserved
1377 */
1378 tmp = (ass & 0x38) >> 3; /* external Amp control */
1379 switch (tmp) {
1380 case 1:
1381 spec->init_amp = ALC_INIT_GPIO1;
1382 break;
1383 case 3:
1384 spec->init_amp = ALC_INIT_GPIO2;
1385 break;
1386 case 7:
1387 spec->init_amp = ALC_INIT_GPIO3;
1388 break;
1389 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001390 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001391 spec->init_amp = ALC_INIT_DEFAULT;
1392 break;
1393 }
1394
1395 /* is laptop or Desktop and enable the function "Mute internal speaker
1396 * when the external headphone out jack is plugged"
1397 */
1398 if (!(ass & 0x8000))
1399 return 1;
1400 /*
1401 * 10~8 : Jack location
1402 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1403 * 14~13: Resvered
1404 * 15 : 1 --> enable the function "Mute internal speaker
1405 * when the external headphone out jack is plugged"
1406 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001407 if (!spec->autocfg.hp_pins[0] &&
1408 !(spec->autocfg.line_out_pins[0] &&
1409 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001410 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001411 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1412 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001413 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001414 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001415 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001416 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001417 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001418 else if (tmp == 3)
1419 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001420 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001421 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001422 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1423 spec->autocfg.line_outs))
1424 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001425 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001426 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001427 return 1;
1428}
Kailang Yangea1fb292008-08-26 12:58:38 +02001429
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001430/* Check the validity of ALC subsystem-id
1431 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1432static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001433{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001434 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001435 struct alc_spec *spec = codec->spec;
1436 snd_printd("realtek: "
1437 "Enable default setup for auto mode as fallback\n");
1438 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001439 }
Takashi Iwai21268962011-07-07 15:01:13 +02001440}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001441
Takashi Iwai41e41f12005-06-08 14:48:49 +02001442/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001443 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001444 */
1445
1446struct alc_pincfg {
1447 hda_nid_t nid;
1448 u32 val;
1449};
1450
Todd Broche1eb5f12010-12-06 11:19:51 -08001451struct alc_model_fixup {
1452 const int id;
1453 const char *name;
1454};
1455
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001456struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001457 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001458 bool chained;
1459 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001460 union {
1461 unsigned int sku;
1462 const struct alc_pincfg *pins;
1463 const struct hda_verb *verbs;
1464 void (*func)(struct hda_codec *codec,
1465 const struct alc_fixup *fix,
1466 int action);
1467 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001468};
1469
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001470enum {
1471 ALC_FIXUP_INVALID,
1472 ALC_FIXUP_SKU,
1473 ALC_FIXUP_PINS,
1474 ALC_FIXUP_VERBS,
1475 ALC_FIXUP_FUNC,
1476};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001477
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001478enum {
1479 ALC_FIXUP_ACT_PRE_PROBE,
1480 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001481 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001482};
1483
1484static void alc_apply_fixup(struct hda_codec *codec, int action)
1485{
1486 struct alc_spec *spec = codec->spec;
1487 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001488#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001489 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001490#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001491 int depth = 0;
1492
1493 if (!spec->fixup_list)
1494 return;
1495
1496 while (id >= 0) {
1497 const struct alc_fixup *fix = spec->fixup_list + id;
1498 const struct alc_pincfg *cfg;
1499
1500 switch (fix->type) {
1501 case ALC_FIXUP_SKU:
1502 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001503 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001504 snd_printdd(KERN_INFO "hda_codec: %s: "
1505 "Apply sku override for %s\n",
1506 codec->chip_name, modelname);
1507 spec->cdefine.sku_cfg = fix->v.sku;
1508 spec->cdefine.fixup = 1;
1509 break;
1510 case ALC_FIXUP_PINS:
1511 cfg = fix->v.pins;
1512 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1513 break;
1514 snd_printdd(KERN_INFO "hda_codec: %s: "
1515 "Apply pincfg for %s\n",
1516 codec->chip_name, modelname);
1517 for (; cfg->nid; cfg++)
1518 snd_hda_codec_set_pincfg(codec, cfg->nid,
1519 cfg->val);
1520 break;
1521 case ALC_FIXUP_VERBS:
1522 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1523 break;
1524 snd_printdd(KERN_INFO "hda_codec: %s: "
1525 "Apply fix-verbs for %s\n",
1526 codec->chip_name, modelname);
1527 add_verb(codec->spec, fix->v.verbs);
1528 break;
1529 case ALC_FIXUP_FUNC:
1530 if (!fix->v.func)
1531 break;
1532 snd_printdd(KERN_INFO "hda_codec: %s: "
1533 "Apply fix-func for %s\n",
1534 codec->chip_name, modelname);
1535 fix->v.func(codec, fix, action);
1536 break;
1537 default:
1538 snd_printk(KERN_ERR "hda_codec: %s: "
1539 "Invalid fixup type %d\n",
1540 codec->chip_name, fix->type);
1541 break;
1542 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001543 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001544 break;
1545 if (++depth > 10)
1546 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001547 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001548 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001549}
1550
Todd Broche1eb5f12010-12-06 11:19:51 -08001551static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001552 const struct alc_model_fixup *models,
1553 const struct snd_pci_quirk *quirk,
1554 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001555{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001556 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001557 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001558 int id = -1;
1559 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001560
Takashi Iwai9155f822012-02-20 18:41:02 +01001561 /* when model=nofixup is given, don't pick up any fixups */
1562 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
1563 spec->fixup_list = NULL;
1564 spec->fixup_id = -1;
1565 return;
1566 }
1567
Todd Broche1eb5f12010-12-06 11:19:51 -08001568 if (codec->modelname && models) {
1569 while (models->name) {
1570 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001571 id = models->id;
1572 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001573 break;
1574 }
1575 models++;
1576 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001577 }
1578 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001579 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1580 if (q) {
1581 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001582#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001583 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001584#endif
1585 }
1586 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001587 if (id < 0) {
1588 for (q = quirk; q->subvendor; q++) {
1589 unsigned int vendorid =
1590 q->subdevice | (q->subvendor << 16);
1591 if (vendorid == codec->subsystem_id) {
1592 id = q->value;
1593#ifdef CONFIG_SND_DEBUG_VERBOSE
1594 name = q->name;
1595#endif
1596 break;
1597 }
1598 }
1599 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001600
1601 spec->fixup_id = id;
1602 if (id >= 0) {
1603 spec->fixup_list = fixlist;
1604 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001605 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001606}
1607
Takashi Iwai1d045db2011-07-07 18:23:21 +02001608/*
1609 * COEF access helper functions
1610 */
Kailang Yang274693f2009-12-03 10:07:50 +01001611static int alc_read_coef_idx(struct hda_codec *codec,
1612 unsigned int coef_idx)
1613{
1614 unsigned int val;
1615 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1616 coef_idx);
1617 val = snd_hda_codec_read(codec, 0x20, 0,
1618 AC_VERB_GET_PROC_COEF, 0);
1619 return val;
1620}
1621
Kailang Yang977ddd62010-09-15 10:02:29 +02001622static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1623 unsigned int coef_val)
1624{
1625 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1626 coef_idx);
1627 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1628 coef_val);
1629}
1630
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001631/* a special bypass for COEF 0; read the cached value at the second time */
1632static unsigned int alc_get_coef0(struct hda_codec *codec)
1633{
1634 struct alc_spec *spec = codec->spec;
1635 if (!spec->coef0)
1636 spec->coef0 = alc_read_coef_idx(codec, 0);
1637 return spec->coef0;
1638}
1639
Takashi Iwai1d045db2011-07-07 18:23:21 +02001640/*
1641 * Digital I/O handling
1642 */
1643
Takashi Iwai757899a2010-07-30 10:48:14 +02001644/* set right pin controls for digital I/O */
1645static void alc_auto_init_digital(struct hda_codec *codec)
1646{
1647 struct alc_spec *spec = codec->spec;
1648 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001649 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001650
1651 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1652 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001653 if (!pin)
1654 continue;
1655 snd_hda_codec_write(codec, pin, 0,
1656 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1657 if (!i)
1658 dac = spec->multiout.dig_out_nid;
1659 else
1660 dac = spec->slave_dig_outs[i - 1];
1661 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1662 continue;
1663 snd_hda_codec_write(codec, dac, 0,
1664 AC_VERB_SET_AMP_GAIN_MUTE,
1665 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001666 }
1667 pin = spec->autocfg.dig_in_pin;
1668 if (pin)
1669 snd_hda_codec_write(codec, pin, 0,
1670 AC_VERB_SET_PIN_WIDGET_CONTROL,
1671 PIN_IN);
1672}
1673
1674/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1675static void alc_auto_parse_digital(struct hda_codec *codec)
1676{
1677 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001678 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001679 hda_nid_t dig_nid;
1680
1681 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001682 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001683 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001684 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001685 err = snd_hda_get_connections(codec,
1686 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001687 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001688 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001689 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001690 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001691 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001692 spec->multiout.dig_out_nid = dig_nid;
1693 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1694 } else {
1695 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001696 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001697 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001698 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001699 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001700 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001701 }
1702
1703 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001704 dig_nid = codec->start_nid;
1705 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1706 unsigned int wcaps = get_wcaps(codec, dig_nid);
1707 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1708 continue;
1709 if (!(wcaps & AC_WCAP_DIGITAL))
1710 continue;
1711 if (!(wcaps & AC_WCAP_CONN_LIST))
1712 continue;
1713 err = get_connection_index(codec, dig_nid,
1714 spec->autocfg.dig_in_pin);
1715 if (err >= 0) {
1716 spec->dig_in_nid = dig_nid;
1717 break;
1718 }
1719 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001720 }
1721}
1722
Takashi Iwaif95474e2007-07-10 00:47:43 +02001723/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001724 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001725 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001726static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_info *uinfo)
1728{
1729 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1730 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001731 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001732 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001733
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001734 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001735 if (spec->vol_in_capsrc)
1736 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1737 else
1738 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1739 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001740 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001741 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001742 return err;
1743}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001745static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1746 unsigned int size, unsigned int __user *tlv)
1747{
1748 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1749 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001750 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001751 int err;
1752
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001753 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001754 if (spec->vol_in_capsrc)
1755 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1756 else
1757 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1758 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001759 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001760 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001761 return err;
1762}
1763
1764typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1765 struct snd_ctl_elem_value *ucontrol);
1766
1767static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1768 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001769 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001770{
1771 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1772 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001773 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001774
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001775 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001776 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001777 for (i = 0; i < spec->num_adc_nids; i++) {
1778 kcontrol->private_value =
1779 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1780 3, 0, HDA_INPUT);
1781 err = func(kcontrol, ucontrol);
1782 if (err < 0)
1783 goto error;
1784 }
1785 } else {
1786 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001787 if (spec->vol_in_capsrc)
1788 kcontrol->private_value =
1789 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1790 3, 0, HDA_OUTPUT);
1791 else
1792 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001793 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1794 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001795 err = func(kcontrol, ucontrol);
1796 }
1797 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001798 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001799 return err;
1800}
1801
1802static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1803 struct snd_ctl_elem_value *ucontrol)
1804{
1805 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001806 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001807}
1808
1809static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1810 struct snd_ctl_elem_value *ucontrol)
1811{
1812 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001813 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001814}
1815
1816/* capture mixer elements */
1817#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1818
1819static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1820 struct snd_ctl_elem_value *ucontrol)
1821{
1822 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001823 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001824}
1825
1826static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1827 struct snd_ctl_elem_value *ucontrol)
1828{
1829 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001830 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001831}
1832
Takashi Iwaia23b6882009-03-23 15:21:36 +01001833#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001834 { \
1835 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1836 .name = "Capture Switch", \
1837 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1838 .count = num, \
1839 .info = alc_cap_sw_info, \
1840 .get = alc_cap_sw_get, \
1841 .put = alc_cap_sw_put, \
1842 }, \
1843 { \
1844 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1845 .name = "Capture Volume", \
1846 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1847 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1848 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1849 .count = num, \
1850 .info = alc_cap_vol_info, \
1851 .get = alc_cap_vol_get, \
1852 .put = alc_cap_vol_put, \
1853 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001854 }
1855
1856#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001857 { \
1858 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1859 /* .name = "Capture Source", */ \
1860 .name = "Input Source", \
1861 .count = num, \
1862 .info = alc_mux_enum_info, \
1863 .get = alc_mux_enum_get, \
1864 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001865 }
1866
1867#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001868static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001869 _DEFINE_CAPMIX(num), \
1870 _DEFINE_CAPSRC(num), \
1871 { } /* end */ \
1872}
1873
1874#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001875static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001876 _DEFINE_CAPMIX(num), \
1877 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001878}
1879
1880/* up to three ADCs */
1881DEFINE_CAPMIX(1);
1882DEFINE_CAPMIX(2);
1883DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001884DEFINE_CAPMIX_NOSRC(1);
1885DEFINE_CAPMIX_NOSRC(2);
1886DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001887
1888/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001889 * virtual master controls
1890 */
1891
1892/*
1893 * slave controls for virtual master
1894 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001895static const char * const alc_slave_pfxs[] = {
1896 "Front", "Surround", "Center", "LFE", "Side",
1897 "Headphone", "Speaker", "Mono", "Line-Out",
1898 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001899 NULL,
1900};
1901
1902/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001903 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001905
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001906#define NID_MAPPING (-1)
1907
1908#define SUBDEV_SPEAKER_ (0 << 6)
1909#define SUBDEV_HP_ (1 << 6)
1910#define SUBDEV_LINE_ (2 << 6)
1911#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1912#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1913#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1914
Takashi Iwai603c4012008-07-30 15:01:44 +02001915static void alc_free_kctls(struct hda_codec *codec);
1916
Takashi Iwai67d634c2009-11-16 15:35:59 +01001917#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001918/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001919static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001920 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001921 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001922 { } /* end */
1923};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001924#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001925
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001926static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927{
1928 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001929 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001930 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001931 int i, j, err;
1932 unsigned int u;
1933 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934
1935 for (i = 0; i < spec->num_mixers; i++) {
1936 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1937 if (err < 0)
1938 return err;
1939 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001940 if (spec->cap_mixer) {
1941 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1942 if (err < 0)
1943 return err;
1944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001946 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001947 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001948 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 if (err < 0)
1950 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001951 if (!spec->no_analog) {
1952 err = snd_hda_create_spdif_share_sw(codec,
1953 &spec->multiout);
1954 if (err < 0)
1955 return err;
1956 spec->multiout.share_spdif = 1;
1957 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 }
1959 if (spec->dig_in_nid) {
1960 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1961 if (err < 0)
1962 return err;
1963 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001964
Takashi Iwai67d634c2009-11-16 15:35:59 +01001965#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001966 /* create beep controls if needed */
1967 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001968 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001969 for (knew = alc_beep_mixer; knew->name; knew++) {
1970 struct snd_kcontrol *kctl;
1971 kctl = snd_ctl_new1(knew, codec);
1972 if (!kctl)
1973 return -ENOMEM;
1974 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001975 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001976 if (err < 0)
1977 return err;
1978 }
1979 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001980#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001981
Takashi Iwai2134ea42008-01-10 16:53:55 +01001982 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001983 if (!spec->no_analog &&
1984 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001985 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001986 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001987 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001988 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001989 vmaster_tlv, alc_slave_pfxs,
1990 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001991 if (err < 0)
1992 return err;
1993 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001994 if (!spec->no_analog &&
1995 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001996 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001997 NULL, alc_slave_pfxs,
1998 "Playback Switch");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001999 if (err < 0)
2000 return err;
2001 }
2002
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002003 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02002004 if (spec->capsrc_nids || spec->adc_nids) {
2005 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
2006 if (!kctl)
2007 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
2008 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002009 err = snd_hda_add_nid(codec, kctl, i,
2010 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02002011 if (err < 0)
2012 return err;
2013 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002014 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02002015 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002016 const char *kname = kctl ? kctl->id.name : NULL;
2017 for (knew = spec->cap_mixer; knew->name; knew++) {
2018 if (kname && strcmp(knew->name, kname) == 0)
2019 continue;
2020 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2021 for (i = 0; kctl && i < kctl->count; i++) {
2022 err = snd_hda_add_nid(codec, kctl, i,
2023 spec->adc_nids[i]);
2024 if (err < 0)
2025 return err;
2026 }
2027 }
2028 }
2029
2030 /* other nid->control mapping */
2031 for (i = 0; i < spec->num_mixers; i++) {
2032 for (knew = spec->mixers[i]; knew->name; knew++) {
2033 if (knew->iface != NID_MAPPING)
2034 continue;
2035 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2036 if (kctl == NULL)
2037 continue;
2038 u = knew->subdevice;
2039 for (j = 0; j < 4; j++, u >>= 8) {
2040 nid = u & 0x3f;
2041 if (nid == 0)
2042 continue;
2043 switch (u & 0xc0) {
2044 case SUBDEV_SPEAKER_:
2045 nid = spec->autocfg.speaker_pins[nid];
2046 break;
2047 case SUBDEV_LINE_:
2048 nid = spec->autocfg.line_out_pins[nid];
2049 break;
2050 case SUBDEV_HP_:
2051 nid = spec->autocfg.hp_pins[nid];
2052 break;
2053 default:
2054 continue;
2055 }
2056 err = snd_hda_add_nid(codec, kctl, 0, nid);
2057 if (err < 0)
2058 return err;
2059 }
2060 u = knew->private_value;
2061 for (j = 0; j < 4; j++, u >>= 8) {
2062 nid = u & 0xff;
2063 if (nid == 0)
2064 continue;
2065 err = snd_hda_add_nid(codec, kctl, 0, nid);
2066 if (err < 0)
2067 return err;
2068 }
2069 }
2070 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002071
2072 alc_free_kctls(codec); /* no longer needed */
2073
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002074 return 0;
2075}
2076
2077static int alc_build_controls(struct hda_codec *codec)
2078{
2079 struct alc_spec *spec = codec->spec;
2080 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002081 if (err < 0)
2082 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002083 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084}
2085
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002086
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002088 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002089 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002090
Takashi Iwai584c0c42011-03-10 12:51:11 +01002091static void alc_init_special_input_src(struct hda_codec *codec);
2092
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093static int alc_init(struct hda_codec *codec)
2094{
2095 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002096 unsigned int i;
2097
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002098 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002099 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002100
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002101 for (i = 0; i < spec->num_init_verbs; i++)
2102 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002103 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002104
2105 if (spec->init_hook)
2106 spec->init_hook(codec);
2107
Takashi Iwai58701122011-01-13 15:41:45 +01002108 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2109
Takashi Iwai01a61e12011-10-28 00:03:22 +02002110 snd_hda_jack_report_sync(codec);
2111
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002112 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 return 0;
2114}
2115
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002116static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2117{
2118 struct alc_spec *spec = codec->spec;
2119
2120 if (spec->unsol_event)
2121 spec->unsol_event(codec, res);
2122}
2123
Takashi Iwaicb53c622007-08-10 17:21:45 +02002124#ifdef CONFIG_SND_HDA_POWER_SAVE
2125static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2126{
2127 struct alc_spec *spec = codec->spec;
2128 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2129}
2130#endif
2131
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132/*
2133 * Analog playback callbacks
2134 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002135static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002137 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138{
2139 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002140 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2141 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142}
2143
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002144static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 struct hda_codec *codec,
2146 unsigned int stream_tag,
2147 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002148 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149{
2150 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002151 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2152 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153}
2154
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002155static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002157 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
2159 struct alc_spec *spec = codec->spec;
2160 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2161}
2162
2163/*
2164 * Digital out
2165 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002166static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002168 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
2170 struct alc_spec *spec = codec->spec;
2171 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2172}
2173
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002174static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002175 struct hda_codec *codec,
2176 unsigned int stream_tag,
2177 unsigned int format,
2178 struct snd_pcm_substream *substream)
2179{
2180 struct alc_spec *spec = codec->spec;
2181 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2182 stream_tag, format, substream);
2183}
2184
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002185static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002186 struct hda_codec *codec,
2187 struct snd_pcm_substream *substream)
2188{
2189 struct alc_spec *spec = codec->spec;
2190 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2191}
2192
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002193static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002195 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
2197 struct alc_spec *spec = codec->spec;
2198 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2199}
2200
2201/*
2202 * Analog capture
2203 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002204static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 struct hda_codec *codec,
2206 unsigned int stream_tag,
2207 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002208 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209{
2210 struct alc_spec *spec = codec->spec;
2211
Takashi Iwai63300792008-01-24 15:31:36 +01002212 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 stream_tag, 0, format);
2214 return 0;
2215}
2216
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002217static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002219 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220{
2221 struct alc_spec *spec = codec->spec;
2222
Takashi Iwai888afa12008-03-18 09:57:50 +01002223 snd_hda_codec_cleanup_stream(codec,
2224 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 return 0;
2226}
2227
Takashi Iwai840b64c2010-07-13 22:49:01 +02002228/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002229static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002230 struct hda_codec *codec,
2231 unsigned int stream_tag,
2232 unsigned int format,
2233 struct snd_pcm_substream *substream)
2234{
2235 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002236 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002237 spec->cur_adc_stream_tag = stream_tag;
2238 spec->cur_adc_format = format;
2239 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2240 return 0;
2241}
2242
Takashi Iwai21268962011-07-07 15:01:13 +02002243static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002244 struct hda_codec *codec,
2245 struct snd_pcm_substream *substream)
2246{
2247 struct alc_spec *spec = codec->spec;
2248 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2249 spec->cur_adc = 0;
2250 return 0;
2251}
2252
Takashi Iwai21268962011-07-07 15:01:13 +02002253static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002254 .substreams = 1,
2255 .channels_min = 2,
2256 .channels_max = 2,
2257 .nid = 0, /* fill later */
2258 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002259 .prepare = dyn_adc_capture_pcm_prepare,
2260 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002261 },
2262};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
2264/*
2265 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002266static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 .substreams = 1,
2268 .channels_min = 2,
2269 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002270 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002272 .open = alc_playback_pcm_open,
2273 .prepare = alc_playback_pcm_prepare,
2274 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 },
2276};
2277
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002278static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002279 .substreams = 1,
2280 .channels_min = 2,
2281 .channels_max = 2,
2282 /* NID is set in alc_build_pcms */
2283};
2284
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002285static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002286 .substreams = 1,
2287 .channels_min = 2,
2288 .channels_max = 2,
2289 /* NID is set in alc_build_pcms */
2290};
2291
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002292static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002293 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 .channels_min = 2,
2295 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002296 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002298 .prepare = alc_alt_capture_pcm_prepare,
2299 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 },
2301};
2302
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002303static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 .substreams = 1,
2305 .channels_min = 2,
2306 .channels_max = 2,
2307 /* NID is set in alc_build_pcms */
2308 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002309 .open = alc_dig_playback_pcm_open,
2310 .close = alc_dig_playback_pcm_close,
2311 .prepare = alc_dig_playback_pcm_prepare,
2312 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 },
2314};
2315
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002316static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 .substreams = 1,
2318 .channels_min = 2,
2319 .channels_max = 2,
2320 /* NID is set in alc_build_pcms */
2321};
2322
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002323/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002324static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002325 .substreams = 0,
2326 .channels_min = 0,
2327 .channels_max = 0,
2328};
2329
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330static int alc_build_pcms(struct hda_codec *codec)
2331{
2332 struct alc_spec *spec = codec->spec;
2333 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002334 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002335 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 int i;
2337
2338 codec->num_pcms = 1;
2339 codec->pcm_info = info;
2340
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002341 if (spec->no_analog)
2342 goto skip_analog;
2343
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002344 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2345 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002347
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002348 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002349 p = spec->stream_analog_playback;
2350 if (!p)
2351 p = &alc_pcm_analog_playback;
2352 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002353 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2354 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002355 if (spec->adc_nids) {
2356 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002357 if (!p) {
2358 if (spec->dyn_adc_switch)
2359 p = &dyn_adc_pcm_analog_capture;
2360 else
2361 p = &alc_pcm_analog_capture;
2362 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002363 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002364 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2365 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366
Takashi Iwai4a471b72005-12-07 13:56:29 +01002367 if (spec->channel_mode) {
2368 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2369 for (i = 0; i < spec->num_channel_mode; i++) {
2370 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2371 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2372 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 }
2374 }
2375
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002376 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002377 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002379 snprintf(spec->stream_name_digital,
2380 sizeof(spec->stream_name_digital),
2381 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002382 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002383 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002384 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002386 if (spec->dig_out_type)
2387 info->pcm_type = spec->dig_out_type;
2388 else
2389 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002390 if (spec->multiout.dig_out_nid) {
2391 p = spec->stream_digital_playback;
2392 if (!p)
2393 p = &alc_pcm_digital_playback;
2394 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2396 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002397 if (spec->dig_in_nid) {
2398 p = spec->stream_digital_capture;
2399 if (!p)
2400 p = &alc_pcm_digital_capture;
2401 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2403 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002404 /* FIXME: do we need this for all Realtek codec models? */
2405 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 }
2407
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002408 if (spec->no_analog)
2409 return 0;
2410
Takashi Iwaie08a0072006-09-07 17:52:14 +02002411 /* If the use of more than one ADC is requested for the current
2412 * model, configure a second analog capture-only PCM.
2413 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002414 have_multi_adcs = (spec->num_adc_nids > 1) &&
2415 !spec->dyn_adc_switch && !spec->auto_mic &&
2416 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002417 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002418 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002419 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002420 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002421 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002422 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002423 p = spec->stream_analog_alt_playback;
2424 if (!p)
2425 p = &alc_pcm_analog_alt_playback;
2426 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002427 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2428 spec->alt_dac_nid;
2429 } else {
2430 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2431 alc_pcm_null_stream;
2432 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2433 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002434 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002435 p = spec->stream_analog_alt_capture;
2436 if (!p)
2437 p = &alc_pcm_analog_alt_capture;
2438 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002439 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2440 spec->adc_nids[1];
2441 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2442 spec->num_adc_nids - 1;
2443 } else {
2444 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2445 alc_pcm_null_stream;
2446 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002447 }
2448 }
2449
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 return 0;
2451}
2452
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002453static inline void alc_shutup(struct hda_codec *codec)
2454{
Takashi Iwai1c716152011-04-07 10:37:16 +02002455 struct alc_spec *spec = codec->spec;
2456
2457 if (spec && spec->shutup)
2458 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002459 snd_hda_shutup_pins(codec);
2460}
2461
Takashi Iwai603c4012008-07-30 15:01:44 +02002462static void alc_free_kctls(struct hda_codec *codec)
2463{
2464 struct alc_spec *spec = codec->spec;
2465
2466 if (spec->kctls.list) {
2467 struct snd_kcontrol_new *kctl = spec->kctls.list;
2468 int i;
2469 for (i = 0; i < spec->kctls.used; i++)
2470 kfree(kctl[i].name);
2471 }
2472 snd_array_free(&spec->kctls);
2473}
2474
Takashi Iwai23c09b02011-08-19 09:05:35 +02002475static void alc_free_bind_ctls(struct hda_codec *codec)
2476{
2477 struct alc_spec *spec = codec->spec;
2478 if (spec->bind_ctls.list) {
2479 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2480 int i;
2481 for (i = 0; i < spec->bind_ctls.used; i++)
2482 kfree(ctl[i]);
2483 }
2484 snd_array_free(&spec->bind_ctls);
2485}
2486
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487static void alc_free(struct hda_codec *codec)
2488{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002489 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002490
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002491 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002492 return;
2493
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002494 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002495 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002496 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002497 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002498 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499}
2500
Hector Martinf5de24b2009-12-20 22:51:31 +01002501#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002502static void alc_power_eapd(struct hda_codec *codec)
2503{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002504 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002505}
2506
Hector Martinf5de24b2009-12-20 22:51:31 +01002507static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2508{
2509 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002510 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002511 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002512 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002513 return 0;
2514}
2515#endif
2516
Takashi Iwai2a439522011-07-26 09:52:50 +02002517#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002518static int alc_resume(struct hda_codec *codec)
2519{
Takashi Iwai1c716152011-04-07 10:37:16 +02002520 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002521 codec->patch_ops.init(codec);
2522 snd_hda_codec_resume_amp(codec);
2523 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002524 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002525 return 0;
2526}
Takashi Iwaie044c392008-10-27 16:56:24 +01002527#endif
2528
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529/*
2530 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002531static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 .build_controls = alc_build_controls,
2533 .build_pcms = alc_build_pcms,
2534 .init = alc_init,
2535 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002536 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002537#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002538 .resume = alc_resume,
2539#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002540#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002541 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002542 .check_power_status = alc_check_power_status,
2543#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002544 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545};
2546
Kailang Yangc027ddc2010-03-19 11:33:06 +01002547/* replace the codec chip_name with the given string */
2548static int alc_codec_rename(struct hda_codec *codec, const char *name)
2549{
2550 kfree(codec->chip_name);
2551 codec->chip_name = kstrdup(name, GFP_KERNEL);
2552 if (!codec->chip_name) {
2553 alc_free(codec);
2554 return -ENOMEM;
2555 }
2556 return 0;
2557}
2558
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002559/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002560 * Rename codecs appropriately from COEF value
2561 */
2562struct alc_codec_rename_table {
2563 unsigned int vendor_id;
2564 unsigned short coef_mask;
2565 unsigned short coef_bits;
2566 const char *name;
2567};
2568
2569static struct alc_codec_rename_table rename_tbl[] = {
2570 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2571 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2572 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2573 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2574 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2575 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2576 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2577 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2578 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2579 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2580 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2581 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2582 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2583 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2584 { } /* terminator */
2585};
2586
2587static int alc_codec_rename_from_preset(struct hda_codec *codec)
2588{
2589 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002590
2591 for (p = rename_tbl; p->vendor_id; p++) {
2592 if (p->vendor_id != codec->vendor_id)
2593 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002594 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002595 return alc_codec_rename(codec, p->name);
2596 }
2597 return 0;
2598}
2599
2600/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002601 * Automatic parse of I/O pins from the BIOS configuration
2602 */
2603
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002604enum {
2605 ALC_CTL_WIDGET_VOL,
2606 ALC_CTL_WIDGET_MUTE,
2607 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002608 ALC_CTL_BIND_VOL,
2609 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002610};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002611static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002612 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2613 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002614 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002615 HDA_BIND_VOL(NULL, 0),
2616 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002617};
2618
2619/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002620static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002621 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002622{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002623 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002624
Takashi Iwaice764ab2011-04-27 16:35:23 +02002625 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002626 if (!knew)
2627 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002628 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002629 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002630 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002631 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002632 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002633 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002634 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002635 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002636 return 0;
2637}
2638
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002639static int add_control_with_pfx(struct alc_spec *spec, int type,
2640 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002641 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002642{
2643 char name[32];
2644 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002645 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002646}
2647
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002648#define add_pb_vol_ctrl(spec, type, pfx, val) \
2649 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2650#define add_pb_sw_ctrl(spec, type, pfx, val) \
2651 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2652#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2653 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2654#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2655 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002656
Takashi Iwai23c09b02011-08-19 09:05:35 +02002657static const char * const channel_name[4] = {
2658 "Front", "Surround", "CLFE", "Side"
2659};
2660
Takashi Iwai6843ca12011-06-24 11:03:58 +02002661static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2662 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002663{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002664 struct auto_pin_cfg *cfg = &spec->autocfg;
2665
Takashi Iwai6843ca12011-06-24 11:03:58 +02002666 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002667 if (cfg->line_outs == 1 && !spec->multi_ios &&
2668 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002669 return "Master";
2670
2671 switch (cfg->line_out_type) {
2672 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002673 if (cfg->line_outs == 1)
2674 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002675 if (cfg->line_outs == 2)
2676 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002677 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002678 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002679 /* for multi-io case, only the primary out */
2680 if (ch && spec->multi_ios)
2681 break;
2682 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002683 return "Headphone";
2684 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002685 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002686 return "PCM";
2687 break;
2688 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002689 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2690 return "PCM";
2691
2692 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002693}
2694
Takashi Iwai164f73e2012-02-21 11:27:09 +01002695#ifdef CONFIG_SND_HDA_POWER_SAVE
2696/* add the powersave loopback-list entry */
2697static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2698{
2699 struct hda_amp_list *list;
2700
2701 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2702 return;
2703 list = spec->loopback_list + spec->num_loopbacks;
2704 list->nid = mix;
2705 list->dir = HDA_INPUT;
2706 list->idx = idx;
2707 spec->num_loopbacks++;
2708 spec->loopback.amplist = spec->loopback_list;
2709}
2710#else
2711#define add_loopback_list(spec, mix, idx) /* NOP */
2712#endif
2713
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002714/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002715static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002716 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002717 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002718{
Kailang Yangdf694da2005-12-05 19:42:22 +01002719 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002720
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002721 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002722 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2723 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002724 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002725 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002726 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2727 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002728 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002729 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002730 return 0;
2731}
2732
Takashi Iwai05f5f472009-08-25 13:10:18 +02002733static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002734{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002735 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2736 return (pincap & AC_PINCAP_IN) != 0;
2737}
2738
Takashi Iwai1d045db2011-07-07 18:23:21 +02002739/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002740static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002741{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002742 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002743 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002744 hda_nid_t *adc_nids = spec->private_adc_nids;
2745 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2746 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002747 int i, nums = 0;
2748
Takashi Iwai24de1832011-11-07 17:13:39 +01002749 if (spec->shared_mic_hp)
2750 max_nums = 1; /* no multi streams with the shared HP/mic */
2751
Takashi Iwaib7821702011-07-06 15:12:46 +02002752 nid = codec->start_nid;
2753 for (i = 0; i < codec->num_nodes; i++, nid++) {
2754 hda_nid_t src;
2755 const hda_nid_t *list;
2756 unsigned int caps = get_wcaps(codec, nid);
2757 int type = get_wcaps_type(caps);
2758
2759 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2760 continue;
2761 adc_nids[nums] = nid;
2762 cap_nids[nums] = nid;
2763 src = nid;
2764 for (;;) {
2765 int n;
2766 type = get_wcaps_type(get_wcaps(codec, src));
2767 if (type == AC_WID_PIN)
2768 break;
2769 if (type == AC_WID_AUD_SEL) {
2770 cap_nids[nums] = src;
2771 break;
2772 }
2773 n = snd_hda_get_conn_list(codec, src, &list);
2774 if (n > 1) {
2775 cap_nids[nums] = src;
2776 break;
2777 } else if (n != 1)
2778 break;
2779 src = *list;
2780 }
2781 if (++nums >= max_nums)
2782 break;
2783 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002784 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002785 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002786 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002787 return nums;
2788}
2789
Takashi Iwai05f5f472009-08-25 13:10:18 +02002790/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002791static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002792{
2793 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002794 const struct auto_pin_cfg *cfg = &spec->autocfg;
2795 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002796 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002797 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002798 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002799 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002800
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002801 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002802 if (num_adcs < 0)
2803 return 0;
2804
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002805 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002806 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002807 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002808
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002809 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002810 if (!alc_is_input_pin(codec, pin))
2811 continue;
2812
David Henningsson5322bf22011-01-05 11:03:56 +01002813 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002814 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2815 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002816 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002817 type_idx++;
2818 else
2819 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002820 prev_label = label;
2821
Takashi Iwai05f5f472009-08-25 13:10:18 +02002822 if (mixer) {
2823 idx = get_connection_index(codec, mixer, pin);
2824 if (idx >= 0) {
2825 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002826 label, type_idx,
2827 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002828 if (err < 0)
2829 return err;
2830 }
2831 }
2832
Takashi Iwaib7821702011-07-06 15:12:46 +02002833 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002834 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002835 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002836 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002837 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002838 snd_hda_add_imux_item(imux, label, idx, NULL);
2839 break;
2840 }
2841 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002842 }
Takashi Iwai21268962011-07-07 15:01:13 +02002843
2844 spec->num_mux_defs = 1;
2845 spec->input_mux = imux;
2846
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002847 return 0;
2848}
2849
Takashi Iwai24de1832011-11-07 17:13:39 +01002850/* create a shared input with the headphone out */
2851static int alc_auto_create_shared_input(struct hda_codec *codec)
2852{
2853 struct alc_spec *spec = codec->spec;
2854 struct auto_pin_cfg *cfg = &spec->autocfg;
2855 unsigned int defcfg;
2856 hda_nid_t nid;
2857
2858 /* only one internal input pin? */
2859 if (cfg->num_inputs != 1)
2860 return 0;
2861 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2862 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2863 return 0;
2864
2865 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2866 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2867 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2868 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2869 else
2870 return 0; /* both not available */
2871
2872 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2873 return 0; /* no input */
2874
2875 cfg->inputs[1].pin = nid;
2876 cfg->inputs[1].type = AUTO_PIN_MIC;
2877 cfg->num_inputs = 2;
2878 spec->shared_mic_hp = 1;
2879 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2880 return 0;
2881}
2882
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002883static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2884 unsigned int pin_type)
2885{
2886 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2887 pin_type);
2888 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002889 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2890 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002891 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002892}
2893
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002894static int get_pin_type(int line_out_type)
2895{
2896 if (line_out_type == AUTO_PIN_HP_OUT)
2897 return PIN_HP;
2898 else
2899 return PIN_OUT;
2900}
2901
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002902static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002903{
2904 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002905 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002906 int i;
2907
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002908 for (i = 0; i < cfg->num_inputs; i++) {
2909 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002910 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002911 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002912 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002913 snd_hda_codec_write(codec, nid, 0,
2914 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002915 AMP_OUT_MUTE);
2916 }
2917 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002918
2919 /* mute all loopback inputs */
2920 if (spec->mixer_nid) {
2921 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2922 for (i = 0; i < nums; i++)
2923 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2924 AC_VERB_SET_AMP_GAIN_MUTE,
2925 AMP_IN_MUTE(i));
2926 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002927}
2928
Takashi Iwai7085ec12009-10-02 09:03:58 +02002929/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002930static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002931{
Takashi Iwai604401a2011-04-27 15:14:23 +02002932 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002933 int i, num;
2934
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002935 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2936 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002937 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2938 for (i = 0; i < num; i++) {
2939 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2940 return list[i];
2941 }
2942 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002943}
2944
Takashi Iwai604401a2011-04-27 15:14:23 +02002945/* go down to the selector widget before the mixer */
2946static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2947{
2948 hda_nid_t srcs[5];
2949 int num = snd_hda_get_connections(codec, pin, srcs,
2950 ARRAY_SIZE(srcs));
2951 if (num != 1 ||
2952 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2953 return pin;
2954 return srcs[0];
2955}
2956
Takashi Iwai7085ec12009-10-02 09:03:58 +02002957/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002958static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002959 hda_nid_t dac)
2960{
David Henningssoncc1c4522010-11-24 14:17:47 +01002961 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002962 int i, num;
2963
Takashi Iwai604401a2011-04-27 15:14:23 +02002964 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002965 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2966 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002967 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002968 return mix[i];
2969 }
2970 return 0;
2971}
2972
Takashi Iwaice764ab2011-04-27 16:35:23 +02002973/* select the connection from pin to DAC if needed */
2974static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2975 hda_nid_t dac)
2976{
2977 hda_nid_t mix[5];
2978 int i, num;
2979
2980 pin = alc_go_down_to_selector(codec, pin);
2981 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2982 if (num < 2)
2983 return 0;
2984 for (i = 0; i < num; i++) {
2985 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2986 snd_hda_codec_update_cache(codec, pin, 0,
2987 AC_VERB_SET_CONNECT_SEL, i);
2988 return 0;
2989 }
2990 }
2991 return 0;
2992}
2993
Takashi Iwai185d99f2012-02-16 18:39:45 +01002994static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2995{
2996 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002997 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002998 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2999 ARRAY_SIZE(spec->private_dac_nids)) ||
3000 found_in_nid_list(nid, spec->multiout.hp_out_nid,
3001 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
3002 found_in_nid_list(nid, spec->multiout.extra_out_nid,
3003 ARRAY_SIZE(spec->multiout.extra_out_nid)))
3004 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01003005 for (i = 0; i < spec->multi_ios; i++) {
3006 if (spec->multi_io[i].dac == nid)
3007 return true;
3008 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003009 return false;
3010}
3011
Takashi Iwai7085ec12009-10-02 09:03:58 +02003012/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02003013static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003014{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003015 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003016 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003017
Takashi Iwai604401a2011-04-27 15:14:23 +02003018 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003019 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003020 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003021 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003022 if (!nid)
3023 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01003024 if (!alc_is_dac_already_used(codec, nid))
3025 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003026 }
3027 return 0;
3028}
3029
Takashi Iwai07b18f62011-11-10 15:42:54 +01003030/* check whether the DAC is reachable from the pin */
3031static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
3032 hda_nid_t pin, hda_nid_t dac)
3033{
3034 hda_nid_t srcs[5];
3035 int i, num;
3036
Takashi Iwaidc31b582012-02-17 17:27:53 +01003037 if (!pin || !dac)
3038 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003039 pin = alc_go_down_to_selector(codec, pin);
3040 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
3041 for (i = 0; i < num; i++) {
3042 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3043 if (nid == dac)
3044 return true;
3045 }
3046 return false;
3047}
3048
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003049static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3050{
Takashi Iwai140547e2012-02-16 17:23:46 +01003051 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003052 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003053 hda_nid_t nid, nid_found, srcs[5];
3054 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01003055 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01003056 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003057 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003058 nid_found = 0;
3059 for (i = 0; i < num; i++) {
3060 if (srcs[i] == spec->mixer_nid)
3061 continue;
3062 nid = alc_auto_mix_to_dac(codec, srcs[i]);
3063 if (nid && !alc_is_dac_already_used(codec, nid)) {
3064 if (nid_found)
3065 return 0;
3066 nid_found = nid;
3067 }
3068 }
3069 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003070}
3071
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003072/* mark up volume and mute control NIDs: used during badness parsing and
3073 * at creating actual controls
3074 */
3075static inline unsigned int get_ctl_pos(unsigned int data)
3076{
3077 hda_nid_t nid = get_amp_nid_(data);
3078 unsigned int dir;
3079 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3080 return 0;
3081 dir = get_amp_direction_(data);
3082 return (nid << 1) | dir;
3083}
3084
3085#define is_ctl_used(bits, data) \
3086 test_bit(get_ctl_pos(data), bits)
3087#define mark_ctl_usage(bits, data) \
3088 set_bit(get_ctl_pos(data), bits)
3089
3090static void clear_vol_marks(struct hda_codec *codec)
3091{
3092 struct alc_spec *spec = codec->spec;
3093 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3094 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3095}
3096
3097/* badness definition */
3098enum {
3099 /* No primary DAC is found for the main output */
3100 BAD_NO_PRIMARY_DAC = 0x10000,
3101 /* No DAC is found for the extra output */
3102 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003103 /* No possible multi-ios */
3104 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003105 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003106 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003107 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003108 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003109 /* Primary DAC shared with main surrounds */
3110 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003111 /* Primary DAC shared with main CLFE */
3112 BAD_SHARED_CLFE = 0x10,
3113 /* Primary DAC shared with extra surrounds */
3114 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003115 /* Volume widget is shared */
3116 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003117};
3118
3119static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3120 hda_nid_t pin, hda_nid_t dac);
3121static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3122 hda_nid_t pin, hda_nid_t dac);
3123
3124static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3125 hda_nid_t dac)
3126{
3127 struct alc_spec *spec = codec->spec;
3128 hda_nid_t nid;
3129 unsigned int val;
3130 int badness = 0;
3131
3132 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3133 if (nid) {
3134 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3135 if (is_ctl_used(spec->vol_ctls, nid))
3136 badness += BAD_SHARED_VOL;
3137 else
3138 mark_ctl_usage(spec->vol_ctls, val);
3139 } else
3140 badness += BAD_SHARED_VOL;
3141 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3142 if (nid) {
3143 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3144 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3145 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3146 else
3147 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3148 if (is_ctl_used(spec->sw_ctls, val))
3149 badness += BAD_SHARED_VOL;
3150 else
3151 mark_ctl_usage(spec->sw_ctls, val);
3152 } else
3153 badness += BAD_SHARED_VOL;
3154 return badness;
3155}
3156
Takashi Iwaidc31b582012-02-17 17:27:53 +01003157struct badness_table {
3158 int no_primary_dac; /* no primary DAC */
3159 int no_dac; /* no secondary DACs */
3160 int shared_primary; /* primary DAC is shared with main output */
3161 int shared_surr; /* secondary DAC shared with main or primary */
3162 int shared_clfe; /* third DAC shared with main or primary */
3163 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3164};
3165
3166static struct badness_table main_out_badness = {
3167 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3168 .no_dac = BAD_NO_DAC,
3169 .shared_primary = BAD_NO_PRIMARY_DAC,
3170 .shared_surr = BAD_SHARED_SURROUND,
3171 .shared_clfe = BAD_SHARED_CLFE,
3172 .shared_surr_main = BAD_SHARED_SURROUND,
3173};
3174
3175static struct badness_table extra_out_badness = {
3176 .no_primary_dac = BAD_NO_DAC,
3177 .no_dac = BAD_NO_DAC,
3178 .shared_primary = BAD_NO_EXTRA_DAC,
3179 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3180 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3181 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3182};
3183
3184/* try to assign DACs to pins and return the resultant badness */
3185static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3186 const hda_nid_t *pins, hda_nid_t *dacs,
3187 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003188{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003189 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003190 struct auto_pin_cfg *cfg = &spec->autocfg;
3191 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003192 int badness = 0;
3193 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003194
Takashi Iwai185d99f2012-02-16 18:39:45 +01003195 if (!num_outs)
3196 return 0;
3197
Takashi Iwaidc31b582012-02-17 17:27:53 +01003198 for (i = 0; i < num_outs; i++) {
3199 hda_nid_t pin = pins[i];
3200 if (!dacs[i])
3201 dacs[i] = alc_auto_look_for_dac(codec, pin);
3202 if (!dacs[i] && !i) {
3203 for (j = 1; j < num_outs; j++) {
3204 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3205 dacs[0] = dacs[j];
3206 dacs[j] = 0;
3207 break;
3208 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003209 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003210 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003211 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003212 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003213 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003214 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003215 else if (cfg->line_outs > i &&
3216 alc_auto_is_dac_reachable(codec, pin,
3217 spec->private_dac_nids[i]))
3218 dac = spec->private_dac_nids[i];
3219 if (dac) {
3220 if (!i)
3221 badness += bad->shared_primary;
3222 else if (i == 1)
3223 badness += bad->shared_surr;
3224 else
3225 badness += bad->shared_clfe;
3226 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003227 spec->private_dac_nids[0])) {
3228 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003229 badness += bad->shared_surr_main;
3230 } else if (!i)
3231 badness += bad->no_primary_dac;
3232 else
3233 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003234 }
3235 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003236 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003237 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003238
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003239 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003240}
3241
3242static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003243 hda_nid_t reference_pin,
3244 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003245
Takashi Iwai185d99f2012-02-16 18:39:45 +01003246static bool alc_map_singles(struct hda_codec *codec, int outs,
3247 const hda_nid_t *pins, hda_nid_t *dacs)
3248{
3249 int i;
3250 bool found = false;
3251 for (i = 0; i < outs; i++) {
3252 if (dacs[i])
3253 continue;
3254 dacs[i] = get_dac_if_single(codec, pins[i]);
3255 if (dacs[i])
3256 found = true;
3257 }
3258 return found;
3259}
3260
Takashi Iwai7085ec12009-10-02 09:03:58 +02003261/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003262static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003263 bool fill_hardwired,
3264 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003265{
3266 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003267 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003268 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003269
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003270 /* set num_dacs once to full for alc_auto_look_for_dac() */
3271 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003272 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003273 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3274 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3275 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003276 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003277 clear_vol_marks(codec);
3278 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003279
3280 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003281 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003282 bool mapped;
3283 do {
3284 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003285 cfg->line_out_pins,
3286 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003287 mapped |= alc_map_singles(codec, cfg->hp_outs,
3288 cfg->hp_pins,
3289 spec->multiout.hp_out_nid);
3290 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3291 cfg->speaker_pins,
3292 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003293 if (fill_mio_first && cfg->line_outs == 1 &&
3294 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3295 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3296 if (!err)
3297 mapped = true;
3298 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003299 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003300 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003301
Takashi Iwaidc31b582012-02-17 17:27:53 +01003302 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3303 spec->private_dac_nids,
3304 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003305
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003306 /* re-count num_dacs and squash invalid entries */
3307 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003308 for (i = 0; i < cfg->line_outs; i++) {
3309 if (spec->private_dac_nids[i])
3310 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003311 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003312 memmove(spec->private_dac_nids + i,
3313 spec->private_dac_nids + i + 1,
3314 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003315 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3316 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003317 }
3318
Takashi Iwai276dd702012-02-17 16:17:03 +01003319 if (fill_mio_first &&
3320 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003321 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003322 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003323 if (err < 0)
3324 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003325 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003326 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003327
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003328 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003329 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3330 spec->multiout.hp_out_nid,
3331 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003332 if (err < 0)
3333 return err;
3334 badness += err;
3335 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003336 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003337 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3338 cfg->speaker_pins,
3339 spec->multiout.extra_out_nid,
3340 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003341 if (err < 0)
3342 return err;
3343 badness += err;
3344 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003345 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3346 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003347 if (err < 0)
3348 return err;
3349 badness += err;
3350 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003351 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3352 /* try multi-ios with HP + inputs */
3353 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, 1);
3354 if (err < 0)
3355 return err;
3356 badness += err;
3357 }
3358
3359 if (spec->multi_ios == 2) {
3360 for (i = 0; i < 2; i++)
3361 spec->private_dac_nids[spec->multiout.num_dacs++] =
3362 spec->multi_io[i].dac;
3363 spec->ext_channel_count = 2;
3364 } else if (spec->multi_ios) {
3365 spec->multi_ios = 0;
3366 badness += BAD_MULTI_IO;
3367 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003368
3369 return badness;
3370}
3371
3372#define DEBUG_BADNESS
3373
3374#ifdef DEBUG_BADNESS
3375#define debug_badness snd_printdd
3376#else
3377#define debug_badness(...)
3378#endif
3379
3380static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3381{
3382 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3383 cfg->line_out_pins[0], cfg->line_out_pins[1],
3384 cfg->line_out_pins[2], cfg->line_out_pins[2],
3385 spec->multiout.dac_nids[0],
3386 spec->multiout.dac_nids[1],
3387 spec->multiout.dac_nids[2],
3388 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003389 if (spec->multi_ios > 0)
3390 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3391 spec->multi_ios,
3392 spec->multi_io[0].pin, spec->multi_io[1].pin,
3393 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003394 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3395 cfg->hp_pins[0], cfg->hp_pins[1],
3396 cfg->hp_pins[2], cfg->hp_pins[2],
3397 spec->multiout.hp_out_nid[0],
3398 spec->multiout.hp_out_nid[1],
3399 spec->multiout.hp_out_nid[2],
3400 spec->multiout.hp_out_nid[3]);
3401 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3402 cfg->speaker_pins[0], cfg->speaker_pins[1],
3403 cfg->speaker_pins[2], cfg->speaker_pins[3],
3404 spec->multiout.extra_out_nid[0],
3405 spec->multiout.extra_out_nid[1],
3406 spec->multiout.extra_out_nid[2],
3407 spec->multiout.extra_out_nid[3]);
3408}
3409
3410static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3411{
3412 struct alc_spec *spec = codec->spec;
3413 struct auto_pin_cfg *cfg = &spec->autocfg;
3414 struct auto_pin_cfg *best_cfg;
3415 int best_badness = INT_MAX;
3416 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003417 bool fill_hardwired = true, fill_mio_first = true;
3418 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003419 bool hp_spk_swapped = false;
3420
3421 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3422 if (!best_cfg)
3423 return -ENOMEM;
3424 *best_cfg = *cfg;
3425
3426 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003427 badness = fill_and_eval_dacs(codec, fill_hardwired,
3428 fill_mio_first);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003429 if (badness < 0)
3430 return badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003431 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3432 cfg->line_out_type, fill_hardwired, fill_mio_first,
3433 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003434 debug_show_configs(spec, cfg);
3435 if (badness < best_badness) {
3436 best_badness = badness;
3437 *best_cfg = *cfg;
3438 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003439 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003440 }
3441 if (!badness)
3442 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003443 fill_mio_first = !fill_mio_first;
3444 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003445 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003446 fill_hardwired = !fill_hardwired;
3447 if (!fill_hardwired)
3448 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003449 if (hp_spk_swapped)
3450 break;
3451 hp_spk_swapped = true;
3452 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003453 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3454 cfg->hp_outs = cfg->line_outs;
3455 memcpy(cfg->hp_pins, cfg->line_out_pins,
3456 sizeof(cfg->hp_pins));
3457 cfg->line_outs = cfg->speaker_outs;
3458 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3459 sizeof(cfg->speaker_pins));
3460 cfg->speaker_outs = 0;
3461 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3462 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003463 fill_hardwired = true;
3464 continue;
3465 }
3466 if (cfg->hp_outs > 0 &&
3467 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3468 cfg->speaker_outs = cfg->line_outs;
3469 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3470 sizeof(cfg->speaker_pins));
3471 cfg->line_outs = cfg->hp_outs;
3472 memcpy(cfg->line_out_pins, cfg->hp_pins,
3473 sizeof(cfg->hp_pins));
3474 cfg->hp_outs = 0;
3475 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3476 cfg->line_out_type = AUTO_PIN_HP_OUT;
3477 fill_hardwired = true;
3478 continue;
3479 }
3480 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003481 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003482
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003483 if (badness) {
3484 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003485 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003486 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003487 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3488 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003489 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003490
David Henningssonfde48a12011-12-09 18:27:42 +08003491 if (cfg->line_out_pins[0])
3492 spec->vmaster_nid =
3493 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3494 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003495
3496 /* clear the bitmap flags for creating controls */
3497 clear_vol_marks(codec);
3498 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003499 return 0;
3500}
3501
Takashi Iwai343a04b2011-07-06 14:28:39 +02003502static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003503 const char *pfx, int cidx,
3504 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003505{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003506 struct alc_spec *spec = codec->spec;
3507 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003508 if (!nid)
3509 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003510 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3511 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3512 return 0;
3513 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003514 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003515 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003516}
3517
Takashi Iwaie29d3772011-11-14 17:13:23 +01003518static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3519 const char *pfx, int cidx,
3520 hda_nid_t nid)
3521{
3522 int chs = 1;
3523 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3524 chs = 3;
3525 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3526}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003527
3528/* create a mute-switch for the given mixer widget;
3529 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3530 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003531static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003532 const char *pfx, int cidx,
3533 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003534{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003535 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003536 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003537 int type;
3538 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003539 if (!nid)
3540 return 0;
3541 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3542 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3543 type = ALC_CTL_WIDGET_MUTE;
3544 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3545 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003546 type = ALC_CTL_WIDGET_MUTE;
3547 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3548 } else {
3549 type = ALC_CTL_BIND_MUTE;
3550 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3551 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003552 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3553 return 0;
3554 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003555 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003556}
3557
Takashi Iwaie29d3772011-11-14 17:13:23 +01003558static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3559 int cidx, hda_nid_t nid)
3560{
3561 int chs = 1;
3562 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3563 chs = 3;
3564 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3565}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003566
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003567static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3568 hda_nid_t pin, hda_nid_t dac)
3569{
3570 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3571 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3572 return pin;
3573 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3574 return mix;
3575 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3576 return dac;
3577 return 0;
3578}
3579
3580static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3581 hda_nid_t pin, hda_nid_t dac)
3582{
3583 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3584 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3585 return dac;
3586 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3587 return mix;
3588 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3589 return pin;
3590 return 0;
3591}
3592
Takashi Iwai7085ec12009-10-02 09:03:58 +02003593/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003594static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003595 const struct auto_pin_cfg *cfg)
3596{
3597 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003598 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003599
Takashi Iwaice764ab2011-04-27 16:35:23 +02003600 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003601 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003602 noutputs += spec->multi_ios;
3603
3604 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003605 const char *name;
3606 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003607 hda_nid_t dac, pin;
3608 hda_nid_t sw, vol;
3609
3610 dac = spec->multiout.dac_nids[i];
3611 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003612 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003613 if (i >= cfg->line_outs)
3614 pin = spec->multi_io[i - 1].pin;
3615 else
3616 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003617
3618 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3619 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003620 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003621 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003622 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003623 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003624 if (err < 0)
3625 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003626 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003627 if (err < 0)
3628 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003629 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 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_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003633 if (err < 0)
3634 return err;
3635 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003636 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003637 if (err < 0)
3638 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003639 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003640 if (err < 0)
3641 return err;
3642 }
3643 }
3644 return 0;
3645}
3646
Takashi Iwai343a04b2011-07-06 14:28:39 +02003647static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003648 hda_nid_t dac, const char *pfx,
3649 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003650{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003651 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003652 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003653 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003654
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003655 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003656 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003657 /* the corresponding DAC is already occupied */
3658 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3659 return 0; /* no way */
3660 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003661 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3662 if (is_ctl_used(spec->sw_ctls, val))
3663 return 0; /* already created */
3664 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003665 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003666 }
3667
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003668 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3669 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003670 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003671 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003672 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003673 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003674 if (err < 0)
3675 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003676 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003677}
3678
Takashi Iwai23c09b02011-08-19 09:05:35 +02003679static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3680 unsigned int nums,
3681 struct hda_ctl_ops *ops)
3682{
3683 struct alc_spec *spec = codec->spec;
3684 struct hda_bind_ctls **ctlp, *ctl;
3685 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3686 ctlp = snd_array_new(&spec->bind_ctls);
3687 if (!ctlp)
3688 return NULL;
3689 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3690 *ctlp = ctl;
3691 if (ctl)
3692 ctl->ops = ops;
3693 return ctl;
3694}
3695
3696/* add playback controls for speaker and HP outputs */
3697static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3698 const hda_nid_t *pins,
3699 const hda_nid_t *dacs,
3700 const char *pfx)
3701{
3702 struct alc_spec *spec = codec->spec;
3703 struct hda_bind_ctls *ctl;
3704 char name[32];
3705 int i, n, err;
3706
3707 if (!num_pins || !pins[0])
3708 return 0;
3709
Takashi Iwai527e4d72011-10-27 16:33:27 +02003710 if (num_pins == 1) {
3711 hda_nid_t dac = *dacs;
3712 if (!dac)
3713 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003714 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003715 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003716
3717 if (dacs[num_pins - 1]) {
3718 /* OK, we have a multi-output system with individual volumes */
3719 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003720 if (num_pins >= 3) {
3721 snprintf(name, sizeof(name), "%s %s",
3722 pfx, channel_name[i]);
3723 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3724 name, 0);
3725 } else {
3726 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3727 pfx, i);
3728 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003729 if (err < 0)
3730 return err;
3731 }
3732 return 0;
3733 }
3734
3735 /* Let's create a bind-controls */
3736 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3737 if (!ctl)
3738 return -ENOMEM;
3739 n = 0;
3740 for (i = 0; i < num_pins; i++) {
3741 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3742 ctl->values[n++] =
3743 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3744 }
3745 if (n) {
3746 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3747 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3748 if (err < 0)
3749 return err;
3750 }
3751
3752 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3753 if (!ctl)
3754 return -ENOMEM;
3755 n = 0;
3756 for (i = 0; i < num_pins; i++) {
3757 hda_nid_t vol;
3758 if (!pins[i] || !dacs[i])
3759 continue;
3760 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3761 if (vol)
3762 ctl->values[n++] =
3763 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3764 }
3765 if (n) {
3766 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3767 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3768 if (err < 0)
3769 return err;
3770 }
3771 return 0;
3772}
3773
Takashi Iwai343a04b2011-07-06 14:28:39 +02003774static int alc_auto_create_hp_out(struct hda_codec *codec)
3775{
3776 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003777 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3778 spec->autocfg.hp_pins,
3779 spec->multiout.hp_out_nid,
3780 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003781}
3782
3783static int alc_auto_create_speaker_out(struct hda_codec *codec)
3784{
3785 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003786 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3787 spec->autocfg.speaker_pins,
3788 spec->multiout.extra_out_nid,
3789 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003790}
3791
Takashi Iwai343a04b2011-07-06 14:28:39 +02003792static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003793 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003794 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003795{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003796 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003797 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003798 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003799
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003800 alc_set_pin_output(codec, pin, pin_type);
3801 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003802 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003803 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003804 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003805 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003806 mix = srcs[i];
3807 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003808 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003809 if (!mix)
3810 return;
3811
3812 /* need the manual connection? */
3813 if (num > 1)
3814 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3815 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003816 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3817 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003818 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003819 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003820 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003821 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003822 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003823 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3824 if (nid)
3825 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3826 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003827
3828 /* unmute DAC if it's not assigned to a mixer */
3829 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3830 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3831 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3832 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003833}
3834
Takashi Iwai343a04b2011-07-06 14:28:39 +02003835static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003836{
3837 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003838 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003839 int i;
3840
3841 for (i = 0; i <= HDA_SIDE; i++) {
3842 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3843 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003844 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003845 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003846 }
3847}
3848
Takashi Iwai343a04b2011-07-06 14:28:39 +02003849static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003850{
3851 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003852 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003853 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003854
David Henningsson636030e2011-10-12 19:26:03 +02003855 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003856 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3857 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003858 pin = spec->autocfg.hp_pins[i];
3859 if (!pin)
3860 break;
3861 dac = spec->multiout.hp_out_nid[i];
3862 if (!dac) {
3863 if (i > 0 && spec->multiout.hp_out_nid[0])
3864 dac = spec->multiout.hp_out_nid[0];
3865 else
3866 dac = spec->multiout.dac_nids[0];
3867 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003868 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3869 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003870 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003871 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3872 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003873 pin = spec->autocfg.speaker_pins[i];
3874 if (!pin)
3875 break;
3876 dac = spec->multiout.extra_out_nid[i];
3877 if (!dac) {
3878 if (i > 0 && spec->multiout.extra_out_nid[0])
3879 dac = spec->multiout.extra_out_nid[0];
3880 else
3881 dac = spec->multiout.dac_nids[0];
3882 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003883 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3884 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003885}
3886
Takashi Iwai276dd702012-02-17 16:17:03 +01003887/* check whether the given pin can be a multi-io pin */
3888static bool can_be_multiio_pin(struct hda_codec *codec,
3889 unsigned int location, hda_nid_t nid)
3890{
3891 unsigned int defcfg, caps;
3892
3893 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3894 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3895 return false;
3896 if (location && get_defcfg_location(defcfg) != location)
3897 return false;
3898 caps = snd_hda_query_pin_caps(codec, nid);
3899 if (!(caps & AC_PINCAP_OUT))
3900 return false;
3901 return true;
3902}
3903
Takashi Iwaice764ab2011-04-27 16:35:23 +02003904/*
3905 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003906 *
3907 * When hardwired is set, try to fill ony hardwired pins, and returns
3908 * zero if any pins are filled, non-zero if nothing found.
3909 * When hardwired is off, try to fill possible input pins, and returns
3910 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003911 */
3912static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003913 hda_nid_t reference_pin,
3914 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003915{
3916 struct alc_spec *spec = codec->spec;
3917 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003918 int type, i, j, dacs, num_pins, old_pins;
3919 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3920 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003921 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003922
Takashi Iwai276dd702012-02-17 16:17:03 +01003923 old_pins = spec->multi_ios;
3924 if (old_pins >= 2)
3925 goto end_fill;
3926
3927 num_pins = 0;
3928 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3929 for (i = 0; i < cfg->num_inputs; i++) {
3930 if (cfg->inputs[i].type != type)
3931 continue;
3932 if (can_be_multiio_pin(codec, location,
3933 cfg->inputs[i].pin))
3934 num_pins++;
3935 }
3936 }
3937 if (num_pins < 2)
3938 goto end_fill;
3939
Takashi Iwai07b18f62011-11-10 15:42:54 +01003940 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003941 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3942 for (i = 0; i < cfg->num_inputs; i++) {
3943 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003944 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003945
Takashi Iwaice764ab2011-04-27 16:35:23 +02003946 if (cfg->inputs[i].type != type)
3947 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003948 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003949 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003950 for (j = 0; j < spec->multi_ios; j++) {
3951 if (nid == spec->multi_io[j].pin)
3952 break;
3953 }
3954 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003955 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003956
3957 if (offset && offset + spec->multi_ios < dacs) {
3958 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003959 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3960 dac = 0;
3961 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003962 if (hardwired)
3963 dac = get_dac_if_single(codec, nid);
3964 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003965 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003966 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003967 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003968 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003969 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003970 spec->multi_io[spec->multi_ios].pin = nid;
3971 spec->multi_io[spec->multi_ios].dac = dac;
3972 spec->multi_ios++;
3973 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003974 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003975 }
3976 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003977 end_fill:
3978 if (badness)
3979 badness = BAD_MULTI_IO;
3980 if (old_pins == spec->multi_ios) {
3981 if (hardwired)
3982 return 1; /* nothing found */
3983 else
3984 return badness; /* no badness if nothing found */
3985 }
3986 if (!hardwired && spec->multi_ios < 2) {
3987 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003988 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003989 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003990
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003991 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003992}
3993
3994static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3995 struct snd_ctl_elem_info *uinfo)
3996{
3997 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3998 struct alc_spec *spec = codec->spec;
3999
4000 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4001 uinfo->count = 1;
4002 uinfo->value.enumerated.items = spec->multi_ios + 1;
4003 if (uinfo->value.enumerated.item > spec->multi_ios)
4004 uinfo->value.enumerated.item = spec->multi_ios;
4005 sprintf(uinfo->value.enumerated.name, "%dch",
4006 (uinfo->value.enumerated.item + 1) * 2);
4007 return 0;
4008}
4009
4010static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
4011 struct snd_ctl_elem_value *ucontrol)
4012{
4013 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4014 struct alc_spec *spec = codec->spec;
4015 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
4016 return 0;
4017}
4018
4019static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
4020{
4021 struct alc_spec *spec = codec->spec;
4022 hda_nid_t nid = spec->multi_io[idx].pin;
4023
4024 if (!spec->multi_io[idx].ctl_in)
4025 spec->multi_io[idx].ctl_in =
4026 snd_hda_codec_read(codec, nid, 0,
4027 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
4028 if (output) {
4029 snd_hda_codec_update_cache(codec, nid, 0,
4030 AC_VERB_SET_PIN_WIDGET_CONTROL,
4031 PIN_OUT);
4032 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4033 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4034 HDA_AMP_MUTE, 0);
4035 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
4036 } else {
4037 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4038 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4039 HDA_AMP_MUTE, HDA_AMP_MUTE);
4040 snd_hda_codec_update_cache(codec, nid, 0,
4041 AC_VERB_SET_PIN_WIDGET_CONTROL,
4042 spec->multi_io[idx].ctl_in);
4043 }
4044 return 0;
4045}
4046
4047static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4048 struct snd_ctl_elem_value *ucontrol)
4049{
4050 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4051 struct alc_spec *spec = codec->spec;
4052 int i, ch;
4053
4054 ch = ucontrol->value.enumerated.item[0];
4055 if (ch < 0 || ch > spec->multi_ios)
4056 return -EINVAL;
4057 if (ch == (spec->ext_channel_count - 1) / 2)
4058 return 0;
4059 spec->ext_channel_count = (ch + 1) * 2;
4060 for (i = 0; i < spec->multi_ios; i++)
4061 alc_set_multi_io(codec, i, i < ch);
4062 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004063 if (spec->need_dac_fix && !spec->const_channel_count)
4064 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004065 return 1;
4066}
4067
Takashi Iwaia9111322011-05-02 11:30:18 +02004068static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004069 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4070 .name = "Channel Mode",
4071 .info = alc_auto_ch_mode_info,
4072 .get = alc_auto_ch_mode_get,
4073 .put = alc_auto_ch_mode_put,
4074};
4075
Takashi Iwai23c09b02011-08-19 09:05:35 +02004076static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004077{
4078 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004079
Takashi Iwaic2674682011-08-24 17:57:44 +02004080 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004081 struct snd_kcontrol_new *knew;
4082
4083 knew = alc_kcontrol_new(spec);
4084 if (!knew)
4085 return -ENOMEM;
4086 *knew = alc_auto_channel_mode_enum;
4087 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4088 if (!knew->name)
4089 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004090 }
4091 return 0;
4092}
4093
Takashi Iwai1d045db2011-07-07 18:23:21 +02004094/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4095 * active input pins
4096 */
4097static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4098{
4099 struct alc_spec *spec = codec->spec;
4100 const struct hda_input_mux *imux;
4101 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4102 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4103 int i, n, nums;
4104
4105 imux = spec->input_mux;
4106 if (!imux)
4107 return;
4108 if (spec->dyn_adc_switch)
4109 return;
4110
4111 nums = 0;
4112 for (n = 0; n < spec->num_adc_nids; n++) {
4113 hda_nid_t cap = spec->private_capsrc_nids[n];
4114 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4115 for (i = 0; i < imux->num_items; i++) {
4116 hda_nid_t pin = spec->imux_pins[i];
4117 if (pin) {
4118 if (get_connection_index(codec, cap, pin) < 0)
4119 break;
4120 } else if (num_conns <= imux->items[i].index)
4121 break;
4122 }
4123 if (i >= imux->num_items) {
4124 adc_nids[nums] = spec->private_adc_nids[n];
4125 capsrc_nids[nums++] = cap;
4126 }
4127 }
4128 if (!nums) {
4129 /* check whether ADC-switch is possible */
4130 if (!alc_check_dyn_adc_switch(codec)) {
4131 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4132 " using fallback 0x%x\n",
4133 codec->chip_name, spec->private_adc_nids[0]);
4134 spec->num_adc_nids = 1;
4135 spec->auto_mic = 0;
4136 return;
4137 }
4138 } else if (nums != spec->num_adc_nids) {
4139 memcpy(spec->private_adc_nids, adc_nids,
4140 nums * sizeof(hda_nid_t));
4141 memcpy(spec->private_capsrc_nids, capsrc_nids,
4142 nums * sizeof(hda_nid_t));
4143 spec->num_adc_nids = nums;
4144 }
4145
4146 if (spec->auto_mic)
4147 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4148 else if (spec->input_mux->num_items == 1)
4149 spec->num_adc_nids = 1; /* reduce to a single ADC */
4150}
4151
4152/*
4153 * initialize ADC paths
4154 */
4155static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4156{
4157 struct alc_spec *spec = codec->spec;
4158 hda_nid_t nid;
4159
4160 nid = spec->adc_nids[adc_idx];
4161 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004162 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004163 snd_hda_codec_write(codec, nid, 0,
4164 AC_VERB_SET_AMP_GAIN_MUTE,
4165 AMP_IN_MUTE(0));
4166 return;
4167 }
4168 if (!spec->capsrc_nids)
4169 return;
4170 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004171 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004172 snd_hda_codec_write(codec, nid, 0,
4173 AC_VERB_SET_AMP_GAIN_MUTE,
4174 AMP_OUT_MUTE);
4175}
4176
4177static void alc_auto_init_input_src(struct hda_codec *codec)
4178{
4179 struct alc_spec *spec = codec->spec;
4180 int c, nums;
4181
4182 for (c = 0; c < spec->num_adc_nids; c++)
4183 alc_auto_init_adc(codec, c);
4184 if (spec->dyn_adc_switch)
4185 nums = 1;
4186 else
4187 nums = spec->num_adc_nids;
4188 for (c = 0; c < nums; c++)
4189 alc_mux_select(codec, 0, spec->cur_mux[c], true);
4190}
4191
4192/* add mic boosts if needed */
4193static int alc_auto_add_mic_boost(struct hda_codec *codec)
4194{
4195 struct alc_spec *spec = codec->spec;
4196 struct auto_pin_cfg *cfg = &spec->autocfg;
4197 int i, err;
4198 int type_idx = 0;
4199 hda_nid_t nid;
4200 const char *prev_label = NULL;
4201
4202 for (i = 0; i < cfg->num_inputs; i++) {
4203 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4204 break;
4205 nid = cfg->inputs[i].pin;
4206 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4207 const char *label;
4208 char boost_label[32];
4209
4210 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004211 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4212 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004213 if (prev_label && !strcmp(label, prev_label))
4214 type_idx++;
4215 else
4216 type_idx = 0;
4217 prev_label = label;
4218
4219 snprintf(boost_label, sizeof(boost_label),
4220 "%s Boost Volume", label);
4221 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4222 boost_label, type_idx,
4223 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4224 if (err < 0)
4225 return err;
4226 }
4227 }
4228 return 0;
4229}
4230
4231/* select or unmute the given capsrc route */
4232static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4233 int idx)
4234{
4235 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4236 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4237 HDA_AMP_MUTE, 0);
4238 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4239 snd_hda_codec_write_cache(codec, cap, 0,
4240 AC_VERB_SET_CONNECT_SEL, idx);
4241 }
4242}
4243
4244/* set the default connection to that pin */
4245static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4246{
4247 struct alc_spec *spec = codec->spec;
4248 int i;
4249
4250 if (!pin)
4251 return 0;
4252 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004253 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004254 int idx;
4255
4256 idx = get_connection_index(codec, cap, pin);
4257 if (idx < 0)
4258 continue;
4259 select_or_unmute_capsrc(codec, cap, idx);
4260 return i; /* return the found index */
4261 }
4262 return -1; /* not found */
4263}
4264
4265/* initialize some special cases for input sources */
4266static void alc_init_special_input_src(struct hda_codec *codec)
4267{
4268 struct alc_spec *spec = codec->spec;
4269 int i;
4270
4271 for (i = 0; i < spec->autocfg.num_inputs; i++)
4272 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4273}
4274
4275/* assign appropriate capture mixers */
4276static void set_capture_mixer(struct hda_codec *codec)
4277{
4278 struct alc_spec *spec = codec->spec;
4279 static const struct snd_kcontrol_new *caps[2][3] = {
4280 { alc_capture_mixer_nosrc1,
4281 alc_capture_mixer_nosrc2,
4282 alc_capture_mixer_nosrc3 },
4283 { alc_capture_mixer1,
4284 alc_capture_mixer2,
4285 alc_capture_mixer3 },
4286 };
4287
4288 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004289 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004290 if (!spec->capsrc_nids)
4291 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004292 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004293 return; /* no volume in capsrc, too */
4294 spec->vol_in_capsrc = 1;
4295 }
4296
4297 if (spec->num_adc_nids > 0) {
4298 int mux = 0;
4299 int num_adcs = 0;
4300
4301 if (spec->input_mux && spec->input_mux->num_items > 1)
4302 mux = 1;
4303 if (spec->auto_mic) {
4304 num_adcs = 1;
4305 mux = 0;
4306 } else if (spec->dyn_adc_switch)
4307 num_adcs = 1;
4308 if (!num_adcs) {
4309 if (spec->num_adc_nids > 3)
4310 spec->num_adc_nids = 3;
4311 else if (!spec->num_adc_nids)
4312 return;
4313 num_adcs = spec->num_adc_nids;
4314 }
4315 spec->cap_mixer = caps[mux][num_adcs - 1];
4316 }
4317}
4318
4319/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004320 * standard auto-parser initializations
4321 */
4322static void alc_auto_init_std(struct hda_codec *codec)
4323{
4324 struct alc_spec *spec = codec->spec;
4325 alc_auto_init_multi_out(codec);
4326 alc_auto_init_extra_out(codec);
4327 alc_auto_init_analog_input(codec);
4328 alc_auto_init_input_src(codec);
4329 alc_auto_init_digital(codec);
4330 if (spec->unsol_event)
4331 alc_inithook(codec);
4332}
4333
4334/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004335 * Digital-beep handlers
4336 */
4337#ifdef CONFIG_SND_HDA_INPUT_BEEP
4338#define set_beep_amp(spec, nid, idx, dir) \
4339 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4340
4341static const struct snd_pci_quirk beep_white_list[] = {
4342 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4343 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4344 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4345 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4346 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4347 {}
4348};
4349
4350static inline int has_cdefine_beep(struct hda_codec *codec)
4351{
4352 struct alc_spec *spec = codec->spec;
4353 const struct snd_pci_quirk *q;
4354 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4355 if (q)
4356 return q->value;
4357 return spec->cdefine.enable_pcbeep;
4358}
4359#else
4360#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4361#define has_cdefine_beep(codec) 0
4362#endif
4363
4364/* parse the BIOS configuration and set up the alc_spec */
4365/* return 1 if successful, 0 if the proper config is not found,
4366 * or a negative error code
4367 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004368static int alc_parse_auto_config(struct hda_codec *codec,
4369 const hda_nid_t *ignore_nids,
4370 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004371{
4372 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004373 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004374 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004375
Takashi Iwai53c334a2011-08-23 18:27:14 +02004376 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4377 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004378 if (err < 0)
4379 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004380 if (!cfg->line_outs) {
4381 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004382 spec->multiout.max_channels = 2;
4383 spec->no_analog = 1;
4384 goto dig_only;
4385 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004386 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004387 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004388
Takashi Iwai06503672011-10-06 08:27:19 +02004389 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4390 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004391 /* use HP as primary out */
4392 cfg->speaker_outs = cfg->line_outs;
4393 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4394 sizeof(cfg->speaker_pins));
4395 cfg->line_outs = cfg->hp_outs;
4396 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4397 cfg->hp_outs = 0;
4398 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4399 cfg->line_out_type = AUTO_PIN_HP_OUT;
4400 }
4401
Takashi Iwai1d045db2011-07-07 18:23:21 +02004402 err = alc_auto_fill_dac_nids(codec);
4403 if (err < 0)
4404 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004405 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004406 if (err < 0)
4407 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004408 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004409 if (err < 0)
4410 return err;
4411 err = alc_auto_create_hp_out(codec);
4412 if (err < 0)
4413 return err;
4414 err = alc_auto_create_speaker_out(codec);
4415 if (err < 0)
4416 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004417 err = alc_auto_create_shared_input(codec);
4418 if (err < 0)
4419 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004420 err = alc_auto_create_input_ctls(codec);
4421 if (err < 0)
4422 return err;
4423
4424 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4425
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004426 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004427 alc_auto_parse_digital(codec);
4428
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004429 if (!spec->no_analog)
4430 alc_remove_invalid_adc_nids(codec);
4431
4432 if (ssid_nids)
4433 alc_ssid_check(codec, ssid_nids);
4434
4435 if (!spec->no_analog) {
4436 alc_auto_check_switches(codec);
4437 err = alc_auto_add_mic_boost(codec);
4438 if (err < 0)
4439 return err;
4440 }
4441
Takashi Iwai1d045db2011-07-07 18:23:21 +02004442 if (spec->kctls.list)
4443 add_mixer(spec, spec->kctls.list);
4444
Takashi Iwai1d045db2011-07-07 18:23:21 +02004445 return 1;
4446}
4447
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004448static int alc880_parse_auto_config(struct hda_codec *codec)
4449{
4450 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4451 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4452 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4453}
4454
Takashi Iwai1d045db2011-07-07 18:23:21 +02004455/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004456 * ALC880 fix-ups
4457 */
4458enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004459 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004460 ALC880_FIXUP_GPIO2,
4461 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004462 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004463 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004464 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004465 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004466 ALC880_FIXUP_VOL_KNOB,
4467 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004468 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004469 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004470 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004471 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004472 ALC880_FIXUP_3ST_BASE,
4473 ALC880_FIXUP_3ST,
4474 ALC880_FIXUP_3ST_DIG,
4475 ALC880_FIXUP_5ST_BASE,
4476 ALC880_FIXUP_5ST,
4477 ALC880_FIXUP_5ST_DIG,
4478 ALC880_FIXUP_6ST_BASE,
4479 ALC880_FIXUP_6ST,
4480 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004481};
4482
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004483/* enable the volume-knob widget support on NID 0x21 */
4484static void alc880_fixup_vol_knob(struct hda_codec *codec,
4485 const struct alc_fixup *fix, int action)
4486{
4487 if (action == ALC_FIXUP_ACT_PROBE)
4488 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4489}
4490
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004491static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004492 [ALC880_FIXUP_GPIO1] = {
4493 .type = ALC_FIXUP_VERBS,
4494 .v.verbs = alc_gpio1_init_verbs,
4495 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004496 [ALC880_FIXUP_GPIO2] = {
4497 .type = ALC_FIXUP_VERBS,
4498 .v.verbs = alc_gpio2_init_verbs,
4499 },
4500 [ALC880_FIXUP_MEDION_RIM] = {
4501 .type = ALC_FIXUP_VERBS,
4502 .v.verbs = (const struct hda_verb[]) {
4503 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4504 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4505 { }
4506 },
4507 .chained = true,
4508 .chain_id = ALC880_FIXUP_GPIO2,
4509 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004510 [ALC880_FIXUP_LG] = {
4511 .type = ALC_FIXUP_PINS,
4512 .v.pins = (const struct alc_pincfg[]) {
4513 /* disable bogus unused pins */
4514 { 0x16, 0x411111f0 },
4515 { 0x18, 0x411111f0 },
4516 { 0x1a, 0x411111f0 },
4517 { }
4518 }
4519 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004520 [ALC880_FIXUP_W810] = {
4521 .type = ALC_FIXUP_PINS,
4522 .v.pins = (const struct alc_pincfg[]) {
4523 /* disable bogus unused pins */
4524 { 0x17, 0x411111f0 },
4525 { }
4526 },
4527 .chained = true,
4528 .chain_id = ALC880_FIXUP_GPIO2,
4529 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004530 [ALC880_FIXUP_EAPD_COEF] = {
4531 .type = ALC_FIXUP_VERBS,
4532 .v.verbs = (const struct hda_verb[]) {
4533 /* change to EAPD mode */
4534 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4535 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4536 {}
4537 },
4538 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004539 [ALC880_FIXUP_TCL_S700] = {
4540 .type = ALC_FIXUP_VERBS,
4541 .v.verbs = (const struct hda_verb[]) {
4542 /* change to EAPD mode */
4543 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4544 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4545 {}
4546 },
4547 .chained = true,
4548 .chain_id = ALC880_FIXUP_GPIO2,
4549 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004550 [ALC880_FIXUP_VOL_KNOB] = {
4551 .type = ALC_FIXUP_FUNC,
4552 .v.func = alc880_fixup_vol_knob,
4553 },
4554 [ALC880_FIXUP_FUJITSU] = {
4555 /* override all pins as BIOS on old Amilo is broken */
4556 .type = ALC_FIXUP_PINS,
4557 .v.pins = (const struct alc_pincfg[]) {
4558 { 0x14, 0x0121411f }, /* HP */
4559 { 0x15, 0x99030120 }, /* speaker */
4560 { 0x16, 0x99030130 }, /* bass speaker */
4561 { 0x17, 0x411111f0 }, /* N/A */
4562 { 0x18, 0x411111f0 }, /* N/A */
4563 { 0x19, 0x01a19950 }, /* mic-in */
4564 { 0x1a, 0x411111f0 }, /* N/A */
4565 { 0x1b, 0x411111f0 }, /* N/A */
4566 { 0x1c, 0x411111f0 }, /* N/A */
4567 { 0x1d, 0x411111f0 }, /* N/A */
4568 { 0x1e, 0x01454140 }, /* SPDIF out */
4569 { }
4570 },
4571 .chained = true,
4572 .chain_id = ALC880_FIXUP_VOL_KNOB,
4573 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004574 [ALC880_FIXUP_F1734] = {
4575 /* almost compatible with FUJITSU, but no bass and SPDIF */
4576 .type = ALC_FIXUP_PINS,
4577 .v.pins = (const struct alc_pincfg[]) {
4578 { 0x14, 0x0121411f }, /* HP */
4579 { 0x15, 0x99030120 }, /* speaker */
4580 { 0x16, 0x411111f0 }, /* N/A */
4581 { 0x17, 0x411111f0 }, /* N/A */
4582 { 0x18, 0x411111f0 }, /* N/A */
4583 { 0x19, 0x01a19950 }, /* mic-in */
4584 { 0x1a, 0x411111f0 }, /* N/A */
4585 { 0x1b, 0x411111f0 }, /* N/A */
4586 { 0x1c, 0x411111f0 }, /* N/A */
4587 { 0x1d, 0x411111f0 }, /* N/A */
4588 { 0x1e, 0x411111f0 }, /* N/A */
4589 { }
4590 },
4591 .chained = true,
4592 .chain_id = ALC880_FIXUP_VOL_KNOB,
4593 },
Takashi Iwai817de922012-02-20 17:20:48 +01004594 [ALC880_FIXUP_UNIWILL] = {
4595 /* need to fix HP and speaker pins to be parsed correctly */
4596 .type = ALC_FIXUP_PINS,
4597 .v.pins = (const struct alc_pincfg[]) {
4598 { 0x14, 0x0121411f }, /* HP */
4599 { 0x15, 0x99030120 }, /* speaker */
4600 { 0x16, 0x99030130 }, /* bass speaker */
4601 { }
4602 },
4603 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004604 [ALC880_FIXUP_UNIWILL_DIG] = {
4605 .type = ALC_FIXUP_PINS,
4606 .v.pins = (const struct alc_pincfg[]) {
4607 /* disable bogus unused pins */
4608 { 0x17, 0x411111f0 },
4609 { 0x19, 0x411111f0 },
4610 { 0x1b, 0x411111f0 },
4611 { 0x1f, 0x411111f0 },
4612 { }
4613 }
4614 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004615 [ALC880_FIXUP_Z71V] = {
4616 .type = ALC_FIXUP_PINS,
4617 .v.pins = (const struct alc_pincfg[]) {
4618 /* set up the whole pins as BIOS is utterly broken */
4619 { 0x14, 0x99030120 }, /* speaker */
4620 { 0x15, 0x0121411f }, /* HP */
4621 { 0x16, 0x411111f0 }, /* N/A */
4622 { 0x17, 0x411111f0 }, /* N/A */
4623 { 0x18, 0x01a19950 }, /* mic-in */
4624 { 0x19, 0x411111f0 }, /* N/A */
4625 { 0x1a, 0x01813031 }, /* line-in */
4626 { 0x1b, 0x411111f0 }, /* N/A */
4627 { 0x1c, 0x411111f0 }, /* N/A */
4628 { 0x1d, 0x411111f0 }, /* N/A */
4629 { 0x1e, 0x0144111e }, /* SPDIF */
4630 { }
4631 }
4632 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004633 [ALC880_FIXUP_3ST_BASE] = {
4634 .type = ALC_FIXUP_PINS,
4635 .v.pins = (const struct alc_pincfg[]) {
4636 { 0x14, 0x01014010 }, /* line-out */
4637 { 0x15, 0x411111f0 }, /* N/A */
4638 { 0x16, 0x411111f0 }, /* N/A */
4639 { 0x17, 0x411111f0 }, /* N/A */
4640 { 0x18, 0x01a19c30 }, /* mic-in */
4641 { 0x19, 0x0121411f }, /* HP */
4642 { 0x1a, 0x01813031 }, /* line-in */
4643 { 0x1b, 0x02a19c40 }, /* front-mic */
4644 { 0x1c, 0x411111f0 }, /* N/A */
4645 { 0x1d, 0x411111f0 }, /* N/A */
4646 /* 0x1e is filled in below */
4647 { 0x1f, 0x411111f0 }, /* N/A */
4648 { }
4649 }
4650 },
4651 [ALC880_FIXUP_3ST] = {
4652 .type = ALC_FIXUP_PINS,
4653 .v.pins = (const struct alc_pincfg[]) {
4654 { 0x1e, 0x411111f0 }, /* N/A */
4655 { }
4656 },
4657 .chained = true,
4658 .chain_id = ALC880_FIXUP_3ST_BASE,
4659 },
4660 [ALC880_FIXUP_3ST_DIG] = {
4661 .type = ALC_FIXUP_PINS,
4662 .v.pins = (const struct alc_pincfg[]) {
4663 { 0x1e, 0x0144111e }, /* SPDIF */
4664 { }
4665 },
4666 .chained = true,
4667 .chain_id = ALC880_FIXUP_3ST_BASE,
4668 },
4669 [ALC880_FIXUP_5ST_BASE] = {
4670 .type = ALC_FIXUP_PINS,
4671 .v.pins = (const struct alc_pincfg[]) {
4672 { 0x14, 0x01014010 }, /* front */
4673 { 0x15, 0x411111f0 }, /* N/A */
4674 { 0x16, 0x01011411 }, /* CLFE */
4675 { 0x17, 0x01016412 }, /* surr */
4676 { 0x18, 0x01a19c30 }, /* mic-in */
4677 { 0x19, 0x0121411f }, /* HP */
4678 { 0x1a, 0x01813031 }, /* line-in */
4679 { 0x1b, 0x02a19c40 }, /* front-mic */
4680 { 0x1c, 0x411111f0 }, /* N/A */
4681 { 0x1d, 0x411111f0 }, /* N/A */
4682 /* 0x1e is filled in below */
4683 { 0x1f, 0x411111f0 }, /* N/A */
4684 { }
4685 }
4686 },
4687 [ALC880_FIXUP_5ST] = {
4688 .type = ALC_FIXUP_PINS,
4689 .v.pins = (const struct alc_pincfg[]) {
4690 { 0x1e, 0x411111f0 }, /* N/A */
4691 { }
4692 },
4693 .chained = true,
4694 .chain_id = ALC880_FIXUP_5ST_BASE,
4695 },
4696 [ALC880_FIXUP_5ST_DIG] = {
4697 .type = ALC_FIXUP_PINS,
4698 .v.pins = (const struct alc_pincfg[]) {
4699 { 0x1e, 0x0144111e }, /* SPDIF */
4700 { }
4701 },
4702 .chained = true,
4703 .chain_id = ALC880_FIXUP_5ST_BASE,
4704 },
4705 [ALC880_FIXUP_6ST_BASE] = {
4706 .type = ALC_FIXUP_PINS,
4707 .v.pins = (const struct alc_pincfg[]) {
4708 { 0x14, 0x01014010 }, /* front */
4709 { 0x15, 0x01016412 }, /* surr */
4710 { 0x16, 0x01011411 }, /* CLFE */
4711 { 0x17, 0x01012414 }, /* side */
4712 { 0x18, 0x01a19c30 }, /* mic-in */
4713 { 0x19, 0x02a19c40 }, /* front-mic */
4714 { 0x1a, 0x01813031 }, /* line-in */
4715 { 0x1b, 0x0121411f }, /* HP */
4716 { 0x1c, 0x411111f0 }, /* N/A */
4717 { 0x1d, 0x411111f0 }, /* N/A */
4718 /* 0x1e is filled in below */
4719 { 0x1f, 0x411111f0 }, /* N/A */
4720 { }
4721 }
4722 },
4723 [ALC880_FIXUP_6ST] = {
4724 .type = ALC_FIXUP_PINS,
4725 .v.pins = (const struct alc_pincfg[]) {
4726 { 0x1e, 0x411111f0 }, /* N/A */
4727 { }
4728 },
4729 .chained = true,
4730 .chain_id = ALC880_FIXUP_6ST_BASE,
4731 },
4732 [ALC880_FIXUP_6ST_DIG] = {
4733 .type = ALC_FIXUP_PINS,
4734 .v.pins = (const struct alc_pincfg[]) {
4735 { 0x1e, 0x0144111e }, /* SPDIF */
4736 { }
4737 },
4738 .chained = true,
4739 .chain_id = ALC880_FIXUP_6ST_BASE,
4740 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004741};
4742
4743static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004744 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004745 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004746 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4747 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004748 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004749 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004750 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004751 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004752 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004753 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004754 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004755 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004756 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004757 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004758 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004759 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4760 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4761 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004762 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004763
4764 /* Below is the copied entries from alc880_quirks.c.
4765 * It's not quite sure whether BIOS sets the correct pin-config table
4766 * on these machines, thus they are kept to be compatible with
4767 * the old static quirks. Once when it's confirmed to work without
4768 * these overrides, it'd be better to remove.
4769 */
4770 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4771 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4772 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4773 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4774 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4775 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4776 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4777 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4778 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4779 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4780 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4781 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4782 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4783 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4784 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4785 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4786 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4787 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4788 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4789 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4790 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4791 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4792 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4793 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4794 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4795 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4796 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4797 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4798 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4799 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4800 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4801 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4802 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4803 /* default Intel */
4804 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4805 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4806 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4807 {}
4808};
4809
4810static const struct alc_model_fixup alc880_fixup_models[] = {
4811 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4812 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4813 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4814 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4815 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4816 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004817 {}
4818};
4819
4820
4821/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004822 * OK, here we have finally the patch for ALC880
4823 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004824static int patch_alc880(struct hda_codec *codec)
4825{
4826 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004827 int err;
4828
4829 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4830 if (spec == NULL)
4831 return -ENOMEM;
4832
4833 codec->spec = spec;
4834
4835 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004836 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004837
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004838 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4839 alc880_fixups);
4840 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004841
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004842 /* automatic parse from the BIOS config */
4843 err = alc880_parse_auto_config(codec);
4844 if (err < 0)
4845 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004846
Takashi Iwai60a6a842011-07-27 14:01:24 +02004847 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004848 alc_auto_fill_adc_caps(codec);
4849 alc_rebuild_imux_for_auto_mic(codec);
4850 alc_remove_invalid_adc_nids(codec);
4851 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004852
4853 if (!spec->no_analog && !spec->cap_mixer)
4854 set_capture_mixer(codec);
4855
4856 if (!spec->no_analog) {
4857 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004858 if (err < 0)
4859 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004860 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4861 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004862
Takashi Iwai1d045db2011-07-07 18:23:21 +02004863 codec->patch_ops = alc_patch_ops;
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004864 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004865
Takashi Iwai589876e2012-02-20 15:47:55 +01004866 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4867
Takashi Iwai1d045db2011-07-07 18:23:21 +02004868 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004869
4870 error:
4871 alc_free(codec);
4872 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004873}
4874
4875
4876/*
4877 * ALC260 support
4878 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004879static int alc260_parse_auto_config(struct hda_codec *codec)
4880{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004882 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4883 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004884}
4885
Takashi Iwai1d045db2011-07-07 18:23:21 +02004886/*
4887 * Pin config fixes
4888 */
4889enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004890 ALC260_FIXUP_HP_DC5750,
4891 ALC260_FIXUP_HP_PIN_0F,
4892 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004893 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004894 ALC260_FIXUP_GPIO1_TOGGLE,
4895 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004896 ALC260_FIXUP_HP_B1900,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004897};
4898
Takashi Iwai20f7d922012-02-16 12:35:16 +01004899static void alc260_gpio1_automute(struct hda_codec *codec)
4900{
4901 struct alc_spec *spec = codec->spec;
4902 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4903 spec->hp_jack_present);
4904}
4905
4906static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4907 const struct alc_fixup *fix, int action)
4908{
4909 struct alc_spec *spec = codec->spec;
4910 if (action == ALC_FIXUP_ACT_PROBE) {
4911 /* although the machine has only one output pin, we need to
4912 * toggle GPIO1 according to the jack state
4913 */
4914 spec->automute_hook = alc260_gpio1_automute;
4915 spec->detect_hp = 1;
4916 spec->automute_speaker = 1;
4917 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4918 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4919 spec->unsol_event = alc_sku_unsol_event;
4920 add_verb(codec->spec, alc_gpio1_init_verbs);
4921 }
4922}
4923
Takashi Iwai1d045db2011-07-07 18:23:21 +02004924static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004925 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004926 .type = ALC_FIXUP_PINS,
4927 .v.pins = (const struct alc_pincfg[]) {
4928 { 0x11, 0x90130110 }, /* speaker */
4929 { }
4930 }
4931 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004932 [ALC260_FIXUP_HP_PIN_0F] = {
4933 .type = ALC_FIXUP_PINS,
4934 .v.pins = (const struct alc_pincfg[]) {
4935 { 0x0f, 0x01214000 }, /* HP */
4936 { }
4937 }
4938 },
4939 [ALC260_FIXUP_COEF] = {
4940 .type = ALC_FIXUP_VERBS,
4941 .v.verbs = (const struct hda_verb[]) {
4942 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4943 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4944 { }
4945 },
4946 .chained = true,
4947 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4948 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004949 [ALC260_FIXUP_GPIO1] = {
4950 .type = ALC_FIXUP_VERBS,
4951 .v.verbs = alc_gpio1_init_verbs,
4952 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004953 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4954 .type = ALC_FIXUP_FUNC,
4955 .v.func = alc260_fixup_gpio1_toggle,
4956 .chained = true,
4957 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4958 },
4959 [ALC260_FIXUP_REPLACER] = {
4960 .type = ALC_FIXUP_VERBS,
4961 .v.verbs = (const struct hda_verb[]) {
4962 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4963 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4964 { }
4965 },
4966 .chained = true,
4967 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4968 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004969 [ALC260_FIXUP_HP_B1900] = {
4970 .type = ALC_FIXUP_FUNC,
4971 .v.func = alc260_fixup_gpio1_toggle,
4972 .chained = true,
4973 .chain_id = ALC260_FIXUP_COEF,
4974 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004975};
4976
4977static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004978 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004979 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004980 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004981 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004982 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004983 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004984 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004985 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004986 {}
4987};
4988
4989/*
4990 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004991static int patch_alc260(struct hda_codec *codec)
4992{
4993 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004994 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995
4996 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4997 if (spec == NULL)
4998 return -ENOMEM;
4999
5000 codec->spec = spec;
5001
5002 spec->mixer_nid = 0x07;
5003
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005004 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5005 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005006
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005007 /* automatic parse from the BIOS config */
5008 err = alc260_parse_auto_config(codec);
5009 if (err < 0)
5010 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005011
Takashi Iwai60a6a842011-07-27 14:01:24 +02005012 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005013 alc_auto_fill_adc_caps(codec);
5014 alc_rebuild_imux_for_auto_mic(codec);
5015 alc_remove_invalid_adc_nids(codec);
5016 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005017
5018 if (!spec->no_analog && !spec->cap_mixer)
5019 set_capture_mixer(codec);
5020
5021 if (!spec->no_analog) {
5022 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005023 if (err < 0)
5024 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005025 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5026 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005027
Takashi Iwai1d045db2011-07-07 18:23:21 +02005028 codec->patch_ops = alc_patch_ops;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005029 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005030 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005031
Takashi Iwai589876e2012-02-20 15:47:55 +01005032 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5033
Takashi Iwai1d045db2011-07-07 18:23:21 +02005034 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005035
5036 error:
5037 alc_free(codec);
5038 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005039}
5040
5041
5042/*
5043 * ALC882/883/885/888/889 support
5044 *
5045 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5046 * configuration. Each pin widget can choose any input DACs and a mixer.
5047 * Each ADC is connected from a mixer of all inputs. This makes possible
5048 * 6-channel independent captures.
5049 *
5050 * In addition, an independent DAC for the multi-playback (not used in this
5051 * driver yet).
5052 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005053
5054/*
5055 * Pin config fixes
5056 */
5057enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005058 ALC882_FIXUP_ABIT_AW9D_MAX,
5059 ALC882_FIXUP_LENOVO_Y530,
5060 ALC882_FIXUP_PB_M5210,
5061 ALC882_FIXUP_ACER_ASPIRE_7736,
5062 ALC882_FIXUP_ASUS_W90V,
5063 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005064 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005065 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005066 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005067 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005068 ALC882_FIXUP_GPIO1,
5069 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005070 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005071 ALC889_FIXUP_COEF,
5072 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005073 ALC882_FIXUP_ACER_ASPIRE_4930G,
5074 ALC882_FIXUP_ACER_ASPIRE_8930G,
5075 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005076 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005077 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005078 ALC889_FIXUP_MBP_VREF,
5079 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005080};
5081
Takashi Iwai68ef0562011-11-09 18:24:44 +01005082static void alc889_fixup_coef(struct hda_codec *codec,
5083 const struct alc_fixup *fix, int action)
5084{
5085 if (action != ALC_FIXUP_ACT_INIT)
5086 return;
5087 alc889_coef_init(codec);
5088}
5089
Takashi Iwai56710872011-11-14 17:42:11 +01005090/* toggle speaker-output according to the hp-jack state */
5091static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5092{
5093 unsigned int gpiostate, gpiomask, gpiodir;
5094
5095 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5096 AC_VERB_GET_GPIO_DATA, 0);
5097
5098 if (!muted)
5099 gpiostate |= (1 << pin);
5100 else
5101 gpiostate &= ~(1 << pin);
5102
5103 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5104 AC_VERB_GET_GPIO_MASK, 0);
5105 gpiomask |= (1 << pin);
5106
5107 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5108 AC_VERB_GET_GPIO_DIRECTION, 0);
5109 gpiodir |= (1 << pin);
5110
5111
5112 snd_hda_codec_write(codec, codec->afg, 0,
5113 AC_VERB_SET_GPIO_MASK, gpiomask);
5114 snd_hda_codec_write(codec, codec->afg, 0,
5115 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5116
5117 msleep(1);
5118
5119 snd_hda_codec_write(codec, codec->afg, 0,
5120 AC_VERB_SET_GPIO_DATA, gpiostate);
5121}
5122
5123/* set up GPIO at initialization */
5124static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5125 const struct alc_fixup *fix, int action)
5126{
5127 if (action != ALC_FIXUP_ACT_INIT)
5128 return;
5129 alc882_gpio_mute(codec, 0, 0);
5130 alc882_gpio_mute(codec, 1, 0);
5131}
5132
Takashi Iwai02a237b2012-02-13 15:25:07 +01005133/* Fix the connection of some pins for ALC889:
5134 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5135 * work correctly (bko#42740)
5136 */
5137static void alc889_fixup_dac_route(struct hda_codec *codec,
5138 const struct alc_fixup *fix, int action)
5139{
5140 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5141 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5142 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5143 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5144 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5145 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5146 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5147 }
5148}
5149
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005150/* Set VREF on HP pin */
5151static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5152 const struct alc_fixup *fix, int action)
5153{
5154 struct alc_spec *spec = codec->spec;
5155 static hda_nid_t nids[2] = { 0x14, 0x15 };
5156 int i;
5157
5158 if (action != ALC_FIXUP_ACT_INIT)
5159 return;
5160 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5161 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5162 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5163 continue;
5164 val = snd_hda_codec_read(codec, nids[i], 0,
5165 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5166 val |= AC_PINCTL_VREF_80;
5167 snd_hda_codec_write(codec, nids[i], 0,
5168 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5169 spec->keep_vref_in_automute = 1;
5170 break;
5171 }
5172}
5173
5174/* Set VREF on speaker pins on imac91 */
5175static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5176 const struct alc_fixup *fix, int action)
5177{
5178 struct alc_spec *spec = codec->spec;
5179 static hda_nid_t nids[2] = { 0x18, 0x1a };
5180 int i;
5181
5182 if (action != ALC_FIXUP_ACT_INIT)
5183 return;
5184 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5185 unsigned int val;
5186 val = snd_hda_codec_read(codec, nids[i], 0,
5187 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5188 val |= AC_PINCTL_VREF_50;
5189 snd_hda_codec_write(codec, nids[i], 0,
5190 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5191 }
5192 spec->keep_vref_in_automute = 1;
5193}
5194
Takashi Iwai1d045db2011-07-07 18:23:21 +02005195static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005196 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005197 .type = ALC_FIXUP_PINS,
5198 .v.pins = (const struct alc_pincfg[]) {
5199 { 0x15, 0x01080104 }, /* side */
5200 { 0x16, 0x01011012 }, /* rear */
5201 { 0x17, 0x01016011 }, /* clfe */
5202 { }
5203 }
5204 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005205 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005206 .type = ALC_FIXUP_PINS,
5207 .v.pins = (const struct alc_pincfg[]) {
5208 { 0x15, 0x99130112 }, /* rear int speakers */
5209 { 0x16, 0x99130111 }, /* subwoofer */
5210 { }
5211 }
5212 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005213 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005214 .type = ALC_FIXUP_VERBS,
5215 .v.verbs = (const struct hda_verb[]) {
5216 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5217 {}
5218 }
5219 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005220 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005221 .type = ALC_FIXUP_SKU,
5222 .v.sku = ALC_FIXUP_SKU_IGNORE,
5223 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005224 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005225 .type = ALC_FIXUP_PINS,
5226 .v.pins = (const struct alc_pincfg[]) {
5227 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5228 { }
5229 }
5230 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005231 [ALC889_FIXUP_VAIO_TT] = {
5232 .type = ALC_FIXUP_PINS,
5233 .v.pins = (const struct alc_pincfg[]) {
5234 { 0x17, 0x90170111 }, /* hidden surround speaker */
5235 { }
5236 }
5237 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005238 [ALC888_FIXUP_EEE1601] = {
5239 .type = ALC_FIXUP_VERBS,
5240 .v.verbs = (const struct hda_verb[]) {
5241 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5242 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5243 { }
5244 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005245 },
5246 [ALC882_FIXUP_EAPD] = {
5247 .type = ALC_FIXUP_VERBS,
5248 .v.verbs = (const struct hda_verb[]) {
5249 /* change to EAPD mode */
5250 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5251 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5252 { }
5253 }
5254 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005255 [ALC883_FIXUP_EAPD] = {
5256 .type = ALC_FIXUP_VERBS,
5257 .v.verbs = (const struct hda_verb[]) {
5258 /* change to EAPD mode */
5259 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5260 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5261 { }
5262 }
5263 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005264 [ALC883_FIXUP_ACER_EAPD] = {
5265 .type = ALC_FIXUP_VERBS,
5266 .v.verbs = (const struct hda_verb[]) {
5267 /* eanable EAPD on Acer laptops */
5268 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5269 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5270 { }
5271 }
5272 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005273 [ALC882_FIXUP_GPIO1] = {
5274 .type = ALC_FIXUP_VERBS,
5275 .v.verbs = alc_gpio1_init_verbs,
5276 },
5277 [ALC882_FIXUP_GPIO2] = {
5278 .type = ALC_FIXUP_VERBS,
5279 .v.verbs = alc_gpio2_init_verbs,
5280 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005281 [ALC882_FIXUP_GPIO3] = {
5282 .type = ALC_FIXUP_VERBS,
5283 .v.verbs = alc_gpio3_init_verbs,
5284 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005285 [ALC882_FIXUP_ASUS_W2JC] = {
5286 .type = ALC_FIXUP_VERBS,
5287 .v.verbs = alc_gpio1_init_verbs,
5288 .chained = true,
5289 .chain_id = ALC882_FIXUP_EAPD,
5290 },
5291 [ALC889_FIXUP_COEF] = {
5292 .type = ALC_FIXUP_FUNC,
5293 .v.func = alc889_fixup_coef,
5294 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005295 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5296 .type = ALC_FIXUP_PINS,
5297 .v.pins = (const struct alc_pincfg[]) {
5298 { 0x16, 0x99130111 }, /* CLFE speaker */
5299 { 0x17, 0x99130112 }, /* surround speaker */
5300 { }
5301 }
5302 },
5303 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5304 .type = ALC_FIXUP_PINS,
5305 .v.pins = (const struct alc_pincfg[]) {
5306 { 0x16, 0x99130111 }, /* CLFE speaker */
5307 { 0x1b, 0x99130112 }, /* surround speaker */
5308 { }
5309 },
5310 .chained = true,
5311 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5312 },
5313 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5314 /* additional init verbs for Acer Aspire 8930G */
5315 .type = ALC_FIXUP_VERBS,
5316 .v.verbs = (const struct hda_verb[]) {
5317 /* Enable all DACs */
5318 /* DAC DISABLE/MUTE 1? */
5319 /* setting bits 1-5 disables DAC nids 0x02-0x06
5320 * apparently. Init=0x38 */
5321 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5322 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5323 /* DAC DISABLE/MUTE 2? */
5324 /* some bit here disables the other DACs.
5325 * Init=0x4900 */
5326 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5327 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5328 /* DMIC fix
5329 * This laptop has a stereo digital microphone.
5330 * The mics are only 1cm apart which makes the stereo
5331 * useless. However, either the mic or the ALC889
5332 * makes the signal become a difference/sum signal
5333 * instead of standard stereo, which is annoying.
5334 * So instead we flip this bit which makes the
5335 * codec replicate the sum signal to both channels,
5336 * turning it into a normal mono mic.
5337 */
5338 /* DMIC_CONTROL? Init value = 0x0001 */
5339 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5340 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5341 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5342 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5343 { }
5344 }
5345 },
Takashi Iwai56710872011-11-14 17:42:11 +01005346 [ALC885_FIXUP_MACPRO_GPIO] = {
5347 .type = ALC_FIXUP_FUNC,
5348 .v.func = alc885_fixup_macpro_gpio,
5349 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005350 [ALC889_FIXUP_DAC_ROUTE] = {
5351 .type = ALC_FIXUP_FUNC,
5352 .v.func = alc889_fixup_dac_route,
5353 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005354 [ALC889_FIXUP_MBP_VREF] = {
5355 .type = ALC_FIXUP_FUNC,
5356 .v.func = alc889_fixup_mbp_vref,
5357 .chained = true,
5358 .chain_id = ALC882_FIXUP_GPIO1,
5359 },
5360 [ALC889_FIXUP_IMAC91_VREF] = {
5361 .type = ALC_FIXUP_FUNC,
5362 .v.func = alc889_fixup_imac91_vref,
5363 .chained = true,
5364 .chain_id = ALC882_FIXUP_GPIO1,
5365 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005366};
5367
5368static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005369 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5370 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5371 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5372 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5373 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5374 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005375 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5376 ALC882_FIXUP_ACER_ASPIRE_4930G),
5377 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5378 ALC882_FIXUP_ACER_ASPIRE_4930G),
5379 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5380 ALC882_FIXUP_ACER_ASPIRE_8930G),
5381 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5382 ALC882_FIXUP_ACER_ASPIRE_8930G),
5383 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5384 ALC882_FIXUP_ACER_ASPIRE_4930G),
5385 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5386 ALC882_FIXUP_ACER_ASPIRE_4930G),
5387 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5388 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005389 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005390 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005391 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005392 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005393 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005394 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005395 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005396 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005397
5398 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005399 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5400 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5401 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005402 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5403 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5404 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005405 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5406 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005407 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005408 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5409 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5410 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5411 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005412 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005413 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5414 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5415 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5416 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5417 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5418 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005419
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005420 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005421 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005422 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005423 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5424 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005425 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005426 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005427 {}
5428};
5429
5430/*
5431 * BIOS auto configuration
5432 */
5433/* almost identical with ALC880 parser... */
5434static int alc882_parse_auto_config(struct hda_codec *codec)
5435{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005436 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005437 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5438 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005439}
5440
Takashi Iwai1d045db2011-07-07 18:23:21 +02005441/*
5442 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005443static int patch_alc882(struct hda_codec *codec)
5444{
5445 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005446 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005447
5448 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5449 if (spec == NULL)
5450 return -ENOMEM;
5451
5452 codec->spec = spec;
5453
5454 spec->mixer_nid = 0x0b;
5455
5456 switch (codec->vendor_id) {
5457 case 0x10ec0882:
5458 case 0x10ec0885:
5459 break;
5460 default:
5461 /* ALC883 and variants */
5462 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5463 break;
5464 }
5465
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005466 err = alc_codec_rename_from_preset(codec);
5467 if (err < 0)
5468 goto error;
5469
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005470 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
5471 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005472
5473 alc_auto_parse_customize_define(codec);
5474
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005475 /* automatic parse from the BIOS config */
5476 err = alc882_parse_auto_config(codec);
5477 if (err < 0)
5478 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005479
Takashi Iwai60a6a842011-07-27 14:01:24 +02005480 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481 alc_auto_fill_adc_caps(codec);
5482 alc_rebuild_imux_for_auto_mic(codec);
5483 alc_remove_invalid_adc_nids(codec);
5484 }
5485
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005486 if (!spec->no_analog && !spec->cap_mixer)
5487 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005488
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005489 if (!spec->no_analog && has_cdefine_beep(codec)) {
5490 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005491 if (err < 0)
5492 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005493 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005494 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005495
Takashi Iwai1d045db2011-07-07 18:23:21 +02005496 codec->patch_ops = alc_patch_ops;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005497 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005498
Takashi Iwai589876e2012-02-20 15:47:55 +01005499 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5500
Takashi Iwai1d045db2011-07-07 18:23:21 +02005501 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005502
5503 error:
5504 alc_free(codec);
5505 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005506}
5507
5508
5509/*
5510 * ALC262 support
5511 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512static int alc262_parse_auto_config(struct hda_codec *codec)
5513{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005514 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005515 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5516 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005517}
5518
5519/*
5520 * Pin config fixes
5521 */
5522enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005523 ALC262_FIXUP_FSC_H270,
5524 ALC262_FIXUP_HP_Z200,
5525 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005526 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005527 ALC262_FIXUP_BENQ,
5528 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005529};
5530
5531static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005532 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005533 .type = ALC_FIXUP_PINS,
5534 .v.pins = (const struct alc_pincfg[]) {
5535 { 0x14, 0x99130110 }, /* speaker */
5536 { 0x15, 0x0221142f }, /* front HP */
5537 { 0x1b, 0x0121141f }, /* rear HP */
5538 { }
5539 }
5540 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005541 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005542 .type = ALC_FIXUP_PINS,
5543 .v.pins = (const struct alc_pincfg[]) {
5544 { 0x16, 0x99130120 }, /* internal speaker */
5545 { }
5546 }
5547 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005548 [ALC262_FIXUP_TYAN] = {
5549 .type = ALC_FIXUP_PINS,
5550 .v.pins = (const struct alc_pincfg[]) {
5551 { 0x14, 0x1993e1f0 }, /* int AUX */
5552 { }
5553 }
5554 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005555 [ALC262_FIXUP_LENOVO_3000] = {
5556 .type = ALC_FIXUP_VERBS,
5557 .v.verbs = (const struct hda_verb[]) {
5558 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005559 {}
5560 },
5561 .chained = true,
5562 .chain_id = ALC262_FIXUP_BENQ,
5563 },
5564 [ALC262_FIXUP_BENQ] = {
5565 .type = ALC_FIXUP_VERBS,
5566 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005567 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5568 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5569 {}
5570 }
5571 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005572 [ALC262_FIXUP_BENQ_T31] = {
5573 .type = ALC_FIXUP_VERBS,
5574 .v.verbs = (const struct hda_verb[]) {
5575 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5576 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5577 {}
5578 }
5579 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005580};
5581
5582static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005583 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005584 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5585 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005586 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5587 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005588 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005589 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5590 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005591 {}
5592};
5593
5594
Takashi Iwai1d045db2011-07-07 18:23:21 +02005595/*
5596 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005597static int patch_alc262(struct hda_codec *codec)
5598{
5599 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005600 int err;
5601
5602 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5603 if (spec == NULL)
5604 return -ENOMEM;
5605
5606 codec->spec = spec;
5607
5608 spec->mixer_nid = 0x0b;
5609
5610#if 0
5611 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5612 * under-run
5613 */
5614 {
5615 int tmp;
5616 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5617 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5618 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5619 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5620 }
5621#endif
5622 alc_auto_parse_customize_define(codec);
5623
5624 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5625
Takashi Iwai42399f72011-11-07 17:18:44 +01005626 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5627 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005628
Takashi Iwai42399f72011-11-07 17:18:44 +01005629 /* automatic parse from the BIOS config */
5630 err = alc262_parse_auto_config(codec);
5631 if (err < 0)
5632 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005633
Takashi Iwai60a6a842011-07-27 14:01:24 +02005634 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005635 alc_auto_fill_adc_caps(codec);
5636 alc_rebuild_imux_for_auto_mic(codec);
5637 alc_remove_invalid_adc_nids(codec);
5638 }
5639
5640 if (!spec->no_analog && !spec->cap_mixer)
5641 set_capture_mixer(codec);
5642
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643 if (!spec->no_analog && has_cdefine_beep(codec)) {
5644 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005645 if (err < 0)
5646 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005647 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005648 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649
Takashi Iwai1d045db2011-07-07 18:23:21 +02005650 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01005651 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652 spec->shutup = alc_eapd_shutup;
5653
Takashi Iwai589876e2012-02-20 15:47:55 +01005654 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5655
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005657
5658 error:
5659 alc_free(codec);
5660 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661}
5662
5663/*
5664 * ALC268
5665 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005666/* bind Beep switches of both NID 0x0f and 0x10 */
5667static const struct hda_bind_ctls alc268_bind_beep_sw = {
5668 .ops = &snd_hda_bind_sw,
5669 .values = {
5670 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5671 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5672 0
5673 },
5674};
5675
5676static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5677 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5678 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5679 { }
5680};
5681
5682/* set PCBEEP vol = 0, mute connections */
5683static const struct hda_verb alc268_beep_init_verbs[] = {
5684 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5685 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5686 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5687 { }
5688};
5689
5690/*
5691 * BIOS auto configuration
5692 */
5693static int alc268_parse_auto_config(struct hda_codec *codec)
5694{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005695 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005696 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005697 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5698 if (err > 0) {
5699 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5700 add_mixer(spec, alc268_beep_mixer);
5701 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005702 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005703 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005704 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005705}
5706
Takashi Iwai1d045db2011-07-07 18:23:21 +02005707/*
5708 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005709static int patch_alc268(struct hda_codec *codec)
5710{
5711 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712 int i, has_beep, err;
5713
5714 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5715 if (spec == NULL)
5716 return -ENOMEM;
5717
5718 codec->spec = spec;
5719
5720 /* ALC268 has no aa-loopback mixer */
5721
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005722 /* automatic parse from the BIOS config */
5723 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005724 if (err < 0)
5725 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005726
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727 has_beep = 0;
5728 for (i = 0; i < spec->num_mixers; i++) {
5729 if (spec->mixers[i] == alc268_beep_mixer) {
5730 has_beep = 1;
5731 break;
5732 }
5733 }
5734
5735 if (has_beep) {
5736 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005737 if (err < 0)
5738 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005739 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5740 /* override the amp caps for beep generator */
5741 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5742 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5743 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5744 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5745 (0 << AC_AMPCAP_MUTE_SHIFT));
5746 }
5747
Takashi Iwai60a6a842011-07-27 14:01:24 +02005748 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005749 alc_auto_fill_adc_caps(codec);
5750 alc_rebuild_imux_for_auto_mic(codec);
5751 alc_remove_invalid_adc_nids(codec);
5752 }
5753
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005754 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005755 set_capture_mixer(codec);
5756
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005758 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005759 spec->shutup = alc_eapd_shutup;
5760
Takashi Iwai1d045db2011-07-07 18:23:21 +02005761 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005762
5763 error:
5764 alc_free(codec);
5765 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005766}
5767
5768/*
5769 * ALC269
5770 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005771static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5772 .substreams = 1,
5773 .channels_min = 2,
5774 .channels_max = 8,
5775 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5776 /* NID is set in alc_build_pcms */
5777 .ops = {
5778 .open = alc_playback_pcm_open,
5779 .prepare = alc_playback_pcm_prepare,
5780 .cleanup = alc_playback_pcm_cleanup
5781 },
5782};
5783
5784static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5785 .substreams = 1,
5786 .channels_min = 2,
5787 .channels_max = 2,
5788 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5789 /* NID is set in alc_build_pcms */
5790};
5791
5792#ifdef CONFIG_SND_HDA_POWER_SAVE
5793static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5794{
5795 switch (codec->subsystem_id) {
5796 case 0x103c1586:
5797 return 1;
5798 }
5799 return 0;
5800}
5801
5802static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5803{
5804 /* update mute-LED according to the speaker mute state */
5805 if (nid == 0x01 || nid == 0x14) {
5806 int pinval;
5807 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5808 HDA_AMP_MUTE)
5809 pinval = 0x24;
5810 else
5811 pinval = 0x20;
5812 /* mic2 vref pin is used for mute LED control */
5813 snd_hda_codec_update_cache(codec, 0x19, 0,
5814 AC_VERB_SET_PIN_WIDGET_CONTROL,
5815 pinval);
5816 }
5817 return alc_check_power_status(codec, nid);
5818}
5819#endif /* CONFIG_SND_HDA_POWER_SAVE */
5820
5821/* different alc269-variants */
5822enum {
5823 ALC269_TYPE_ALC269VA,
5824 ALC269_TYPE_ALC269VB,
5825 ALC269_TYPE_ALC269VC,
5826};
5827
5828/*
5829 * BIOS auto configuration
5830 */
5831static int alc269_parse_auto_config(struct hda_codec *codec)
5832{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005833 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005834 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5835 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5836 struct alc_spec *spec = codec->spec;
5837 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5838 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005839
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005840 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005841}
5842
Takashi Iwai1d045db2011-07-07 18:23:21 +02005843static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5844{
5845 int val = alc_read_coef_idx(codec, 0x04);
5846 if (power_up)
5847 val |= 1 << 11;
5848 else
5849 val &= ~(1 << 11);
5850 alc_write_coef_idx(codec, 0x04, val);
5851}
5852
5853static void alc269_shutup(struct hda_codec *codec)
5854{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005855 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005856 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005857 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005858 alc269_toggle_power_output(codec, 0);
5859 msleep(150);
5860 }
5861}
5862
Takashi Iwai2a439522011-07-26 09:52:50 +02005863#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005864static int alc269_resume(struct hda_codec *codec)
5865{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005866 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005867 alc269_toggle_power_output(codec, 0);
5868 msleep(150);
5869 }
5870
5871 codec->patch_ops.init(codec);
5872
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005873 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005874 alc269_toggle_power_output(codec, 1);
5875 msleep(200);
5876 }
5877
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005878 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005879 alc269_toggle_power_output(codec, 1);
5880
5881 snd_hda_codec_resume_amp(codec);
5882 snd_hda_codec_resume_cache(codec);
5883 hda_call_check_power_status(codec, 0x01);
5884 return 0;
5885}
Takashi Iwai2a439522011-07-26 09:52:50 +02005886#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005887
5888static void alc269_fixup_hweq(struct hda_codec *codec,
5889 const struct alc_fixup *fix, int action)
5890{
5891 int coef;
5892
5893 if (action != ALC_FIXUP_ACT_INIT)
5894 return;
5895 coef = alc_read_coef_idx(codec, 0x1e);
5896 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5897}
5898
5899static void alc271_fixup_dmic(struct hda_codec *codec,
5900 const struct alc_fixup *fix, int action)
5901{
5902 static const struct hda_verb verbs[] = {
5903 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5904 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5905 {}
5906 };
5907 unsigned int cfg;
5908
5909 if (strcmp(codec->chip_name, "ALC271X"))
5910 return;
5911 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5912 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5913 snd_hda_sequence_write(codec, verbs);
5914}
5915
Takashi Iwai017f2a12011-07-09 14:42:25 +02005916static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5917 const struct alc_fixup *fix, int action)
5918{
5919 struct alc_spec *spec = codec->spec;
5920
5921 if (action != ALC_FIXUP_ACT_PROBE)
5922 return;
5923
5924 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5925 * fix the sample rate of analog I/O to 44.1kHz
5926 */
5927 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5928 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5929}
5930
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005931static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5932 const struct alc_fixup *fix, int action)
5933{
5934 int coef;
5935
5936 if (action != ALC_FIXUP_ACT_INIT)
5937 return;
5938 /* The digital-mic unit sends PDM (differential signal) instead of
5939 * the standard PCM, thus you can't record a valid mono stream as is.
5940 * Below is a workaround specific to ALC269 to control the dmic
5941 * signal source as mono.
5942 */
5943 coef = alc_read_coef_idx(codec, 0x07);
5944 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5945}
5946
Takashi Iwai24519912011-08-16 15:08:49 +02005947static void alc269_quanta_automute(struct hda_codec *codec)
5948{
David Henningsson42cf0d02011-09-20 12:04:56 +02005949 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005950
5951 snd_hda_codec_write(codec, 0x20, 0,
5952 AC_VERB_SET_COEF_INDEX, 0x0c);
5953 snd_hda_codec_write(codec, 0x20, 0,
5954 AC_VERB_SET_PROC_COEF, 0x680);
5955
5956 snd_hda_codec_write(codec, 0x20, 0,
5957 AC_VERB_SET_COEF_INDEX, 0x0c);
5958 snd_hda_codec_write(codec, 0x20, 0,
5959 AC_VERB_SET_PROC_COEF, 0x480);
5960}
5961
5962static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5963 const struct alc_fixup *fix, int action)
5964{
5965 struct alc_spec *spec = codec->spec;
5966 if (action != ALC_FIXUP_ACT_PROBE)
5967 return;
5968 spec->automute_hook = alc269_quanta_automute;
5969}
5970
Takashi Iwai1d045db2011-07-07 18:23:21 +02005971enum {
5972 ALC269_FIXUP_SONY_VAIO,
5973 ALC275_FIXUP_SONY_VAIO_GPIO2,
5974 ALC269_FIXUP_DELL_M101Z,
5975 ALC269_FIXUP_SKU_IGNORE,
5976 ALC269_FIXUP_ASUS_G73JW,
5977 ALC269_FIXUP_LENOVO_EAPD,
5978 ALC275_FIXUP_SONY_HWEQ,
5979 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005980 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005981 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005982 ALC269_FIXUP_QUANTA_MUTE,
5983 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005984 ALC269_FIXUP_AMIC,
5985 ALC269_FIXUP_DMIC,
5986 ALC269VB_FIXUP_AMIC,
5987 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005988};
5989
5990static const struct alc_fixup alc269_fixups[] = {
5991 [ALC269_FIXUP_SONY_VAIO] = {
5992 .type = ALC_FIXUP_VERBS,
5993 .v.verbs = (const struct hda_verb[]) {
5994 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5995 {}
5996 }
5997 },
5998 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5999 .type = ALC_FIXUP_VERBS,
6000 .v.verbs = (const struct hda_verb[]) {
6001 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6002 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6003 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6004 { }
6005 },
6006 .chained = true,
6007 .chain_id = ALC269_FIXUP_SONY_VAIO
6008 },
6009 [ALC269_FIXUP_DELL_M101Z] = {
6010 .type = ALC_FIXUP_VERBS,
6011 .v.verbs = (const struct hda_verb[]) {
6012 /* Enables internal speaker */
6013 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6014 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6015 {}
6016 }
6017 },
6018 [ALC269_FIXUP_SKU_IGNORE] = {
6019 .type = ALC_FIXUP_SKU,
6020 .v.sku = ALC_FIXUP_SKU_IGNORE,
6021 },
6022 [ALC269_FIXUP_ASUS_G73JW] = {
6023 .type = ALC_FIXUP_PINS,
6024 .v.pins = (const struct alc_pincfg[]) {
6025 { 0x17, 0x99130111 }, /* subwoofer */
6026 { }
6027 }
6028 },
6029 [ALC269_FIXUP_LENOVO_EAPD] = {
6030 .type = ALC_FIXUP_VERBS,
6031 .v.verbs = (const struct hda_verb[]) {
6032 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6033 {}
6034 }
6035 },
6036 [ALC275_FIXUP_SONY_HWEQ] = {
6037 .type = ALC_FIXUP_FUNC,
6038 .v.func = alc269_fixup_hweq,
6039 .chained = true,
6040 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6041 },
6042 [ALC271_FIXUP_DMIC] = {
6043 .type = ALC_FIXUP_FUNC,
6044 .v.func = alc271_fixup_dmic,
6045 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006046 [ALC269_FIXUP_PCM_44K] = {
6047 .type = ALC_FIXUP_FUNC,
6048 .v.func = alc269_fixup_pcm_44k,
6049 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006050 [ALC269_FIXUP_STEREO_DMIC] = {
6051 .type = ALC_FIXUP_FUNC,
6052 .v.func = alc269_fixup_stereo_dmic,
6053 },
Takashi Iwai24519912011-08-16 15:08:49 +02006054 [ALC269_FIXUP_QUANTA_MUTE] = {
6055 .type = ALC_FIXUP_FUNC,
6056 .v.func = alc269_fixup_quanta_mute,
6057 },
6058 [ALC269_FIXUP_LIFEBOOK] = {
6059 .type = ALC_FIXUP_PINS,
6060 .v.pins = (const struct alc_pincfg[]) {
6061 { 0x1a, 0x2101103f }, /* dock line-out */
6062 { 0x1b, 0x23a11040 }, /* dock mic-in */
6063 { }
6064 },
6065 .chained = true,
6066 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6067 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006068 [ALC269_FIXUP_AMIC] = {
6069 .type = ALC_FIXUP_PINS,
6070 .v.pins = (const struct alc_pincfg[]) {
6071 { 0x14, 0x99130110 }, /* speaker */
6072 { 0x15, 0x0121401f }, /* HP out */
6073 { 0x18, 0x01a19c20 }, /* mic */
6074 { 0x19, 0x99a3092f }, /* int-mic */
6075 { }
6076 },
6077 },
6078 [ALC269_FIXUP_DMIC] = {
6079 .type = ALC_FIXUP_PINS,
6080 .v.pins = (const struct alc_pincfg[]) {
6081 { 0x12, 0x99a3092f }, /* int-mic */
6082 { 0x14, 0x99130110 }, /* speaker */
6083 { 0x15, 0x0121401f }, /* HP out */
6084 { 0x18, 0x01a19c20 }, /* mic */
6085 { }
6086 },
6087 },
6088 [ALC269VB_FIXUP_AMIC] = {
6089 .type = ALC_FIXUP_PINS,
6090 .v.pins = (const struct alc_pincfg[]) {
6091 { 0x14, 0x99130110 }, /* speaker */
6092 { 0x18, 0x01a19c20 }, /* mic */
6093 { 0x19, 0x99a3092f }, /* int-mic */
6094 { 0x21, 0x0121401f }, /* HP out */
6095 { }
6096 },
6097 },
David Henningsson2267ea92012-01-03 08:45:56 +01006098 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006099 .type = ALC_FIXUP_PINS,
6100 .v.pins = (const struct alc_pincfg[]) {
6101 { 0x12, 0x99a3092f }, /* int-mic */
6102 { 0x14, 0x99130110 }, /* speaker */
6103 { 0x18, 0x01a19c20 }, /* mic */
6104 { 0x21, 0x0121401f }, /* HP out */
6105 { }
6106 },
6107 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006108};
6109
6110static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02006111 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006112 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6113 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6114 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6115 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6116 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006117 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6118 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6119 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6120 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6121 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6122 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006123 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006124 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6125 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6126 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6127 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6128 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006129 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006130 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006131 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006132
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006133#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006134 /* Below is a quirk table taken from the old code.
6135 * Basically the device should work as is without the fixup table.
6136 * If BIOS doesn't give a proper info, enable the corresponding
6137 * fixup entry.
6138 */
6139 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6140 ALC269_FIXUP_AMIC),
6141 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006142 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6143 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6144 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6145 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6146 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6147 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6148 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6149 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6150 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6151 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6152 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6153 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6154 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6155 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6156 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6157 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6158 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6159 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6160 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6161 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6162 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6163 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6164 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6165 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6166 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6167 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6168 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6169 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6170 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6171 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6172 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6173 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6174 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6175 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6176 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6177 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6178 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6179 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6180#endif
6181 {}
6182};
6183
6184static const struct alc_model_fixup alc269_fixup_models[] = {
6185 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6186 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006187 {}
6188};
6189
6190
6191static int alc269_fill_coef(struct hda_codec *codec)
6192{
6193 int val;
6194
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006195 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006196 alc_write_coef_idx(codec, 0xf, 0x960b);
6197 alc_write_coef_idx(codec, 0xe, 0x8817);
6198 }
6199
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006200 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006201 alc_write_coef_idx(codec, 0xf, 0x960b);
6202 alc_write_coef_idx(codec, 0xe, 0x8814);
6203 }
6204
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006205 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006206 val = alc_read_coef_idx(codec, 0x04);
6207 /* Power up output pin */
6208 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6209 }
6210
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006211 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006212 val = alc_read_coef_idx(codec, 0xd);
6213 if ((val & 0x0c00) >> 10 != 0x1) {
6214 /* Capless ramp up clock control */
6215 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6216 }
6217 val = alc_read_coef_idx(codec, 0x17);
6218 if ((val & 0x01c0) >> 6 != 0x4) {
6219 /* Class D power on reset */
6220 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6221 }
6222 }
6223
6224 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6225 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6226
6227 val = alc_read_coef_idx(codec, 0x4); /* HP */
6228 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6229
6230 return 0;
6231}
6232
6233/*
6234 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006235static int patch_alc269(struct hda_codec *codec)
6236{
6237 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006238 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006239
6240 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6241 if (spec == NULL)
6242 return -ENOMEM;
6243
6244 codec->spec = spec;
6245
6246 spec->mixer_nid = 0x0b;
6247
6248 alc_auto_parse_customize_define(codec);
6249
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006250 err = alc_codec_rename_from_preset(codec);
6251 if (err < 0)
6252 goto error;
6253
Takashi Iwai1d045db2011-07-07 18:23:21 +02006254 if (codec->vendor_id == 0x10ec0269) {
6255 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006256 switch (alc_get_coef0(codec) & 0x00f0) {
6257 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006258 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006259 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006260 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006261 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006262 break;
6263 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006264 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6265 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006266 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006267 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006268 break;
6269 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006270 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006271 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006272 if (err < 0)
6273 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006274 alc269_fill_coef(codec);
6275 }
6276
Takashi Iwaia4297b52011-08-23 18:40:12 +02006277 alc_pick_fixup(codec, alc269_fixup_models,
6278 alc269_fixup_tbl, alc269_fixups);
6279 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006280
Takashi Iwaia4297b52011-08-23 18:40:12 +02006281 /* automatic parse from the BIOS config */
6282 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006283 if (err < 0)
6284 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006285
Takashi Iwai60a6a842011-07-27 14:01:24 +02006286 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006287 alc_auto_fill_adc_caps(codec);
6288 alc_rebuild_imux_for_auto_mic(codec);
6289 alc_remove_invalid_adc_nids(codec);
6290 }
6291
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006292 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006293 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006294
6295 if (!spec->no_analog && has_cdefine_beep(codec)) {
6296 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006297 if (err < 0)
6298 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006300 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006301
Takashi Iwai1d045db2011-07-07 18:23:21 +02006302 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006303#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006304 codec->patch_ops.resume = alc269_resume;
6305#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02006306 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006307 spec->shutup = alc269_shutup;
6308
Takashi Iwai1d045db2011-07-07 18:23:21 +02006309#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai1d045db2011-07-07 18:23:21 +02006310 if (alc269_mic2_for_mute_led(codec))
6311 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
6312#endif
6313
Takashi Iwai589876e2012-02-20 15:47:55 +01006314 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6315
Takashi Iwai1d045db2011-07-07 18:23:21 +02006316 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006317
6318 error:
6319 alc_free(codec);
6320 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006321}
6322
6323/*
6324 * ALC861
6325 */
6326
Takashi Iwai1d045db2011-07-07 18:23:21 +02006327static int alc861_parse_auto_config(struct hda_codec *codec)
6328{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006329 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006330 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6331 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006332}
6333
Takashi Iwai1d045db2011-07-07 18:23:21 +02006334/* Pin config fixes */
6335enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006336 ALC861_FIXUP_FSC_AMILO_PI1505,
6337 ALC861_FIXUP_AMP_VREF_0F,
6338 ALC861_FIXUP_NO_JACK_DETECT,
6339 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006340};
6341
Takashi Iwai31150f22012-01-30 10:54:08 +01006342/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6343static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6344 const struct alc_fixup *fix, int action)
6345{
6346 struct alc_spec *spec = codec->spec;
6347 unsigned int val;
6348
6349 if (action != ALC_FIXUP_ACT_INIT)
6350 return;
6351 val = snd_hda_codec_read(codec, 0x0f, 0,
6352 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6353 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6354 val |= AC_PINCTL_IN_EN;
6355 val |= AC_PINCTL_VREF_50;
6356 snd_hda_codec_write(codec, 0x0f, 0,
6357 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6358 spec->keep_vref_in_automute = 1;
6359}
6360
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006361/* suppress the jack-detection */
6362static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6363 const struct alc_fixup *fix, int action)
6364{
6365 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6366 codec->no_jack_detect = 1;
6367}
6368
Takashi Iwai1d045db2011-07-07 18:23:21 +02006369static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006370 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006371 .type = ALC_FIXUP_PINS,
6372 .v.pins = (const struct alc_pincfg[]) {
6373 { 0x0b, 0x0221101f }, /* HP */
6374 { 0x0f, 0x90170310 }, /* speaker */
6375 { }
6376 }
6377 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006378 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006379 .type = ALC_FIXUP_FUNC,
6380 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006381 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006382 [ALC861_FIXUP_NO_JACK_DETECT] = {
6383 .type = ALC_FIXUP_FUNC,
6384 .v.func = alc_fixup_no_jack_detect,
6385 },
6386 [ALC861_FIXUP_ASUS_A6RP] = {
6387 .type = ALC_FIXUP_FUNC,
6388 .v.func = alc861_fixup_asus_amp_vref_0f,
6389 .chained = true,
6390 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6391 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006392};
6393
6394static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006395 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6396 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6397 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6398 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6399 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6400 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006401 {}
6402};
6403
6404/*
6405 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006406static int patch_alc861(struct hda_codec *codec)
6407{
6408 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006409 int err;
6410
6411 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6412 if (spec == NULL)
6413 return -ENOMEM;
6414
6415 codec->spec = spec;
6416
6417 spec->mixer_nid = 0x15;
6418
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006419 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6420 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006421
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006422 /* automatic parse from the BIOS config */
6423 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006424 if (err < 0)
6425 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006426
Takashi Iwai60a6a842011-07-27 14:01:24 +02006427 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006428 alc_auto_fill_adc_caps(codec);
6429 alc_rebuild_imux_for_auto_mic(codec);
6430 alc_remove_invalid_adc_nids(codec);
6431 }
6432
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006433 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006434 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006435
6436 if (!spec->no_analog) {
6437 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006438 if (err < 0)
6439 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006440 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6441 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006442
Takashi Iwai1d045db2011-07-07 18:23:21 +02006443 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006444 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006445#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006446 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006447#endif
6448
Takashi Iwai589876e2012-02-20 15:47:55 +01006449 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6450
Takashi Iwai1d045db2011-07-07 18:23:21 +02006451 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006452
6453 error:
6454 alc_free(codec);
6455 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006456}
6457
6458/*
6459 * ALC861-VD support
6460 *
6461 * Based on ALC882
6462 *
6463 * In addition, an independent DAC
6464 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006465static int alc861vd_parse_auto_config(struct hda_codec *codec)
6466{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006467 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006468 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6469 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006470}
6471
Takashi Iwai1d045db2011-07-07 18:23:21 +02006472enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006473 ALC660VD_FIX_ASUS_GPIO1,
6474 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006475};
6476
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006477/* exclude VREF80 */
6478static void alc861vd_fixup_dallas(struct hda_codec *codec,
6479 const struct alc_fixup *fix, int action)
6480{
6481 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6482 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6483 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6484 }
6485}
6486
Takashi Iwai1d045db2011-07-07 18:23:21 +02006487static const struct alc_fixup alc861vd_fixups[] = {
6488 [ALC660VD_FIX_ASUS_GPIO1] = {
6489 .type = ALC_FIXUP_VERBS,
6490 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006491 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006492 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6493 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6494 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6495 { }
6496 }
6497 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006498 [ALC861VD_FIX_DALLAS] = {
6499 .type = ALC_FIXUP_FUNC,
6500 .v.func = alc861vd_fixup_dallas,
6501 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006502};
6503
6504static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006505 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006506 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006507 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006508 {}
6509};
6510
6511static const struct hda_verb alc660vd_eapd_verbs[] = {
6512 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6513 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6514 { }
6515};
6516
6517/*
6518 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006519static int patch_alc861vd(struct hda_codec *codec)
6520{
6521 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006522 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006523
6524 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6525 if (spec == NULL)
6526 return -ENOMEM;
6527
6528 codec->spec = spec;
6529
6530 spec->mixer_nid = 0x0b;
6531
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006532 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6533 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006534
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006535 /* automatic parse from the BIOS config */
6536 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006537 if (err < 0)
6538 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006539
Takashi Iwai1d045db2011-07-07 18:23:21 +02006540 if (codec->vendor_id == 0x10ec0660) {
6541 /* always turn on EAPD */
6542 add_verb(spec, alc660vd_eapd_verbs);
6543 }
6544
Takashi Iwai60a6a842011-07-27 14:01:24 +02006545 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006546 alc_auto_fill_adc_caps(codec);
6547 alc_rebuild_imux_for_auto_mic(codec);
6548 alc_remove_invalid_adc_nids(codec);
6549 }
6550
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006551 if (!spec->no_analog && !spec->cap_mixer)
6552 set_capture_mixer(codec);
6553
6554 if (!spec->no_analog) {
6555 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006556 if (err < 0)
6557 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006558 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6559 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006560
Takashi Iwai1d045db2011-07-07 18:23:21 +02006561 codec->patch_ops = alc_patch_ops;
6562
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006563 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006564 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006565
Takashi Iwai589876e2012-02-20 15:47:55 +01006566 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6567
Takashi Iwai1d045db2011-07-07 18:23:21 +02006568 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006569
6570 error:
6571 alc_free(codec);
6572 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006573}
6574
6575/*
6576 * ALC662 support
6577 *
6578 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6579 * configuration. Each pin widget can choose any input DACs and a mixer.
6580 * Each ADC is connected from a mixer of all inputs. This makes possible
6581 * 6-channel independent captures.
6582 *
6583 * In addition, an independent DAC for the multi-playback (not used in this
6584 * driver yet).
6585 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006586
6587/*
6588 * BIOS auto configuration
6589 */
6590
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006591static int alc662_parse_auto_config(struct hda_codec *codec)
6592{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006593 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006594 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6595 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6596 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006597
Kailang Yang6227cdc2010-02-25 08:36:52 +01006598 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6599 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006600 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006601 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006602 ssids = alc662_ssids;
6603 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006604}
6605
Todd Broch6be79482010-12-07 16:51:05 -08006606static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006607 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006608{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006609 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006610 return;
Todd Broch6be79482010-12-07 16:51:05 -08006611 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6612 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6613 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6614 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6615 (0 << AC_AMPCAP_MUTE_SHIFT)))
6616 printk(KERN_WARNING
6617 "hda_codec: failed to override amp caps for NID 0x2\n");
6618}
6619
David Henningsson6cb3b702010-09-09 08:51:44 +02006620enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006621 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006622 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006623 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006624 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006625 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006626 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006627 ALC662_FIXUP_ASUS_MODE1,
6628 ALC662_FIXUP_ASUS_MODE2,
6629 ALC662_FIXUP_ASUS_MODE3,
6630 ALC662_FIXUP_ASUS_MODE4,
6631 ALC662_FIXUP_ASUS_MODE5,
6632 ALC662_FIXUP_ASUS_MODE6,
6633 ALC662_FIXUP_ASUS_MODE7,
6634 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006635 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006636};
6637
6638static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006639 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006640 .type = ALC_FIXUP_PINS,
6641 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006642 { 0x15, 0x99130112 }, /* subwoofer */
6643 { }
6644 }
6645 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006646 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006647 .type = ALC_FIXUP_PINS,
6648 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006649 { 0x17, 0x99130112 }, /* subwoofer */
6650 { }
6651 }
6652 },
Todd Broch6be79482010-12-07 16:51:05 -08006653 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006654 .type = ALC_FIXUP_FUNC,
6655 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006656 },
6657 [ALC662_FIXUP_CZC_P10T] = {
6658 .type = ALC_FIXUP_VERBS,
6659 .v.verbs = (const struct hda_verb[]) {
6660 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6661 {}
6662 }
6663 },
David Henningsson94024cd2011-04-29 14:10:55 +02006664 [ALC662_FIXUP_SKU_IGNORE] = {
6665 .type = ALC_FIXUP_SKU,
6666 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006667 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006668 [ALC662_FIXUP_HP_RP5800] = {
6669 .type = ALC_FIXUP_PINS,
6670 .v.pins = (const struct alc_pincfg[]) {
6671 { 0x14, 0x0221201f }, /* HP out */
6672 { }
6673 },
6674 .chained = true,
6675 .chain_id = ALC662_FIXUP_SKU_IGNORE
6676 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006677 [ALC662_FIXUP_ASUS_MODE1] = {
6678 .type = ALC_FIXUP_PINS,
6679 .v.pins = (const struct alc_pincfg[]) {
6680 { 0x14, 0x99130110 }, /* speaker */
6681 { 0x18, 0x01a19c20 }, /* mic */
6682 { 0x19, 0x99a3092f }, /* int-mic */
6683 { 0x21, 0x0121401f }, /* HP out */
6684 { }
6685 },
6686 .chained = true,
6687 .chain_id = ALC662_FIXUP_SKU_IGNORE
6688 },
6689 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006690 .type = ALC_FIXUP_PINS,
6691 .v.pins = (const struct alc_pincfg[]) {
6692 { 0x14, 0x99130110 }, /* speaker */
6693 { 0x18, 0x01a19820 }, /* mic */
6694 { 0x19, 0x99a3092f }, /* int-mic */
6695 { 0x1b, 0x0121401f }, /* HP out */
6696 { }
6697 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006698 .chained = true,
6699 .chain_id = ALC662_FIXUP_SKU_IGNORE
6700 },
6701 [ALC662_FIXUP_ASUS_MODE3] = {
6702 .type = ALC_FIXUP_PINS,
6703 .v.pins = (const struct alc_pincfg[]) {
6704 { 0x14, 0x99130110 }, /* speaker */
6705 { 0x15, 0x0121441f }, /* HP */
6706 { 0x18, 0x01a19840 }, /* mic */
6707 { 0x19, 0x99a3094f }, /* int-mic */
6708 { 0x21, 0x01211420 }, /* HP2 */
6709 { }
6710 },
6711 .chained = true,
6712 .chain_id = ALC662_FIXUP_SKU_IGNORE
6713 },
6714 [ALC662_FIXUP_ASUS_MODE4] = {
6715 .type = ALC_FIXUP_PINS,
6716 .v.pins = (const struct alc_pincfg[]) {
6717 { 0x14, 0x99130110 }, /* speaker */
6718 { 0x16, 0x99130111 }, /* speaker */
6719 { 0x18, 0x01a19840 }, /* mic */
6720 { 0x19, 0x99a3094f }, /* int-mic */
6721 { 0x21, 0x0121441f }, /* HP */
6722 { }
6723 },
6724 .chained = true,
6725 .chain_id = ALC662_FIXUP_SKU_IGNORE
6726 },
6727 [ALC662_FIXUP_ASUS_MODE5] = {
6728 .type = ALC_FIXUP_PINS,
6729 .v.pins = (const struct alc_pincfg[]) {
6730 { 0x14, 0x99130110 }, /* speaker */
6731 { 0x15, 0x0121441f }, /* HP */
6732 { 0x16, 0x99130111 }, /* speaker */
6733 { 0x18, 0x01a19840 }, /* mic */
6734 { 0x19, 0x99a3094f }, /* int-mic */
6735 { }
6736 },
6737 .chained = true,
6738 .chain_id = ALC662_FIXUP_SKU_IGNORE
6739 },
6740 [ALC662_FIXUP_ASUS_MODE6] = {
6741 .type = ALC_FIXUP_PINS,
6742 .v.pins = (const struct alc_pincfg[]) {
6743 { 0x14, 0x99130110 }, /* speaker */
6744 { 0x15, 0x01211420 }, /* HP2 */
6745 { 0x18, 0x01a19840 }, /* mic */
6746 { 0x19, 0x99a3094f }, /* int-mic */
6747 { 0x1b, 0x0121441f }, /* HP */
6748 { }
6749 },
6750 .chained = true,
6751 .chain_id = ALC662_FIXUP_SKU_IGNORE
6752 },
6753 [ALC662_FIXUP_ASUS_MODE7] = {
6754 .type = ALC_FIXUP_PINS,
6755 .v.pins = (const struct alc_pincfg[]) {
6756 { 0x14, 0x99130110 }, /* speaker */
6757 { 0x17, 0x99130111 }, /* speaker */
6758 { 0x18, 0x01a19840 }, /* mic */
6759 { 0x19, 0x99a3094f }, /* int-mic */
6760 { 0x1b, 0x01214020 }, /* HP */
6761 { 0x21, 0x0121401f }, /* HP */
6762 { }
6763 },
6764 .chained = true,
6765 .chain_id = ALC662_FIXUP_SKU_IGNORE
6766 },
6767 [ALC662_FIXUP_ASUS_MODE8] = {
6768 .type = ALC_FIXUP_PINS,
6769 .v.pins = (const struct alc_pincfg[]) {
6770 { 0x14, 0x99130110 }, /* speaker */
6771 { 0x12, 0x99a30970 }, /* int-mic */
6772 { 0x15, 0x01214020 }, /* HP */
6773 { 0x17, 0x99130111 }, /* speaker */
6774 { 0x18, 0x01a19840 }, /* mic */
6775 { 0x21, 0x0121401f }, /* HP */
6776 { }
6777 },
6778 .chained = true,
6779 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006780 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006781 [ALC662_FIXUP_NO_JACK_DETECT] = {
6782 .type = ALC_FIXUP_FUNC,
6783 .v.func = alc_fixup_no_jack_detect,
6784 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006785};
6786
Takashi Iwaia9111322011-05-02 11:30:18 +02006787static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006788 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006789 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006790 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006791 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006792 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006793 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006794 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006795 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006796 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006797 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006798 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006799
6800#if 0
6801 /* Below is a quirk table taken from the old code.
6802 * Basically the device should work as is without the fixup table.
6803 * If BIOS doesn't give a proper info, enable the corresponding
6804 * fixup entry.
6805 */
6806 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6807 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6808 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6809 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6810 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6811 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6812 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6813 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6814 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6815 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6816 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6817 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6818 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6819 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6820 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6821 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6822 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6823 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6824 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6825 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6826 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6827 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6828 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6829 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6830 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6831 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6832 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6833 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6834 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6835 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6836 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6837 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6838 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6839 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6840 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6841 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6842 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6843 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6844 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6845 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6846 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6847 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6848 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6849 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6850 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6851 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6852 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6853 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6854 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6855 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6856#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006857 {}
6858};
6859
Todd Broch6be79482010-12-07 16:51:05 -08006860static const struct alc_model_fixup alc662_fixup_models[] = {
6861 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006862 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6863 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6864 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6865 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6866 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6867 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6868 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6869 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006870 {}
6871};
David Henningsson6cb3b702010-09-09 08:51:44 +02006872
6873
Takashi Iwai1d045db2011-07-07 18:23:21 +02006874/*
6875 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006876static int patch_alc662(struct hda_codec *codec)
6877{
6878 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006879 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006880
6881 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6882 if (!spec)
6883 return -ENOMEM;
6884
6885 codec->spec = spec;
6886
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006887 spec->mixer_nid = 0x0b;
6888
Takashi Iwai53c334a2011-08-23 18:27:14 +02006889 /* handle multiple HPs as is */
6890 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6891
Kailang Yangda00c242010-03-19 11:23:45 +01006892 alc_auto_parse_customize_define(codec);
6893
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006894 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6895
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006896 err = alc_codec_rename_from_preset(codec);
6897 if (err < 0)
6898 goto error;
6899
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006900 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006901 codec->bus->pci->subsystem_vendor == 0x1025 &&
6902 spec->cdefine.platform_type == 1) {
6903 if (alc_codec_rename(codec, "ALC272X") < 0)
6904 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006905 }
Kailang Yang274693f2009-12-03 10:07:50 +01006906
Takashi Iwaib9c51062011-08-24 18:08:07 +02006907 alc_pick_fixup(codec, alc662_fixup_models,
6908 alc662_fixup_tbl, alc662_fixups);
6909 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6910 /* automatic parse from the BIOS config */
6911 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006912 if (err < 0)
6913 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006914
Takashi Iwai60a6a842011-07-27 14:01:24 +02006915 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006916 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006917 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006918 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006919 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006920
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006921 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006922 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006923
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006924 if (!spec->no_analog && has_cdefine_beep(codec)) {
6925 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006926 if (err < 0)
6927 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006928 switch (codec->vendor_id) {
6929 case 0x10ec0662:
6930 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6931 break;
6932 case 0x10ec0272:
6933 case 0x10ec0663:
6934 case 0x10ec0665:
6935 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6936 break;
6937 case 0x10ec0273:
6938 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6939 break;
6940 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006941 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006942
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006943 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006944 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006945 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006946
Takashi Iwai589876e2012-02-20 15:47:55 +01006947 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6948
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006949 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006950
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006951 error:
6952 alc_free(codec);
6953 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006954}
6955
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006956/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006957 * ALC680 support
6958 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006959
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006960static int alc680_parse_auto_config(struct hda_codec *codec)
6961{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006962 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006963}
6964
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006965/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006966 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006967static int patch_alc680(struct hda_codec *codec)
6968{
6969 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006970 int err;
6971
6972 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6973 if (spec == NULL)
6974 return -ENOMEM;
6975
6976 codec->spec = spec;
6977
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006978 /* ALC680 has no aa-loopback mixer */
6979
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006980 /* automatic parse from the BIOS config */
6981 err = alc680_parse_auto_config(codec);
6982 if (err < 0) {
6983 alc_free(codec);
6984 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006985 }
6986
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006987 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006988 set_capture_mixer(codec);
6989
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006990 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006991 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006992
6993 return 0;
6994}
6995
6996/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006997 * patch entries
6998 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006999static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02007000 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007001 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007002 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007003 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02007004 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007005 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007006 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007007 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007008 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007009 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007010 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007011 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007012 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7013 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7014 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007015 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02007016 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007017 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7018 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007019 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7020 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007021 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007022 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007023 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007024 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007025 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007026 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02007027 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007028 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02007029 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007030 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02007031 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007032 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007033 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007034 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02007035 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007036 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02007037 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007038 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007039 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007040 {} /* terminator */
7041};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007042
7043MODULE_ALIAS("snd-hda-codec-id:10ec*");
7044
7045MODULE_LICENSE("GPL");
7046MODULE_DESCRIPTION("Realtek HD-audio codec");
7047
7048static struct hda_codec_preset_list realtek_list = {
7049 .preset = snd_hda_preset_realtek,
7050 .owner = THIS_MODULE,
7051};
7052
7053static int __init patch_realtek_init(void)
7054{
7055 return snd_hda_add_codec_preset(&realtek_list);
7056}
7057
7058static void __exit patch_realtek_exit(void)
7059{
7060 snd_hda_delete_codec_preset(&realtek_list);
7061}
7062
7063module_init(patch_realtek_init)
7064module_exit(patch_realtek_exit)