blob: ae9732ce86705f3bf7e4a552726477784413520a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e482006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Takashi Iwaic14c95f2012-02-16 16:38:07 +010083#define MAX_VOL_NIDS 0x40
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085struct alc_spec {
86 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020089 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010090 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Takashi Iwai2d9c6482009-10-13 08:06:55 +020092 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020093 * don't forget NULL
94 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020095 */
96 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Takashi Iwaiaa563af2009-07-31 10:05:11 +020098 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020099 const struct hda_pcm_stream *stream_analog_playback;
100 const struct hda_pcm_stream *stream_analog_capture;
101 const struct hda_pcm_stream *stream_analog_alt_playback;
102 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200104 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200105 const struct hda_pcm_stream *stream_digital_playback;
106 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200109 struct hda_multi_out multiout; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
112 */
Takashi Iwai63300792008-01-24 15:31:36 +0100113 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100114 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100115 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 /* capture */
118 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200119 const hda_nid_t *adc_nids;
120 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200121 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200122 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwaic14c95f2012-02-16 16:38:07 +0100123 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
124 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Takashi Iwai840b64c2010-07-13 22:49:01 +0200126 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200127 hda_nid_t cur_adc;
128 unsigned int cur_adc_stream_tag;
129 unsigned int cur_adc_format;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200132 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 const struct hda_input_mux *input_mux;
134 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200135 hda_nid_t ext_mic_pin;
136 hda_nid_t dock_mic_pin;
137 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100140 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200142 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200143 int const_channel_count;
144 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100147 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200148
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100151 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200152 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200153 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200154 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200155 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
156 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200157 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
158 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
159 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100160
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100161 /* hooks */
162 void (*init_hook)(struct hda_codec *codec);
163 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500165 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100166#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200167 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200168 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100169
Takashi Iwai834be882006-03-01 14:16:17 +0100170 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200171 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200172 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200173 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200174 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200175 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200176 unsigned int automute_speaker:1; /* automute speaker outputs */
177 unsigned int automute_lo:1; /* automute LO outputs */
178 unsigned int detect_hp:1; /* Headphone detection enabled */
179 unsigned int detect_lo:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100182 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200183
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100184 /* other flags */
185 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200186 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100187 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200188 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200189 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100190 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200191
192 /* auto-mute control */
193 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200194 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200195
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200196 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200197 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100198
Takashi Iwai2134ea42008-01-10 16:53:55 +0100199 /* for virtual master */
200 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100201 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200202#ifdef CONFIG_SND_HDA_POWER_SAVE
203 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100204 int num_loopbacks;
205 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200206#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200207
208 /* for PLL fix */
209 hda_nid_t pll_nid;
210 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200211 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100212
213 /* fix-up list */
214 int fixup_id;
215 const struct alc_fixup *fixup_list;
216 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200217
218 /* multi-io */
219 int multi_ios;
220 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200221
222 /* bind volumes */
223 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100224};
225
Takashi Iwai44c02402011-07-08 15:14:19 +0200226static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
227 int dir, unsigned int bits)
228{
229 if (!nid)
230 return false;
231 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
232 if (query_amp_caps(codec, nid, dir) & bits)
233 return true;
234 return false;
235}
236
237#define nid_has_mute(codec, nid, dir) \
238 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
239#define nid_has_volume(codec, nid, dir) \
240 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242/*
243 * input MUX handling
244 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200245static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200250 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
251 if (mux_idx >= spec->num_mux_defs)
252 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100253 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
254 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200255 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256}
257
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200258static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
259 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
261 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262 struct alc_spec *spec = codec->spec;
263 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
264
265 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
266 return 0;
267}
268
Takashi Iwai21268962011-07-07 15:01:13 +0200269static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Takashi Iwai21268962011-07-07 15:01:13 +0200271 struct alc_spec *spec = codec->spec;
272 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
273
274 if (spec->cur_adc && spec->cur_adc != new_adc) {
275 /* stream is running, let's swap the current ADC */
276 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
277 spec->cur_adc = new_adc;
278 snd_hda_codec_setup_stream(codec, new_adc,
279 spec->cur_adc_stream_tag, 0,
280 spec->cur_adc_format);
281 return true;
282 }
283 return false;
284}
285
Takashi Iwai61071592011-11-23 07:52:15 +0100286static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
287{
288 return spec->capsrc_nids ?
289 spec->capsrc_nids[idx] : spec->adc_nids[idx];
290}
291
Takashi Iwai24de1832011-11-07 17:13:39 +0100292static void call_update_outputs(struct hda_codec *codec);
293
Takashi Iwai21268962011-07-07 15:01:13 +0200294/* select the given imux item; either unmute exclusively or select the route */
295static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
296 unsigned int idx, bool force)
297{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100299 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100300 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100301 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200302 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Takashi Iwai5803a322012-02-21 11:59:45 +0100304 if (!spec->input_mux)
305 return 0;
306
Takashi Iwaicd896c32008-11-18 12:36:33 +0100307 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
308 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100309 if (!imux->num_items && mux_idx > 0)
310 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100311 if (!imux->num_items)
312 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100313
Takashi Iwai21268962011-07-07 15:01:13 +0200314 if (idx >= imux->num_items)
315 idx = imux->num_items - 1;
316 if (spec->cur_mux[adc_idx] == idx && !force)
317 return 0;
318 spec->cur_mux[adc_idx] = idx;
319
Takashi Iwai24de1832011-11-07 17:13:39 +0100320 /* for shared I/O, change the pin-control accordingly */
321 if (spec->shared_mic_hp) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200322 unsigned int val;
323 hda_nid_t pin = spec->autocfg.inputs[1].pin;
Takashi Iwai24de1832011-11-07 17:13:39 +0100324 /* NOTE: this assumes that there are only two inputs, the
325 * first is the real internal mic and the second is HP jack.
326 */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200327 if (spec->cur_mux[adc_idx])
Takashi Iwai47408602012-04-20 13:06:53 +0200328 val = snd_hda_get_default_vref(codec, pin) | PIN_IN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200329 else
330 val = PIN_HP;
331 snd_hda_set_pin_ctl(codec, pin, val);
Takashi Iwai24de1832011-11-07 17:13:39 +0100332 spec->automute_speaker = !spec->cur_mux[adc_idx];
333 call_update_outputs(codec);
334 }
335
Takashi Iwai21268962011-07-07 15:01:13 +0200336 if (spec->dyn_adc_switch) {
337 alc_dyn_adc_pcm_resetup(codec, idx);
338 adc_idx = spec->dyn_adc_idx[idx];
339 }
340
Takashi Iwai61071592011-11-23 07:52:15 +0100341 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200342
343 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100344 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
345 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200346 return 1;
347
Takashi Iwaia22d5432009-07-27 12:54:26 +0200348 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200349 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100350 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100351 int active = imux->items[idx].index;
352 for (i = 0; i < num_conns; i++) {
353 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
354 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100355 HDA_AMP_MUTE, v);
356 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100357 } else {
358 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200359 snd_hda_codec_write_cache(codec, nid, 0,
360 AC_VERB_SET_CONNECT_SEL,
361 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100362 }
Takashi Iwai21268962011-07-07 15:01:13 +0200363 return 1;
364}
365
366static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
367 struct snd_ctl_elem_value *ucontrol)
368{
369 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
370 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
371 return alc_mux_select(codec, adc_idx,
372 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100373}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100376 * set up the input pin config (depending on the given auto-pin type)
377 */
378static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
379 int auto_pin_type)
380{
381 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200382 if (auto_pin_type == AUTO_PIN_MIC)
383 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200384 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100385}
386
387/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200388 * Append the given mixer and verb elements for the later use
389 * The mixer array is referred in build_controls(), and init_verbs are
390 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100391 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200392static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100393{
394 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
395 return;
396 spec->mixers[spec->num_mixers++] = mix;
397}
398
399static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
400{
401 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
402 return;
403 spec->init_verbs[spec->num_init_verbs++] = verb;
404}
405
406/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200407 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100408 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200409/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200410static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200411 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
412 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
413 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
414 { }
415};
416
Takashi Iwaia9111322011-05-02 11:30:18 +0200417static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200418 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
419 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
420 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
421 { }
422};
423
Takashi Iwaia9111322011-05-02 11:30:18 +0200424static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200425 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
427 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
428 { }
429};
430
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200431/*
432 * Fix hardware PLL issue
433 * On some codecs, the analog PLL gating control must be off while
434 * the default value is 1.
435 */
436static void alc_fix_pll(struct hda_codec *codec)
437{
438 struct alc_spec *spec = codec->spec;
439 unsigned int val;
440
441 if (!spec->pll_nid)
442 return;
443 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
444 spec->pll_coef_idx);
445 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
446 AC_VERB_GET_PROC_COEF, 0);
447 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
448 spec->pll_coef_idx);
449 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
450 val & ~(1 << spec->pll_coef_bit));
451}
452
453static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
454 unsigned int coef_idx, unsigned int coef_bit)
455{
456 struct alc_spec *spec = codec->spec;
457 spec->pll_nid = nid;
458 spec->pll_coef_idx = coef_idx;
459 spec->pll_coef_bit = coef_bit;
460 alc_fix_pll(codec);
461}
462
Takashi Iwai1d045db2011-07-07 18:23:21 +0200463/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200464 * Jack detections for HP auto-mute and mic-switch
465 */
466
467/* check each pin in the given array; returns true if any of them is plugged */
468static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200469{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200470 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200471
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200472 for (i = 0; i < num_pins; i++) {
473 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200474 if (!nid)
475 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200476 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200477 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200478 return present;
479}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200480
Takashi Iwai1d045db2011-07-07 18:23:21 +0200481/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200482static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200483 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200484{
485 struct alc_spec *spec = codec->spec;
486 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200487 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200488 int i;
489
490 for (i = 0; i < num_pins; i++) {
491 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100492 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200493 if (!nid)
494 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200495 switch (spec->automute_mode) {
496 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100497 /* don't reset VREF value in case it's controlling
498 * the amp (see alc861_fixup_asus_amp_vref_0f())
499 */
500 if (spec->keep_vref_in_automute) {
501 val = snd_hda_codec_read(codec, nid, 0,
502 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
503 val &= ~PIN_HP;
504 } else
505 val = 0;
506 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200507 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200508 break;
509 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200510 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200511 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200512 break;
513 case ALC_AUTOMUTE_MIXER:
514 nid = spec->automute_mixer_nid[i];
515 if (!nid)
516 break;
517 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200518 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200519 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200520 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200521 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200522 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200523 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200524}
525
David Henningsson42cf0d02011-09-20 12:04:56 +0200526/* Toggle outputs muting */
527static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200528{
529 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200530 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200531
Takashi Iwaic0a20262011-06-10 15:28:15 +0200532 /* Control HP pins/amps depending on master_mute state;
533 * in general, HP pins/amps control should be enabled in all cases,
534 * but currently set only for master_mute, just to be safe
535 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100536 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
537 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200538 spec->autocfg.hp_pins, spec->master_mute, true);
539
David Henningsson42cf0d02011-09-20 12:04:56 +0200540 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200541 on = 0;
542 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200543 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200544 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200545 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200546 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200547
548 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200549 /* if LO is a copy of either HP or Speaker, don't need to handle it */
550 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
551 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200552 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200553 if (!spec->automute_lo)
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;
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.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200559 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200560}
561
David Henningsson42cf0d02011-09-20 12:04:56 +0200562static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200563{
564 struct alc_spec *spec = codec->spec;
565 if (spec->automute_hook)
566 spec->automute_hook(codec);
567 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200568 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200569}
570
Takashi Iwai1d045db2011-07-07 18:23:21 +0200571/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200572static void alc_hp_automute(struct hda_codec *codec)
573{
574 struct alc_spec *spec = codec->spec;
575
David Henningsson42cf0d02011-09-20 12:04:56 +0200576 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
578 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200579 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200580 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200581 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582}
583
Takashi Iwai1d045db2011-07-07 18:23:21 +0200584/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200585static void alc_line_automute(struct hda_codec *codec)
586{
587 struct alc_spec *spec = codec->spec;
588
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200589 /* check LO jack only when it's different from HP */
590 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
591 return;
592
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200593 spec->line_jack_present =
594 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
595 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200596 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200597 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200598 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200599}
600
Takashi Iwai8d087c72011-06-28 12:45:47 +0200601#define get_connection_index(codec, mux, nid) \
602 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200603
Takashi Iwai1d045db2011-07-07 18:23:21 +0200604/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200605static void alc_mic_automute(struct hda_codec *codec)
606{
607 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200608 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200609
Takashi Iwai21268962011-07-07 15:01:13 +0200610 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200611 return;
612 if (snd_BUG_ON(!spec->adc_nids))
613 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200614 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200615 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200616
Takashi Iwai21268962011-07-07 15:01:13 +0200617 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
618 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
619 else if (spec->dock_mic_idx >= 0 &&
620 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
621 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
622 else
623 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200624}
625
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100626/* handle the specified unsol action (ALC_XXX_EVENT) */
627static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200628{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100629 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200630 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200631 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200632 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200633 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200634 alc_line_automute(codec);
635 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200636 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200637 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200638 break;
639 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200640 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200641}
642
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100643/* update the master volume per volume-knob's unsol event */
644static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
645{
646 unsigned int val;
647 struct snd_kcontrol *kctl;
648 struct snd_ctl_elem_value *uctl;
649
650 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
651 if (!kctl)
652 return;
653 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
654 if (!uctl)
655 return;
656 val = snd_hda_codec_read(codec, nid, 0,
657 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
658 val &= HDA_AMP_VOLMASK;
659 uctl->value.integer.value[0] = val;
660 uctl->value.integer.value[1] = val;
661 kctl->put(kctl, uctl);
662 kfree(uctl);
663}
664
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100665/* unsolicited event for HP jack sensing */
666static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
667{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100668 int action;
669
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100670 if (codec->vendor_id == 0x10ec0880)
671 res >>= 28;
672 else
673 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100674 action = snd_hda_jack_get_action(codec, res);
David Henningssone21af482012-03-05 11:38:46 +0100675 if (action == ALC_DCVOL_EVENT) {
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100676 /* Execute the dc-vol event here as it requires the NID
677 * but we don't pass NID to alc_exec_unsol_event().
678 * Once when we convert all static quirks to the auto-parser,
679 * this can be integerated into there.
680 */
681 struct hda_jack_tbl *jack;
682 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
683 if (jack)
684 alc_update_knob_master(codec, jack->nid);
685 return;
686 }
687 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100688}
689
Takashi Iwai1d045db2011-07-07 18:23:21 +0200690/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200691static void alc_inithook(struct hda_codec *codec)
692{
Takashi Iwaid922b512011-04-28 12:18:53 +0200693 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200694 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200695 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200696}
697
Kailang Yangf9423e72008-05-27 12:32:25 +0200698/* additional initialization for ALC888 variants */
699static void alc888_coef_init(struct hda_codec *codec)
700{
701 unsigned int tmp;
702
703 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
704 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
705 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100706 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200707 /* alc888S-VC */
708 snd_hda_codec_read(codec, 0x20, 0,
709 AC_VERB_SET_PROC_COEF, 0x830);
710 else
711 /* alc888-VB */
712 snd_hda_codec_read(codec, 0x20, 0,
713 AC_VERB_SET_PROC_COEF, 0x3030);
714}
715
Takashi Iwai1d045db2011-07-07 18:23:21 +0200716/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200717static void alc889_coef_init(struct hda_codec *codec)
718{
719 unsigned int tmp;
720
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
722 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
723 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
724 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
725}
726
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100727/* turn on/off EAPD control (only if available) */
728static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
729{
730 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
731 return;
732 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
733 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
734 on ? 2 : 0);
735}
736
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200737/* turn on/off EAPD controls of the codec */
738static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
739{
740 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200741 static hda_nid_t pins[] = {
742 0x0f, 0x10, 0x14, 0x15, 0
743 };
744 hda_nid_t *p;
745 for (p = pins; *p; p++)
746 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200747}
748
Takashi Iwai1c7161532011-04-07 10:37:16 +0200749/* generic shutup callback;
750 * just turning off EPAD and a little pause for avoiding pop-noise
751 */
752static void alc_eapd_shutup(struct hda_codec *codec)
753{
754 alc_auto_setup_eapd(codec, false);
755 msleep(200);
756}
757
Takashi Iwai1d045db2011-07-07 18:23:21 +0200758/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200759static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200760{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200761 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200762
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200763 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200764 switch (type) {
765 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200766 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
767 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200768 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200769 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
770 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200771 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200772 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
773 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200774 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200775 switch (codec->vendor_id) {
776 case 0x10ec0260:
777 snd_hda_codec_write(codec, 0x1a, 0,
778 AC_VERB_SET_COEF_INDEX, 7);
779 tmp = snd_hda_codec_read(codec, 0x1a, 0,
780 AC_VERB_GET_PROC_COEF, 0);
781 snd_hda_codec_write(codec, 0x1a, 0,
782 AC_VERB_SET_COEF_INDEX, 7);
783 snd_hda_codec_write(codec, 0x1a, 0,
784 AC_VERB_SET_PROC_COEF,
785 tmp | 0x2010);
786 break;
787 case 0x10ec0262:
788 case 0x10ec0880:
789 case 0x10ec0882:
790 case 0x10ec0883:
791 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100792 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100793 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200794 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200795 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200796 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200797 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200798 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100799#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200800 case 0x10ec0267:
801 case 0x10ec0268:
802 snd_hda_codec_write(codec, 0x20, 0,
803 AC_VERB_SET_COEF_INDEX, 7);
804 tmp = snd_hda_codec_read(codec, 0x20, 0,
805 AC_VERB_GET_PROC_COEF, 0);
806 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200807 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200808 snd_hda_codec_write(codec, 0x20, 0,
809 AC_VERB_SET_PROC_COEF,
810 tmp | 0x3000);
811 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100812#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200813 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200814 break;
815 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200816}
Kailang Yangea1fb292008-08-26 12:58:38 +0200817
Takashi Iwai1d045db2011-07-07 18:23:21 +0200818/*
819 * Auto-Mute mode mixer enum support
820 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200821static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
822 struct snd_ctl_elem_info *uinfo)
823{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200824 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
825 struct alc_spec *spec = codec->spec;
826 static const char * const texts2[] = {
827 "Disabled", "Enabled"
828 };
829 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100830 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200831 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200832 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200833
834 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
835 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200836 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200837 uinfo->value.enumerated.items = 3;
838 texts = texts3;
839 } else {
840 uinfo->value.enumerated.items = 2;
841 texts = texts2;
842 }
843 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
844 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200845 strcpy(uinfo->value.enumerated.name,
846 texts[uinfo->value.enumerated.item]);
847 return 0;
848}
849
850static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
851 struct snd_ctl_elem_value *ucontrol)
852{
853 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
854 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200855 unsigned int val = 0;
856 if (spec->automute_speaker)
857 val++;
858 if (spec->automute_lo)
859 val++;
860
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200861 ucontrol->value.enumerated.item[0] = val;
862 return 0;
863}
864
865static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
866 struct snd_ctl_elem_value *ucontrol)
867{
868 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
869 struct alc_spec *spec = codec->spec;
870
871 switch (ucontrol->value.enumerated.item[0]) {
872 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200873 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200874 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200875 spec->automute_speaker = 0;
876 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200877 break;
878 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200879 if (spec->automute_speaker_possible) {
880 if (!spec->automute_lo && spec->automute_speaker)
881 return 0;
882 spec->automute_speaker = 1;
883 spec->automute_lo = 0;
884 } else if (spec->automute_lo_possible) {
885 if (spec->automute_lo)
886 return 0;
887 spec->automute_lo = 1;
888 } else
889 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200890 break;
891 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200892 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200893 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200894 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200895 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200896 spec->automute_speaker = 1;
897 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200898 break;
899 default:
900 return -EINVAL;
901 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200902 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200903 return 1;
904}
905
Takashi Iwaia9111322011-05-02 11:30:18 +0200906static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200907 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
908 .name = "Auto-Mute Mode",
909 .info = alc_automute_mode_info,
910 .get = alc_automute_mode_get,
911 .put = alc_automute_mode_put,
912};
913
Takashi Iwai1d045db2011-07-07 18:23:21 +0200914static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
915{
916 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
917 return snd_array_new(&spec->kctls);
918}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200919
920static int alc_add_automute_mode_enum(struct hda_codec *codec)
921{
922 struct alc_spec *spec = codec->spec;
923 struct snd_kcontrol_new *knew;
924
925 knew = alc_kcontrol_new(spec);
926 if (!knew)
927 return -ENOMEM;
928 *knew = alc_automute_mode_enum;
929 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
930 if (!knew->name)
931 return -ENOMEM;
932 return 0;
933}
934
Takashi Iwai1d045db2011-07-07 18:23:21 +0200935/*
936 * Check the availability of HP/line-out auto-mute;
937 * Set up appropriately if really supported
938 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200939static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200940{
941 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200942 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200943 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200944 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200945
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200946 if (cfg->hp_pins[0])
947 present++;
948 if (cfg->line_out_pins[0])
949 present++;
950 if (cfg->speaker_pins[0])
951 present++;
952 if (present < 2) /* need two different output types */
953 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200954
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200955 if (!cfg->speaker_pins[0] &&
956 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200957 memcpy(cfg->speaker_pins, cfg->line_out_pins,
958 sizeof(cfg->speaker_pins));
959 cfg->speaker_outs = cfg->line_outs;
960 }
961
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200962 if (!cfg->hp_pins[0] &&
963 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200964 memcpy(cfg->hp_pins, cfg->line_out_pins,
965 sizeof(cfg->hp_pins));
966 cfg->hp_outs = cfg->line_outs;
967 }
968
David Henningsson42cf0d02011-09-20 12:04:56 +0200969 spec->automute_mode = ALC_AUTOMUTE_PIN;
970
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200971 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200972 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200973 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200974 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200975 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200976 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200977 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200978 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200979 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200980
David Henningsson42cf0d02011-09-20 12:04:56 +0200981 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
982 if (cfg->speaker_outs)
983 for (i = 0; i < cfg->line_outs; i++) {
984 hda_nid_t nid = cfg->line_out_pins[i];
985 if (!is_jack_detectable(codec, nid))
986 continue;
987 snd_printdd("realtek: Enable Line-Out "
988 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200989 snd_hda_jack_detect_enable(codec, nid,
990 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200991 spec->detect_lo = 1;
992 }
993 spec->automute_lo_possible = spec->detect_hp;
994 }
995
996 spec->automute_speaker_possible = cfg->speaker_outs &&
997 (spec->detect_hp || spec->detect_lo);
998
999 spec->automute_lo = spec->automute_lo_possible;
1000 spec->automute_speaker = spec->automute_speaker_possible;
1001
1002 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001003 /* create a control for automute mode */
1004 alc_add_automute_mode_enum(codec);
1005 spec->unsol_event = alc_sku_unsol_event;
1006 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001007}
1008
Takashi Iwai1d045db2011-07-07 18:23:21 +02001009/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001010static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1011{
1012 int i;
1013 for (i = 0; i < nums; i++)
1014 if (list[i] == nid)
1015 return i;
1016 return -1;
1017}
1018
Takashi Iwai1d045db2011-07-07 18:23:21 +02001019/* check whether dynamic ADC-switching is available */
1020static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1021{
1022 struct alc_spec *spec = codec->spec;
1023 struct hda_input_mux *imux = &spec->private_imux[0];
1024 int i, n, idx;
1025 hda_nid_t cap, pin;
1026
1027 if (imux != spec->input_mux) /* no dynamic imux? */
1028 return false;
1029
1030 for (n = 0; n < spec->num_adc_nids; n++) {
1031 cap = spec->private_capsrc_nids[n];
1032 for (i = 0; i < imux->num_items; i++) {
1033 pin = spec->imux_pins[i];
1034 if (!pin)
1035 return false;
1036 if (get_connection_index(codec, cap, pin) < 0)
1037 break;
1038 }
1039 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001040 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001041 }
1042
1043 for (i = 0; i < imux->num_items; i++) {
1044 pin = spec->imux_pins[i];
1045 for (n = 0; n < spec->num_adc_nids; n++) {
1046 cap = spec->private_capsrc_nids[n];
1047 idx = get_connection_index(codec, cap, pin);
1048 if (idx >= 0) {
1049 imux->items[i].index = idx;
1050 spec->dyn_adc_idx[i] = n;
1051 break;
1052 }
1053 }
1054 }
1055
1056 snd_printdd("realtek: enabling ADC switching\n");
1057 spec->dyn_adc_switch = 1;
1058 return true;
1059}
Takashi Iwai21268962011-07-07 15:01:13 +02001060
Takashi Iwai21268962011-07-07 15:01:13 +02001061/* check whether all auto-mic pins are valid; setup indices if OK */
1062static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1063{
1064 struct alc_spec *spec = codec->spec;
1065 const struct hda_input_mux *imux;
1066
1067 if (!spec->auto_mic)
1068 return false;
1069 if (spec->auto_mic_valid_imux)
1070 return true; /* already checked */
1071
1072 /* fill up imux indices */
1073 if (!alc_check_dyn_adc_switch(codec)) {
1074 spec->auto_mic = 0;
1075 return false;
1076 }
1077
1078 imux = spec->input_mux;
1079 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1080 spec->imux_pins, imux->num_items);
1081 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1082 spec->imux_pins, imux->num_items);
1083 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1084 spec->imux_pins, imux->num_items);
1085 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1086 spec->auto_mic = 0;
1087 return false; /* no corresponding imux */
1088 }
1089
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001090 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001091 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001092 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1093 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001094
1095 spec->auto_mic_valid_imux = 1;
1096 spec->auto_mic = 1;
1097 return true;
1098}
1099
Takashi Iwai1d045db2011-07-07 18:23:21 +02001100/*
1101 * Check the availability of auto-mic switch;
1102 * Set up if really supported
1103 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001104static void alc_init_auto_mic(struct hda_codec *codec)
1105{
1106 struct alc_spec *spec = codec->spec;
1107 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001108 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001109 int i;
1110
Takashi Iwai24de1832011-11-07 17:13:39 +01001111 if (spec->shared_mic_hp)
1112 return; /* no auto-mic for the shared I/O */
1113
Takashi Iwai21268962011-07-07 15:01:13 +02001114 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1115
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001116 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001117 for (i = 0; i < cfg->num_inputs; i++) {
1118 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001119 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001120 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001121 switch (snd_hda_get_input_pin_attr(defcfg)) {
1122 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001123 if (fixed)
1124 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001125 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1126 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001127 fixed = nid;
1128 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001129 case INPUT_PIN_ATTR_UNUSED:
1130 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001131 case INPUT_PIN_ATTR_DOCK:
1132 if (dock)
1133 return; /* already occupied */
1134 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1135 return; /* invalid type */
1136 dock = nid;
1137 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001138 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001139 if (ext)
1140 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001141 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1142 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001143 ext = nid;
1144 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 }
1146 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001147 if (!ext && dock) {
1148 ext = dock;
1149 dock = 0;
1150 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001151 if (!ext || !fixed)
1152 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001153 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001154 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001155 if (dock && !is_jack_detectable(codec, dock))
1156 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001157
1158 /* check imux indices */
1159 spec->ext_mic_pin = ext;
1160 spec->int_mic_pin = fixed;
1161 spec->dock_mic_pin = dock;
1162
1163 spec->auto_mic = 1;
1164 if (!alc_auto_mic_check_imux(codec))
1165 return;
1166
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001167 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1168 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001169 spec->unsol_event = alc_sku_unsol_event;
1170}
1171
Takashi Iwai1d045db2011-07-07 18:23:21 +02001172/* check the availabilities of auto-mute and auto-mic switches */
1173static void alc_auto_check_switches(struct hda_codec *codec)
1174{
David Henningsson42cf0d02011-09-20 12:04:56 +02001175 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001176 alc_init_auto_mic(codec);
1177}
1178
1179/*
1180 * Realtek SSID verification
1181 */
1182
David Henningsson90622912010-10-14 14:50:18 +02001183/* Could be any non-zero and even value. When used as fixup, tells
1184 * the driver to ignore any present sku defines.
1185 */
1186#define ALC_FIXUP_SKU_IGNORE (2)
1187
Kailang Yangda00c242010-03-19 11:23:45 +01001188static int alc_auto_parse_customize_define(struct hda_codec *codec)
1189{
1190 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001191 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001192 struct alc_spec *spec = codec->spec;
1193
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001194 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1195
David Henningsson90622912010-10-14 14:50:18 +02001196 if (spec->cdefine.fixup) {
1197 ass = spec->cdefine.sku_cfg;
1198 if (ass == ALC_FIXUP_SKU_IGNORE)
1199 return -1;
1200 goto do_sku;
1201 }
1202
Kailang Yangda00c242010-03-19 11:23:45 +01001203 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001204 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001205 goto do_sku;
1206
1207 nid = 0x1d;
1208 if (codec->vendor_id == 0x10ec0260)
1209 nid = 0x17;
1210 ass = snd_hda_codec_get_pincfg(codec, nid);
1211
1212 if (!(ass & 1)) {
1213 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1214 codec->chip_name, ass);
1215 return -1;
1216 }
1217
1218 /* check sum */
1219 tmp = 0;
1220 for (i = 1; i < 16; i++) {
1221 if ((ass >> i) & 1)
1222 tmp++;
1223 }
1224 if (((ass >> 16) & 0xf) != tmp)
1225 return -1;
1226
1227 spec->cdefine.port_connectivity = ass >> 30;
1228 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1229 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1230 spec->cdefine.customization = ass >> 8;
1231do_sku:
1232 spec->cdefine.sku_cfg = ass;
1233 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1234 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1235 spec->cdefine.swap = (ass & 0x2) >> 1;
1236 spec->cdefine.override = ass & 0x1;
1237
1238 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1239 nid, spec->cdefine.sku_cfg);
1240 snd_printd("SKU: port_connectivity=0x%x\n",
1241 spec->cdefine.port_connectivity);
1242 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1243 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1244 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1245 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1246 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1247 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1248 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1249
1250 return 0;
1251}
1252
Takashi Iwai1d045db2011-07-07 18:23:21 +02001253/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001254static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1255{
Takashi Iwai21268962011-07-07 15:01:13 +02001256 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001257}
1258
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001259/* check subsystem ID and set up device-specific initialization;
1260 * return 1 if initialized, 0 if invalid SSID
1261 */
1262/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1263 * 31 ~ 16 : Manufacture ID
1264 * 15 ~ 8 : SKU ID
1265 * 7 ~ 0 : Assembly ID
1266 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1267 */
1268static int alc_subsystem_id(struct hda_codec *codec,
1269 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001270 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001271{
1272 unsigned int ass, tmp, i;
1273 unsigned nid;
1274 struct alc_spec *spec = codec->spec;
1275
David Henningsson90622912010-10-14 14:50:18 +02001276 if (spec->cdefine.fixup) {
1277 ass = spec->cdefine.sku_cfg;
1278 if (ass == ALC_FIXUP_SKU_IGNORE)
1279 return 0;
1280 goto do_sku;
1281 }
1282
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001283 ass = codec->subsystem_id & 0xffff;
1284 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1285 goto do_sku;
1286
1287 /* invalid SSID, check the special NID pin defcfg instead */
1288 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001289 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001290 * 29~21 : reserve
1291 * 20 : PCBEEP input
1292 * 19~16 : Check sum (15:1)
1293 * 15~1 : Custom
1294 * 0 : override
1295 */
1296 nid = 0x1d;
1297 if (codec->vendor_id == 0x10ec0260)
1298 nid = 0x17;
1299 ass = snd_hda_codec_get_pincfg(codec, nid);
1300 snd_printd("realtek: No valid SSID, "
1301 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001302 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001303 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001304 return 0;
1305 if ((ass >> 30) != 1) /* no physical connection */
1306 return 0;
1307
1308 /* check sum */
1309 tmp = 0;
1310 for (i = 1; i < 16; i++) {
1311 if ((ass >> i) & 1)
1312 tmp++;
1313 }
1314 if (((ass >> 16) & 0xf) != tmp)
1315 return 0;
1316do_sku:
1317 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1318 ass & 0xffff, codec->vendor_id);
1319 /*
1320 * 0 : override
1321 * 1 : Swap Jack
1322 * 2 : 0 --> Desktop, 1 --> Laptop
1323 * 3~5 : External Amplifier control
1324 * 7~6 : Reserved
1325 */
1326 tmp = (ass & 0x38) >> 3; /* external Amp control */
1327 switch (tmp) {
1328 case 1:
1329 spec->init_amp = ALC_INIT_GPIO1;
1330 break;
1331 case 3:
1332 spec->init_amp = ALC_INIT_GPIO2;
1333 break;
1334 case 7:
1335 spec->init_amp = ALC_INIT_GPIO3;
1336 break;
1337 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001338 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001339 spec->init_amp = ALC_INIT_DEFAULT;
1340 break;
1341 }
1342
1343 /* is laptop or Desktop and enable the function "Mute internal speaker
1344 * when the external headphone out jack is plugged"
1345 */
1346 if (!(ass & 0x8000))
1347 return 1;
1348 /*
1349 * 10~8 : Jack location
1350 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1351 * 14~13: Resvered
1352 * 15 : 1 --> enable the function "Mute internal speaker
1353 * when the external headphone out jack is plugged"
1354 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001355 if (!spec->autocfg.hp_pins[0] &&
1356 !(spec->autocfg.line_out_pins[0] &&
1357 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001358 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001359 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1360 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001361 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001362 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001363 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001364 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001365 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001366 else if (tmp == 3)
1367 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001368 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001369 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001370 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1371 spec->autocfg.line_outs))
1372 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001373 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001374 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001375 return 1;
1376}
Kailang Yangea1fb292008-08-26 12:58:38 +02001377
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001378/* Check the validity of ALC subsystem-id
1379 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1380static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001381{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001382 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001383 struct alc_spec *spec = codec->spec;
1384 snd_printd("realtek: "
1385 "Enable default setup for auto mode as fallback\n");
1386 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001387 }
Takashi Iwai21268962011-07-07 15:01:13 +02001388}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001389
Takashi Iwai41e41f12005-06-08 14:48:49 +02001390/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001391 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001392 */
1393
1394struct alc_pincfg {
1395 hda_nid_t nid;
1396 u32 val;
1397};
1398
Todd Broche1eb5f12010-12-06 11:19:51 -08001399struct alc_model_fixup {
1400 const int id;
1401 const char *name;
1402};
1403
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001404struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001405 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001406 bool chained;
1407 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001408 union {
1409 unsigned int sku;
1410 const struct alc_pincfg *pins;
1411 const struct hda_verb *verbs;
1412 void (*func)(struct hda_codec *codec,
1413 const struct alc_fixup *fix,
1414 int action);
1415 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001416};
1417
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001418enum {
1419 ALC_FIXUP_INVALID,
1420 ALC_FIXUP_SKU,
1421 ALC_FIXUP_PINS,
1422 ALC_FIXUP_VERBS,
1423 ALC_FIXUP_FUNC,
1424};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001425
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001426enum {
1427 ALC_FIXUP_ACT_PRE_PROBE,
1428 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001429 ALC_FIXUP_ACT_INIT,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001430 ALC_FIXUP_ACT_BUILD,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001431};
1432
Takashi Iwai118cb4a2012-04-19 07:33:27 +02001433static void alc_apply_pincfgs(struct hda_codec *codec,
1434 const struct alc_pincfg *cfg)
1435{
1436 for (; cfg->nid; cfg++)
1437 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
1438}
1439
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001440static void alc_apply_fixup(struct hda_codec *codec, int action)
1441{
1442 struct alc_spec *spec = codec->spec;
1443 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001444#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001445 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001446#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001447 int depth = 0;
1448
1449 if (!spec->fixup_list)
1450 return;
1451
1452 while (id >= 0) {
1453 const struct alc_fixup *fix = spec->fixup_list + id;
1454 const struct alc_pincfg *cfg;
1455
1456 switch (fix->type) {
1457 case ALC_FIXUP_SKU:
1458 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001459 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001460 snd_printdd(KERN_INFO "hda_codec: %s: "
1461 "Apply sku override for %s\n",
1462 codec->chip_name, modelname);
1463 spec->cdefine.sku_cfg = fix->v.sku;
1464 spec->cdefine.fixup = 1;
1465 break;
1466 case ALC_FIXUP_PINS:
1467 cfg = fix->v.pins;
1468 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1469 break;
1470 snd_printdd(KERN_INFO "hda_codec: %s: "
1471 "Apply pincfg for %s\n",
1472 codec->chip_name, modelname);
Takashi Iwai118cb4a2012-04-19 07:33:27 +02001473 alc_apply_pincfgs(codec, cfg);
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001474 break;
1475 case ALC_FIXUP_VERBS:
1476 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1477 break;
1478 snd_printdd(KERN_INFO "hda_codec: %s: "
1479 "Apply fix-verbs for %s\n",
1480 codec->chip_name, modelname);
1481 add_verb(codec->spec, fix->v.verbs);
1482 break;
1483 case ALC_FIXUP_FUNC:
1484 if (!fix->v.func)
1485 break;
1486 snd_printdd(KERN_INFO "hda_codec: %s: "
1487 "Apply fix-func for %s\n",
1488 codec->chip_name, modelname);
1489 fix->v.func(codec, fix, action);
1490 break;
1491 default:
1492 snd_printk(KERN_ERR "hda_codec: %s: "
1493 "Invalid fixup type %d\n",
1494 codec->chip_name, fix->type);
1495 break;
1496 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001497 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001498 break;
1499 if (++depth > 10)
1500 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001501 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001502 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001503}
1504
Todd Broche1eb5f12010-12-06 11:19:51 -08001505static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001506 const struct alc_model_fixup *models,
1507 const struct snd_pci_quirk *quirk,
1508 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001509{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001510 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001511 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001512 int id = -1;
1513 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001514
Takashi Iwai9155f822012-02-20 18:41:02 +01001515 /* when model=nofixup is given, don't pick up any fixups */
1516 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
1517 spec->fixup_list = NULL;
1518 spec->fixup_id = -1;
1519 return;
1520 }
1521
Todd Broche1eb5f12010-12-06 11:19:51 -08001522 if (codec->modelname && models) {
1523 while (models->name) {
1524 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001525 id = models->id;
1526 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001527 break;
1528 }
1529 models++;
1530 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001531 }
1532 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001533 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1534 if (q) {
1535 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001536#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001537 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001538#endif
1539 }
1540 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001541 if (id < 0) {
1542 for (q = quirk; q->subvendor; q++) {
1543 unsigned int vendorid =
1544 q->subdevice | (q->subvendor << 16);
1545 if (vendorid == codec->subsystem_id) {
1546 id = q->value;
1547#ifdef CONFIG_SND_DEBUG_VERBOSE
1548 name = q->name;
1549#endif
1550 break;
1551 }
1552 }
1553 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001554
1555 spec->fixup_id = id;
1556 if (id >= 0) {
1557 spec->fixup_list = fixlist;
1558 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001559 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001560}
1561
Takashi Iwai1d045db2011-07-07 18:23:21 +02001562/*
1563 * COEF access helper functions
1564 */
Kailang Yang274693f2009-12-03 10:07:50 +01001565static int alc_read_coef_idx(struct hda_codec *codec,
1566 unsigned int coef_idx)
1567{
1568 unsigned int val;
1569 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1570 coef_idx);
1571 val = snd_hda_codec_read(codec, 0x20, 0,
1572 AC_VERB_GET_PROC_COEF, 0);
1573 return val;
1574}
1575
Kailang Yang977ddd62010-09-15 10:02:29 +02001576static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1577 unsigned int coef_val)
1578{
1579 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1580 coef_idx);
1581 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1582 coef_val);
1583}
1584
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001585/* a special bypass for COEF 0; read the cached value at the second time */
1586static unsigned int alc_get_coef0(struct hda_codec *codec)
1587{
1588 struct alc_spec *spec = codec->spec;
1589 if (!spec->coef0)
1590 spec->coef0 = alc_read_coef_idx(codec, 0);
1591 return spec->coef0;
1592}
1593
Takashi Iwai1d045db2011-07-07 18:23:21 +02001594/*
1595 * Digital I/O handling
1596 */
1597
Takashi Iwai757899a2010-07-30 10:48:14 +02001598/* set right pin controls for digital I/O */
1599static void alc_auto_init_digital(struct hda_codec *codec)
1600{
1601 struct alc_spec *spec = codec->spec;
1602 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001603 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001604
1605 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1606 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001607 if (!pin)
1608 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001609 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001610 if (!i)
1611 dac = spec->multiout.dig_out_nid;
1612 else
1613 dac = spec->slave_dig_outs[i - 1];
1614 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1615 continue;
1616 snd_hda_codec_write(codec, dac, 0,
1617 AC_VERB_SET_AMP_GAIN_MUTE,
1618 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001619 }
1620 pin = spec->autocfg.dig_in_pin;
1621 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001622 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001623}
1624
1625/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1626static void alc_auto_parse_digital(struct hda_codec *codec)
1627{
1628 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001629 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001630 hda_nid_t dig_nid;
1631
1632 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001633 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001634 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001635 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001636 err = snd_hda_get_connections(codec,
1637 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001638 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001639 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001640 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001641 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001642 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001643 spec->multiout.dig_out_nid = dig_nid;
1644 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1645 } else {
1646 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001647 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001648 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001649 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001650 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001651 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001652 }
1653
1654 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001655 dig_nid = codec->start_nid;
1656 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1657 unsigned int wcaps = get_wcaps(codec, dig_nid);
1658 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1659 continue;
1660 if (!(wcaps & AC_WCAP_DIGITAL))
1661 continue;
1662 if (!(wcaps & AC_WCAP_CONN_LIST))
1663 continue;
1664 err = get_connection_index(codec, dig_nid,
1665 spec->autocfg.dig_in_pin);
1666 if (err >= 0) {
1667 spec->dig_in_nid = dig_nid;
1668 break;
1669 }
1670 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001671 }
1672}
1673
Takashi Iwaif95474e2007-07-10 00:47:43 +02001674/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001675 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001676 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001677static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1678 struct snd_ctl_elem_info *uinfo)
1679{
1680 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1681 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001682 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001683 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001684
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001685 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001686 if (spec->vol_in_capsrc)
1687 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1688 else
1689 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1690 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001691 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001692 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001693 return err;
1694}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001696static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1697 unsigned int size, unsigned int __user *tlv)
1698{
1699 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1700 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001701 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001702 int err;
1703
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001704 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001705 if (spec->vol_in_capsrc)
1706 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1707 else
1708 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1709 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001710 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001711 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001712 return err;
1713}
1714
1715typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1716 struct snd_ctl_elem_value *ucontrol);
1717
1718static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1719 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001720 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001721{
1722 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1723 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001724 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001725
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001726 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001727 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001728 for (i = 0; i < spec->num_adc_nids; i++) {
1729 kcontrol->private_value =
1730 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1731 3, 0, HDA_INPUT);
1732 err = func(kcontrol, ucontrol);
1733 if (err < 0)
1734 goto error;
1735 }
1736 } else {
1737 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001738 if (spec->vol_in_capsrc)
1739 kcontrol->private_value =
1740 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1741 3, 0, HDA_OUTPUT);
1742 else
1743 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001744 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1745 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001746 err = func(kcontrol, ucontrol);
1747 }
1748 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001749 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001750 return err;
1751}
1752
1753static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1754 struct snd_ctl_elem_value *ucontrol)
1755{
1756 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001757 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001758}
1759
1760static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1761 struct snd_ctl_elem_value *ucontrol)
1762{
1763 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001764 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001765}
1766
1767/* capture mixer elements */
1768#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1769
1770static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1771 struct snd_ctl_elem_value *ucontrol)
1772{
1773 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001774 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001775}
1776
1777static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1778 struct snd_ctl_elem_value *ucontrol)
1779{
1780 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001781 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001782}
1783
Takashi Iwaia23b6882009-03-23 15:21:36 +01001784#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001785 { \
1786 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1787 .name = "Capture Switch", \
1788 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1789 .count = num, \
1790 .info = alc_cap_sw_info, \
1791 .get = alc_cap_sw_get, \
1792 .put = alc_cap_sw_put, \
1793 }, \
1794 { \
1795 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1796 .name = "Capture Volume", \
1797 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1798 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1799 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1800 .count = num, \
1801 .info = alc_cap_vol_info, \
1802 .get = alc_cap_vol_get, \
1803 .put = alc_cap_vol_put, \
1804 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001805 }
1806
1807#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001808 { \
1809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1810 /* .name = "Capture Source", */ \
1811 .name = "Input Source", \
1812 .count = num, \
1813 .info = alc_mux_enum_info, \
1814 .get = alc_mux_enum_get, \
1815 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001816 }
1817
1818#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001819static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001820 _DEFINE_CAPMIX(num), \
1821 _DEFINE_CAPSRC(num), \
1822 { } /* end */ \
1823}
1824
1825#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001826static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001827 _DEFINE_CAPMIX(num), \
1828 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001829}
1830
1831/* up to three ADCs */
1832DEFINE_CAPMIX(1);
1833DEFINE_CAPMIX(2);
1834DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001835DEFINE_CAPMIX_NOSRC(1);
1836DEFINE_CAPMIX_NOSRC(2);
1837DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001838
1839/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001840 * virtual master controls
1841 */
1842
1843/*
1844 * slave controls for virtual master
1845 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001846static const char * const alc_slave_pfxs[] = {
1847 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001848 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001849 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001850 NULL,
1851};
1852
1853/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001854 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001855 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001856
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001857#define NID_MAPPING (-1)
1858
1859#define SUBDEV_SPEAKER_ (0 << 6)
1860#define SUBDEV_HP_ (1 << 6)
1861#define SUBDEV_LINE_ (2 << 6)
1862#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1863#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1864#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1865
Takashi Iwai603c4012008-07-30 15:01:44 +02001866static void alc_free_kctls(struct hda_codec *codec);
1867
Takashi Iwai67d634c2009-11-16 15:35:59 +01001868#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001869/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001870static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001871 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001872 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001873 { } /* end */
1874};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001875#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001876
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001877static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878{
1879 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001880 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001881 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001882 int i, j, err;
1883 unsigned int u;
1884 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
1886 for (i = 0; i < spec->num_mixers; i++) {
1887 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1888 if (err < 0)
1889 return err;
1890 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001891 if (spec->cap_mixer) {
1892 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1893 if (err < 0)
1894 return err;
1895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001897 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001898 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001899 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 if (err < 0)
1901 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001902 if (!spec->no_analog) {
1903 err = snd_hda_create_spdif_share_sw(codec,
1904 &spec->multiout);
1905 if (err < 0)
1906 return err;
1907 spec->multiout.share_spdif = 1;
1908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 }
1910 if (spec->dig_in_nid) {
1911 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1912 if (err < 0)
1913 return err;
1914 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001915
Takashi Iwai67d634c2009-11-16 15:35:59 +01001916#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001917 /* create beep controls if needed */
1918 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001919 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001920 for (knew = alc_beep_mixer; knew->name; knew++) {
1921 struct snd_kcontrol *kctl;
1922 kctl = snd_ctl_new1(knew, codec);
1923 if (!kctl)
1924 return -ENOMEM;
1925 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001926 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001927 if (err < 0)
1928 return err;
1929 }
1930 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001931#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001932
Takashi Iwai2134ea42008-01-10 16:53:55 +01001933 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001934 if (!spec->no_analog &&
1935 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001936 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001937 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001938 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001939 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001940 vmaster_tlv, alc_slave_pfxs,
1941 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001942 if (err < 0)
1943 return err;
1944 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001945 if (!spec->no_analog &&
1946 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001947 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1948 NULL, alc_slave_pfxs,
1949 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001950 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001951 if (err < 0)
1952 return err;
1953 }
1954
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001955 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001956 if (spec->capsrc_nids || spec->adc_nids) {
1957 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1958 if (!kctl)
1959 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1960 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001961 err = snd_hda_add_nid(codec, kctl, i,
1962 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001963 if (err < 0)
1964 return err;
1965 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001966 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001967 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001968 const char *kname = kctl ? kctl->id.name : NULL;
1969 for (knew = spec->cap_mixer; knew->name; knew++) {
1970 if (kname && strcmp(knew->name, kname) == 0)
1971 continue;
1972 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1973 for (i = 0; kctl && i < kctl->count; i++) {
1974 err = snd_hda_add_nid(codec, kctl, i,
1975 spec->adc_nids[i]);
1976 if (err < 0)
1977 return err;
1978 }
1979 }
1980 }
1981
1982 /* other nid->control mapping */
1983 for (i = 0; i < spec->num_mixers; i++) {
1984 for (knew = spec->mixers[i]; knew->name; knew++) {
1985 if (knew->iface != NID_MAPPING)
1986 continue;
1987 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1988 if (kctl == NULL)
1989 continue;
1990 u = knew->subdevice;
1991 for (j = 0; j < 4; j++, u >>= 8) {
1992 nid = u & 0x3f;
1993 if (nid == 0)
1994 continue;
1995 switch (u & 0xc0) {
1996 case SUBDEV_SPEAKER_:
1997 nid = spec->autocfg.speaker_pins[nid];
1998 break;
1999 case SUBDEV_LINE_:
2000 nid = spec->autocfg.line_out_pins[nid];
2001 break;
2002 case SUBDEV_HP_:
2003 nid = spec->autocfg.hp_pins[nid];
2004 break;
2005 default:
2006 continue;
2007 }
2008 err = snd_hda_add_nid(codec, kctl, 0, nid);
2009 if (err < 0)
2010 return err;
2011 }
2012 u = knew->private_value;
2013 for (j = 0; j < 4; j++, u >>= 8) {
2014 nid = u & 0xff;
2015 if (nid == 0)
2016 continue;
2017 err = snd_hda_add_nid(codec, kctl, 0, nid);
2018 if (err < 0)
2019 return err;
2020 }
2021 }
2022 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002023
2024 alc_free_kctls(codec); /* no longer needed */
2025
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002026 return 0;
2027}
2028
2029static int alc_build_controls(struct hda_codec *codec)
2030{
2031 struct alc_spec *spec = codec->spec;
2032 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002033 if (err < 0)
2034 return err;
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002035 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
2036 if (err < 0)
2037 return err;
2038 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2039 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040}
2041
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002044 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002045 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002046
Takashi Iwai584c0c42011-03-10 12:51:11 +01002047static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002048static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002049
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050static int alc_init(struct hda_codec *codec)
2051{
2052 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002053 unsigned int i;
2054
Takashi Iwai546bb672012-03-07 08:37:19 +01002055 if (spec->init_hook)
2056 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002057
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002058 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002059 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002060
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002061 for (i = 0; i < spec->num_init_verbs; i++)
2062 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002063 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002064 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002065
Takashi Iwai58701122011-01-13 15:41:45 +01002066 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2067
Takashi Iwai01a61e12011-10-28 00:03:22 +02002068 snd_hda_jack_report_sync(codec);
2069
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002070 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 return 0;
2072}
2073
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002074static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2075{
2076 struct alc_spec *spec = codec->spec;
2077
2078 if (spec->unsol_event)
2079 spec->unsol_event(codec, res);
2080}
2081
Takashi Iwaicb53c622007-08-10 17:21:45 +02002082#ifdef CONFIG_SND_HDA_POWER_SAVE
2083static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2084{
2085 struct alc_spec *spec = codec->spec;
2086 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2087}
2088#endif
2089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090/*
2091 * Analog playback callbacks
2092 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002093static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002095 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
2097 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002098 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2099 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100}
2101
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002102static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct hda_codec *codec,
2104 unsigned int stream_tag,
2105 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002106 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002109 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2110 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111}
2112
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002113static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002115 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
2117 struct alc_spec *spec = codec->spec;
2118 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2119}
2120
2121/*
2122 * Digital out
2123 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002124static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002126 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127{
2128 struct alc_spec *spec = codec->spec;
2129 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2130}
2131
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002132static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002133 struct hda_codec *codec,
2134 unsigned int stream_tag,
2135 unsigned int format,
2136 struct snd_pcm_substream *substream)
2137{
2138 struct alc_spec *spec = codec->spec;
2139 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2140 stream_tag, format, substream);
2141}
2142
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002143static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002144 struct hda_codec *codec,
2145 struct snd_pcm_substream *substream)
2146{
2147 struct alc_spec *spec = codec->spec;
2148 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2149}
2150
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002151static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002153 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154{
2155 struct alc_spec *spec = codec->spec;
2156 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2157}
2158
2159/*
2160 * Analog capture
2161 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002162static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 struct hda_codec *codec,
2164 unsigned int stream_tag,
2165 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002166 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167{
2168 struct alc_spec *spec = codec->spec;
2169
Takashi Iwai63300792008-01-24 15:31:36 +01002170 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 stream_tag, 0, format);
2172 return 0;
2173}
2174
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002175static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002177 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
2179 struct alc_spec *spec = codec->spec;
2180
Takashi Iwai888afa12008-03-18 09:57:50 +01002181 snd_hda_codec_cleanup_stream(codec,
2182 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 return 0;
2184}
2185
Takashi Iwai840b64c2010-07-13 22:49:01 +02002186/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002187static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002188 struct hda_codec *codec,
2189 unsigned int stream_tag,
2190 unsigned int format,
2191 struct snd_pcm_substream *substream)
2192{
2193 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002194 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002195 spec->cur_adc_stream_tag = stream_tag;
2196 spec->cur_adc_format = format;
2197 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2198 return 0;
2199}
2200
Takashi Iwai21268962011-07-07 15:01:13 +02002201static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002202 struct hda_codec *codec,
2203 struct snd_pcm_substream *substream)
2204{
2205 struct alc_spec *spec = codec->spec;
2206 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2207 spec->cur_adc = 0;
2208 return 0;
2209}
2210
Takashi Iwai21268962011-07-07 15:01:13 +02002211static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002212 .substreams = 1,
2213 .channels_min = 2,
2214 .channels_max = 2,
2215 .nid = 0, /* fill later */
2216 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002217 .prepare = dyn_adc_capture_pcm_prepare,
2218 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002219 },
2220};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
2222/*
2223 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002224static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 .substreams = 1,
2226 .channels_min = 2,
2227 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002228 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002230 .open = alc_playback_pcm_open,
2231 .prepare = alc_playback_pcm_prepare,
2232 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 },
2234};
2235
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002236static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002237 .substreams = 1,
2238 .channels_min = 2,
2239 .channels_max = 2,
2240 /* NID is set in alc_build_pcms */
2241};
2242
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002243static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002244 .substreams = 1,
2245 .channels_min = 2,
2246 .channels_max = 2,
2247 /* NID is set in alc_build_pcms */
2248};
2249
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002250static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002251 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 .channels_min = 2,
2253 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002254 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002256 .prepare = alc_alt_capture_pcm_prepare,
2257 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 },
2259};
2260
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002261static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 .substreams = 1,
2263 .channels_min = 2,
2264 .channels_max = 2,
2265 /* NID is set in alc_build_pcms */
2266 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002267 .open = alc_dig_playback_pcm_open,
2268 .close = alc_dig_playback_pcm_close,
2269 .prepare = alc_dig_playback_pcm_prepare,
2270 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 },
2272};
2273
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002274static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 .substreams = 1,
2276 .channels_min = 2,
2277 .channels_max = 2,
2278 /* NID is set in alc_build_pcms */
2279};
2280
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002281/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002282static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002283 .substreams = 0,
2284 .channels_min = 0,
2285 .channels_max = 0,
2286};
2287
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288static int alc_build_pcms(struct hda_codec *codec)
2289{
2290 struct alc_spec *spec = codec->spec;
2291 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002292 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002293 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 int i;
2295
2296 codec->num_pcms = 1;
2297 codec->pcm_info = info;
2298
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002299 if (spec->no_analog)
2300 goto skip_analog;
2301
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002302 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2303 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002305
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002306 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002307 p = spec->stream_analog_playback;
2308 if (!p)
2309 p = &alc_pcm_analog_playback;
2310 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002311 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2312 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002313 if (spec->adc_nids) {
2314 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002315 if (!p) {
2316 if (spec->dyn_adc_switch)
2317 p = &dyn_adc_pcm_analog_capture;
2318 else
2319 p = &alc_pcm_analog_capture;
2320 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002321 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002322 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324
Takashi Iwai4a471b72005-12-07 13:56:29 +01002325 if (spec->channel_mode) {
2326 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2327 for (i = 0; i < spec->num_channel_mode; i++) {
2328 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2330 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 }
2332 }
2333
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002334 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002335 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002337 snprintf(spec->stream_name_digital,
2338 sizeof(spec->stream_name_digital),
2339 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002340 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002341 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002342 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002344 if (spec->dig_out_type)
2345 info->pcm_type = spec->dig_out_type;
2346 else
2347 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002348 if (spec->multiout.dig_out_nid) {
2349 p = spec->stream_digital_playback;
2350 if (!p)
2351 p = &alc_pcm_digital_playback;
2352 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2354 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002355 if (spec->dig_in_nid) {
2356 p = spec->stream_digital_capture;
2357 if (!p)
2358 p = &alc_pcm_digital_capture;
2359 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2361 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002362 /* FIXME: do we need this for all Realtek codec models? */
2363 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 }
2365
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002366 if (spec->no_analog)
2367 return 0;
2368
Takashi Iwaie08a0072006-09-07 17:52:14 +02002369 /* If the use of more than one ADC is requested for the current
2370 * model, configure a second analog capture-only PCM.
2371 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002372 have_multi_adcs = (spec->num_adc_nids > 1) &&
2373 !spec->dyn_adc_switch && !spec->auto_mic &&
2374 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002375 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002376 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002377 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002378 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002379 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002380 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002381 p = spec->stream_analog_alt_playback;
2382 if (!p)
2383 p = &alc_pcm_analog_alt_playback;
2384 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002385 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2386 spec->alt_dac_nid;
2387 } else {
2388 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2389 alc_pcm_null_stream;
2390 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2391 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002392 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002393 p = spec->stream_analog_alt_capture;
2394 if (!p)
2395 p = &alc_pcm_analog_alt_capture;
2396 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002397 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2398 spec->adc_nids[1];
2399 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2400 spec->num_adc_nids - 1;
2401 } else {
2402 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2403 alc_pcm_null_stream;
2404 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002405 }
2406 }
2407
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 return 0;
2409}
2410
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002411static inline void alc_shutup(struct hda_codec *codec)
2412{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002413 struct alc_spec *spec = codec->spec;
2414
2415 if (spec && spec->shutup)
2416 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002417 snd_hda_shutup_pins(codec);
2418}
2419
Takashi Iwai603c4012008-07-30 15:01:44 +02002420static void alc_free_kctls(struct hda_codec *codec)
2421{
2422 struct alc_spec *spec = codec->spec;
2423
2424 if (spec->kctls.list) {
2425 struct snd_kcontrol_new *kctl = spec->kctls.list;
2426 int i;
2427 for (i = 0; i < spec->kctls.used; i++)
2428 kfree(kctl[i].name);
2429 }
2430 snd_array_free(&spec->kctls);
2431}
2432
Takashi Iwai23c09b02011-08-19 09:05:35 +02002433static void alc_free_bind_ctls(struct hda_codec *codec)
2434{
2435 struct alc_spec *spec = codec->spec;
2436 if (spec->bind_ctls.list) {
2437 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2438 int i;
2439 for (i = 0; i < spec->bind_ctls.used; i++)
2440 kfree(ctl[i]);
2441 }
2442 snd_array_free(&spec->bind_ctls);
2443}
2444
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445static void alc_free(struct hda_codec *codec)
2446{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002447 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002448
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002449 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002450 return;
2451
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002452 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002453 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002454 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002455 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002456 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457}
2458
Hector Martinf5de24b2009-12-20 22:51:31 +01002459#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002460static void alc_power_eapd(struct hda_codec *codec)
2461{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002462 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002463}
2464
Hector Martinf5de24b2009-12-20 22:51:31 +01002465static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2466{
2467 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002468 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002469 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002470 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002471 return 0;
2472}
2473#endif
2474
Takashi Iwai2a439522011-07-26 09:52:50 +02002475#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002476static int alc_resume(struct hda_codec *codec)
2477{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002478 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002479 codec->patch_ops.init(codec);
2480 snd_hda_codec_resume_amp(codec);
2481 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002482 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002483 return 0;
2484}
Takashi Iwaie044c392008-10-27 16:56:24 +01002485#endif
2486
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487/*
2488 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002489static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 .build_controls = alc_build_controls,
2491 .build_pcms = alc_build_pcms,
2492 .init = alc_init,
2493 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002494 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002495#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002496 .resume = alc_resume,
2497#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002498#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002499 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002500 .check_power_status = alc_check_power_status,
2501#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002502 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503};
2504
Kailang Yangc027ddc2010-03-19 11:33:06 +01002505/* replace the codec chip_name with the given string */
2506static int alc_codec_rename(struct hda_codec *codec, const char *name)
2507{
2508 kfree(codec->chip_name);
2509 codec->chip_name = kstrdup(name, GFP_KERNEL);
2510 if (!codec->chip_name) {
2511 alc_free(codec);
2512 return -ENOMEM;
2513 }
2514 return 0;
2515}
2516
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002517/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002518 * Rename codecs appropriately from COEF value
2519 */
2520struct alc_codec_rename_table {
2521 unsigned int vendor_id;
2522 unsigned short coef_mask;
2523 unsigned short coef_bits;
2524 const char *name;
2525};
2526
2527static struct alc_codec_rename_table rename_tbl[] = {
2528 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2529 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2530 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2531 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2532 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2533 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2534 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2535 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2536 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2537 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2538 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2539 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2540 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2541 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2542 { } /* terminator */
2543};
2544
2545static int alc_codec_rename_from_preset(struct hda_codec *codec)
2546{
2547 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002548
2549 for (p = rename_tbl; p->vendor_id; p++) {
2550 if (p->vendor_id != codec->vendor_id)
2551 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002552 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002553 return alc_codec_rename(codec, p->name);
2554 }
2555 return 0;
2556}
2557
2558/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002559 * Automatic parse of I/O pins from the BIOS configuration
2560 */
2561
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002562enum {
2563 ALC_CTL_WIDGET_VOL,
2564 ALC_CTL_WIDGET_MUTE,
2565 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002566 ALC_CTL_BIND_VOL,
2567 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002568};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002569static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002570 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2571 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002572 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002573 HDA_BIND_VOL(NULL, 0),
2574 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002575};
2576
2577/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002578static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002579 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002580{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002581 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002582
Takashi Iwaice764ab2011-04-27 16:35:23 +02002583 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002584 if (!knew)
2585 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002586 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002587 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002588 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002589 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002590 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002591 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002592 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002593 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002594 return 0;
2595}
2596
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002597static int add_control_with_pfx(struct alc_spec *spec, int type,
2598 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002599 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002600{
2601 char name[32];
2602 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002603 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002604}
2605
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002606#define add_pb_vol_ctrl(spec, type, pfx, val) \
2607 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2608#define add_pb_sw_ctrl(spec, type, pfx, val) \
2609 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2610#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2611 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2612#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2613 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002614
Takashi Iwai23c09b02011-08-19 09:05:35 +02002615static const char * const channel_name[4] = {
2616 "Front", "Surround", "CLFE", "Side"
2617};
2618
Takashi Iwai6843ca12011-06-24 11:03:58 +02002619static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2620 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002621{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002622 struct auto_pin_cfg *cfg = &spec->autocfg;
2623
Takashi Iwai6843ca12011-06-24 11:03:58 +02002624 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002625 if (cfg->line_outs == 1 && !spec->multi_ios &&
2626 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002627 return "Master";
2628
2629 switch (cfg->line_out_type) {
2630 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002631 if (cfg->line_outs == 1)
2632 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002633 if (cfg->line_outs == 2)
2634 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002635 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002636 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002637 /* for multi-io case, only the primary out */
2638 if (ch && spec->multi_ios)
2639 break;
2640 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002641 return "Headphone";
2642 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002643 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002644 return "PCM";
2645 break;
2646 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002647 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2648 return "PCM";
2649
2650 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002651}
2652
Takashi Iwai164f73e2012-02-21 11:27:09 +01002653#ifdef CONFIG_SND_HDA_POWER_SAVE
2654/* add the powersave loopback-list entry */
2655static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2656{
2657 struct hda_amp_list *list;
2658
2659 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2660 return;
2661 list = spec->loopback_list + spec->num_loopbacks;
2662 list->nid = mix;
2663 list->dir = HDA_INPUT;
2664 list->idx = idx;
2665 spec->num_loopbacks++;
2666 spec->loopback.amplist = spec->loopback_list;
2667}
2668#else
2669#define add_loopback_list(spec, mix, idx) /* NOP */
2670#endif
2671
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002672/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002673static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002674 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002675 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002676{
Kailang Yangdf694da2005-12-05 19:42:22 +01002677 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002678
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002679 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002680 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2681 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002682 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002683 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002684 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2685 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002686 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002687 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002688 return 0;
2689}
2690
Takashi Iwai05f5f472009-08-25 13:10:18 +02002691static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002692{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002693 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2694 return (pincap & AC_PINCAP_IN) != 0;
2695}
2696
Takashi Iwai1d045db2011-07-07 18:23:21 +02002697/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002698static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002699{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002700 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002701 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002702 hda_nid_t *adc_nids = spec->private_adc_nids;
2703 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2704 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002705 int i, nums = 0;
2706
2707 nid = codec->start_nid;
2708 for (i = 0; i < codec->num_nodes; i++, nid++) {
2709 hda_nid_t src;
2710 const hda_nid_t *list;
2711 unsigned int caps = get_wcaps(codec, nid);
2712 int type = get_wcaps_type(caps);
2713
2714 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2715 continue;
2716 adc_nids[nums] = nid;
2717 cap_nids[nums] = nid;
2718 src = nid;
2719 for (;;) {
2720 int n;
2721 type = get_wcaps_type(get_wcaps(codec, src));
2722 if (type == AC_WID_PIN)
2723 break;
2724 if (type == AC_WID_AUD_SEL) {
2725 cap_nids[nums] = src;
2726 break;
2727 }
2728 n = snd_hda_get_conn_list(codec, src, &list);
2729 if (n > 1) {
2730 cap_nids[nums] = src;
2731 break;
2732 } else if (n != 1)
2733 break;
2734 src = *list;
2735 }
2736 if (++nums >= max_nums)
2737 break;
2738 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002739 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002740 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002741 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002742 return nums;
2743}
2744
Takashi Iwai05f5f472009-08-25 13:10:18 +02002745/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002746static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002747{
2748 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002749 const struct auto_pin_cfg *cfg = &spec->autocfg;
2750 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002751 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002752 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002753 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002754 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002755
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002756 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002757 if (num_adcs < 0)
2758 return 0;
2759
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002760 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002761 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002762 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002763
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002764 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002765 if (!alc_is_input_pin(codec, pin))
2766 continue;
2767
David Henningsson5322bf22011-01-05 11:03:56 +01002768 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002769 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2770 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002771 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002772 type_idx++;
2773 else
2774 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002775 prev_label = label;
2776
Takashi Iwai05f5f472009-08-25 13:10:18 +02002777 if (mixer) {
2778 idx = get_connection_index(codec, mixer, pin);
2779 if (idx >= 0) {
2780 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002781 label, type_idx,
2782 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002783 if (err < 0)
2784 return err;
2785 }
2786 }
2787
Takashi Iwaib7821702011-07-06 15:12:46 +02002788 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002789 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002790 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002791 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002792 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002793 snd_hda_add_imux_item(imux, label, idx, NULL);
2794 break;
2795 }
2796 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002797 }
Takashi Iwai21268962011-07-07 15:01:13 +02002798
2799 spec->num_mux_defs = 1;
2800 spec->input_mux = imux;
2801
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002802 return 0;
2803}
2804
Takashi Iwai24de1832011-11-07 17:13:39 +01002805/* create a shared input with the headphone out */
2806static int alc_auto_create_shared_input(struct hda_codec *codec)
2807{
2808 struct alc_spec *spec = codec->spec;
2809 struct auto_pin_cfg *cfg = &spec->autocfg;
2810 unsigned int defcfg;
2811 hda_nid_t nid;
2812
2813 /* only one internal input pin? */
2814 if (cfg->num_inputs != 1)
2815 return 0;
2816 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2817 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2818 return 0;
2819
2820 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2821 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2822 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2823 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2824 else
2825 return 0; /* both not available */
2826
2827 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2828 return 0; /* no input */
2829
2830 cfg->inputs[1].pin = nid;
2831 cfg->inputs[1].type = AUTO_PIN_MIC;
2832 cfg->num_inputs = 2;
2833 spec->shared_mic_hp = 1;
2834 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2835 return 0;
2836}
2837
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002838static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2839 unsigned int pin_type)
2840{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002841 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002842 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002843 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2844 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002845 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002846}
2847
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002848static int get_pin_type(int line_out_type)
2849{
2850 if (line_out_type == AUTO_PIN_HP_OUT)
2851 return PIN_HP;
2852 else
2853 return PIN_OUT;
2854}
2855
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002856static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002857{
2858 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002859 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002860 int i;
2861
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002862 for (i = 0; i < cfg->num_inputs; i++) {
2863 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002864 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002865 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002866 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002867 snd_hda_codec_write(codec, nid, 0,
2868 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002869 AMP_OUT_MUTE);
2870 }
2871 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002872
2873 /* mute all loopback inputs */
2874 if (spec->mixer_nid) {
2875 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2876 for (i = 0; i < nums; i++)
2877 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2878 AC_VERB_SET_AMP_GAIN_MUTE,
2879 AMP_IN_MUTE(i));
2880 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002881}
2882
Takashi Iwai7085ec12009-10-02 09:03:58 +02002883/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002884static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002885{
Takashi Iwai604401a2011-04-27 15:14:23 +02002886 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002887 int i, num;
2888
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002889 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2890 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002891 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2892 for (i = 0; i < num; i++) {
2893 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2894 return list[i];
2895 }
2896 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002897}
2898
Takashi Iwai604401a2011-04-27 15:14:23 +02002899/* go down to the selector widget before the mixer */
2900static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2901{
2902 hda_nid_t srcs[5];
2903 int num = snd_hda_get_connections(codec, pin, srcs,
2904 ARRAY_SIZE(srcs));
2905 if (num != 1 ||
2906 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2907 return pin;
2908 return srcs[0];
2909}
2910
Takashi Iwai7085ec12009-10-02 09:03:58 +02002911/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002912static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002913 hda_nid_t dac)
2914{
David Henningssoncc1c4522010-11-24 14:17:47 +01002915 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002916 int i, num;
2917
Takashi Iwai604401a2011-04-27 15:14:23 +02002918 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002919 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2920 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002921 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002922 return mix[i];
2923 }
2924 return 0;
2925}
2926
Takashi Iwaice764ab2011-04-27 16:35:23 +02002927/* select the connection from pin to DAC if needed */
2928static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2929 hda_nid_t dac)
2930{
2931 hda_nid_t mix[5];
2932 int i, num;
2933
2934 pin = alc_go_down_to_selector(codec, pin);
2935 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2936 if (num < 2)
2937 return 0;
2938 for (i = 0; i < num; i++) {
2939 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2940 snd_hda_codec_update_cache(codec, pin, 0,
2941 AC_VERB_SET_CONNECT_SEL, i);
2942 return 0;
2943 }
2944 }
2945 return 0;
2946}
2947
Takashi Iwai185d99f2012-02-16 18:39:45 +01002948static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2949{
2950 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002951 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002952 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2953 ARRAY_SIZE(spec->private_dac_nids)) ||
2954 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2955 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2956 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2957 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2958 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002959 for (i = 0; i < spec->multi_ios; i++) {
2960 if (spec->multi_io[i].dac == nid)
2961 return true;
2962 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002963 return false;
2964}
2965
Takashi Iwai7085ec12009-10-02 09:03:58 +02002966/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002967static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002968{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002969 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002970 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002971
Takashi Iwai604401a2011-04-27 15:14:23 +02002972 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002973 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002974 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002975 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002976 if (!nid)
2977 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002978 if (!alc_is_dac_already_used(codec, nid))
2979 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002980 }
2981 return 0;
2982}
2983
Takashi Iwai07b18f62011-11-10 15:42:54 +01002984/* check whether the DAC is reachable from the pin */
2985static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2986 hda_nid_t pin, hda_nid_t dac)
2987{
2988 hda_nid_t srcs[5];
2989 int i, num;
2990
Takashi Iwaidc31b582012-02-17 17:27:53 +01002991 if (!pin || !dac)
2992 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002993 pin = alc_go_down_to_selector(codec, pin);
2994 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2995 for (i = 0; i < num; i++) {
2996 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2997 if (nid == dac)
2998 return true;
2999 }
3000 return false;
3001}
3002
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003003static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3004{
Takashi Iwai140547e2012-02-16 17:23:46 +01003005 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003006 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003007 hda_nid_t nid, nid_found, srcs[5];
3008 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01003009 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01003010 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003011 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003012 nid_found = 0;
3013 for (i = 0; i < num; i++) {
3014 if (srcs[i] == spec->mixer_nid)
3015 continue;
3016 nid = alc_auto_mix_to_dac(codec, srcs[i]);
3017 if (nid && !alc_is_dac_already_used(codec, nid)) {
3018 if (nid_found)
3019 return 0;
3020 nid_found = nid;
3021 }
3022 }
3023 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003024}
3025
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003026/* mark up volume and mute control NIDs: used during badness parsing and
3027 * at creating actual controls
3028 */
3029static inline unsigned int get_ctl_pos(unsigned int data)
3030{
3031 hda_nid_t nid = get_amp_nid_(data);
3032 unsigned int dir;
3033 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3034 return 0;
3035 dir = get_amp_direction_(data);
3036 return (nid << 1) | dir;
3037}
3038
3039#define is_ctl_used(bits, data) \
3040 test_bit(get_ctl_pos(data), bits)
3041#define mark_ctl_usage(bits, data) \
3042 set_bit(get_ctl_pos(data), bits)
3043
3044static void clear_vol_marks(struct hda_codec *codec)
3045{
3046 struct alc_spec *spec = codec->spec;
3047 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3048 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3049}
3050
3051/* badness definition */
3052enum {
3053 /* No primary DAC is found for the main output */
3054 BAD_NO_PRIMARY_DAC = 0x10000,
3055 /* No DAC is found for the extra output */
3056 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003057 /* No possible multi-ios */
3058 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003059 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003060 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003061 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003062 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003063 /* Primary DAC shared with main surrounds */
3064 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003065 /* Primary DAC shared with main CLFE */
3066 BAD_SHARED_CLFE = 0x10,
3067 /* Primary DAC shared with extra surrounds */
3068 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003069 /* Volume widget is shared */
3070 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003071};
3072
3073static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3074 hda_nid_t pin, hda_nid_t dac);
3075static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3076 hda_nid_t pin, hda_nid_t dac);
3077
3078static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3079 hda_nid_t dac)
3080{
3081 struct alc_spec *spec = codec->spec;
3082 hda_nid_t nid;
3083 unsigned int val;
3084 int badness = 0;
3085
3086 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3087 if (nid) {
3088 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3089 if (is_ctl_used(spec->vol_ctls, nid))
3090 badness += BAD_SHARED_VOL;
3091 else
3092 mark_ctl_usage(spec->vol_ctls, val);
3093 } else
3094 badness += BAD_SHARED_VOL;
3095 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3096 if (nid) {
3097 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3098 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3099 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3100 else
3101 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3102 if (is_ctl_used(spec->sw_ctls, val))
3103 badness += BAD_SHARED_VOL;
3104 else
3105 mark_ctl_usage(spec->sw_ctls, val);
3106 } else
3107 badness += BAD_SHARED_VOL;
3108 return badness;
3109}
3110
Takashi Iwaidc31b582012-02-17 17:27:53 +01003111struct badness_table {
3112 int no_primary_dac; /* no primary DAC */
3113 int no_dac; /* no secondary DACs */
3114 int shared_primary; /* primary DAC is shared with main output */
3115 int shared_surr; /* secondary DAC shared with main or primary */
3116 int shared_clfe; /* third DAC shared with main or primary */
3117 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3118};
3119
3120static struct badness_table main_out_badness = {
3121 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3122 .no_dac = BAD_NO_DAC,
3123 .shared_primary = BAD_NO_PRIMARY_DAC,
3124 .shared_surr = BAD_SHARED_SURROUND,
3125 .shared_clfe = BAD_SHARED_CLFE,
3126 .shared_surr_main = BAD_SHARED_SURROUND,
3127};
3128
3129static struct badness_table extra_out_badness = {
3130 .no_primary_dac = BAD_NO_DAC,
3131 .no_dac = BAD_NO_DAC,
3132 .shared_primary = BAD_NO_EXTRA_DAC,
3133 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3134 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3135 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3136};
3137
3138/* try to assign DACs to pins and return the resultant badness */
3139static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3140 const hda_nid_t *pins, hda_nid_t *dacs,
3141 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003142{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003143 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003144 struct auto_pin_cfg *cfg = &spec->autocfg;
3145 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003146 int badness = 0;
3147 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003148
Takashi Iwai185d99f2012-02-16 18:39:45 +01003149 if (!num_outs)
3150 return 0;
3151
Takashi Iwaidc31b582012-02-17 17:27:53 +01003152 for (i = 0; i < num_outs; i++) {
3153 hda_nid_t pin = pins[i];
3154 if (!dacs[i])
3155 dacs[i] = alc_auto_look_for_dac(codec, pin);
3156 if (!dacs[i] && !i) {
3157 for (j = 1; j < num_outs; j++) {
3158 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3159 dacs[0] = dacs[j];
3160 dacs[j] = 0;
3161 break;
3162 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003163 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003164 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003165 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003166 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003167 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003168 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003169 else if (cfg->line_outs > i &&
3170 alc_auto_is_dac_reachable(codec, pin,
3171 spec->private_dac_nids[i]))
3172 dac = spec->private_dac_nids[i];
3173 if (dac) {
3174 if (!i)
3175 badness += bad->shared_primary;
3176 else if (i == 1)
3177 badness += bad->shared_surr;
3178 else
3179 badness += bad->shared_clfe;
3180 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003181 spec->private_dac_nids[0])) {
3182 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003183 badness += bad->shared_surr_main;
3184 } else if (!i)
3185 badness += bad->no_primary_dac;
3186 else
3187 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003188 }
3189 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003190 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003191 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003192
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003193 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003194}
3195
3196static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003197 hda_nid_t reference_pin,
3198 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003199
Takashi Iwai185d99f2012-02-16 18:39:45 +01003200static bool alc_map_singles(struct hda_codec *codec, int outs,
3201 const hda_nid_t *pins, hda_nid_t *dacs)
3202{
3203 int i;
3204 bool found = false;
3205 for (i = 0; i < outs; i++) {
3206 if (dacs[i])
3207 continue;
3208 dacs[i] = get_dac_if_single(codec, pins[i]);
3209 if (dacs[i])
3210 found = true;
3211 }
3212 return found;
3213}
3214
Takashi Iwai7085ec12009-10-02 09:03:58 +02003215/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003216static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003217 bool fill_hardwired,
3218 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003219{
3220 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003221 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003222 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003223
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003224 /* set num_dacs once to full for alc_auto_look_for_dac() */
3225 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003226 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003227 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3228 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3229 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003230 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003231 clear_vol_marks(codec);
3232 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003233
3234 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003235 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003236 bool mapped;
3237 do {
3238 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003239 cfg->line_out_pins,
3240 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003241 mapped |= alc_map_singles(codec, cfg->hp_outs,
3242 cfg->hp_pins,
3243 spec->multiout.hp_out_nid);
3244 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3245 cfg->speaker_pins,
3246 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003247 if (fill_mio_first && cfg->line_outs == 1 &&
3248 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3249 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3250 if (!err)
3251 mapped = true;
3252 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003253 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003254 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003255
Takashi Iwaidc31b582012-02-17 17:27:53 +01003256 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3257 spec->private_dac_nids,
3258 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003259
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003260 /* re-count num_dacs and squash invalid entries */
3261 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003262 for (i = 0; i < cfg->line_outs; i++) {
3263 if (spec->private_dac_nids[i])
3264 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003265 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003266 memmove(spec->private_dac_nids + i,
3267 spec->private_dac_nids + i + 1,
3268 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003269 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3270 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003271 }
3272
Takashi Iwai276dd702012-02-17 16:17:03 +01003273 if (fill_mio_first &&
3274 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003275 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003276 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003277 if (err < 0)
3278 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003279 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003280 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003281
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003282 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003283 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3284 spec->multiout.hp_out_nid,
3285 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003286 if (err < 0)
3287 return err;
3288 badness += err;
3289 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003290 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003291 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3292 cfg->speaker_pins,
3293 spec->multiout.extra_out_nid,
3294 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003295 if (err < 0)
3296 return err;
3297 badness += err;
3298 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003299 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3300 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003301 if (err < 0)
3302 return err;
3303 badness += err;
3304 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003305 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3306 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003307 int offset = 0;
3308 if (cfg->line_outs >= 3)
3309 offset = 1;
3310 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3311 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003312 if (err < 0)
3313 return err;
3314 badness += err;
3315 }
3316
3317 if (spec->multi_ios == 2) {
3318 for (i = 0; i < 2; i++)
3319 spec->private_dac_nids[spec->multiout.num_dacs++] =
3320 spec->multi_io[i].dac;
3321 spec->ext_channel_count = 2;
3322 } else if (spec->multi_ios) {
3323 spec->multi_ios = 0;
3324 badness += BAD_MULTI_IO;
3325 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003326
3327 return badness;
3328}
3329
3330#define DEBUG_BADNESS
3331
3332#ifdef DEBUG_BADNESS
3333#define debug_badness snd_printdd
3334#else
3335#define debug_badness(...)
3336#endif
3337
3338static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3339{
3340 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3341 cfg->line_out_pins[0], cfg->line_out_pins[1],
3342 cfg->line_out_pins[2], cfg->line_out_pins[2],
3343 spec->multiout.dac_nids[0],
3344 spec->multiout.dac_nids[1],
3345 spec->multiout.dac_nids[2],
3346 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003347 if (spec->multi_ios > 0)
3348 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3349 spec->multi_ios,
3350 spec->multi_io[0].pin, spec->multi_io[1].pin,
3351 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003352 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3353 cfg->hp_pins[0], cfg->hp_pins[1],
3354 cfg->hp_pins[2], cfg->hp_pins[2],
3355 spec->multiout.hp_out_nid[0],
3356 spec->multiout.hp_out_nid[1],
3357 spec->multiout.hp_out_nid[2],
3358 spec->multiout.hp_out_nid[3]);
3359 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3360 cfg->speaker_pins[0], cfg->speaker_pins[1],
3361 cfg->speaker_pins[2], cfg->speaker_pins[3],
3362 spec->multiout.extra_out_nid[0],
3363 spec->multiout.extra_out_nid[1],
3364 spec->multiout.extra_out_nid[2],
3365 spec->multiout.extra_out_nid[3]);
3366}
3367
3368static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3369{
3370 struct alc_spec *spec = codec->spec;
3371 struct auto_pin_cfg *cfg = &spec->autocfg;
3372 struct auto_pin_cfg *best_cfg;
3373 int best_badness = INT_MAX;
3374 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003375 bool fill_hardwired = true, fill_mio_first = true;
3376 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003377 bool hp_spk_swapped = false;
3378
3379 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3380 if (!best_cfg)
3381 return -ENOMEM;
3382 *best_cfg = *cfg;
3383
3384 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003385 badness = fill_and_eval_dacs(codec, fill_hardwired,
3386 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003387 if (badness < 0) {
3388 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003389 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003390 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003391 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3392 cfg->line_out_type, fill_hardwired, fill_mio_first,
3393 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003394 debug_show_configs(spec, cfg);
3395 if (badness < best_badness) {
3396 best_badness = badness;
3397 *best_cfg = *cfg;
3398 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003399 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003400 }
3401 if (!badness)
3402 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003403 fill_mio_first = !fill_mio_first;
3404 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003405 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003406 fill_hardwired = !fill_hardwired;
3407 if (!fill_hardwired)
3408 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003409 if (hp_spk_swapped)
3410 break;
3411 hp_spk_swapped = true;
3412 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003413 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3414 cfg->hp_outs = cfg->line_outs;
3415 memcpy(cfg->hp_pins, cfg->line_out_pins,
3416 sizeof(cfg->hp_pins));
3417 cfg->line_outs = cfg->speaker_outs;
3418 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3419 sizeof(cfg->speaker_pins));
3420 cfg->speaker_outs = 0;
3421 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3422 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003423 fill_hardwired = true;
3424 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003425 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003426 if (cfg->hp_outs > 0 &&
3427 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3428 cfg->speaker_outs = cfg->line_outs;
3429 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3430 sizeof(cfg->speaker_pins));
3431 cfg->line_outs = cfg->hp_outs;
3432 memcpy(cfg->line_out_pins, cfg->hp_pins,
3433 sizeof(cfg->hp_pins));
3434 cfg->hp_outs = 0;
3435 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3436 cfg->line_out_type = AUTO_PIN_HP_OUT;
3437 fill_hardwired = true;
3438 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003439 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003440 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003441 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003442
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003443 if (badness) {
3444 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003445 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003446 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003447 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3448 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003449 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003450
David Henningssonfde48a12011-12-09 18:27:42 +08003451 if (cfg->line_out_pins[0])
3452 spec->vmaster_nid =
3453 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3454 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003455
3456 /* clear the bitmap flags for creating controls */
3457 clear_vol_marks(codec);
3458 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003459 return 0;
3460}
3461
Takashi Iwai343a04b2011-07-06 14:28:39 +02003462static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003463 const char *pfx, int cidx,
3464 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003465{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003466 struct alc_spec *spec = codec->spec;
3467 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003468 if (!nid)
3469 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003470 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3471 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3472 return 0;
3473 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003474 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003475 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003476}
3477
Takashi Iwaie29d3772011-11-14 17:13:23 +01003478static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3479 const char *pfx, int cidx,
3480 hda_nid_t nid)
3481{
3482 int chs = 1;
3483 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3484 chs = 3;
3485 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3486}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003487
3488/* create a mute-switch for the given mixer widget;
3489 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3490 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003491static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003492 const char *pfx, int cidx,
3493 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003494{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003495 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003496 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003497 int type;
3498 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003499 if (!nid)
3500 return 0;
3501 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3502 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3503 type = ALC_CTL_WIDGET_MUTE;
3504 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3505 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003506 type = ALC_CTL_WIDGET_MUTE;
3507 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3508 } else {
3509 type = ALC_CTL_BIND_MUTE;
3510 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3511 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003512 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3513 return 0;
3514 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003515 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003516}
3517
Takashi Iwaie29d3772011-11-14 17:13:23 +01003518static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3519 int cidx, hda_nid_t nid)
3520{
3521 int chs = 1;
3522 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3523 chs = 3;
3524 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3525}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003526
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003527static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3528 hda_nid_t pin, hda_nid_t dac)
3529{
3530 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3531 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3532 return pin;
3533 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3534 return mix;
3535 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3536 return dac;
3537 return 0;
3538}
3539
3540static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3541 hda_nid_t pin, hda_nid_t dac)
3542{
3543 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3544 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3545 return dac;
3546 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3547 return mix;
3548 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3549 return pin;
3550 return 0;
3551}
3552
Takashi Iwai7085ec12009-10-02 09:03:58 +02003553/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003554static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003555 const struct auto_pin_cfg *cfg)
3556{
3557 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003558 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003559
Takashi Iwaice764ab2011-04-27 16:35:23 +02003560 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003561 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003562 noutputs += spec->multi_ios;
3563
3564 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003565 const char *name;
3566 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003567 hda_nid_t dac, pin;
3568 hda_nid_t sw, vol;
3569
3570 dac = spec->multiout.dac_nids[i];
3571 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003572 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003573 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003574 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003575 index = 0;
3576 name = channel_name[i];
3577 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003578 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003579 name = alc_get_line_out_pfx(spec, i, true, &index);
3580 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003581
3582 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3583 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003584 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003585 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003586 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003587 if (err < 0)
3588 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003589 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003590 if (err < 0)
3591 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003592 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003593 if (err < 0)
3594 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003595 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003596 if (err < 0)
3597 return err;
3598 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003599 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003600 if (err < 0)
3601 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003602 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003603 if (err < 0)
3604 return err;
3605 }
3606 }
3607 return 0;
3608}
3609
Takashi Iwai343a04b2011-07-06 14:28:39 +02003610static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003611 hda_nid_t dac, const char *pfx,
3612 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003613{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003614 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003615 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003616 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003617
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003618 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003619 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003620 /* the corresponding DAC is already occupied */
3621 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3622 return 0; /* no way */
3623 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003624 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3625 if (is_ctl_used(spec->sw_ctls, val))
3626 return 0; /* already created */
3627 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003628 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003629 }
3630
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003631 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3632 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003633 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003634 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003635 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003636 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003637 if (err < 0)
3638 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003639 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003640}
3641
Takashi Iwai23c09b02011-08-19 09:05:35 +02003642static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3643 unsigned int nums,
3644 struct hda_ctl_ops *ops)
3645{
3646 struct alc_spec *spec = codec->spec;
3647 struct hda_bind_ctls **ctlp, *ctl;
3648 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3649 ctlp = snd_array_new(&spec->bind_ctls);
3650 if (!ctlp)
3651 return NULL;
3652 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3653 *ctlp = ctl;
3654 if (ctl)
3655 ctl->ops = ops;
3656 return ctl;
3657}
3658
3659/* add playback controls for speaker and HP outputs */
3660static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3661 const hda_nid_t *pins,
3662 const hda_nid_t *dacs,
3663 const char *pfx)
3664{
3665 struct alc_spec *spec = codec->spec;
3666 struct hda_bind_ctls *ctl;
3667 char name[32];
3668 int i, n, err;
3669
3670 if (!num_pins || !pins[0])
3671 return 0;
3672
Takashi Iwai527e4d72011-10-27 16:33:27 +02003673 if (num_pins == 1) {
3674 hda_nid_t dac = *dacs;
3675 if (!dac)
3676 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003677 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003678 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003679
Takashi Iwai23c09b02011-08-19 09:05:35 +02003680 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003681 hda_nid_t dac;
3682 if (dacs[num_pins - 1])
3683 dac = dacs[i]; /* with individual volumes */
3684 else
3685 dac = 0;
3686 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3687 err = alc_auto_create_extra_out(codec, pins[i], dac,
3688 "Bass Speaker", 0);
3689 } else if (num_pins >= 3) {
3690 snprintf(name, sizeof(name), "%s %s",
3691 pfx, channel_name[i]);
3692 err = alc_auto_create_extra_out(codec, pins[i], dac,
3693 name, 0);
3694 } else {
3695 err = alc_auto_create_extra_out(codec, pins[i], dac,
3696 pfx, i);
3697 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003698 if (err < 0)
3699 return err;
3700 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003701 if (dacs[num_pins - 1])
3702 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003703
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003704 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003705 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3706 if (!ctl)
3707 return -ENOMEM;
3708 n = 0;
3709 for (i = 0; i < num_pins; i++) {
3710 hda_nid_t vol;
3711 if (!pins[i] || !dacs[i])
3712 continue;
3713 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3714 if (vol)
3715 ctl->values[n++] =
3716 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3717 }
3718 if (n) {
3719 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3720 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3721 if (err < 0)
3722 return err;
3723 }
3724 return 0;
3725}
3726
Takashi Iwai343a04b2011-07-06 14:28:39 +02003727static int alc_auto_create_hp_out(struct hda_codec *codec)
3728{
3729 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003730 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3731 spec->autocfg.hp_pins,
3732 spec->multiout.hp_out_nid,
3733 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003734}
3735
3736static int alc_auto_create_speaker_out(struct hda_codec *codec)
3737{
3738 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003739 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3740 spec->autocfg.speaker_pins,
3741 spec->multiout.extra_out_nid,
3742 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003743}
3744
Takashi Iwai343a04b2011-07-06 14:28:39 +02003745static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003746 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003747 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003748{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003749 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003750 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003751 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003752
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003753 alc_set_pin_output(codec, pin, pin_type);
3754 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003755 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003756 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003757 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003758 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003759 mix = srcs[i];
3760 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003761 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003762 if (!mix)
3763 return;
3764
3765 /* need the manual connection? */
3766 if (num > 1)
3767 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3768 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003769 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3770 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003771 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003772 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003773 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003774 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003775 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003776 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3777 if (nid)
3778 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3779 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003780
3781 /* unmute DAC if it's not assigned to a mixer */
3782 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3783 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3784 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3785 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003786}
3787
Takashi Iwai343a04b2011-07-06 14:28:39 +02003788static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003789{
3790 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003791 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003792 int i;
3793
3794 for (i = 0; i <= HDA_SIDE; i++) {
3795 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3796 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003797 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003798 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003799 }
3800}
3801
Takashi Iwai343a04b2011-07-06 14:28:39 +02003802static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003803{
3804 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003805 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003806 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003807
David Henningsson636030e2011-10-12 19:26:03 +02003808 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003809 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3810 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003811 pin = spec->autocfg.hp_pins[i];
3812 if (!pin)
3813 break;
3814 dac = spec->multiout.hp_out_nid[i];
3815 if (!dac) {
3816 if (i > 0 && spec->multiout.hp_out_nid[0])
3817 dac = spec->multiout.hp_out_nid[0];
3818 else
3819 dac = spec->multiout.dac_nids[0];
3820 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003821 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3822 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003823 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003824 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3825 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003826 pin = spec->autocfg.speaker_pins[i];
3827 if (!pin)
3828 break;
3829 dac = spec->multiout.extra_out_nid[i];
3830 if (!dac) {
3831 if (i > 0 && spec->multiout.extra_out_nid[0])
3832 dac = spec->multiout.extra_out_nid[0];
3833 else
3834 dac = spec->multiout.dac_nids[0];
3835 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003836 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3837 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003838}
3839
Takashi Iwai276dd702012-02-17 16:17:03 +01003840/* check whether the given pin can be a multi-io pin */
3841static bool can_be_multiio_pin(struct hda_codec *codec,
3842 unsigned int location, hda_nid_t nid)
3843{
3844 unsigned int defcfg, caps;
3845
3846 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3847 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3848 return false;
3849 if (location && get_defcfg_location(defcfg) != location)
3850 return false;
3851 caps = snd_hda_query_pin_caps(codec, nid);
3852 if (!(caps & AC_PINCAP_OUT))
3853 return false;
3854 return true;
3855}
3856
Takashi Iwaice764ab2011-04-27 16:35:23 +02003857/*
3858 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003859 *
3860 * When hardwired is set, try to fill ony hardwired pins, and returns
3861 * zero if any pins are filled, non-zero if nothing found.
3862 * When hardwired is off, try to fill possible input pins, and returns
3863 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003864 */
3865static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003866 hda_nid_t reference_pin,
3867 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003868{
3869 struct alc_spec *spec = codec->spec;
3870 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003871 int type, i, j, dacs, num_pins, old_pins;
3872 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3873 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003874 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003875
Takashi Iwai276dd702012-02-17 16:17:03 +01003876 old_pins = spec->multi_ios;
3877 if (old_pins >= 2)
3878 goto end_fill;
3879
3880 num_pins = 0;
3881 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3882 for (i = 0; i < cfg->num_inputs; i++) {
3883 if (cfg->inputs[i].type != type)
3884 continue;
3885 if (can_be_multiio_pin(codec, location,
3886 cfg->inputs[i].pin))
3887 num_pins++;
3888 }
3889 }
3890 if (num_pins < 2)
3891 goto end_fill;
3892
Takashi Iwai07b18f62011-11-10 15:42:54 +01003893 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003894 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3895 for (i = 0; i < cfg->num_inputs; i++) {
3896 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003897 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003898
Takashi Iwaice764ab2011-04-27 16:35:23 +02003899 if (cfg->inputs[i].type != type)
3900 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003901 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003902 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003903 for (j = 0; j < spec->multi_ios; j++) {
3904 if (nid == spec->multi_io[j].pin)
3905 break;
3906 }
3907 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003908 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003909
3910 if (offset && offset + spec->multi_ios < dacs) {
3911 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003912 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3913 dac = 0;
3914 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003915 if (hardwired)
3916 dac = get_dac_if_single(codec, nid);
3917 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003918 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003919 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003920 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003921 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003922 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003923 spec->multi_io[spec->multi_ios].pin = nid;
3924 spec->multi_io[spec->multi_ios].dac = dac;
3925 spec->multi_ios++;
3926 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003927 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003928 }
3929 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003930 end_fill:
3931 if (badness)
3932 badness = BAD_MULTI_IO;
3933 if (old_pins == spec->multi_ios) {
3934 if (hardwired)
3935 return 1; /* nothing found */
3936 else
3937 return badness; /* no badness if nothing found */
3938 }
3939 if (!hardwired && spec->multi_ios < 2) {
3940 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003941 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003942 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003943
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003944 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003945}
3946
3947static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3948 struct snd_ctl_elem_info *uinfo)
3949{
3950 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3951 struct alc_spec *spec = codec->spec;
3952
3953 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3954 uinfo->count = 1;
3955 uinfo->value.enumerated.items = spec->multi_ios + 1;
3956 if (uinfo->value.enumerated.item > spec->multi_ios)
3957 uinfo->value.enumerated.item = spec->multi_ios;
3958 sprintf(uinfo->value.enumerated.name, "%dch",
3959 (uinfo->value.enumerated.item + 1) * 2);
3960 return 0;
3961}
3962
3963static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3964 struct snd_ctl_elem_value *ucontrol)
3965{
3966 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3967 struct alc_spec *spec = codec->spec;
3968 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3969 return 0;
3970}
3971
3972static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3973{
3974 struct alc_spec *spec = codec->spec;
3975 hda_nid_t nid = spec->multi_io[idx].pin;
3976
3977 if (!spec->multi_io[idx].ctl_in)
3978 spec->multi_io[idx].ctl_in =
3979 snd_hda_codec_read(codec, nid, 0,
3980 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3981 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003982 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003983 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3984 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3985 HDA_AMP_MUTE, 0);
3986 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3987 } else {
3988 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3989 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3990 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003991 snd_hda_set_pin_ctl_cache(codec, nid,
3992 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003993 }
3994 return 0;
3995}
3996
3997static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3998 struct snd_ctl_elem_value *ucontrol)
3999{
4000 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4001 struct alc_spec *spec = codec->spec;
4002 int i, ch;
4003
4004 ch = ucontrol->value.enumerated.item[0];
4005 if (ch < 0 || ch > spec->multi_ios)
4006 return -EINVAL;
4007 if (ch == (spec->ext_channel_count - 1) / 2)
4008 return 0;
4009 spec->ext_channel_count = (ch + 1) * 2;
4010 for (i = 0; i < spec->multi_ios; i++)
4011 alc_set_multi_io(codec, i, i < ch);
4012 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004013 if (spec->need_dac_fix && !spec->const_channel_count)
4014 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004015 return 1;
4016}
4017
Takashi Iwaia9111322011-05-02 11:30:18 +02004018static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004019 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4020 .name = "Channel Mode",
4021 .info = alc_auto_ch_mode_info,
4022 .get = alc_auto_ch_mode_get,
4023 .put = alc_auto_ch_mode_put,
4024};
4025
Takashi Iwai23c09b02011-08-19 09:05:35 +02004026static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004027{
4028 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004029
Takashi Iwaic2674682011-08-24 17:57:44 +02004030 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004031 struct snd_kcontrol_new *knew;
4032
4033 knew = alc_kcontrol_new(spec);
4034 if (!knew)
4035 return -ENOMEM;
4036 *knew = alc_auto_channel_mode_enum;
4037 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4038 if (!knew->name)
4039 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004040 }
4041 return 0;
4042}
4043
Takashi Iwai1d045db2011-07-07 18:23:21 +02004044/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4045 * active input pins
4046 */
4047static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4048{
4049 struct alc_spec *spec = codec->spec;
4050 const struct hda_input_mux *imux;
4051 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4052 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4053 int i, n, nums;
4054
4055 imux = spec->input_mux;
4056 if (!imux)
4057 return;
4058 if (spec->dyn_adc_switch)
4059 return;
4060
Takashi Iwai26acaf02012-03-22 14:36:50 +01004061 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004062 nums = 0;
4063 for (n = 0; n < spec->num_adc_nids; n++) {
4064 hda_nid_t cap = spec->private_capsrc_nids[n];
4065 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4066 for (i = 0; i < imux->num_items; i++) {
4067 hda_nid_t pin = spec->imux_pins[i];
4068 if (pin) {
4069 if (get_connection_index(codec, cap, pin) < 0)
4070 break;
4071 } else if (num_conns <= imux->items[i].index)
4072 break;
4073 }
4074 if (i >= imux->num_items) {
4075 adc_nids[nums] = spec->private_adc_nids[n];
4076 capsrc_nids[nums++] = cap;
4077 }
4078 }
4079 if (!nums) {
4080 /* check whether ADC-switch is possible */
4081 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004082 if (spec->shared_mic_hp) {
4083 spec->shared_mic_hp = 0;
4084 spec->private_imux[0].num_items = 1;
4085 goto again;
4086 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004087 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4088 " using fallback 0x%x\n",
4089 codec->chip_name, spec->private_adc_nids[0]);
4090 spec->num_adc_nids = 1;
4091 spec->auto_mic = 0;
4092 return;
4093 }
4094 } else if (nums != spec->num_adc_nids) {
4095 memcpy(spec->private_adc_nids, adc_nids,
4096 nums * sizeof(hda_nid_t));
4097 memcpy(spec->private_capsrc_nids, capsrc_nids,
4098 nums * sizeof(hda_nid_t));
4099 spec->num_adc_nids = nums;
4100 }
4101
4102 if (spec->auto_mic)
4103 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004104 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004105 spec->num_adc_nids = 1; /* reduce to a single ADC */
4106}
4107
4108/*
4109 * initialize ADC paths
4110 */
4111static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4112{
4113 struct alc_spec *spec = codec->spec;
4114 hda_nid_t nid;
4115
4116 nid = spec->adc_nids[adc_idx];
4117 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004118 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004119 snd_hda_codec_write(codec, nid, 0,
4120 AC_VERB_SET_AMP_GAIN_MUTE,
4121 AMP_IN_MUTE(0));
4122 return;
4123 }
4124 if (!spec->capsrc_nids)
4125 return;
4126 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004127 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004128 snd_hda_codec_write(codec, nid, 0,
4129 AC_VERB_SET_AMP_GAIN_MUTE,
4130 AMP_OUT_MUTE);
4131}
4132
4133static void alc_auto_init_input_src(struct hda_codec *codec)
4134{
4135 struct alc_spec *spec = codec->spec;
4136 int c, nums;
4137
4138 for (c = 0; c < spec->num_adc_nids; c++)
4139 alc_auto_init_adc(codec, c);
4140 if (spec->dyn_adc_switch)
4141 nums = 1;
4142 else
4143 nums = spec->num_adc_nids;
4144 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004145 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004146}
4147
4148/* add mic boosts if needed */
4149static int alc_auto_add_mic_boost(struct hda_codec *codec)
4150{
4151 struct alc_spec *spec = codec->spec;
4152 struct auto_pin_cfg *cfg = &spec->autocfg;
4153 int i, err;
4154 int type_idx = 0;
4155 hda_nid_t nid;
4156 const char *prev_label = NULL;
4157
4158 for (i = 0; i < cfg->num_inputs; i++) {
4159 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4160 break;
4161 nid = cfg->inputs[i].pin;
4162 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4163 const char *label;
4164 char boost_label[32];
4165
4166 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004167 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4168 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004169 if (prev_label && !strcmp(label, prev_label))
4170 type_idx++;
4171 else
4172 type_idx = 0;
4173 prev_label = label;
4174
4175 snprintf(boost_label, sizeof(boost_label),
4176 "%s Boost Volume", label);
4177 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4178 boost_label, type_idx,
4179 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4180 if (err < 0)
4181 return err;
4182 }
4183 }
4184 return 0;
4185}
4186
4187/* select or unmute the given capsrc route */
4188static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4189 int idx)
4190{
4191 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4192 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4193 HDA_AMP_MUTE, 0);
4194 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4195 snd_hda_codec_write_cache(codec, cap, 0,
4196 AC_VERB_SET_CONNECT_SEL, idx);
4197 }
4198}
4199
4200/* set the default connection to that pin */
4201static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4202{
4203 struct alc_spec *spec = codec->spec;
4204 int i;
4205
4206 if (!pin)
4207 return 0;
4208 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004209 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004210 int idx;
4211
4212 idx = get_connection_index(codec, cap, pin);
4213 if (idx < 0)
4214 continue;
4215 select_or_unmute_capsrc(codec, cap, idx);
4216 return i; /* return the found index */
4217 }
4218 return -1; /* not found */
4219}
4220
4221/* initialize some special cases for input sources */
4222static void alc_init_special_input_src(struct hda_codec *codec)
4223{
4224 struct alc_spec *spec = codec->spec;
4225 int i;
4226
4227 for (i = 0; i < spec->autocfg.num_inputs; i++)
4228 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4229}
4230
4231/* assign appropriate capture mixers */
4232static void set_capture_mixer(struct hda_codec *codec)
4233{
4234 struct alc_spec *spec = codec->spec;
4235 static const struct snd_kcontrol_new *caps[2][3] = {
4236 { alc_capture_mixer_nosrc1,
4237 alc_capture_mixer_nosrc2,
4238 alc_capture_mixer_nosrc3 },
4239 { alc_capture_mixer1,
4240 alc_capture_mixer2,
4241 alc_capture_mixer3 },
4242 };
4243
4244 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004245 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004246 if (!spec->capsrc_nids)
4247 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004248 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004249 return; /* no volume in capsrc, too */
4250 spec->vol_in_capsrc = 1;
4251 }
4252
4253 if (spec->num_adc_nids > 0) {
4254 int mux = 0;
4255 int num_adcs = 0;
4256
4257 if (spec->input_mux && spec->input_mux->num_items > 1)
4258 mux = 1;
4259 if (spec->auto_mic) {
4260 num_adcs = 1;
4261 mux = 0;
4262 } else if (spec->dyn_adc_switch)
4263 num_adcs = 1;
4264 if (!num_adcs) {
4265 if (spec->num_adc_nids > 3)
4266 spec->num_adc_nids = 3;
4267 else if (!spec->num_adc_nids)
4268 return;
4269 num_adcs = spec->num_adc_nids;
4270 }
4271 spec->cap_mixer = caps[mux][num_adcs - 1];
4272 }
4273}
4274
4275/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004276 * standard auto-parser initializations
4277 */
4278static void alc_auto_init_std(struct hda_codec *codec)
4279{
4280 struct alc_spec *spec = codec->spec;
4281 alc_auto_init_multi_out(codec);
4282 alc_auto_init_extra_out(codec);
4283 alc_auto_init_analog_input(codec);
4284 alc_auto_init_input_src(codec);
4285 alc_auto_init_digital(codec);
4286 if (spec->unsol_event)
4287 alc_inithook(codec);
4288}
4289
4290/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004291 * Digital-beep handlers
4292 */
4293#ifdef CONFIG_SND_HDA_INPUT_BEEP
4294#define set_beep_amp(spec, nid, idx, dir) \
4295 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4296
4297static const struct snd_pci_quirk beep_white_list[] = {
4298 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4299 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4300 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4301 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004302 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004303 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4304 {}
4305};
4306
4307static inline int has_cdefine_beep(struct hda_codec *codec)
4308{
4309 struct alc_spec *spec = codec->spec;
4310 const struct snd_pci_quirk *q;
4311 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4312 if (q)
4313 return q->value;
4314 return spec->cdefine.enable_pcbeep;
4315}
4316#else
4317#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4318#define has_cdefine_beep(codec) 0
4319#endif
4320
4321/* parse the BIOS configuration and set up the alc_spec */
4322/* return 1 if successful, 0 if the proper config is not found,
4323 * or a negative error code
4324 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004325static int alc_parse_auto_config(struct hda_codec *codec,
4326 const hda_nid_t *ignore_nids,
4327 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004328{
4329 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004330 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004331 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004332
Takashi Iwai53c334a2011-08-23 18:27:14 +02004333 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4334 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004335 if (err < 0)
4336 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004337 if (!cfg->line_outs) {
4338 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004339 spec->multiout.max_channels = 2;
4340 spec->no_analog = 1;
4341 goto dig_only;
4342 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004343 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004344 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004345
Takashi Iwai06503672011-10-06 08:27:19 +02004346 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4347 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004348 /* use HP as primary out */
4349 cfg->speaker_outs = cfg->line_outs;
4350 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4351 sizeof(cfg->speaker_pins));
4352 cfg->line_outs = cfg->hp_outs;
4353 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4354 cfg->hp_outs = 0;
4355 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4356 cfg->line_out_type = AUTO_PIN_HP_OUT;
4357 }
4358
Takashi Iwai1d045db2011-07-07 18:23:21 +02004359 err = alc_auto_fill_dac_nids(codec);
4360 if (err < 0)
4361 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004362 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004363 if (err < 0)
4364 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004365 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004366 if (err < 0)
4367 return err;
4368 err = alc_auto_create_hp_out(codec);
4369 if (err < 0)
4370 return err;
4371 err = alc_auto_create_speaker_out(codec);
4372 if (err < 0)
4373 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004374 err = alc_auto_create_shared_input(codec);
4375 if (err < 0)
4376 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004377 err = alc_auto_create_input_ctls(codec);
4378 if (err < 0)
4379 return err;
4380
4381 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4382
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004383 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004384 alc_auto_parse_digital(codec);
4385
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004386 if (!spec->no_analog)
4387 alc_remove_invalid_adc_nids(codec);
4388
4389 if (ssid_nids)
4390 alc_ssid_check(codec, ssid_nids);
4391
4392 if (!spec->no_analog) {
4393 alc_auto_check_switches(codec);
4394 err = alc_auto_add_mic_boost(codec);
4395 if (err < 0)
4396 return err;
4397 }
4398
Takashi Iwai1d045db2011-07-07 18:23:21 +02004399 if (spec->kctls.list)
4400 add_mixer(spec, spec->kctls.list);
4401
Takashi Iwai070cff42012-02-21 12:54:17 +01004402 if (!spec->no_analog && !spec->cap_mixer)
4403 set_capture_mixer(codec);
4404
Takashi Iwai1d045db2011-07-07 18:23:21 +02004405 return 1;
4406}
4407
Takashi Iwai3de95172012-05-07 18:03:15 +02004408/* common preparation job for alc_spec */
4409static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4410{
4411 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4412 int err;
4413
4414 if (!spec)
4415 return -ENOMEM;
4416 codec->spec = spec;
4417 spec->mixer_nid = mixer_nid;
4418
4419 err = alc_codec_rename_from_preset(codec);
4420 if (err < 0) {
4421 kfree(spec);
4422 return err;
4423 }
4424 return 0;
4425}
4426
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004427static int alc880_parse_auto_config(struct hda_codec *codec)
4428{
4429 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004430 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004431 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4432}
4433
Takashi Iwai1d045db2011-07-07 18:23:21 +02004434/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004435 * ALC880 fix-ups
4436 */
4437enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004438 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004439 ALC880_FIXUP_GPIO2,
4440 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004441 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004442 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004443 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004444 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004445 ALC880_FIXUP_VOL_KNOB,
4446 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004447 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004448 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004449 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004450 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004451 ALC880_FIXUP_3ST_BASE,
4452 ALC880_FIXUP_3ST,
4453 ALC880_FIXUP_3ST_DIG,
4454 ALC880_FIXUP_5ST_BASE,
4455 ALC880_FIXUP_5ST,
4456 ALC880_FIXUP_5ST_DIG,
4457 ALC880_FIXUP_6ST_BASE,
4458 ALC880_FIXUP_6ST,
4459 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004460};
4461
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004462/* enable the volume-knob widget support on NID 0x21 */
4463static void alc880_fixup_vol_knob(struct hda_codec *codec,
4464 const struct alc_fixup *fix, int action)
4465{
4466 if (action == ALC_FIXUP_ACT_PROBE)
4467 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4468}
4469
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004470static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004471 [ALC880_FIXUP_GPIO1] = {
4472 .type = ALC_FIXUP_VERBS,
4473 .v.verbs = alc_gpio1_init_verbs,
4474 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004475 [ALC880_FIXUP_GPIO2] = {
4476 .type = ALC_FIXUP_VERBS,
4477 .v.verbs = alc_gpio2_init_verbs,
4478 },
4479 [ALC880_FIXUP_MEDION_RIM] = {
4480 .type = ALC_FIXUP_VERBS,
4481 .v.verbs = (const struct hda_verb[]) {
4482 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4483 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4484 { }
4485 },
4486 .chained = true,
4487 .chain_id = ALC880_FIXUP_GPIO2,
4488 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004489 [ALC880_FIXUP_LG] = {
4490 .type = ALC_FIXUP_PINS,
4491 .v.pins = (const struct alc_pincfg[]) {
4492 /* disable bogus unused pins */
4493 { 0x16, 0x411111f0 },
4494 { 0x18, 0x411111f0 },
4495 { 0x1a, 0x411111f0 },
4496 { }
4497 }
4498 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004499 [ALC880_FIXUP_W810] = {
4500 .type = ALC_FIXUP_PINS,
4501 .v.pins = (const struct alc_pincfg[]) {
4502 /* disable bogus unused pins */
4503 { 0x17, 0x411111f0 },
4504 { }
4505 },
4506 .chained = true,
4507 .chain_id = ALC880_FIXUP_GPIO2,
4508 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004509 [ALC880_FIXUP_EAPD_COEF] = {
4510 .type = ALC_FIXUP_VERBS,
4511 .v.verbs = (const struct hda_verb[]) {
4512 /* change to EAPD mode */
4513 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4514 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4515 {}
4516 },
4517 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004518 [ALC880_FIXUP_TCL_S700] = {
4519 .type = ALC_FIXUP_VERBS,
4520 .v.verbs = (const struct hda_verb[]) {
4521 /* change to EAPD mode */
4522 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4523 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4524 {}
4525 },
4526 .chained = true,
4527 .chain_id = ALC880_FIXUP_GPIO2,
4528 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004529 [ALC880_FIXUP_VOL_KNOB] = {
4530 .type = ALC_FIXUP_FUNC,
4531 .v.func = alc880_fixup_vol_knob,
4532 },
4533 [ALC880_FIXUP_FUJITSU] = {
4534 /* override all pins as BIOS on old Amilo is broken */
4535 .type = ALC_FIXUP_PINS,
4536 .v.pins = (const struct alc_pincfg[]) {
4537 { 0x14, 0x0121411f }, /* HP */
4538 { 0x15, 0x99030120 }, /* speaker */
4539 { 0x16, 0x99030130 }, /* bass speaker */
4540 { 0x17, 0x411111f0 }, /* N/A */
4541 { 0x18, 0x411111f0 }, /* N/A */
4542 { 0x19, 0x01a19950 }, /* mic-in */
4543 { 0x1a, 0x411111f0 }, /* N/A */
4544 { 0x1b, 0x411111f0 }, /* N/A */
4545 { 0x1c, 0x411111f0 }, /* N/A */
4546 { 0x1d, 0x411111f0 }, /* N/A */
4547 { 0x1e, 0x01454140 }, /* SPDIF out */
4548 { }
4549 },
4550 .chained = true,
4551 .chain_id = ALC880_FIXUP_VOL_KNOB,
4552 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004553 [ALC880_FIXUP_F1734] = {
4554 /* almost compatible with FUJITSU, but no bass and SPDIF */
4555 .type = ALC_FIXUP_PINS,
4556 .v.pins = (const struct alc_pincfg[]) {
4557 { 0x14, 0x0121411f }, /* HP */
4558 { 0x15, 0x99030120 }, /* speaker */
4559 { 0x16, 0x411111f0 }, /* N/A */
4560 { 0x17, 0x411111f0 }, /* N/A */
4561 { 0x18, 0x411111f0 }, /* N/A */
4562 { 0x19, 0x01a19950 }, /* mic-in */
4563 { 0x1a, 0x411111f0 }, /* N/A */
4564 { 0x1b, 0x411111f0 }, /* N/A */
4565 { 0x1c, 0x411111f0 }, /* N/A */
4566 { 0x1d, 0x411111f0 }, /* N/A */
4567 { 0x1e, 0x411111f0 }, /* N/A */
4568 { }
4569 },
4570 .chained = true,
4571 .chain_id = ALC880_FIXUP_VOL_KNOB,
4572 },
Takashi Iwai817de922012-02-20 17:20:48 +01004573 [ALC880_FIXUP_UNIWILL] = {
4574 /* need to fix HP and speaker pins to be parsed correctly */
4575 .type = ALC_FIXUP_PINS,
4576 .v.pins = (const struct alc_pincfg[]) {
4577 { 0x14, 0x0121411f }, /* HP */
4578 { 0x15, 0x99030120 }, /* speaker */
4579 { 0x16, 0x99030130 }, /* bass speaker */
4580 { }
4581 },
4582 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004583 [ALC880_FIXUP_UNIWILL_DIG] = {
4584 .type = ALC_FIXUP_PINS,
4585 .v.pins = (const struct alc_pincfg[]) {
4586 /* disable bogus unused pins */
4587 { 0x17, 0x411111f0 },
4588 { 0x19, 0x411111f0 },
4589 { 0x1b, 0x411111f0 },
4590 { 0x1f, 0x411111f0 },
4591 { }
4592 }
4593 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004594 [ALC880_FIXUP_Z71V] = {
4595 .type = ALC_FIXUP_PINS,
4596 .v.pins = (const struct alc_pincfg[]) {
4597 /* set up the whole pins as BIOS is utterly broken */
4598 { 0x14, 0x99030120 }, /* speaker */
4599 { 0x15, 0x0121411f }, /* HP */
4600 { 0x16, 0x411111f0 }, /* N/A */
4601 { 0x17, 0x411111f0 }, /* N/A */
4602 { 0x18, 0x01a19950 }, /* mic-in */
4603 { 0x19, 0x411111f0 }, /* N/A */
4604 { 0x1a, 0x01813031 }, /* line-in */
4605 { 0x1b, 0x411111f0 }, /* N/A */
4606 { 0x1c, 0x411111f0 }, /* N/A */
4607 { 0x1d, 0x411111f0 }, /* N/A */
4608 { 0x1e, 0x0144111e }, /* SPDIF */
4609 { }
4610 }
4611 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004612 [ALC880_FIXUP_3ST_BASE] = {
4613 .type = ALC_FIXUP_PINS,
4614 .v.pins = (const struct alc_pincfg[]) {
4615 { 0x14, 0x01014010 }, /* line-out */
4616 { 0x15, 0x411111f0 }, /* N/A */
4617 { 0x16, 0x411111f0 }, /* N/A */
4618 { 0x17, 0x411111f0 }, /* N/A */
4619 { 0x18, 0x01a19c30 }, /* mic-in */
4620 { 0x19, 0x0121411f }, /* HP */
4621 { 0x1a, 0x01813031 }, /* line-in */
4622 { 0x1b, 0x02a19c40 }, /* front-mic */
4623 { 0x1c, 0x411111f0 }, /* N/A */
4624 { 0x1d, 0x411111f0 }, /* N/A */
4625 /* 0x1e is filled in below */
4626 { 0x1f, 0x411111f0 }, /* N/A */
4627 { }
4628 }
4629 },
4630 [ALC880_FIXUP_3ST] = {
4631 .type = ALC_FIXUP_PINS,
4632 .v.pins = (const struct alc_pincfg[]) {
4633 { 0x1e, 0x411111f0 }, /* N/A */
4634 { }
4635 },
4636 .chained = true,
4637 .chain_id = ALC880_FIXUP_3ST_BASE,
4638 },
4639 [ALC880_FIXUP_3ST_DIG] = {
4640 .type = ALC_FIXUP_PINS,
4641 .v.pins = (const struct alc_pincfg[]) {
4642 { 0x1e, 0x0144111e }, /* SPDIF */
4643 { }
4644 },
4645 .chained = true,
4646 .chain_id = ALC880_FIXUP_3ST_BASE,
4647 },
4648 [ALC880_FIXUP_5ST_BASE] = {
4649 .type = ALC_FIXUP_PINS,
4650 .v.pins = (const struct alc_pincfg[]) {
4651 { 0x14, 0x01014010 }, /* front */
4652 { 0x15, 0x411111f0 }, /* N/A */
4653 { 0x16, 0x01011411 }, /* CLFE */
4654 { 0x17, 0x01016412 }, /* surr */
4655 { 0x18, 0x01a19c30 }, /* mic-in */
4656 { 0x19, 0x0121411f }, /* HP */
4657 { 0x1a, 0x01813031 }, /* line-in */
4658 { 0x1b, 0x02a19c40 }, /* front-mic */
4659 { 0x1c, 0x411111f0 }, /* N/A */
4660 { 0x1d, 0x411111f0 }, /* N/A */
4661 /* 0x1e is filled in below */
4662 { 0x1f, 0x411111f0 }, /* N/A */
4663 { }
4664 }
4665 },
4666 [ALC880_FIXUP_5ST] = {
4667 .type = ALC_FIXUP_PINS,
4668 .v.pins = (const struct alc_pincfg[]) {
4669 { 0x1e, 0x411111f0 }, /* N/A */
4670 { }
4671 },
4672 .chained = true,
4673 .chain_id = ALC880_FIXUP_5ST_BASE,
4674 },
4675 [ALC880_FIXUP_5ST_DIG] = {
4676 .type = ALC_FIXUP_PINS,
4677 .v.pins = (const struct alc_pincfg[]) {
4678 { 0x1e, 0x0144111e }, /* SPDIF */
4679 { }
4680 },
4681 .chained = true,
4682 .chain_id = ALC880_FIXUP_5ST_BASE,
4683 },
4684 [ALC880_FIXUP_6ST_BASE] = {
4685 .type = ALC_FIXUP_PINS,
4686 .v.pins = (const struct alc_pincfg[]) {
4687 { 0x14, 0x01014010 }, /* front */
4688 { 0x15, 0x01016412 }, /* surr */
4689 { 0x16, 0x01011411 }, /* CLFE */
4690 { 0x17, 0x01012414 }, /* side */
4691 { 0x18, 0x01a19c30 }, /* mic-in */
4692 { 0x19, 0x02a19c40 }, /* front-mic */
4693 { 0x1a, 0x01813031 }, /* line-in */
4694 { 0x1b, 0x0121411f }, /* HP */
4695 { 0x1c, 0x411111f0 }, /* N/A */
4696 { 0x1d, 0x411111f0 }, /* N/A */
4697 /* 0x1e is filled in below */
4698 { 0x1f, 0x411111f0 }, /* N/A */
4699 { }
4700 }
4701 },
4702 [ALC880_FIXUP_6ST] = {
4703 .type = ALC_FIXUP_PINS,
4704 .v.pins = (const struct alc_pincfg[]) {
4705 { 0x1e, 0x411111f0 }, /* N/A */
4706 { }
4707 },
4708 .chained = true,
4709 .chain_id = ALC880_FIXUP_6ST_BASE,
4710 },
4711 [ALC880_FIXUP_6ST_DIG] = {
4712 .type = ALC_FIXUP_PINS,
4713 .v.pins = (const struct alc_pincfg[]) {
4714 { 0x1e, 0x0144111e }, /* SPDIF */
4715 { }
4716 },
4717 .chained = true,
4718 .chain_id = ALC880_FIXUP_6ST_BASE,
4719 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004720};
4721
4722static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004723 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004724 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004725 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4726 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004727 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004728 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004729 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004730 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004731 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004732 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004733 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004734 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004735 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004736 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004737 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004738 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4739 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4740 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004741 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004742
4743 /* Below is the copied entries from alc880_quirks.c.
4744 * It's not quite sure whether BIOS sets the correct pin-config table
4745 * on these machines, thus they are kept to be compatible with
4746 * the old static quirks. Once when it's confirmed to work without
4747 * these overrides, it'd be better to remove.
4748 */
4749 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4750 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4751 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4752 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4753 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4754 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4755 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4756 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4757 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4758 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4759 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4760 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4761 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4762 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4763 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4764 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4765 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4766 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4767 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4768 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4769 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4770 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4771 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4772 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4773 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4774 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4775 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4776 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4777 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4778 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4779 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4780 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4781 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4782 /* default Intel */
4783 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4784 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4785 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4786 {}
4787};
4788
4789static const struct alc_model_fixup alc880_fixup_models[] = {
4790 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4791 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4792 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4793 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4794 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4795 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004796 {}
4797};
4798
4799
4800/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004801 * OK, here we have finally the patch for ALC880
4802 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004803static int patch_alc880(struct hda_codec *codec)
4804{
4805 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004806 int err;
4807
Takashi Iwai3de95172012-05-07 18:03:15 +02004808 err = alc_alloc_spec(codec, 0x0b);
4809 if (err < 0)
4810 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004811
Takashi Iwai3de95172012-05-07 18:03:15 +02004812 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004813 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004814
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004815 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4816 alc880_fixups);
4817 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004818
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004819 /* automatic parse from the BIOS config */
4820 err = alc880_parse_auto_config(codec);
4821 if (err < 0)
4822 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004823
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004824 if (!spec->no_analog) {
4825 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004826 if (err < 0)
4827 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004828 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4829 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004830
Takashi Iwai1d045db2011-07-07 18:23:21 +02004831 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004832
Takashi Iwai589876e2012-02-20 15:47:55 +01004833 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4834
Takashi Iwai1d045db2011-07-07 18:23:21 +02004835 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004836
4837 error:
4838 alc_free(codec);
4839 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004840}
4841
4842
4843/*
4844 * ALC260 support
4845 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004846static int alc260_parse_auto_config(struct hda_codec *codec)
4847{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004848 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004849 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4850 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004851}
4852
Takashi Iwai1d045db2011-07-07 18:23:21 +02004853/*
4854 * Pin config fixes
4855 */
4856enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004857 ALC260_FIXUP_HP_DC5750,
4858 ALC260_FIXUP_HP_PIN_0F,
4859 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004860 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004861 ALC260_FIXUP_GPIO1_TOGGLE,
4862 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004863 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004864 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004865};
4866
Takashi Iwai20f7d922012-02-16 12:35:16 +01004867static void alc260_gpio1_automute(struct hda_codec *codec)
4868{
4869 struct alc_spec *spec = codec->spec;
4870 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4871 spec->hp_jack_present);
4872}
4873
4874static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4875 const struct alc_fixup *fix, int action)
4876{
4877 struct alc_spec *spec = codec->spec;
4878 if (action == ALC_FIXUP_ACT_PROBE) {
4879 /* although the machine has only one output pin, we need to
4880 * toggle GPIO1 according to the jack state
4881 */
4882 spec->automute_hook = alc260_gpio1_automute;
4883 spec->detect_hp = 1;
4884 spec->automute_speaker = 1;
4885 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4886 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4887 spec->unsol_event = alc_sku_unsol_event;
4888 add_verb(codec->spec, alc_gpio1_init_verbs);
4889 }
4890}
4891
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004892static void alc260_fixup_kn1(struct hda_codec *codec,
4893 const struct alc_fixup *fix, int action)
4894{
4895 struct alc_spec *spec = codec->spec;
4896 static const struct alc_pincfg pincfgs[] = {
4897 { 0x0f, 0x02214000 }, /* HP/speaker */
4898 { 0x12, 0x90a60160 }, /* int mic */
4899 { 0x13, 0x02a19000 }, /* ext mic */
4900 { 0x18, 0x01446000 }, /* SPDIF out */
4901 /* disable bogus I/O pins */
4902 { 0x10, 0x411111f0 },
4903 { 0x11, 0x411111f0 },
4904 { 0x14, 0x411111f0 },
4905 { 0x15, 0x411111f0 },
4906 { 0x16, 0x411111f0 },
4907 { 0x17, 0x411111f0 },
4908 { 0x19, 0x411111f0 },
4909 { }
4910 };
4911
4912 switch (action) {
4913 case ALC_FIXUP_ACT_PRE_PROBE:
4914 alc_apply_pincfgs(codec, pincfgs);
4915 break;
4916 case ALC_FIXUP_ACT_PROBE:
4917 spec->init_amp = ALC_INIT_NONE;
4918 break;
4919 }
4920}
4921
Takashi Iwai1d045db2011-07-07 18:23:21 +02004922static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004923 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004924 .type = ALC_FIXUP_PINS,
4925 .v.pins = (const struct alc_pincfg[]) {
4926 { 0x11, 0x90130110 }, /* speaker */
4927 { }
4928 }
4929 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004930 [ALC260_FIXUP_HP_PIN_0F] = {
4931 .type = ALC_FIXUP_PINS,
4932 .v.pins = (const struct alc_pincfg[]) {
4933 { 0x0f, 0x01214000 }, /* HP */
4934 { }
4935 }
4936 },
4937 [ALC260_FIXUP_COEF] = {
4938 .type = ALC_FIXUP_VERBS,
4939 .v.verbs = (const struct hda_verb[]) {
4940 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4941 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4942 { }
4943 },
4944 .chained = true,
4945 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4946 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004947 [ALC260_FIXUP_GPIO1] = {
4948 .type = ALC_FIXUP_VERBS,
4949 .v.verbs = alc_gpio1_init_verbs,
4950 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004951 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4952 .type = ALC_FIXUP_FUNC,
4953 .v.func = alc260_fixup_gpio1_toggle,
4954 .chained = true,
4955 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4956 },
4957 [ALC260_FIXUP_REPLACER] = {
4958 .type = ALC_FIXUP_VERBS,
4959 .v.verbs = (const struct hda_verb[]) {
4960 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4961 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4962 { }
4963 },
4964 .chained = true,
4965 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4966 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004967 [ALC260_FIXUP_HP_B1900] = {
4968 .type = ALC_FIXUP_FUNC,
4969 .v.func = alc260_fixup_gpio1_toggle,
4970 .chained = true,
4971 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004972 },
4973 [ALC260_FIXUP_KN1] = {
4974 .type = ALC_FIXUP_FUNC,
4975 .v.func = alc260_fixup_kn1,
4976 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004977};
4978
4979static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004980 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004981 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004982 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004983 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004984 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004985 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004986 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004987 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004988 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989 {}
4990};
4991
4992/*
4993 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004994static int patch_alc260(struct hda_codec *codec)
4995{
4996 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004997 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004998
Takashi Iwai3de95172012-05-07 18:03:15 +02004999 err = alc_alloc_spec(codec, 0x07);
5000 if (err < 0)
5001 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005002
Takashi Iwai3de95172012-05-07 18:03:15 +02005003 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005004
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005005 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5006 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005007
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005008 /* automatic parse from the BIOS config */
5009 err = alc260_parse_auto_config(codec);
5010 if (err < 0)
5011 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005012
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005013 if (!spec->no_analog) {
5014 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005015 if (err < 0)
5016 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005017 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5018 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005019
Takashi Iwai1d045db2011-07-07 18:23:21 +02005020 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005021 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005022
Takashi Iwai589876e2012-02-20 15:47:55 +01005023 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5024
Takashi Iwai1d045db2011-07-07 18:23:21 +02005025 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005026
5027 error:
5028 alc_free(codec);
5029 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005030}
5031
5032
5033/*
5034 * ALC882/883/885/888/889 support
5035 *
5036 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5037 * configuration. Each pin widget can choose any input DACs and a mixer.
5038 * Each ADC is connected from a mixer of all inputs. This makes possible
5039 * 6-channel independent captures.
5040 *
5041 * In addition, an independent DAC for the multi-playback (not used in this
5042 * driver yet).
5043 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005044
5045/*
5046 * Pin config fixes
5047 */
5048enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005049 ALC882_FIXUP_ABIT_AW9D_MAX,
5050 ALC882_FIXUP_LENOVO_Y530,
5051 ALC882_FIXUP_PB_M5210,
5052 ALC882_FIXUP_ACER_ASPIRE_7736,
5053 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005054 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005055 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005056 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005057 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005058 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005059 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005060 ALC882_FIXUP_GPIO1,
5061 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005062 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005063 ALC889_FIXUP_COEF,
5064 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005065 ALC882_FIXUP_ACER_ASPIRE_4930G,
5066 ALC882_FIXUP_ACER_ASPIRE_8930G,
5067 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005068 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005069 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005070 ALC889_FIXUP_MBP_VREF,
5071 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005072};
5073
Takashi Iwai68ef0562011-11-09 18:24:44 +01005074static void alc889_fixup_coef(struct hda_codec *codec,
5075 const struct alc_fixup *fix, int action)
5076{
5077 if (action != ALC_FIXUP_ACT_INIT)
5078 return;
5079 alc889_coef_init(codec);
5080}
5081
Takashi Iwai56710872011-11-14 17:42:11 +01005082/* toggle speaker-output according to the hp-jack state */
5083static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5084{
5085 unsigned int gpiostate, gpiomask, gpiodir;
5086
5087 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5088 AC_VERB_GET_GPIO_DATA, 0);
5089
5090 if (!muted)
5091 gpiostate |= (1 << pin);
5092 else
5093 gpiostate &= ~(1 << pin);
5094
5095 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5096 AC_VERB_GET_GPIO_MASK, 0);
5097 gpiomask |= (1 << pin);
5098
5099 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5100 AC_VERB_GET_GPIO_DIRECTION, 0);
5101 gpiodir |= (1 << pin);
5102
5103
5104 snd_hda_codec_write(codec, codec->afg, 0,
5105 AC_VERB_SET_GPIO_MASK, gpiomask);
5106 snd_hda_codec_write(codec, codec->afg, 0,
5107 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5108
5109 msleep(1);
5110
5111 snd_hda_codec_write(codec, codec->afg, 0,
5112 AC_VERB_SET_GPIO_DATA, gpiostate);
5113}
5114
5115/* set up GPIO at initialization */
5116static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5117 const struct alc_fixup *fix, int action)
5118{
5119 if (action != ALC_FIXUP_ACT_INIT)
5120 return;
5121 alc882_gpio_mute(codec, 0, 0);
5122 alc882_gpio_mute(codec, 1, 0);
5123}
5124
Takashi Iwai02a237b2012-02-13 15:25:07 +01005125/* Fix the connection of some pins for ALC889:
5126 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5127 * work correctly (bko#42740)
5128 */
5129static void alc889_fixup_dac_route(struct hda_codec *codec,
5130 const struct alc_fixup *fix, int action)
5131{
5132 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005133 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005134 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5135 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5136 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5137 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5138 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5139 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005140 } else if (action == ALC_FIXUP_ACT_PROBE) {
5141 /* restore the connections */
5142 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5143 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5144 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5145 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5146 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005147 }
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;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005167 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005168 spec->keep_vref_in_automute = 1;
5169 break;
5170 }
5171}
5172
5173/* Set VREF on speaker pins on imac91 */
5174static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5175 const struct alc_fixup *fix, int action)
5176{
5177 struct alc_spec *spec = codec->spec;
5178 static hda_nid_t nids[2] = { 0x18, 0x1a };
5179 int i;
5180
5181 if (action != ALC_FIXUP_ACT_INIT)
5182 return;
5183 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5184 unsigned int val;
5185 val = snd_hda_codec_read(codec, nids[i], 0,
5186 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5187 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005188 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005189 }
5190 spec->keep_vref_in_automute = 1;
5191}
5192
Takashi Iwai1d045db2011-07-07 18:23:21 +02005193static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005194 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005195 .type = ALC_FIXUP_PINS,
5196 .v.pins = (const struct alc_pincfg[]) {
5197 { 0x15, 0x01080104 }, /* side */
5198 { 0x16, 0x01011012 }, /* rear */
5199 { 0x17, 0x01016011 }, /* clfe */
5200 { }
5201 }
5202 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005203 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005204 .type = ALC_FIXUP_PINS,
5205 .v.pins = (const struct alc_pincfg[]) {
5206 { 0x15, 0x99130112 }, /* rear int speakers */
5207 { 0x16, 0x99130111 }, /* subwoofer */
5208 { }
5209 }
5210 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005211 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005212 .type = ALC_FIXUP_VERBS,
5213 .v.verbs = (const struct hda_verb[]) {
5214 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5215 {}
5216 }
5217 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005218 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005219 .type = ALC_FIXUP_SKU,
5220 .v.sku = ALC_FIXUP_SKU_IGNORE,
5221 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005222 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005223 .type = ALC_FIXUP_PINS,
5224 .v.pins = (const struct alc_pincfg[]) {
5225 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5226 { }
5227 }
5228 },
Marton Balint8f239212012-03-05 21:33:23 +01005229 [ALC889_FIXUP_CD] = {
5230 .type = ALC_FIXUP_PINS,
5231 .v.pins = (const struct alc_pincfg[]) {
5232 { 0x1c, 0x993301f0 }, /* CD */
5233 { }
5234 }
5235 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005236 [ALC889_FIXUP_VAIO_TT] = {
5237 .type = ALC_FIXUP_PINS,
5238 .v.pins = (const struct alc_pincfg[]) {
5239 { 0x17, 0x90170111 }, /* hidden surround speaker */
5240 { }
5241 }
5242 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005243 [ALC888_FIXUP_EEE1601] = {
5244 .type = ALC_FIXUP_VERBS,
5245 .v.verbs = (const struct hda_verb[]) {
5246 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5247 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5248 { }
5249 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005250 },
5251 [ALC882_FIXUP_EAPD] = {
5252 .type = ALC_FIXUP_VERBS,
5253 .v.verbs = (const struct hda_verb[]) {
5254 /* change to EAPD mode */
5255 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5256 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5257 { }
5258 }
5259 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005260 [ALC883_FIXUP_EAPD] = {
5261 .type = ALC_FIXUP_VERBS,
5262 .v.verbs = (const struct hda_verb[]) {
5263 /* change to EAPD mode */
5264 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5265 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5266 { }
5267 }
5268 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005269 [ALC883_FIXUP_ACER_EAPD] = {
5270 .type = ALC_FIXUP_VERBS,
5271 .v.verbs = (const struct hda_verb[]) {
5272 /* eanable EAPD on Acer laptops */
5273 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5274 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5275 { }
5276 }
5277 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005278 [ALC882_FIXUP_GPIO1] = {
5279 .type = ALC_FIXUP_VERBS,
5280 .v.verbs = alc_gpio1_init_verbs,
5281 },
5282 [ALC882_FIXUP_GPIO2] = {
5283 .type = ALC_FIXUP_VERBS,
5284 .v.verbs = alc_gpio2_init_verbs,
5285 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005286 [ALC882_FIXUP_GPIO3] = {
5287 .type = ALC_FIXUP_VERBS,
5288 .v.verbs = alc_gpio3_init_verbs,
5289 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005290 [ALC882_FIXUP_ASUS_W2JC] = {
5291 .type = ALC_FIXUP_VERBS,
5292 .v.verbs = alc_gpio1_init_verbs,
5293 .chained = true,
5294 .chain_id = ALC882_FIXUP_EAPD,
5295 },
5296 [ALC889_FIXUP_COEF] = {
5297 .type = ALC_FIXUP_FUNC,
5298 .v.func = alc889_fixup_coef,
5299 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005300 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5301 .type = ALC_FIXUP_PINS,
5302 .v.pins = (const struct alc_pincfg[]) {
5303 { 0x16, 0x99130111 }, /* CLFE speaker */
5304 { 0x17, 0x99130112 }, /* surround speaker */
5305 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005306 },
5307 .chained = true,
5308 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005309 },
5310 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5311 .type = ALC_FIXUP_PINS,
5312 .v.pins = (const struct alc_pincfg[]) {
5313 { 0x16, 0x99130111 }, /* CLFE speaker */
5314 { 0x1b, 0x99130112 }, /* surround speaker */
5315 { }
5316 },
5317 .chained = true,
5318 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5319 },
5320 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5321 /* additional init verbs for Acer Aspire 8930G */
5322 .type = ALC_FIXUP_VERBS,
5323 .v.verbs = (const struct hda_verb[]) {
5324 /* Enable all DACs */
5325 /* DAC DISABLE/MUTE 1? */
5326 /* setting bits 1-5 disables DAC nids 0x02-0x06
5327 * apparently. Init=0x38 */
5328 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5329 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5330 /* DAC DISABLE/MUTE 2? */
5331 /* some bit here disables the other DACs.
5332 * Init=0x4900 */
5333 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5334 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5335 /* DMIC fix
5336 * This laptop has a stereo digital microphone.
5337 * The mics are only 1cm apart which makes the stereo
5338 * useless. However, either the mic or the ALC889
5339 * makes the signal become a difference/sum signal
5340 * instead of standard stereo, which is annoying.
5341 * So instead we flip this bit which makes the
5342 * codec replicate the sum signal to both channels,
5343 * turning it into a normal mono mic.
5344 */
5345 /* DMIC_CONTROL? Init value = 0x0001 */
5346 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5347 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5348 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5349 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5350 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005351 },
5352 .chained = true,
5353 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005354 },
Takashi Iwai56710872011-11-14 17:42:11 +01005355 [ALC885_FIXUP_MACPRO_GPIO] = {
5356 .type = ALC_FIXUP_FUNC,
5357 .v.func = alc885_fixup_macpro_gpio,
5358 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005359 [ALC889_FIXUP_DAC_ROUTE] = {
5360 .type = ALC_FIXUP_FUNC,
5361 .v.func = alc889_fixup_dac_route,
5362 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005363 [ALC889_FIXUP_MBP_VREF] = {
5364 .type = ALC_FIXUP_FUNC,
5365 .v.func = alc889_fixup_mbp_vref,
5366 .chained = true,
5367 .chain_id = ALC882_FIXUP_GPIO1,
5368 },
5369 [ALC889_FIXUP_IMAC91_VREF] = {
5370 .type = ALC_FIXUP_FUNC,
5371 .v.func = alc889_fixup_imac91_vref,
5372 .chained = true,
5373 .chain_id = ALC882_FIXUP_GPIO1,
5374 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005375};
5376
5377static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005378 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5379 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5380 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5381 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5382 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5383 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005384 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5385 ALC882_FIXUP_ACER_ASPIRE_4930G),
5386 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5387 ALC882_FIXUP_ACER_ASPIRE_4930G),
5388 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5389 ALC882_FIXUP_ACER_ASPIRE_8930G),
5390 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5391 ALC882_FIXUP_ACER_ASPIRE_8930G),
5392 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5393 ALC882_FIXUP_ACER_ASPIRE_4930G),
5394 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5395 ALC882_FIXUP_ACER_ASPIRE_4930G),
5396 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5397 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005398 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005399 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5400 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005401 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005402 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005403 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005404 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005405 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005406 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005407 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005408 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005409
5410 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005411 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5412 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5413 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005414 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5415 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5416 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005417 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5418 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005419 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005420 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5421 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5422 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5423 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005424 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005425 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5426 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5427 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005428 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005429 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5430 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5431 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005432
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005433 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005434 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005435 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005436 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005437 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005438 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5439 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005440 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005441 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005442 {}
5443};
5444
Takashi Iwai912093b2012-04-11 14:03:41 +02005445static const struct alc_model_fixup alc882_fixup_models[] = {
5446 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5447 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5448 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
5449 {}
5450};
5451
Takashi Iwai1d045db2011-07-07 18:23:21 +02005452/*
5453 * BIOS auto configuration
5454 */
5455/* almost identical with ALC880 parser... */
5456static int alc882_parse_auto_config(struct hda_codec *codec)
5457{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005458 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005459 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5460 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005461}
5462
Takashi Iwai1d045db2011-07-07 18:23:21 +02005463/*
5464 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005465static int patch_alc882(struct hda_codec *codec)
5466{
5467 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005468 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005469
Takashi Iwai3de95172012-05-07 18:03:15 +02005470 err = alc_alloc_spec(codec, 0x0b);
5471 if (err < 0)
5472 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005473
Takashi Iwai3de95172012-05-07 18:03:15 +02005474 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005475
5476 switch (codec->vendor_id) {
5477 case 0x10ec0882:
5478 case 0x10ec0885:
5479 break;
5480 default:
5481 /* ALC883 and variants */
5482 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5483 break;
5484 }
5485
Takashi Iwai912093b2012-04-11 14:03:41 +02005486 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5487 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005488 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489
5490 alc_auto_parse_customize_define(codec);
5491
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005492 /* automatic parse from the BIOS config */
5493 err = alc882_parse_auto_config(codec);
5494 if (err < 0)
5495 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005496
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005497 if (!spec->no_analog && has_cdefine_beep(codec)) {
5498 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005499 if (err < 0)
5500 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005501 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005502 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005503
Takashi Iwai1d045db2011-07-07 18:23:21 +02005504 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505
Takashi Iwai589876e2012-02-20 15:47:55 +01005506 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5507
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005509
5510 error:
5511 alc_free(codec);
5512 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005513}
5514
5515
5516/*
5517 * ALC262 support
5518 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005519static int alc262_parse_auto_config(struct hda_codec *codec)
5520{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005521 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005522 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5523 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005524}
5525
5526/*
5527 * Pin config fixes
5528 */
5529enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005530 ALC262_FIXUP_FSC_H270,
5531 ALC262_FIXUP_HP_Z200,
5532 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005533 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005534 ALC262_FIXUP_BENQ,
5535 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005536};
5537
5538static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005539 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005540 .type = ALC_FIXUP_PINS,
5541 .v.pins = (const struct alc_pincfg[]) {
5542 { 0x14, 0x99130110 }, /* speaker */
5543 { 0x15, 0x0221142f }, /* front HP */
5544 { 0x1b, 0x0121141f }, /* rear HP */
5545 { }
5546 }
5547 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005548 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005549 .type = ALC_FIXUP_PINS,
5550 .v.pins = (const struct alc_pincfg[]) {
5551 { 0x16, 0x99130120 }, /* internal speaker */
5552 { }
5553 }
5554 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005555 [ALC262_FIXUP_TYAN] = {
5556 .type = ALC_FIXUP_PINS,
5557 .v.pins = (const struct alc_pincfg[]) {
5558 { 0x14, 0x1993e1f0 }, /* int AUX */
5559 { }
5560 }
5561 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005562 [ALC262_FIXUP_LENOVO_3000] = {
5563 .type = ALC_FIXUP_VERBS,
5564 .v.verbs = (const struct hda_verb[]) {
5565 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005566 {}
5567 },
5568 .chained = true,
5569 .chain_id = ALC262_FIXUP_BENQ,
5570 },
5571 [ALC262_FIXUP_BENQ] = {
5572 .type = ALC_FIXUP_VERBS,
5573 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005574 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5575 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5576 {}
5577 }
5578 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005579 [ALC262_FIXUP_BENQ_T31] = {
5580 .type = ALC_FIXUP_VERBS,
5581 .v.verbs = (const struct hda_verb[]) {
5582 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5583 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5584 {}
5585 }
5586 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005587};
5588
5589static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005590 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005591 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5592 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005593 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5594 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005595 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005596 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5597 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005598 {}
5599};
5600
5601
Takashi Iwai1d045db2011-07-07 18:23:21 +02005602/*
5603 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604static int patch_alc262(struct hda_codec *codec)
5605{
5606 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005607 int err;
5608
Takashi Iwai3de95172012-05-07 18:03:15 +02005609 err = alc_alloc_spec(codec, 0x0b);
5610 if (err < 0)
5611 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005612
Takashi Iwai3de95172012-05-07 18:03:15 +02005613 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005614
5615#if 0
5616 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5617 * under-run
5618 */
5619 {
5620 int tmp;
5621 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5622 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5623 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5624 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5625 }
5626#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005627 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5628
Takashi Iwai42399f72011-11-07 17:18:44 +01005629 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5630 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005631
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005632 alc_auto_parse_customize_define(codec);
5633
Takashi Iwai42399f72011-11-07 17:18:44 +01005634 /* automatic parse from the BIOS config */
5635 err = alc262_parse_auto_config(codec);
5636 if (err < 0)
5637 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005638
Takashi Iwai1d045db2011-07-07 18:23:21 +02005639 if (!spec->no_analog && has_cdefine_beep(codec)) {
5640 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005641 if (err < 0)
5642 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005644 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645
Takashi Iwai1d045db2011-07-07 18:23:21 +02005646 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005647 spec->shutup = alc_eapd_shutup;
5648
Takashi Iwai589876e2012-02-20 15:47:55 +01005649 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5650
Takashi Iwai1d045db2011-07-07 18:23:21 +02005651 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005652
5653 error:
5654 alc_free(codec);
5655 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656}
5657
5658/*
5659 * ALC268
5660 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661/* bind Beep switches of both NID 0x0f and 0x10 */
5662static const struct hda_bind_ctls alc268_bind_beep_sw = {
5663 .ops = &snd_hda_bind_sw,
5664 .values = {
5665 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5666 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5667 0
5668 },
5669};
5670
5671static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5672 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5673 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5674 { }
5675};
5676
5677/* set PCBEEP vol = 0, mute connections */
5678static const struct hda_verb alc268_beep_init_verbs[] = {
5679 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5680 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5681 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5682 { }
5683};
5684
5685/*
5686 * BIOS auto configuration
5687 */
5688static int alc268_parse_auto_config(struct hda_codec *codec)
5689{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005690 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005692 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5693 if (err > 0) {
5694 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5695 add_mixer(spec, alc268_beep_mixer);
5696 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005697 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005698 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005699 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005700}
5701
Takashi Iwai1d045db2011-07-07 18:23:21 +02005702/*
5703 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005704static int patch_alc268(struct hda_codec *codec)
5705{
5706 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005707 int i, has_beep, err;
5708
Takashi Iwai1d045db2011-07-07 18:23:21 +02005709 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005710 err = alc_alloc_spec(codec, 0);
5711 if (err < 0)
5712 return err;
5713
5714 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005715
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005716 /* automatic parse from the BIOS config */
5717 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005718 if (err < 0)
5719 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005720
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721 has_beep = 0;
5722 for (i = 0; i < spec->num_mixers; i++) {
5723 if (spec->mixers[i] == alc268_beep_mixer) {
5724 has_beep = 1;
5725 break;
5726 }
5727 }
5728
5729 if (has_beep) {
5730 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005731 if (err < 0)
5732 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005733 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5734 /* override the amp caps for beep generator */
5735 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5736 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5737 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5738 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5739 (0 << AC_AMPCAP_MUTE_SHIFT));
5740 }
5741
Takashi Iwai1d045db2011-07-07 18:23:21 +02005742 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743 spec->shutup = alc_eapd_shutup;
5744
Takashi Iwai1d045db2011-07-07 18:23:21 +02005745 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005746
5747 error:
5748 alc_free(codec);
5749 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750}
5751
5752/*
5753 * ALC269
5754 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005755static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5756 .substreams = 1,
5757 .channels_min = 2,
5758 .channels_max = 8,
5759 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5760 /* NID is set in alc_build_pcms */
5761 .ops = {
5762 .open = alc_playback_pcm_open,
5763 .prepare = alc_playback_pcm_prepare,
5764 .cleanup = alc_playback_pcm_cleanup
5765 },
5766};
5767
5768static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5769 .substreams = 1,
5770 .channels_min = 2,
5771 .channels_max = 2,
5772 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5773 /* NID is set in alc_build_pcms */
5774};
5775
Takashi Iwai1d045db2011-07-07 18:23:21 +02005776/* different alc269-variants */
5777enum {
5778 ALC269_TYPE_ALC269VA,
5779 ALC269_TYPE_ALC269VB,
5780 ALC269_TYPE_ALC269VC,
5781};
5782
5783/*
5784 * BIOS auto configuration
5785 */
5786static int alc269_parse_auto_config(struct hda_codec *codec)
5787{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005788 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005789 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5790 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5791 struct alc_spec *spec = codec->spec;
5792 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5793 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005794
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005795 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005796}
5797
Takashi Iwai1d045db2011-07-07 18:23:21 +02005798static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5799{
5800 int val = alc_read_coef_idx(codec, 0x04);
5801 if (power_up)
5802 val |= 1 << 11;
5803 else
5804 val &= ~(1 << 11);
5805 alc_write_coef_idx(codec, 0x04, val);
5806}
5807
5808static void alc269_shutup(struct hda_codec *codec)
5809{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005810 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005811 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005812 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005813 alc269_toggle_power_output(codec, 0);
5814 msleep(150);
5815 }
5816}
5817
Takashi Iwai2a439522011-07-26 09:52:50 +02005818#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005819static int alc269_resume(struct hda_codec *codec)
5820{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005821 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005822 alc269_toggle_power_output(codec, 0);
5823 msleep(150);
5824 }
5825
5826 codec->patch_ops.init(codec);
5827
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005828 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005829 alc269_toggle_power_output(codec, 1);
5830 msleep(200);
5831 }
5832
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005833 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005834 alc269_toggle_power_output(codec, 1);
5835
5836 snd_hda_codec_resume_amp(codec);
5837 snd_hda_codec_resume_cache(codec);
5838 hda_call_check_power_status(codec, 0x01);
5839 return 0;
5840}
Takashi Iwai2a439522011-07-26 09:52:50 +02005841#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005842
5843static void alc269_fixup_hweq(struct hda_codec *codec,
5844 const struct alc_fixup *fix, int action)
5845{
5846 int coef;
5847
5848 if (action != ALC_FIXUP_ACT_INIT)
5849 return;
5850 coef = alc_read_coef_idx(codec, 0x1e);
5851 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5852}
5853
5854static void alc271_fixup_dmic(struct hda_codec *codec,
5855 const struct alc_fixup *fix, int action)
5856{
5857 static const struct hda_verb verbs[] = {
5858 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5859 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5860 {}
5861 };
5862 unsigned int cfg;
5863
5864 if (strcmp(codec->chip_name, "ALC271X"))
5865 return;
5866 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5867 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5868 snd_hda_sequence_write(codec, verbs);
5869}
5870
Takashi Iwai017f2a12011-07-09 14:42:25 +02005871static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5872 const struct alc_fixup *fix, int action)
5873{
5874 struct alc_spec *spec = codec->spec;
5875
5876 if (action != ALC_FIXUP_ACT_PROBE)
5877 return;
5878
5879 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5880 * fix the sample rate of analog I/O to 44.1kHz
5881 */
5882 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5883 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5884}
5885
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005886static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5887 const struct alc_fixup *fix, int action)
5888{
5889 int coef;
5890
5891 if (action != ALC_FIXUP_ACT_INIT)
5892 return;
5893 /* The digital-mic unit sends PDM (differential signal) instead of
5894 * the standard PCM, thus you can't record a valid mono stream as is.
5895 * Below is a workaround specific to ALC269 to control the dmic
5896 * signal source as mono.
5897 */
5898 coef = alc_read_coef_idx(codec, 0x07);
5899 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5900}
5901
Takashi Iwai24519912011-08-16 15:08:49 +02005902static void alc269_quanta_automute(struct hda_codec *codec)
5903{
David Henningsson42cf0d02011-09-20 12:04:56 +02005904 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005905
5906 snd_hda_codec_write(codec, 0x20, 0,
5907 AC_VERB_SET_COEF_INDEX, 0x0c);
5908 snd_hda_codec_write(codec, 0x20, 0,
5909 AC_VERB_SET_PROC_COEF, 0x680);
5910
5911 snd_hda_codec_write(codec, 0x20, 0,
5912 AC_VERB_SET_COEF_INDEX, 0x0c);
5913 snd_hda_codec_write(codec, 0x20, 0,
5914 AC_VERB_SET_PROC_COEF, 0x480);
5915}
5916
5917static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5918 const struct alc_fixup *fix, int action)
5919{
5920 struct alc_spec *spec = codec->spec;
5921 if (action != ALC_FIXUP_ACT_PROBE)
5922 return;
5923 spec->automute_hook = alc269_quanta_automute;
5924}
5925
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005926/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5927static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5928{
5929 struct hda_codec *codec = private_data;
5930 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005931 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005932}
5933
5934static void alc269_fixup_mic2_mute(struct hda_codec *codec,
5935 const struct alc_fixup *fix, int action)
5936{
5937 struct alc_spec *spec = codec->spec;
5938 switch (action) {
5939 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005940 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01005941 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005942 /* fallthru */
5943 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005944 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005945 break;
5946 }
5947}
5948
Takashi Iwai1d045db2011-07-07 18:23:21 +02005949enum {
5950 ALC269_FIXUP_SONY_VAIO,
5951 ALC275_FIXUP_SONY_VAIO_GPIO2,
5952 ALC269_FIXUP_DELL_M101Z,
5953 ALC269_FIXUP_SKU_IGNORE,
5954 ALC269_FIXUP_ASUS_G73JW,
5955 ALC269_FIXUP_LENOVO_EAPD,
5956 ALC275_FIXUP_SONY_HWEQ,
5957 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005958 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005959 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005960 ALC269_FIXUP_QUANTA_MUTE,
5961 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005962 ALC269_FIXUP_AMIC,
5963 ALC269_FIXUP_DMIC,
5964 ALC269VB_FIXUP_AMIC,
5965 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005966 ALC269_FIXUP_MIC2_MUTE_LED,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005967};
5968
5969static const struct alc_fixup alc269_fixups[] = {
5970 [ALC269_FIXUP_SONY_VAIO] = {
5971 .type = ALC_FIXUP_VERBS,
5972 .v.verbs = (const struct hda_verb[]) {
5973 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5974 {}
5975 }
5976 },
5977 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5978 .type = ALC_FIXUP_VERBS,
5979 .v.verbs = (const struct hda_verb[]) {
5980 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5981 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5982 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5983 { }
5984 },
5985 .chained = true,
5986 .chain_id = ALC269_FIXUP_SONY_VAIO
5987 },
5988 [ALC269_FIXUP_DELL_M101Z] = {
5989 .type = ALC_FIXUP_VERBS,
5990 .v.verbs = (const struct hda_verb[]) {
5991 /* Enables internal speaker */
5992 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5993 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5994 {}
5995 }
5996 },
5997 [ALC269_FIXUP_SKU_IGNORE] = {
5998 .type = ALC_FIXUP_SKU,
5999 .v.sku = ALC_FIXUP_SKU_IGNORE,
6000 },
6001 [ALC269_FIXUP_ASUS_G73JW] = {
6002 .type = ALC_FIXUP_PINS,
6003 .v.pins = (const struct alc_pincfg[]) {
6004 { 0x17, 0x99130111 }, /* subwoofer */
6005 { }
6006 }
6007 },
6008 [ALC269_FIXUP_LENOVO_EAPD] = {
6009 .type = ALC_FIXUP_VERBS,
6010 .v.verbs = (const struct hda_verb[]) {
6011 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6012 {}
6013 }
6014 },
6015 [ALC275_FIXUP_SONY_HWEQ] = {
6016 .type = ALC_FIXUP_FUNC,
6017 .v.func = alc269_fixup_hweq,
6018 .chained = true,
6019 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6020 },
6021 [ALC271_FIXUP_DMIC] = {
6022 .type = ALC_FIXUP_FUNC,
6023 .v.func = alc271_fixup_dmic,
6024 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006025 [ALC269_FIXUP_PCM_44K] = {
6026 .type = ALC_FIXUP_FUNC,
6027 .v.func = alc269_fixup_pcm_44k,
6028 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006029 [ALC269_FIXUP_STEREO_DMIC] = {
6030 .type = ALC_FIXUP_FUNC,
6031 .v.func = alc269_fixup_stereo_dmic,
6032 },
Takashi Iwai24519912011-08-16 15:08:49 +02006033 [ALC269_FIXUP_QUANTA_MUTE] = {
6034 .type = ALC_FIXUP_FUNC,
6035 .v.func = alc269_fixup_quanta_mute,
6036 },
6037 [ALC269_FIXUP_LIFEBOOK] = {
6038 .type = ALC_FIXUP_PINS,
6039 .v.pins = (const struct alc_pincfg[]) {
6040 { 0x1a, 0x2101103f }, /* dock line-out */
6041 { 0x1b, 0x23a11040 }, /* dock mic-in */
6042 { }
6043 },
6044 .chained = true,
6045 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6046 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006047 [ALC269_FIXUP_AMIC] = {
6048 .type = ALC_FIXUP_PINS,
6049 .v.pins = (const struct alc_pincfg[]) {
6050 { 0x14, 0x99130110 }, /* speaker */
6051 { 0x15, 0x0121401f }, /* HP out */
6052 { 0x18, 0x01a19c20 }, /* mic */
6053 { 0x19, 0x99a3092f }, /* int-mic */
6054 { }
6055 },
6056 },
6057 [ALC269_FIXUP_DMIC] = {
6058 .type = ALC_FIXUP_PINS,
6059 .v.pins = (const struct alc_pincfg[]) {
6060 { 0x12, 0x99a3092f }, /* int-mic */
6061 { 0x14, 0x99130110 }, /* speaker */
6062 { 0x15, 0x0121401f }, /* HP out */
6063 { 0x18, 0x01a19c20 }, /* mic */
6064 { }
6065 },
6066 },
6067 [ALC269VB_FIXUP_AMIC] = {
6068 .type = ALC_FIXUP_PINS,
6069 .v.pins = (const struct alc_pincfg[]) {
6070 { 0x14, 0x99130110 }, /* speaker */
6071 { 0x18, 0x01a19c20 }, /* mic */
6072 { 0x19, 0x99a3092f }, /* int-mic */
6073 { 0x21, 0x0121401f }, /* HP out */
6074 { }
6075 },
6076 },
David Henningsson2267ea92012-01-03 08:45:56 +01006077 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006078 .type = ALC_FIXUP_PINS,
6079 .v.pins = (const struct alc_pincfg[]) {
6080 { 0x12, 0x99a3092f }, /* int-mic */
6081 { 0x14, 0x99130110 }, /* speaker */
6082 { 0x18, 0x01a19c20 }, /* mic */
6083 { 0x21, 0x0121401f }, /* HP out */
6084 { }
6085 },
6086 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006087 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6088 .type = ALC_FIXUP_FUNC,
6089 .v.func = alc269_fixup_mic2_mute,
6090 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006091};
6092
6093static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006094 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006095 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006096 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006097 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6098 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6099 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6100 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6101 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006102 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6103 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6104 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6105 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6106 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6107 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006108 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006109 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6110 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6111 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6112 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6113 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006114 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006115 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006116 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006117
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006118#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006119 /* Below is a quirk table taken from the old code.
6120 * Basically the device should work as is without the fixup table.
6121 * If BIOS doesn't give a proper info, enable the corresponding
6122 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006123 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006124 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6125 ALC269_FIXUP_AMIC),
6126 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006127 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6128 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6129 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6130 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6131 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6132 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6133 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6134 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6135 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6136 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6137 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6138 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6139 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6140 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6141 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6142 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6143 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6144 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6145 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6146 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6147 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6148 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6149 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6150 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6151 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6152 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6153 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6154 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6155 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6156 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6157 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6158 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6159 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6160 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6161 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6162 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6163 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6164 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6165#endif
6166 {}
6167};
6168
6169static const struct alc_model_fixup alc269_fixup_models[] = {
6170 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6171 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006172 {}
6173};
6174
6175
Takashi Iwai546bb672012-03-07 08:37:19 +01006176static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006177{
Kailang Yang526af6e2012-03-07 08:25:20 +01006178 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006179 int val;
6180
Kailang Yang526af6e2012-03-07 08:25:20 +01006181 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006182 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006183
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006184 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006185 alc_write_coef_idx(codec, 0xf, 0x960b);
6186 alc_write_coef_idx(codec, 0xe, 0x8817);
6187 }
6188
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006189 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006190 alc_write_coef_idx(codec, 0xf, 0x960b);
6191 alc_write_coef_idx(codec, 0xe, 0x8814);
6192 }
6193
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006194 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006195 val = alc_read_coef_idx(codec, 0x04);
6196 /* Power up output pin */
6197 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6198 }
6199
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006200 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006201 val = alc_read_coef_idx(codec, 0xd);
6202 if ((val & 0x0c00) >> 10 != 0x1) {
6203 /* Capless ramp up clock control */
6204 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6205 }
6206 val = alc_read_coef_idx(codec, 0x17);
6207 if ((val & 0x01c0) >> 6 != 0x4) {
6208 /* Class D power on reset */
6209 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6210 }
6211 }
6212
6213 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6214 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6215
6216 val = alc_read_coef_idx(codec, 0x4); /* HP */
6217 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006218}
6219
6220/*
6221 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006222static int patch_alc269(struct hda_codec *codec)
6223{
6224 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006225 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006226
Takashi Iwai3de95172012-05-07 18:03:15 +02006227 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006228 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006229 return err;
6230
6231 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006232
Takashi Iwai1d045db2011-07-07 18:23:21 +02006233 if (codec->vendor_id == 0x10ec0269) {
6234 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006235 switch (alc_get_coef0(codec) & 0x00f0) {
6236 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006237 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006238 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006239 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006240 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006241 break;
6242 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006243 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6244 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006245 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006246 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006247 break;
6248 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006249 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006250 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006251 if (err < 0)
6252 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006253 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006254 alc269_fill_coef(codec);
6255 }
6256
Takashi Iwaia4297b52011-08-23 18:40:12 +02006257 alc_pick_fixup(codec, alc269_fixup_models,
6258 alc269_fixup_tbl, alc269_fixups);
6259 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006260
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006261 alc_auto_parse_customize_define(codec);
6262
Takashi Iwaia4297b52011-08-23 18:40:12 +02006263 /* automatic parse from the BIOS config */
6264 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006265 if (err < 0)
6266 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006267
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006268 if (!spec->no_analog && has_cdefine_beep(codec)) {
6269 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006270 if (err < 0)
6271 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006272 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006273 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006274
Takashi Iwai1d045db2011-07-07 18:23:21 +02006275 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006276#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006277 codec->patch_ops.resume = alc269_resume;
6278#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006279 spec->shutup = alc269_shutup;
6280
Takashi Iwai589876e2012-02-20 15:47:55 +01006281 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6282
Takashi Iwai1d045db2011-07-07 18:23:21 +02006283 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006284
6285 error:
6286 alc_free(codec);
6287 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006288}
6289
6290/*
6291 * ALC861
6292 */
6293
Takashi Iwai1d045db2011-07-07 18:23:21 +02006294static int alc861_parse_auto_config(struct hda_codec *codec)
6295{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006296 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006297 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6298 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299}
6300
Takashi Iwai1d045db2011-07-07 18:23:21 +02006301/* Pin config fixes */
6302enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006303 ALC861_FIXUP_FSC_AMILO_PI1505,
6304 ALC861_FIXUP_AMP_VREF_0F,
6305 ALC861_FIXUP_NO_JACK_DETECT,
6306 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006307};
6308
Takashi Iwai31150f22012-01-30 10:54:08 +01006309/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6310static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6311 const struct alc_fixup *fix, int action)
6312{
6313 struct alc_spec *spec = codec->spec;
6314 unsigned int val;
6315
6316 if (action != ALC_FIXUP_ACT_INIT)
6317 return;
6318 val = snd_hda_codec_read(codec, 0x0f, 0,
6319 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6320 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6321 val |= AC_PINCTL_IN_EN;
6322 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006323 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006324 spec->keep_vref_in_automute = 1;
6325}
6326
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006327/* suppress the jack-detection */
6328static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6329 const struct alc_fixup *fix, int action)
6330{
6331 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6332 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006333}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006334
Takashi Iwai1d045db2011-07-07 18:23:21 +02006335static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006336 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006337 .type = ALC_FIXUP_PINS,
6338 .v.pins = (const struct alc_pincfg[]) {
6339 { 0x0b, 0x0221101f }, /* HP */
6340 { 0x0f, 0x90170310 }, /* speaker */
6341 { }
6342 }
6343 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006344 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006345 .type = ALC_FIXUP_FUNC,
6346 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006347 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006348 [ALC861_FIXUP_NO_JACK_DETECT] = {
6349 .type = ALC_FIXUP_FUNC,
6350 .v.func = alc_fixup_no_jack_detect,
6351 },
6352 [ALC861_FIXUP_ASUS_A6RP] = {
6353 .type = ALC_FIXUP_FUNC,
6354 .v.func = alc861_fixup_asus_amp_vref_0f,
6355 .chained = true,
6356 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6357 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006358};
6359
6360static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006361 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6362 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6363 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6364 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6365 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6366 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006367 {}
6368};
6369
6370/*
6371 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006372static int patch_alc861(struct hda_codec *codec)
6373{
6374 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006375 int err;
6376
Takashi Iwai3de95172012-05-07 18:03:15 +02006377 err = alc_alloc_spec(codec, 0x15);
6378 if (err < 0)
6379 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006380
Takashi Iwai3de95172012-05-07 18:03:15 +02006381 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006382
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006383 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6384 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006385
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006386 /* automatic parse from the BIOS config */
6387 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006388 if (err < 0)
6389 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006390
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006391 if (!spec->no_analog) {
6392 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006393 if (err < 0)
6394 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006395 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6396 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006397
Takashi Iwai1d045db2011-07-07 18:23:21 +02006398 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006399#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006400 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006401#endif
6402
Takashi Iwai589876e2012-02-20 15:47:55 +01006403 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6404
Takashi Iwai1d045db2011-07-07 18:23:21 +02006405 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006406
6407 error:
6408 alc_free(codec);
6409 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006410}
6411
6412/*
6413 * ALC861-VD support
6414 *
6415 * Based on ALC882
6416 *
6417 * In addition, an independent DAC
6418 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006419static int alc861vd_parse_auto_config(struct hda_codec *codec)
6420{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006421 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006422 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6423 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006424}
6425
Takashi Iwai1d045db2011-07-07 18:23:21 +02006426enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006427 ALC660VD_FIX_ASUS_GPIO1,
6428 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006429};
6430
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006431/* exclude VREF80 */
6432static void alc861vd_fixup_dallas(struct hda_codec *codec,
6433 const struct alc_fixup *fix, int action)
6434{
6435 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6436 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6437 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6438 }
6439}
6440
Takashi Iwai1d045db2011-07-07 18:23:21 +02006441static const struct alc_fixup alc861vd_fixups[] = {
6442 [ALC660VD_FIX_ASUS_GPIO1] = {
6443 .type = ALC_FIXUP_VERBS,
6444 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006445 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006446 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6447 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6448 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6449 { }
6450 }
6451 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006452 [ALC861VD_FIX_DALLAS] = {
6453 .type = ALC_FIXUP_FUNC,
6454 .v.func = alc861vd_fixup_dallas,
6455 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006456};
6457
6458static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006459 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006460 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006461 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006462 {}
6463};
6464
6465static const struct hda_verb alc660vd_eapd_verbs[] = {
6466 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6467 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6468 { }
6469};
6470
6471/*
6472 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006473static int patch_alc861vd(struct hda_codec *codec)
6474{
6475 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006476 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006477
Takashi Iwai3de95172012-05-07 18:03:15 +02006478 err = alc_alloc_spec(codec, 0x0b);
6479 if (err < 0)
6480 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006481
Takashi Iwai3de95172012-05-07 18:03:15 +02006482 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006483
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006484 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6485 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006486
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006487 /* automatic parse from the BIOS config */
6488 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006489 if (err < 0)
6490 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006491
Takashi Iwai1d045db2011-07-07 18:23:21 +02006492 if (codec->vendor_id == 0x10ec0660) {
6493 /* always turn on EAPD */
6494 add_verb(spec, alc660vd_eapd_verbs);
6495 }
6496
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006497 if (!spec->no_analog) {
6498 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006499 if (err < 0)
6500 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006501 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6502 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006503
Takashi Iwai1d045db2011-07-07 18:23:21 +02006504 codec->patch_ops = alc_patch_ops;
6505
Takashi Iwai1d045db2011-07-07 18:23:21 +02006506 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006507
Takashi Iwai589876e2012-02-20 15:47:55 +01006508 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6509
Takashi Iwai1d045db2011-07-07 18:23:21 +02006510 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006511
6512 error:
6513 alc_free(codec);
6514 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006515}
6516
6517/*
6518 * ALC662 support
6519 *
6520 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6521 * configuration. Each pin widget can choose any input DACs and a mixer.
6522 * Each ADC is connected from a mixer of all inputs. This makes possible
6523 * 6-channel independent captures.
6524 *
6525 * In addition, an independent DAC for the multi-playback (not used in this
6526 * driver yet).
6527 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006528
6529/*
6530 * BIOS auto configuration
6531 */
6532
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006533static int alc662_parse_auto_config(struct hda_codec *codec)
6534{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006535 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006536 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6537 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6538 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006539
Kailang Yang6227cdc2010-02-25 08:36:52 +01006540 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6541 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006542 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006543 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006544 ssids = alc662_ssids;
6545 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006546}
6547
Todd Broch6be79482010-12-07 16:51:05 -08006548static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006549 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006550{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006551 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006552 return;
Todd Broch6be79482010-12-07 16:51:05 -08006553 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6554 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6555 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6556 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6557 (0 << AC_AMPCAP_MUTE_SHIFT)))
6558 printk(KERN_WARNING
6559 "hda_codec: failed to override amp caps for NID 0x2\n");
6560}
6561
David Henningsson6cb3b702010-09-09 08:51:44 +02006562enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006563 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006564 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006565 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006566 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006567 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006568 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006569 ALC662_FIXUP_ASUS_MODE1,
6570 ALC662_FIXUP_ASUS_MODE2,
6571 ALC662_FIXUP_ASUS_MODE3,
6572 ALC662_FIXUP_ASUS_MODE4,
6573 ALC662_FIXUP_ASUS_MODE5,
6574 ALC662_FIXUP_ASUS_MODE6,
6575 ALC662_FIXUP_ASUS_MODE7,
6576 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006577 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006578};
6579
6580static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006581 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006582 .type = ALC_FIXUP_PINS,
6583 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006584 { 0x15, 0x99130112 }, /* subwoofer */
6585 { }
6586 }
6587 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006588 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006589 .type = ALC_FIXUP_PINS,
6590 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006591 { 0x17, 0x99130112 }, /* subwoofer */
6592 { }
6593 }
6594 },
Todd Broch6be79482010-12-07 16:51:05 -08006595 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006596 .type = ALC_FIXUP_FUNC,
6597 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006598 },
6599 [ALC662_FIXUP_CZC_P10T] = {
6600 .type = ALC_FIXUP_VERBS,
6601 .v.verbs = (const struct hda_verb[]) {
6602 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6603 {}
6604 }
6605 },
David Henningsson94024cd2011-04-29 14:10:55 +02006606 [ALC662_FIXUP_SKU_IGNORE] = {
6607 .type = ALC_FIXUP_SKU,
6608 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006609 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006610 [ALC662_FIXUP_HP_RP5800] = {
6611 .type = ALC_FIXUP_PINS,
6612 .v.pins = (const struct alc_pincfg[]) {
6613 { 0x14, 0x0221201f }, /* HP out */
6614 { }
6615 },
6616 .chained = true,
6617 .chain_id = ALC662_FIXUP_SKU_IGNORE
6618 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006619 [ALC662_FIXUP_ASUS_MODE1] = {
6620 .type = ALC_FIXUP_PINS,
6621 .v.pins = (const struct alc_pincfg[]) {
6622 { 0x14, 0x99130110 }, /* speaker */
6623 { 0x18, 0x01a19c20 }, /* mic */
6624 { 0x19, 0x99a3092f }, /* int-mic */
6625 { 0x21, 0x0121401f }, /* HP out */
6626 { }
6627 },
6628 .chained = true,
6629 .chain_id = ALC662_FIXUP_SKU_IGNORE
6630 },
6631 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006632 .type = ALC_FIXUP_PINS,
6633 .v.pins = (const struct alc_pincfg[]) {
6634 { 0x14, 0x99130110 }, /* speaker */
6635 { 0x18, 0x01a19820 }, /* mic */
6636 { 0x19, 0x99a3092f }, /* int-mic */
6637 { 0x1b, 0x0121401f }, /* HP out */
6638 { }
6639 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006640 .chained = true,
6641 .chain_id = ALC662_FIXUP_SKU_IGNORE
6642 },
6643 [ALC662_FIXUP_ASUS_MODE3] = {
6644 .type = ALC_FIXUP_PINS,
6645 .v.pins = (const struct alc_pincfg[]) {
6646 { 0x14, 0x99130110 }, /* speaker */
6647 { 0x15, 0x0121441f }, /* HP */
6648 { 0x18, 0x01a19840 }, /* mic */
6649 { 0x19, 0x99a3094f }, /* int-mic */
6650 { 0x21, 0x01211420 }, /* HP2 */
6651 { }
6652 },
6653 .chained = true,
6654 .chain_id = ALC662_FIXUP_SKU_IGNORE
6655 },
6656 [ALC662_FIXUP_ASUS_MODE4] = {
6657 .type = ALC_FIXUP_PINS,
6658 .v.pins = (const struct alc_pincfg[]) {
6659 { 0x14, 0x99130110 }, /* speaker */
6660 { 0x16, 0x99130111 }, /* speaker */
6661 { 0x18, 0x01a19840 }, /* mic */
6662 { 0x19, 0x99a3094f }, /* int-mic */
6663 { 0x21, 0x0121441f }, /* HP */
6664 { }
6665 },
6666 .chained = true,
6667 .chain_id = ALC662_FIXUP_SKU_IGNORE
6668 },
6669 [ALC662_FIXUP_ASUS_MODE5] = {
6670 .type = ALC_FIXUP_PINS,
6671 .v.pins = (const struct alc_pincfg[]) {
6672 { 0x14, 0x99130110 }, /* speaker */
6673 { 0x15, 0x0121441f }, /* HP */
6674 { 0x16, 0x99130111 }, /* speaker */
6675 { 0x18, 0x01a19840 }, /* mic */
6676 { 0x19, 0x99a3094f }, /* int-mic */
6677 { }
6678 },
6679 .chained = true,
6680 .chain_id = ALC662_FIXUP_SKU_IGNORE
6681 },
6682 [ALC662_FIXUP_ASUS_MODE6] = {
6683 .type = ALC_FIXUP_PINS,
6684 .v.pins = (const struct alc_pincfg[]) {
6685 { 0x14, 0x99130110 }, /* speaker */
6686 { 0x15, 0x01211420 }, /* HP2 */
6687 { 0x18, 0x01a19840 }, /* mic */
6688 { 0x19, 0x99a3094f }, /* int-mic */
6689 { 0x1b, 0x0121441f }, /* HP */
6690 { }
6691 },
6692 .chained = true,
6693 .chain_id = ALC662_FIXUP_SKU_IGNORE
6694 },
6695 [ALC662_FIXUP_ASUS_MODE7] = {
6696 .type = ALC_FIXUP_PINS,
6697 .v.pins = (const struct alc_pincfg[]) {
6698 { 0x14, 0x99130110 }, /* speaker */
6699 { 0x17, 0x99130111 }, /* speaker */
6700 { 0x18, 0x01a19840 }, /* mic */
6701 { 0x19, 0x99a3094f }, /* int-mic */
6702 { 0x1b, 0x01214020 }, /* HP */
6703 { 0x21, 0x0121401f }, /* HP */
6704 { }
6705 },
6706 .chained = true,
6707 .chain_id = ALC662_FIXUP_SKU_IGNORE
6708 },
6709 [ALC662_FIXUP_ASUS_MODE8] = {
6710 .type = ALC_FIXUP_PINS,
6711 .v.pins = (const struct alc_pincfg[]) {
6712 { 0x14, 0x99130110 }, /* speaker */
6713 { 0x12, 0x99a30970 }, /* int-mic */
6714 { 0x15, 0x01214020 }, /* HP */
6715 { 0x17, 0x99130111 }, /* speaker */
6716 { 0x18, 0x01a19840 }, /* mic */
6717 { 0x21, 0x0121401f }, /* HP */
6718 { }
6719 },
6720 .chained = true,
6721 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006722 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006723 [ALC662_FIXUP_NO_JACK_DETECT] = {
6724 .type = ALC_FIXUP_FUNC,
6725 .v.func = alc_fixup_no_jack_detect,
6726 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006727};
6728
Takashi Iwaia9111322011-05-02 11:30:18 +02006729static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006730 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006731 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006732 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006733 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006734 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006735 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006736 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006737 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006738 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006739 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006740 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006741
6742#if 0
6743 /* Below is a quirk table taken from the old code.
6744 * Basically the device should work as is without the fixup table.
6745 * If BIOS doesn't give a proper info, enable the corresponding
6746 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006747 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006748 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6749 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6750 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6751 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6752 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6753 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6754 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6755 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6756 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6757 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6758 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6759 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6760 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6761 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6762 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6763 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6764 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6765 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6766 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6767 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6768 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6769 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6770 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6771 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6772 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6773 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6774 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6775 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6776 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6777 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6778 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6779 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6780 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6781 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6782 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6783 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6784 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6785 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6786 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6787 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6788 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6789 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6790 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6791 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6792 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6793 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6794 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6795 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6796 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6797 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6798#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006799 {}
6800};
6801
Todd Broch6be79482010-12-07 16:51:05 -08006802static const struct alc_model_fixup alc662_fixup_models[] = {
6803 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006804 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6805 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6806 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6807 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6808 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6809 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6810 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6811 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006812 {}
6813};
David Henningsson6cb3b702010-09-09 08:51:44 +02006814
6815
Takashi Iwai1d045db2011-07-07 18:23:21 +02006816/*
6817 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006818static int patch_alc662(struct hda_codec *codec)
6819{
6820 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006821 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006822
Takashi Iwai3de95172012-05-07 18:03:15 +02006823 err = alc_alloc_spec(codec, 0x0b);
6824 if (err < 0)
6825 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006826
Takashi Iwai3de95172012-05-07 18:03:15 +02006827 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006828
Takashi Iwai53c334a2011-08-23 18:27:14 +02006829 /* handle multiple HPs as is */
6830 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6831
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006832 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6833
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006834 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006835 codec->bus->pci->subsystem_vendor == 0x1025 &&
6836 spec->cdefine.platform_type == 1) {
6837 if (alc_codec_rename(codec, "ALC272X") < 0)
6838 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006839 }
Kailang Yang274693f2009-12-03 10:07:50 +01006840
Takashi Iwaib9c51062011-08-24 18:08:07 +02006841 alc_pick_fixup(codec, alc662_fixup_models,
6842 alc662_fixup_tbl, alc662_fixups);
6843 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006844
6845 alc_auto_parse_customize_define(codec);
6846
Takashi Iwaib9c51062011-08-24 18:08:07 +02006847 /* automatic parse from the BIOS config */
6848 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006849 if (err < 0)
6850 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006851
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006852 if (!spec->no_analog && has_cdefine_beep(codec)) {
6853 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006854 if (err < 0)
6855 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006856 switch (codec->vendor_id) {
6857 case 0x10ec0662:
6858 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6859 break;
6860 case 0x10ec0272:
6861 case 0x10ec0663:
6862 case 0x10ec0665:
6863 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6864 break;
6865 case 0x10ec0273:
6866 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6867 break;
6868 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006869 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006870
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006871 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02006872 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006873
Takashi Iwai589876e2012-02-20 15:47:55 +01006874 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6875
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006876 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006877
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006878 error:
6879 alc_free(codec);
6880 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006881}
6882
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006883/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006884 * ALC680 support
6885 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006886
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006887static int alc680_parse_auto_config(struct hda_codec *codec)
6888{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006889 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006890}
6891
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006892/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006893 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006894static int patch_alc680(struct hda_codec *codec)
6895{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006896 int err;
6897
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006898 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006899 err = alc_alloc_spec(codec, 0);
6900 if (err < 0)
6901 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006902
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006903 /* automatic parse from the BIOS config */
6904 err = alc680_parse_auto_config(codec);
6905 if (err < 0) {
6906 alc_free(codec);
6907 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006908 }
6909
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006910 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006911
6912 return 0;
6913}
6914
6915/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006916 * patch entries
6917 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006918static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006919 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006920 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006921 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006922 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006923 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006924 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006925 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006926 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006927 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006928 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006929 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006930 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006931 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6932 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6933 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006934 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006935 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006936 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6937 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006938 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6939 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006940 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006941 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006942 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006943 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006944 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006945 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006946 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006947 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006948 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006949 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006950 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006951 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006952 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006953 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006954 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006955 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006956 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006957 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006958 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006959 {} /* terminator */
6960};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006961
6962MODULE_ALIAS("snd-hda-codec-id:10ec*");
6963
6964MODULE_LICENSE("GPL");
6965MODULE_DESCRIPTION("Realtek HD-audio codec");
6966
6967static struct hda_codec_preset_list realtek_list = {
6968 .preset = snd_hda_preset_realtek,
6969 .owner = THIS_MODULE,
6970};
6971
6972static int __init patch_realtek_init(void)
6973{
6974 return snd_hda_add_codec_preset(&realtek_list);
6975}
6976
6977static void __exit patch_realtek_exit(void)
6978{
6979 snd_hda_delete_codec_preset(&realtek_list);
6980}
6981
6982module_init(patch_realtek_init)
6983module_exit(patch_realtek_exit)