blob: e142f6f5c499313abebda0874cc589a2679ee5c7 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e482006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Takashi Iwaic14c95f2012-02-16 16:38:07 +010083#define MAX_VOL_NIDS 0x40
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085struct alc_spec {
86 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020089 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010090 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Takashi Iwai2d9c6482009-10-13 08:06:55 +020092 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020093 * don't forget NULL
94 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020095 */
96 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Takashi Iwaiaa563af2009-07-31 10:05:11 +020098 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020099 const struct hda_pcm_stream *stream_analog_playback;
100 const struct hda_pcm_stream *stream_analog_capture;
101 const struct hda_pcm_stream *stream_analog_alt_playback;
102 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200104 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200105 const struct hda_pcm_stream *stream_digital_playback;
106 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200109 struct hda_multi_out multiout; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
112 */
Takashi Iwai63300792008-01-24 15:31:36 +0100113 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100114 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100115 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 /* capture */
118 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200119 const hda_nid_t *adc_nids;
120 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200121 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200122 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwaic14c95f2012-02-16 16:38:07 +0100123 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
124 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Takashi Iwai840b64c2010-07-13 22:49:01 +0200126 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200127 hda_nid_t cur_adc;
128 unsigned int cur_adc_stream_tag;
129 unsigned int cur_adc_format;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200132 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 const struct hda_input_mux *input_mux;
134 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200135 hda_nid_t ext_mic_pin;
136 hda_nid_t dock_mic_pin;
137 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100140 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200142 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200143 int const_channel_count;
144 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100147 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200148
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100151 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200152 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200153 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200154 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200155 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
156 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200157 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
158 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
159 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100160
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100161 /* hooks */
162 void (*init_hook)(struct hda_codec *codec);
163 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500165 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100166#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200167 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200168 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100169
Takashi Iwai834be882006-03-01 14:16:17 +0100170 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200171 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200172 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200173 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200174 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200175 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200176 unsigned int automute_speaker:1; /* automute speaker outputs */
177 unsigned int automute_lo:1; /* automute LO outputs */
178 unsigned int detect_hp:1; /* Headphone detection enabled */
179 unsigned int detect_lo:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100182 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200183
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100184 /* other flags */
185 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200186 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100187 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200188 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200189 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100190 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200191
192 /* auto-mute control */
193 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200194 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200195
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200196 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200197 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100198
Takashi Iwai2134ea42008-01-10 16:53:55 +0100199 /* for virtual master */
200 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200201#ifdef CONFIG_SND_HDA_POWER_SAVE
202 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100203 int num_loopbacks;
204 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200205#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200206
207 /* for PLL fix */
208 hda_nid_t pll_nid;
209 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200210 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100211
212 /* fix-up list */
213 int fixup_id;
214 const struct alc_fixup *fixup_list;
215 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200216
217 /* multi-io */
218 int multi_ios;
219 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200220
221 /* bind volumes */
222 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100223};
224
Takashi Iwai44c02402011-07-08 15:14:19 +0200225static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
226 int dir, unsigned int bits)
227{
228 if (!nid)
229 return false;
230 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
231 if (query_amp_caps(codec, nid, dir) & bits)
232 return true;
233 return false;
234}
235
236#define nid_has_mute(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
238#define nid_has_volume(codec, nid, dir) \
239 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241/*
242 * input MUX handling
243 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200244static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
245 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
247 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
248 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200249 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
250 if (mux_idx >= spec->num_mux_defs)
251 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100252 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
253 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200254 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255}
256
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200257static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
258 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
261 struct alc_spec *spec = codec->spec;
262 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
263
264 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
265 return 0;
266}
267
Takashi Iwai21268962011-07-07 15:01:13 +0200268static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269{
Takashi Iwai21268962011-07-07 15:01:13 +0200270 struct alc_spec *spec = codec->spec;
271 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
272
273 if (spec->cur_adc && spec->cur_adc != new_adc) {
274 /* stream is running, let's swap the current ADC */
275 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
276 spec->cur_adc = new_adc;
277 snd_hda_codec_setup_stream(codec, new_adc,
278 spec->cur_adc_stream_tag, 0,
279 spec->cur_adc_format);
280 return true;
281 }
282 return false;
283}
284
Takashi Iwai61071592011-11-23 07:52:15 +0100285static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
286{
287 return spec->capsrc_nids ?
288 spec->capsrc_nids[idx] : spec->adc_nids[idx];
289}
290
Takashi Iwai24de1832011-11-07 17:13:39 +0100291static void call_update_outputs(struct hda_codec *codec);
292
Takashi Iwai21268962011-07-07 15:01:13 +0200293/* select the given imux item; either unmute exclusively or select the route */
294static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
295 unsigned int idx, bool force)
296{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100298 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100299 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100300 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200301 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302
Takashi Iwai5803a322012-02-21 11:59:45 +0100303 if (!spec->input_mux)
304 return 0;
305
Takashi Iwaicd896c32008-11-18 12:36:33 +0100306 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
307 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100308 if (!imux->num_items && mux_idx > 0)
309 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100310 if (!imux->num_items)
311 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100312
Takashi Iwai21268962011-07-07 15:01:13 +0200313 if (idx >= imux->num_items)
314 idx = imux->num_items - 1;
315 if (spec->cur_mux[adc_idx] == idx && !force)
316 return 0;
317 spec->cur_mux[adc_idx] = idx;
318
Takashi Iwai24de1832011-11-07 17:13:39 +0100319 /* for shared I/O, change the pin-control accordingly */
320 if (spec->shared_mic_hp) {
321 /* NOTE: this assumes that there are only two inputs, the
322 * first is the real internal mic and the second is HP jack.
323 */
324 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
325 AC_VERB_SET_PIN_WIDGET_CONTROL,
326 spec->cur_mux[adc_idx] ?
327 PIN_VREF80 : PIN_HP);
328 spec->automute_speaker = !spec->cur_mux[adc_idx];
329 call_update_outputs(codec);
330 }
331
Takashi Iwai21268962011-07-07 15:01:13 +0200332 if (spec->dyn_adc_switch) {
333 alc_dyn_adc_pcm_resetup(codec, idx);
334 adc_idx = spec->dyn_adc_idx[idx];
335 }
336
Takashi Iwai61071592011-11-23 07:52:15 +0100337 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200338
339 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100340 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
341 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200342 return 1;
343
Takashi Iwaia22d5432009-07-27 12:54:26 +0200344 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200345 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100346 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100347 int active = imux->items[idx].index;
348 for (i = 0; i < num_conns; i++) {
349 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
350 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100351 HDA_AMP_MUTE, v);
352 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100353 } else {
354 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200355 snd_hda_codec_write_cache(codec, nid, 0,
356 AC_VERB_SET_CONNECT_SEL,
357 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100358 }
Takashi Iwai21268962011-07-07 15:01:13 +0200359 return 1;
360}
361
362static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
363 struct snd_ctl_elem_value *ucontrol)
364{
365 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
366 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
367 return alc_mux_select(codec, adc_idx,
368 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100369}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100372 * set up the input pin config (depending on the given auto-pin type)
373 */
374static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
375 int auto_pin_type)
376{
377 unsigned int val = PIN_IN;
378
Takashi Iwai86e29592010-09-09 14:50:17 +0200379 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100380 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200381 unsigned int oldval;
382 oldval = snd_hda_codec_read(codec, nid, 0,
383 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100384 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100385 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200386 /* if the default pin setup is vref50, we give it priority */
387 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100388 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200389 else if (pincap & AC_PINCAP_VREF_50)
390 val = PIN_VREF50;
391 else if (pincap & AC_PINCAP_VREF_100)
392 val = PIN_VREF100;
393 else if (pincap & AC_PINCAP_VREF_GRD)
394 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100395 }
396 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
397}
398
399/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200400 * Append the given mixer and verb elements for the later use
401 * The mixer array is referred in build_controls(), and init_verbs are
402 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100403 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200404static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100405{
406 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
407 return;
408 spec->mixers[spec->num_mixers++] = mix;
409}
410
411static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
412{
413 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
414 return;
415 spec->init_verbs[spec->num_init_verbs++] = verb;
416}
417
418/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200419 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100420 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200421/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200422static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200423 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
424 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
425 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
426 { }
427};
428
Takashi Iwaia9111322011-05-02 11:30:18 +0200429static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200430 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
431 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
432 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
433 { }
434};
435
Takashi Iwaia9111322011-05-02 11:30:18 +0200436static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200437 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
438 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
439 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
440 { }
441};
442
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200443/*
444 * Fix hardware PLL issue
445 * On some codecs, the analog PLL gating control must be off while
446 * the default value is 1.
447 */
448static void alc_fix_pll(struct hda_codec *codec)
449{
450 struct alc_spec *spec = codec->spec;
451 unsigned int val;
452
453 if (!spec->pll_nid)
454 return;
455 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
456 spec->pll_coef_idx);
457 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
458 AC_VERB_GET_PROC_COEF, 0);
459 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
460 spec->pll_coef_idx);
461 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
462 val & ~(1 << spec->pll_coef_bit));
463}
464
465static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
466 unsigned int coef_idx, unsigned int coef_bit)
467{
468 struct alc_spec *spec = codec->spec;
469 spec->pll_nid = nid;
470 spec->pll_coef_idx = coef_idx;
471 spec->pll_coef_bit = coef_bit;
472 alc_fix_pll(codec);
473}
474
Takashi Iwai1d045db2011-07-07 18:23:21 +0200475/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200476 * Jack detections for HP auto-mute and mic-switch
477 */
478
479/* check each pin in the given array; returns true if any of them is plugged */
480static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200481{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200482 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200483
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200484 for (i = 0; i < num_pins; i++) {
485 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200486 if (!nid)
487 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200488 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200489 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200490 return present;
491}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200492
Takashi Iwai1d045db2011-07-07 18:23:21 +0200493/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200494static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200495 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200496{
497 struct alc_spec *spec = codec->spec;
498 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200499 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200500 int i;
501
502 for (i = 0; i < num_pins; i++) {
503 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100504 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200505 if (!nid)
506 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200507 switch (spec->automute_mode) {
508 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100509 /* don't reset VREF value in case it's controlling
510 * the amp (see alc861_fixup_asus_amp_vref_0f())
511 */
512 if (spec->keep_vref_in_automute) {
513 val = snd_hda_codec_read(codec, nid, 0,
514 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
515 val &= ~PIN_HP;
516 } else
517 val = 0;
518 val |= pin_bits;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200519 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200520 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai31150f22012-01-30 10:54:08 +0100521 val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200522 break;
523 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200524 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200525 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200526 break;
527 case ALC_AUTOMUTE_MIXER:
528 nid = spec->automute_mixer_nid[i];
529 if (!nid)
530 break;
531 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200533 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200534 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200535 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200536 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200537 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200538}
539
David Henningsson42cf0d02011-09-20 12:04:56 +0200540/* Toggle outputs muting */
541static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200542{
543 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200544 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200545
Takashi Iwaic0a20262011-06-10 15:28:15 +0200546 /* Control HP pins/amps depending on master_mute state;
547 * in general, HP pins/amps control should be enabled in all cases,
548 * but currently set only for master_mute, just to be safe
549 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100550 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
551 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200552 spec->autocfg.hp_pins, spec->master_mute, true);
553
David Henningsson42cf0d02011-09-20 12:04:56 +0200554 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 on = 0;
556 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200557 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200558 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200559 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561
562 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200563 /* if LO is a copy of either HP or Speaker, don't need to handle it */
564 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
565 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200566 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200567 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200568 on = 0;
569 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200570 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200571 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200572 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200573 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200574}
575
David Henningsson42cf0d02011-09-20 12:04:56 +0200576static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200577{
578 struct alc_spec *spec = codec->spec;
579 if (spec->automute_hook)
580 spec->automute_hook(codec);
581 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200582 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200583}
584
Takashi Iwai1d045db2011-07-07 18:23:21 +0200585/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200586static void alc_hp_automute(struct hda_codec *codec)
587{
588 struct alc_spec *spec = codec->spec;
589
David Henningsson42cf0d02011-09-20 12:04:56 +0200590 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
592 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200593 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200594 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200595 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200596}
597
Takashi Iwai1d045db2011-07-07 18:23:21 +0200598/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200599static void alc_line_automute(struct hda_codec *codec)
600{
601 struct alc_spec *spec = codec->spec;
602
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200603 /* check LO jack only when it's different from HP */
604 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
605 return;
606
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607 spec->line_jack_present =
608 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
609 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200610 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200611 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200612 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200613}
614
Takashi Iwai8d087c72011-06-28 12:45:47 +0200615#define get_connection_index(codec, mux, nid) \
616 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200617
Takashi Iwai1d045db2011-07-07 18:23:21 +0200618/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200619static void alc_mic_automute(struct hda_codec *codec)
620{
621 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200622 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200623
Takashi Iwai21268962011-07-07 15:01:13 +0200624 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200625 return;
626 if (snd_BUG_ON(!spec->adc_nids))
627 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200628 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200629 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200630
Takashi Iwai21268962011-07-07 15:01:13 +0200631 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
632 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
633 else if (spec->dock_mic_idx >= 0 &&
634 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
635 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
636 else
637 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200638}
639
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100640/* handle the specified unsol action (ALC_XXX_EVENT) */
641static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200642{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100643 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200644 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200645 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200646 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200647 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200648 alc_line_automute(codec);
649 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200650 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200651 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200652 break;
653 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200654 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200655}
656
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100657/* update the master volume per volume-knob's unsol event */
658static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
659{
660 unsigned int val;
661 struct snd_kcontrol *kctl;
662 struct snd_ctl_elem_value *uctl;
663
664 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
665 if (!kctl)
666 return;
667 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
668 if (!uctl)
669 return;
670 val = snd_hda_codec_read(codec, nid, 0,
671 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
672 val &= HDA_AMP_VOLMASK;
673 uctl->value.integer.value[0] = val;
674 uctl->value.integer.value[1] = val;
675 kctl->put(kctl, uctl);
676 kfree(uctl);
677}
678
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100679/* unsolicited event for HP jack sensing */
680static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
681{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100682 int action;
683
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100684 if (codec->vendor_id == 0x10ec0880)
685 res >>= 28;
686 else
687 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100688 action = snd_hda_jack_get_action(codec, res);
689 if (res == ALC_DCVOL_EVENT) {
690 /* Execute the dc-vol event here as it requires the NID
691 * but we don't pass NID to alc_exec_unsol_event().
692 * Once when we convert all static quirks to the auto-parser,
693 * this can be integerated into there.
694 */
695 struct hda_jack_tbl *jack;
696 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
697 if (jack)
698 alc_update_knob_master(codec, jack->nid);
699 return;
700 }
701 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100702}
703
Takashi Iwai1d045db2011-07-07 18:23:21 +0200704/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200705static void alc_inithook(struct hda_codec *codec)
706{
Takashi Iwaid922b512011-04-28 12:18:53 +0200707 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200708 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200709 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200710}
711
Kailang Yangf9423e72008-05-27 12:32:25 +0200712/* additional initialization for ALC888 variants */
713static void alc888_coef_init(struct hda_codec *codec)
714{
715 unsigned int tmp;
716
717 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
718 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
719 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100720 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200721 /* alc888S-VC */
722 snd_hda_codec_read(codec, 0x20, 0,
723 AC_VERB_SET_PROC_COEF, 0x830);
724 else
725 /* alc888-VB */
726 snd_hda_codec_read(codec, 0x20, 0,
727 AC_VERB_SET_PROC_COEF, 0x3030);
728}
729
Takashi Iwai1d045db2011-07-07 18:23:21 +0200730/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200731static void alc889_coef_init(struct hda_codec *codec)
732{
733 unsigned int tmp;
734
735 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
736 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
737 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
738 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
739}
740
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100741/* turn on/off EAPD control (only if available) */
742static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
743{
744 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
745 return;
746 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
747 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
748 on ? 2 : 0);
749}
750
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200751/* turn on/off EAPD controls of the codec */
752static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
753{
754 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200755 static hda_nid_t pins[] = {
756 0x0f, 0x10, 0x14, 0x15, 0
757 };
758 hda_nid_t *p;
759 for (p = pins; *p; p++)
760 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200761}
762
Takashi Iwai1c7161532011-04-07 10:37:16 +0200763/* generic shutup callback;
764 * just turning off EPAD and a little pause for avoiding pop-noise
765 */
766static void alc_eapd_shutup(struct hda_codec *codec)
767{
768 alc_auto_setup_eapd(codec, false);
769 msleep(200);
770}
771
Takashi Iwai1d045db2011-07-07 18:23:21 +0200772/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200773static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200774{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200775 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200776
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200777 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200778 switch (type) {
779 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200780 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
781 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200782 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200783 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
784 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200785 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200786 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
787 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200788 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200789 switch (codec->vendor_id) {
790 case 0x10ec0260:
791 snd_hda_codec_write(codec, 0x1a, 0,
792 AC_VERB_SET_COEF_INDEX, 7);
793 tmp = snd_hda_codec_read(codec, 0x1a, 0,
794 AC_VERB_GET_PROC_COEF, 0);
795 snd_hda_codec_write(codec, 0x1a, 0,
796 AC_VERB_SET_COEF_INDEX, 7);
797 snd_hda_codec_write(codec, 0x1a, 0,
798 AC_VERB_SET_PROC_COEF,
799 tmp | 0x2010);
800 break;
801 case 0x10ec0262:
802 case 0x10ec0880:
803 case 0x10ec0882:
804 case 0x10ec0883:
805 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100806 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100807 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200808 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200809 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200810 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200811 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200812 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100813#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200814 case 0x10ec0267:
815 case 0x10ec0268:
816 snd_hda_codec_write(codec, 0x20, 0,
817 AC_VERB_SET_COEF_INDEX, 7);
818 tmp = snd_hda_codec_read(codec, 0x20, 0,
819 AC_VERB_GET_PROC_COEF, 0);
820 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200821 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200822 snd_hda_codec_write(codec, 0x20, 0,
823 AC_VERB_SET_PROC_COEF,
824 tmp | 0x3000);
825 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100826#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200827 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200828 break;
829 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200830}
Kailang Yangea1fb292008-08-26 12:58:38 +0200831
Takashi Iwai1d045db2011-07-07 18:23:21 +0200832/*
833 * Auto-Mute mode mixer enum support
834 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200835static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
836 struct snd_ctl_elem_info *uinfo)
837{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200838 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
839 struct alc_spec *spec = codec->spec;
840 static const char * const texts2[] = {
841 "Disabled", "Enabled"
842 };
843 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200844 "Disabled", "Speaker Only", "Line-Out+Speaker"
845 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200846 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200847
848 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
849 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200850 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200851 uinfo->value.enumerated.items = 3;
852 texts = texts3;
853 } else {
854 uinfo->value.enumerated.items = 2;
855 texts = texts2;
856 }
857 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
858 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200859 strcpy(uinfo->value.enumerated.name,
860 texts[uinfo->value.enumerated.item]);
861 return 0;
862}
863
864static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
865 struct snd_ctl_elem_value *ucontrol)
866{
867 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
868 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200869 unsigned int val = 0;
870 if (spec->automute_speaker)
871 val++;
872 if (spec->automute_lo)
873 val++;
874
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200875 ucontrol->value.enumerated.item[0] = val;
876 return 0;
877}
878
879static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
880 struct snd_ctl_elem_value *ucontrol)
881{
882 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
883 struct alc_spec *spec = codec->spec;
884
885 switch (ucontrol->value.enumerated.item[0]) {
886 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200887 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200888 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200889 spec->automute_speaker = 0;
890 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200891 break;
892 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200893 if (spec->automute_speaker_possible) {
894 if (!spec->automute_lo && spec->automute_speaker)
895 return 0;
896 spec->automute_speaker = 1;
897 spec->automute_lo = 0;
898 } else if (spec->automute_lo_possible) {
899 if (spec->automute_lo)
900 return 0;
901 spec->automute_lo = 1;
902 } else
903 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200904 break;
905 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200906 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200907 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200908 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200910 spec->automute_speaker = 1;
911 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200912 break;
913 default:
914 return -EINVAL;
915 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200916 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200917 return 1;
918}
919
Takashi Iwaia9111322011-05-02 11:30:18 +0200920static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200921 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
922 .name = "Auto-Mute Mode",
923 .info = alc_automute_mode_info,
924 .get = alc_automute_mode_get,
925 .put = alc_automute_mode_put,
926};
927
Takashi Iwai1d045db2011-07-07 18:23:21 +0200928static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
929{
930 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
931 return snd_array_new(&spec->kctls);
932}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200933
934static int alc_add_automute_mode_enum(struct hda_codec *codec)
935{
936 struct alc_spec *spec = codec->spec;
937 struct snd_kcontrol_new *knew;
938
939 knew = alc_kcontrol_new(spec);
940 if (!knew)
941 return -ENOMEM;
942 *knew = alc_automute_mode_enum;
943 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
944 if (!knew->name)
945 return -ENOMEM;
946 return 0;
947}
948
Takashi Iwai1d045db2011-07-07 18:23:21 +0200949/*
950 * Check the availability of HP/line-out auto-mute;
951 * Set up appropriately if really supported
952 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200953static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200954{
955 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200956 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200957 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200958 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200959
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200960 if (cfg->hp_pins[0])
961 present++;
962 if (cfg->line_out_pins[0])
963 present++;
964 if (cfg->speaker_pins[0])
965 present++;
966 if (present < 2) /* need two different output types */
967 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200968
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200969 if (!cfg->speaker_pins[0] &&
970 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200971 memcpy(cfg->speaker_pins, cfg->line_out_pins,
972 sizeof(cfg->speaker_pins));
973 cfg->speaker_outs = cfg->line_outs;
974 }
975
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200976 if (!cfg->hp_pins[0] &&
977 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200978 memcpy(cfg->hp_pins, cfg->line_out_pins,
979 sizeof(cfg->hp_pins));
980 cfg->hp_outs = cfg->line_outs;
981 }
982
David Henningsson42cf0d02011-09-20 12:04:56 +0200983 spec->automute_mode = ALC_AUTOMUTE_PIN;
984
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200985 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200986 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200987 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200988 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200989 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200990 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200991 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200992 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200993 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200994
David Henningsson42cf0d02011-09-20 12:04:56 +0200995 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
996 if (cfg->speaker_outs)
997 for (i = 0; i < cfg->line_outs; i++) {
998 hda_nid_t nid = cfg->line_out_pins[i];
999 if (!is_jack_detectable(codec, nid))
1000 continue;
1001 snd_printdd("realtek: Enable Line-Out "
1002 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001003 snd_hda_jack_detect_enable(codec, nid,
1004 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001005 spec->detect_lo = 1;
1006 }
1007 spec->automute_lo_possible = spec->detect_hp;
1008 }
1009
1010 spec->automute_speaker_possible = cfg->speaker_outs &&
1011 (spec->detect_hp || spec->detect_lo);
1012
1013 spec->automute_lo = spec->automute_lo_possible;
1014 spec->automute_speaker = spec->automute_speaker_possible;
1015
1016 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001017 /* create a control for automute mode */
1018 alc_add_automute_mode_enum(codec);
1019 spec->unsol_event = alc_sku_unsol_event;
1020 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001021}
1022
Takashi Iwai1d045db2011-07-07 18:23:21 +02001023/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001024static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1025{
1026 int i;
1027 for (i = 0; i < nums; i++)
1028 if (list[i] == nid)
1029 return i;
1030 return -1;
1031}
1032
Takashi Iwai1d045db2011-07-07 18:23:21 +02001033/* check whether dynamic ADC-switching is available */
1034static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1035{
1036 struct alc_spec *spec = codec->spec;
1037 struct hda_input_mux *imux = &spec->private_imux[0];
1038 int i, n, idx;
1039 hda_nid_t cap, pin;
1040
1041 if (imux != spec->input_mux) /* no dynamic imux? */
1042 return false;
1043
1044 for (n = 0; n < spec->num_adc_nids; n++) {
1045 cap = spec->private_capsrc_nids[n];
1046 for (i = 0; i < imux->num_items; i++) {
1047 pin = spec->imux_pins[i];
1048 if (!pin)
1049 return false;
1050 if (get_connection_index(codec, cap, pin) < 0)
1051 break;
1052 }
1053 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001054 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001055 }
1056
1057 for (i = 0; i < imux->num_items; i++) {
1058 pin = spec->imux_pins[i];
1059 for (n = 0; n < spec->num_adc_nids; n++) {
1060 cap = spec->private_capsrc_nids[n];
1061 idx = get_connection_index(codec, cap, pin);
1062 if (idx >= 0) {
1063 imux->items[i].index = idx;
1064 spec->dyn_adc_idx[i] = n;
1065 break;
1066 }
1067 }
1068 }
1069
1070 snd_printdd("realtek: enabling ADC switching\n");
1071 spec->dyn_adc_switch = 1;
1072 return true;
1073}
Takashi Iwai21268962011-07-07 15:01:13 +02001074
Takashi Iwai21268962011-07-07 15:01:13 +02001075/* check whether all auto-mic pins are valid; setup indices if OK */
1076static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1077{
1078 struct alc_spec *spec = codec->spec;
1079 const struct hda_input_mux *imux;
1080
1081 if (!spec->auto_mic)
1082 return false;
1083 if (spec->auto_mic_valid_imux)
1084 return true; /* already checked */
1085
1086 /* fill up imux indices */
1087 if (!alc_check_dyn_adc_switch(codec)) {
1088 spec->auto_mic = 0;
1089 return false;
1090 }
1091
1092 imux = spec->input_mux;
1093 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1094 spec->imux_pins, imux->num_items);
1095 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1098 spec->imux_pins, imux->num_items);
1099 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1100 spec->auto_mic = 0;
1101 return false; /* no corresponding imux */
1102 }
1103
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001104 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001105 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001106 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1107 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001108
1109 spec->auto_mic_valid_imux = 1;
1110 spec->auto_mic = 1;
1111 return true;
1112}
1113
Takashi Iwai1d045db2011-07-07 18:23:21 +02001114/*
1115 * Check the availability of auto-mic switch;
1116 * Set up if really supported
1117 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001118static void alc_init_auto_mic(struct hda_codec *codec)
1119{
1120 struct alc_spec *spec = codec->spec;
1121 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001122 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001123 int i;
1124
Takashi Iwai24de1832011-11-07 17:13:39 +01001125 if (spec->shared_mic_hp)
1126 return; /* no auto-mic for the shared I/O */
1127
Takashi Iwai21268962011-07-07 15:01:13 +02001128 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1129
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001130 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001131 for (i = 0; i < cfg->num_inputs; i++) {
1132 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001133 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001134 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001135 switch (snd_hda_get_input_pin_attr(defcfg)) {
1136 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001137 if (fixed)
1138 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001139 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1140 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001141 fixed = nid;
1142 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001143 case INPUT_PIN_ATTR_UNUSED:
1144 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001145 case INPUT_PIN_ATTR_DOCK:
1146 if (dock)
1147 return; /* already occupied */
1148 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1149 return; /* invalid type */
1150 dock = nid;
1151 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001152 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001153 if (ext)
1154 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001155 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1156 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001157 ext = nid;
1158 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001159 }
1160 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001161 if (!ext && dock) {
1162 ext = dock;
1163 dock = 0;
1164 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001165 if (!ext || !fixed)
1166 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001167 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001168 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001169 if (dock && !is_jack_detectable(codec, dock))
1170 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001171
1172 /* check imux indices */
1173 spec->ext_mic_pin = ext;
1174 spec->int_mic_pin = fixed;
1175 spec->dock_mic_pin = dock;
1176
1177 spec->auto_mic = 1;
1178 if (!alc_auto_mic_check_imux(codec))
1179 return;
1180
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001181 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1182 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001183 spec->unsol_event = alc_sku_unsol_event;
1184}
1185
Takashi Iwai1d045db2011-07-07 18:23:21 +02001186/* check the availabilities of auto-mute and auto-mic switches */
1187static void alc_auto_check_switches(struct hda_codec *codec)
1188{
David Henningsson42cf0d02011-09-20 12:04:56 +02001189 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001190 alc_init_auto_mic(codec);
1191}
1192
1193/*
1194 * Realtek SSID verification
1195 */
1196
David Henningsson90622912010-10-14 14:50:18 +02001197/* Could be any non-zero and even value. When used as fixup, tells
1198 * the driver to ignore any present sku defines.
1199 */
1200#define ALC_FIXUP_SKU_IGNORE (2)
1201
Kailang Yangda00c242010-03-19 11:23:45 +01001202static int alc_auto_parse_customize_define(struct hda_codec *codec)
1203{
1204 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001205 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001206 struct alc_spec *spec = codec->spec;
1207
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001208 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1209
David Henningsson90622912010-10-14 14:50:18 +02001210 if (spec->cdefine.fixup) {
1211 ass = spec->cdefine.sku_cfg;
1212 if (ass == ALC_FIXUP_SKU_IGNORE)
1213 return -1;
1214 goto do_sku;
1215 }
1216
Kailang Yangda00c242010-03-19 11:23:45 +01001217 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001218 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001219 goto do_sku;
1220
1221 nid = 0x1d;
1222 if (codec->vendor_id == 0x10ec0260)
1223 nid = 0x17;
1224 ass = snd_hda_codec_get_pincfg(codec, nid);
1225
1226 if (!(ass & 1)) {
1227 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1228 codec->chip_name, ass);
1229 return -1;
1230 }
1231
1232 /* check sum */
1233 tmp = 0;
1234 for (i = 1; i < 16; i++) {
1235 if ((ass >> i) & 1)
1236 tmp++;
1237 }
1238 if (((ass >> 16) & 0xf) != tmp)
1239 return -1;
1240
1241 spec->cdefine.port_connectivity = ass >> 30;
1242 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1243 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1244 spec->cdefine.customization = ass >> 8;
1245do_sku:
1246 spec->cdefine.sku_cfg = ass;
1247 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1248 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1249 spec->cdefine.swap = (ass & 0x2) >> 1;
1250 spec->cdefine.override = ass & 0x1;
1251
1252 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1253 nid, spec->cdefine.sku_cfg);
1254 snd_printd("SKU: port_connectivity=0x%x\n",
1255 spec->cdefine.port_connectivity);
1256 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1257 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1258 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1259 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1260 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1261 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1262 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1263
1264 return 0;
1265}
1266
Takashi Iwai1d045db2011-07-07 18:23:21 +02001267/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001268static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1269{
Takashi Iwai21268962011-07-07 15:01:13 +02001270 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001271}
1272
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001273/* check subsystem ID and set up device-specific initialization;
1274 * return 1 if initialized, 0 if invalid SSID
1275 */
1276/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1277 * 31 ~ 16 : Manufacture ID
1278 * 15 ~ 8 : SKU ID
1279 * 7 ~ 0 : Assembly ID
1280 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1281 */
1282static int alc_subsystem_id(struct hda_codec *codec,
1283 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001284 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001285{
1286 unsigned int ass, tmp, i;
1287 unsigned nid;
1288 struct alc_spec *spec = codec->spec;
1289
David Henningsson90622912010-10-14 14:50:18 +02001290 if (spec->cdefine.fixup) {
1291 ass = spec->cdefine.sku_cfg;
1292 if (ass == ALC_FIXUP_SKU_IGNORE)
1293 return 0;
1294 goto do_sku;
1295 }
1296
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001297 ass = codec->subsystem_id & 0xffff;
1298 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1299 goto do_sku;
1300
1301 /* invalid SSID, check the special NID pin defcfg instead */
1302 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001303 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001304 * 29~21 : reserve
1305 * 20 : PCBEEP input
1306 * 19~16 : Check sum (15:1)
1307 * 15~1 : Custom
1308 * 0 : override
1309 */
1310 nid = 0x1d;
1311 if (codec->vendor_id == 0x10ec0260)
1312 nid = 0x17;
1313 ass = snd_hda_codec_get_pincfg(codec, nid);
1314 snd_printd("realtek: No valid SSID, "
1315 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001316 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001317 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001318 return 0;
1319 if ((ass >> 30) != 1) /* no physical connection */
1320 return 0;
1321
1322 /* check sum */
1323 tmp = 0;
1324 for (i = 1; i < 16; i++) {
1325 if ((ass >> i) & 1)
1326 tmp++;
1327 }
1328 if (((ass >> 16) & 0xf) != tmp)
1329 return 0;
1330do_sku:
1331 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1332 ass & 0xffff, codec->vendor_id);
1333 /*
1334 * 0 : override
1335 * 1 : Swap Jack
1336 * 2 : 0 --> Desktop, 1 --> Laptop
1337 * 3~5 : External Amplifier control
1338 * 7~6 : Reserved
1339 */
1340 tmp = (ass & 0x38) >> 3; /* external Amp control */
1341 switch (tmp) {
1342 case 1:
1343 spec->init_amp = ALC_INIT_GPIO1;
1344 break;
1345 case 3:
1346 spec->init_amp = ALC_INIT_GPIO2;
1347 break;
1348 case 7:
1349 spec->init_amp = ALC_INIT_GPIO3;
1350 break;
1351 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001352 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001353 spec->init_amp = ALC_INIT_DEFAULT;
1354 break;
1355 }
1356
1357 /* is laptop or Desktop and enable the function "Mute internal speaker
1358 * when the external headphone out jack is plugged"
1359 */
1360 if (!(ass & 0x8000))
1361 return 1;
1362 /*
1363 * 10~8 : Jack location
1364 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1365 * 14~13: Resvered
1366 * 15 : 1 --> enable the function "Mute internal speaker
1367 * when the external headphone out jack is plugged"
1368 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001369 if (!spec->autocfg.hp_pins[0] &&
1370 !(spec->autocfg.line_out_pins[0] &&
1371 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001372 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001373 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1374 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001375 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001376 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001377 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001378 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001379 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001380 else if (tmp == 3)
1381 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001382 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001383 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001384 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1385 spec->autocfg.line_outs))
1386 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001387 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001388 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001389 return 1;
1390}
Kailang Yangea1fb292008-08-26 12:58:38 +02001391
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001392/* Check the validity of ALC subsystem-id
1393 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1394static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001395{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001396 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001397 struct alc_spec *spec = codec->spec;
1398 snd_printd("realtek: "
1399 "Enable default setup for auto mode as fallback\n");
1400 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001401 }
Takashi Iwai21268962011-07-07 15:01:13 +02001402}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001403
Takashi Iwai41e41f12005-06-08 14:48:49 +02001404/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001405 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001406 */
1407
1408struct alc_pincfg {
1409 hda_nid_t nid;
1410 u32 val;
1411};
1412
Todd Broche1eb5f12010-12-06 11:19:51 -08001413struct alc_model_fixup {
1414 const int id;
1415 const char *name;
1416};
1417
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001418struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001419 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001420 bool chained;
1421 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001422 union {
1423 unsigned int sku;
1424 const struct alc_pincfg *pins;
1425 const struct hda_verb *verbs;
1426 void (*func)(struct hda_codec *codec,
1427 const struct alc_fixup *fix,
1428 int action);
1429 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001430};
1431
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001432enum {
1433 ALC_FIXUP_INVALID,
1434 ALC_FIXUP_SKU,
1435 ALC_FIXUP_PINS,
1436 ALC_FIXUP_VERBS,
1437 ALC_FIXUP_FUNC,
1438};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001439
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001440enum {
1441 ALC_FIXUP_ACT_PRE_PROBE,
1442 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001443 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001444};
1445
1446static void alc_apply_fixup(struct hda_codec *codec, int action)
1447{
1448 struct alc_spec *spec = codec->spec;
1449 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001450#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001451 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001452#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001453 int depth = 0;
1454
1455 if (!spec->fixup_list)
1456 return;
1457
1458 while (id >= 0) {
1459 const struct alc_fixup *fix = spec->fixup_list + id;
1460 const struct alc_pincfg *cfg;
1461
1462 switch (fix->type) {
1463 case ALC_FIXUP_SKU:
1464 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001465 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001466 snd_printdd(KERN_INFO "hda_codec: %s: "
1467 "Apply sku override for %s\n",
1468 codec->chip_name, modelname);
1469 spec->cdefine.sku_cfg = fix->v.sku;
1470 spec->cdefine.fixup = 1;
1471 break;
1472 case ALC_FIXUP_PINS:
1473 cfg = fix->v.pins;
1474 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1475 break;
1476 snd_printdd(KERN_INFO "hda_codec: %s: "
1477 "Apply pincfg for %s\n",
1478 codec->chip_name, modelname);
1479 for (; cfg->nid; cfg++)
1480 snd_hda_codec_set_pincfg(codec, cfg->nid,
1481 cfg->val);
1482 break;
1483 case ALC_FIXUP_VERBS:
1484 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1485 break;
1486 snd_printdd(KERN_INFO "hda_codec: %s: "
1487 "Apply fix-verbs for %s\n",
1488 codec->chip_name, modelname);
1489 add_verb(codec->spec, fix->v.verbs);
1490 break;
1491 case ALC_FIXUP_FUNC:
1492 if (!fix->v.func)
1493 break;
1494 snd_printdd(KERN_INFO "hda_codec: %s: "
1495 "Apply fix-func for %s\n",
1496 codec->chip_name, modelname);
1497 fix->v.func(codec, fix, action);
1498 break;
1499 default:
1500 snd_printk(KERN_ERR "hda_codec: %s: "
1501 "Invalid fixup type %d\n",
1502 codec->chip_name, fix->type);
1503 break;
1504 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001505 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001506 break;
1507 if (++depth > 10)
1508 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001509 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001510 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001511}
1512
Todd Broche1eb5f12010-12-06 11:19:51 -08001513static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001514 const struct alc_model_fixup *models,
1515 const struct snd_pci_quirk *quirk,
1516 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001517{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001518 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001519 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001520 int id = -1;
1521 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001522
Takashi Iwai9155f822012-02-20 18:41:02 +01001523 /* when model=nofixup is given, don't pick up any fixups */
1524 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
1525 spec->fixup_list = NULL;
1526 spec->fixup_id = -1;
1527 return;
1528 }
1529
Todd Broche1eb5f12010-12-06 11:19:51 -08001530 if (codec->modelname && models) {
1531 while (models->name) {
1532 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001533 id = models->id;
1534 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001535 break;
1536 }
1537 models++;
1538 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001539 }
1540 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001541 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1542 if (q) {
1543 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001544#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001545 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001546#endif
1547 }
1548 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001549 if (id < 0) {
1550 for (q = quirk; q->subvendor; q++) {
1551 unsigned int vendorid =
1552 q->subdevice | (q->subvendor << 16);
1553 if (vendorid == codec->subsystem_id) {
1554 id = q->value;
1555#ifdef CONFIG_SND_DEBUG_VERBOSE
1556 name = q->name;
1557#endif
1558 break;
1559 }
1560 }
1561 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001562
1563 spec->fixup_id = id;
1564 if (id >= 0) {
1565 spec->fixup_list = fixlist;
1566 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001567 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001568}
1569
Takashi Iwai1d045db2011-07-07 18:23:21 +02001570/*
1571 * COEF access helper functions
1572 */
Kailang Yang274693f2009-12-03 10:07:50 +01001573static int alc_read_coef_idx(struct hda_codec *codec,
1574 unsigned int coef_idx)
1575{
1576 unsigned int val;
1577 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1578 coef_idx);
1579 val = snd_hda_codec_read(codec, 0x20, 0,
1580 AC_VERB_GET_PROC_COEF, 0);
1581 return val;
1582}
1583
Kailang Yang977ddd62010-09-15 10:02:29 +02001584static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1585 unsigned int coef_val)
1586{
1587 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1588 coef_idx);
1589 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1590 coef_val);
1591}
1592
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001593/* a special bypass for COEF 0; read the cached value at the second time */
1594static unsigned int alc_get_coef0(struct hda_codec *codec)
1595{
1596 struct alc_spec *spec = codec->spec;
1597 if (!spec->coef0)
1598 spec->coef0 = alc_read_coef_idx(codec, 0);
1599 return spec->coef0;
1600}
1601
Takashi Iwai1d045db2011-07-07 18:23:21 +02001602/*
1603 * Digital I/O handling
1604 */
1605
Takashi Iwai757899a2010-07-30 10:48:14 +02001606/* set right pin controls for digital I/O */
1607static void alc_auto_init_digital(struct hda_codec *codec)
1608{
1609 struct alc_spec *spec = codec->spec;
1610 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001611 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001612
1613 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1614 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001615 if (!pin)
1616 continue;
1617 snd_hda_codec_write(codec, pin, 0,
1618 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1619 if (!i)
1620 dac = spec->multiout.dig_out_nid;
1621 else
1622 dac = spec->slave_dig_outs[i - 1];
1623 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1624 continue;
1625 snd_hda_codec_write(codec, dac, 0,
1626 AC_VERB_SET_AMP_GAIN_MUTE,
1627 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001628 }
1629 pin = spec->autocfg.dig_in_pin;
1630 if (pin)
1631 snd_hda_codec_write(codec, pin, 0,
1632 AC_VERB_SET_PIN_WIDGET_CONTROL,
1633 PIN_IN);
1634}
1635
1636/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1637static void alc_auto_parse_digital(struct hda_codec *codec)
1638{
1639 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001640 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001641 hda_nid_t dig_nid;
1642
1643 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001644 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001645 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001646 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001647 err = snd_hda_get_connections(codec,
1648 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001649 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001650 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001651 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001652 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001653 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001654 spec->multiout.dig_out_nid = dig_nid;
1655 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1656 } else {
1657 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001658 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001659 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001660 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001661 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001662 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001663 }
1664
1665 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001666 dig_nid = codec->start_nid;
1667 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1668 unsigned int wcaps = get_wcaps(codec, dig_nid);
1669 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1670 continue;
1671 if (!(wcaps & AC_WCAP_DIGITAL))
1672 continue;
1673 if (!(wcaps & AC_WCAP_CONN_LIST))
1674 continue;
1675 err = get_connection_index(codec, dig_nid,
1676 spec->autocfg.dig_in_pin);
1677 if (err >= 0) {
1678 spec->dig_in_nid = dig_nid;
1679 break;
1680 }
1681 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001682 }
1683}
1684
Takashi Iwaif95474e2007-07-10 00:47:43 +02001685/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001686 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001687 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001688static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1689 struct snd_ctl_elem_info *uinfo)
1690{
1691 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1692 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001693 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001694 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001695
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001696 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001697 if (spec->vol_in_capsrc)
1698 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1699 else
1700 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1701 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001702 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001703 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001704 return err;
1705}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001707static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1708 unsigned int size, unsigned int __user *tlv)
1709{
1710 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1711 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001712 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001713 int err;
1714
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001715 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001716 if (spec->vol_in_capsrc)
1717 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1718 else
1719 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1720 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001721 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001722 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001723 return err;
1724}
1725
1726typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol);
1728
1729static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001731 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001732{
1733 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1734 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001735 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001736
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001737 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001738 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001739 for (i = 0; i < spec->num_adc_nids; i++) {
1740 kcontrol->private_value =
1741 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1742 3, 0, HDA_INPUT);
1743 err = func(kcontrol, ucontrol);
1744 if (err < 0)
1745 goto error;
1746 }
1747 } else {
1748 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001749 if (spec->vol_in_capsrc)
1750 kcontrol->private_value =
1751 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1752 3, 0, HDA_OUTPUT);
1753 else
1754 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001755 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1756 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001757 err = func(kcontrol, ucontrol);
1758 }
1759 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001760 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001761 return err;
1762}
1763
1764static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1765 struct snd_ctl_elem_value *ucontrol)
1766{
1767 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001768 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001769}
1770
1771static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1772 struct snd_ctl_elem_value *ucontrol)
1773{
1774 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001775 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001776}
1777
1778/* capture mixer elements */
1779#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1780
1781static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1782 struct snd_ctl_elem_value *ucontrol)
1783{
1784 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001785 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001786}
1787
1788static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1789 struct snd_ctl_elem_value *ucontrol)
1790{
1791 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001792 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001793}
1794
Takashi Iwaia23b6882009-03-23 15:21:36 +01001795#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001796 { \
1797 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1798 .name = "Capture Switch", \
1799 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1800 .count = num, \
1801 .info = alc_cap_sw_info, \
1802 .get = alc_cap_sw_get, \
1803 .put = alc_cap_sw_put, \
1804 }, \
1805 { \
1806 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1807 .name = "Capture Volume", \
1808 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1809 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1810 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1811 .count = num, \
1812 .info = alc_cap_vol_info, \
1813 .get = alc_cap_vol_get, \
1814 .put = alc_cap_vol_put, \
1815 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001816 }
1817
1818#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001819 { \
1820 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1821 /* .name = "Capture Source", */ \
1822 .name = "Input Source", \
1823 .count = num, \
1824 .info = alc_mux_enum_info, \
1825 .get = alc_mux_enum_get, \
1826 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001827 }
1828
1829#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001830static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001831 _DEFINE_CAPMIX(num), \
1832 _DEFINE_CAPSRC(num), \
1833 { } /* end */ \
1834}
1835
1836#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001837static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001838 _DEFINE_CAPMIX(num), \
1839 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001840}
1841
1842/* up to three ADCs */
1843DEFINE_CAPMIX(1);
1844DEFINE_CAPMIX(2);
1845DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001846DEFINE_CAPMIX_NOSRC(1);
1847DEFINE_CAPMIX_NOSRC(2);
1848DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001849
1850/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001851 * virtual master controls
1852 */
1853
1854/*
1855 * slave controls for virtual master
1856 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001857static const char * const alc_slave_pfxs[] = {
1858 "Front", "Surround", "Center", "LFE", "Side",
1859 "Headphone", "Speaker", "Mono", "Line-Out",
1860 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001861 NULL,
1862};
1863
1864/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001865 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001867
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001868#define NID_MAPPING (-1)
1869
1870#define SUBDEV_SPEAKER_ (0 << 6)
1871#define SUBDEV_HP_ (1 << 6)
1872#define SUBDEV_LINE_ (2 << 6)
1873#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1874#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1875#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1876
Takashi Iwai603c4012008-07-30 15:01:44 +02001877static void alc_free_kctls(struct hda_codec *codec);
1878
Takashi Iwai67d634c2009-11-16 15:35:59 +01001879#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001880/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001881static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001882 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001883 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001884 { } /* end */
1885};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001886#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001887
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001888static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889{
1890 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001891 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001892 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001893 int i, j, err;
1894 unsigned int u;
1895 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
1897 for (i = 0; i < spec->num_mixers; i++) {
1898 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1899 if (err < 0)
1900 return err;
1901 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001902 if (spec->cap_mixer) {
1903 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1904 if (err < 0)
1905 return err;
1906 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001908 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001909 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001910 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 if (err < 0)
1912 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001913 if (!spec->no_analog) {
1914 err = snd_hda_create_spdif_share_sw(codec,
1915 &spec->multiout);
1916 if (err < 0)
1917 return err;
1918 spec->multiout.share_spdif = 1;
1919 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 }
1921 if (spec->dig_in_nid) {
1922 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1923 if (err < 0)
1924 return err;
1925 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001926
Takashi Iwai67d634c2009-11-16 15:35:59 +01001927#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001928 /* create beep controls if needed */
1929 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001930 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001931 for (knew = alc_beep_mixer; knew->name; knew++) {
1932 struct snd_kcontrol *kctl;
1933 kctl = snd_ctl_new1(knew, codec);
1934 if (!kctl)
1935 return -ENOMEM;
1936 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001937 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001938 if (err < 0)
1939 return err;
1940 }
1941 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001942#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001943
Takashi Iwai2134ea42008-01-10 16:53:55 +01001944 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001945 if (!spec->no_analog &&
1946 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001947 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001948 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001949 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001950 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001951 vmaster_tlv, alc_slave_pfxs,
1952 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001953 if (err < 0)
1954 return err;
1955 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001956 if (!spec->no_analog &&
1957 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001958 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001959 NULL, alc_slave_pfxs,
1960 "Playback Switch");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001961 if (err < 0)
1962 return err;
1963 }
1964
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001965 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001966 if (spec->capsrc_nids || spec->adc_nids) {
1967 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1968 if (!kctl)
1969 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1970 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001971 err = snd_hda_add_nid(codec, kctl, i,
1972 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001973 if (err < 0)
1974 return err;
1975 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001976 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001977 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001978 const char *kname = kctl ? kctl->id.name : NULL;
1979 for (knew = spec->cap_mixer; knew->name; knew++) {
1980 if (kname && strcmp(knew->name, kname) == 0)
1981 continue;
1982 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1983 for (i = 0; kctl && i < kctl->count; i++) {
1984 err = snd_hda_add_nid(codec, kctl, i,
1985 spec->adc_nids[i]);
1986 if (err < 0)
1987 return err;
1988 }
1989 }
1990 }
1991
1992 /* other nid->control mapping */
1993 for (i = 0; i < spec->num_mixers; i++) {
1994 for (knew = spec->mixers[i]; knew->name; knew++) {
1995 if (knew->iface != NID_MAPPING)
1996 continue;
1997 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1998 if (kctl == NULL)
1999 continue;
2000 u = knew->subdevice;
2001 for (j = 0; j < 4; j++, u >>= 8) {
2002 nid = u & 0x3f;
2003 if (nid == 0)
2004 continue;
2005 switch (u & 0xc0) {
2006 case SUBDEV_SPEAKER_:
2007 nid = spec->autocfg.speaker_pins[nid];
2008 break;
2009 case SUBDEV_LINE_:
2010 nid = spec->autocfg.line_out_pins[nid];
2011 break;
2012 case SUBDEV_HP_:
2013 nid = spec->autocfg.hp_pins[nid];
2014 break;
2015 default:
2016 continue;
2017 }
2018 err = snd_hda_add_nid(codec, kctl, 0, nid);
2019 if (err < 0)
2020 return err;
2021 }
2022 u = knew->private_value;
2023 for (j = 0; j < 4; j++, u >>= 8) {
2024 nid = u & 0xff;
2025 if (nid == 0)
2026 continue;
2027 err = snd_hda_add_nid(codec, kctl, 0, nid);
2028 if (err < 0)
2029 return err;
2030 }
2031 }
2032 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002033
2034 alc_free_kctls(codec); /* no longer needed */
2035
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002036 return 0;
2037}
2038
2039static int alc_build_controls(struct hda_codec *codec)
2040{
2041 struct alc_spec *spec = codec->spec;
2042 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002043 if (err < 0)
2044 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002045 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046}
2047
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002050 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002051 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002052
Takashi Iwai584c0c42011-03-10 12:51:11 +01002053static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002054static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056static int alc_init(struct hda_codec *codec)
2057{
2058 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002059 unsigned int i;
2060
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002061 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002062 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002063
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002064 for (i = 0; i < spec->num_init_verbs; i++)
2065 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002066 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002067 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002068
2069 if (spec->init_hook)
2070 spec->init_hook(codec);
2071
Takashi Iwai58701122011-01-13 15:41:45 +01002072 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2073
Takashi Iwai01a61e12011-10-28 00:03:22 +02002074 snd_hda_jack_report_sync(codec);
2075
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002076 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 return 0;
2078}
2079
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002080static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2081{
2082 struct alc_spec *spec = codec->spec;
2083
2084 if (spec->unsol_event)
2085 spec->unsol_event(codec, res);
2086}
2087
Takashi Iwaicb53c622007-08-10 17:21:45 +02002088#ifdef CONFIG_SND_HDA_POWER_SAVE
2089static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2090{
2091 struct alc_spec *spec = codec->spec;
2092 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2093}
2094#endif
2095
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096/*
2097 * Analog playback callbacks
2098 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002099static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002101 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
2103 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002104 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2105 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002108static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct hda_codec *codec,
2110 unsigned int stream_tag,
2111 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002112 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
2114 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002115 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2116 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117}
2118
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002119static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002121 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
2123 struct alc_spec *spec = codec->spec;
2124 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2125}
2126
2127/*
2128 * Digital out
2129 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002130static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002132 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
2134 struct alc_spec *spec = codec->spec;
2135 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2136}
2137
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002138static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002139 struct hda_codec *codec,
2140 unsigned int stream_tag,
2141 unsigned int format,
2142 struct snd_pcm_substream *substream)
2143{
2144 struct alc_spec *spec = codec->spec;
2145 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2146 stream_tag, format, substream);
2147}
2148
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002149static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002150 struct hda_codec *codec,
2151 struct snd_pcm_substream *substream)
2152{
2153 struct alc_spec *spec = codec->spec;
2154 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2155}
2156
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002157static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002159 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160{
2161 struct alc_spec *spec = codec->spec;
2162 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2163}
2164
2165/*
2166 * Analog capture
2167 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002168static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 struct hda_codec *codec,
2170 unsigned int stream_tag,
2171 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002172 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173{
2174 struct alc_spec *spec = codec->spec;
2175
Takashi Iwai63300792008-01-24 15:31:36 +01002176 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 stream_tag, 0, format);
2178 return 0;
2179}
2180
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002181static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002183 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184{
2185 struct alc_spec *spec = codec->spec;
2186
Takashi Iwai888afa12008-03-18 09:57:50 +01002187 snd_hda_codec_cleanup_stream(codec,
2188 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 return 0;
2190}
2191
Takashi Iwai840b64c2010-07-13 22:49:01 +02002192/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002193static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002194 struct hda_codec *codec,
2195 unsigned int stream_tag,
2196 unsigned int format,
2197 struct snd_pcm_substream *substream)
2198{
2199 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002200 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002201 spec->cur_adc_stream_tag = stream_tag;
2202 spec->cur_adc_format = format;
2203 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2204 return 0;
2205}
2206
Takashi Iwai21268962011-07-07 15:01:13 +02002207static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002208 struct hda_codec *codec,
2209 struct snd_pcm_substream *substream)
2210{
2211 struct alc_spec *spec = codec->spec;
2212 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2213 spec->cur_adc = 0;
2214 return 0;
2215}
2216
Takashi Iwai21268962011-07-07 15:01:13 +02002217static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002218 .substreams = 1,
2219 .channels_min = 2,
2220 .channels_max = 2,
2221 .nid = 0, /* fill later */
2222 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002223 .prepare = dyn_adc_capture_pcm_prepare,
2224 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002225 },
2226};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
2228/*
2229 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002230static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 .substreams = 1,
2232 .channels_min = 2,
2233 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002234 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002236 .open = alc_playback_pcm_open,
2237 .prepare = alc_playback_pcm_prepare,
2238 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 },
2240};
2241
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002242static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002243 .substreams = 1,
2244 .channels_min = 2,
2245 .channels_max = 2,
2246 /* NID is set in alc_build_pcms */
2247};
2248
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002249static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002250 .substreams = 1,
2251 .channels_min = 2,
2252 .channels_max = 2,
2253 /* NID is set in alc_build_pcms */
2254};
2255
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002256static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002257 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 .channels_min = 2,
2259 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002260 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002262 .prepare = alc_alt_capture_pcm_prepare,
2263 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 },
2265};
2266
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002267static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 .substreams = 1,
2269 .channels_min = 2,
2270 .channels_max = 2,
2271 /* NID is set in alc_build_pcms */
2272 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002273 .open = alc_dig_playback_pcm_open,
2274 .close = alc_dig_playback_pcm_close,
2275 .prepare = alc_dig_playback_pcm_prepare,
2276 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 },
2278};
2279
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002280static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 .substreams = 1,
2282 .channels_min = 2,
2283 .channels_max = 2,
2284 /* NID is set in alc_build_pcms */
2285};
2286
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002287/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002288static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002289 .substreams = 0,
2290 .channels_min = 0,
2291 .channels_max = 0,
2292};
2293
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294static int alc_build_pcms(struct hda_codec *codec)
2295{
2296 struct alc_spec *spec = codec->spec;
2297 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002298 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002299 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 int i;
2301
2302 codec->num_pcms = 1;
2303 codec->pcm_info = info;
2304
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002305 if (spec->no_analog)
2306 goto skip_analog;
2307
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002308 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2309 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002311
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002312 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002313 p = spec->stream_analog_playback;
2314 if (!p)
2315 p = &alc_pcm_analog_playback;
2316 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002317 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2318 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002319 if (spec->adc_nids) {
2320 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002321 if (!p) {
2322 if (spec->dyn_adc_switch)
2323 p = &dyn_adc_pcm_analog_capture;
2324 else
2325 p = &alc_pcm_analog_capture;
2326 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002327 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002328 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
Takashi Iwai4a471b72005-12-07 13:56:29 +01002331 if (spec->channel_mode) {
2332 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2333 for (i = 0; i < spec->num_channel_mode; i++) {
2334 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2335 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 }
2338 }
2339
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002340 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002341 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002343 snprintf(spec->stream_name_digital,
2344 sizeof(spec->stream_name_digital),
2345 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002346 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002347 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002348 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002350 if (spec->dig_out_type)
2351 info->pcm_type = spec->dig_out_type;
2352 else
2353 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002354 if (spec->multiout.dig_out_nid) {
2355 p = spec->stream_digital_playback;
2356 if (!p)
2357 p = &alc_pcm_digital_playback;
2358 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2360 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002361 if (spec->dig_in_nid) {
2362 p = spec->stream_digital_capture;
2363 if (!p)
2364 p = &alc_pcm_digital_capture;
2365 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2367 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002368 /* FIXME: do we need this for all Realtek codec models? */
2369 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 }
2371
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002372 if (spec->no_analog)
2373 return 0;
2374
Takashi Iwaie08a0072006-09-07 17:52:14 +02002375 /* If the use of more than one ADC is requested for the current
2376 * model, configure a second analog capture-only PCM.
2377 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002378 have_multi_adcs = (spec->num_adc_nids > 1) &&
2379 !spec->dyn_adc_switch && !spec->auto_mic &&
2380 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002381 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002382 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002383 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002384 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002385 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002386 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002387 p = spec->stream_analog_alt_playback;
2388 if (!p)
2389 p = &alc_pcm_analog_alt_playback;
2390 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002391 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2392 spec->alt_dac_nid;
2393 } else {
2394 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2395 alc_pcm_null_stream;
2396 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2397 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002398 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002399 p = spec->stream_analog_alt_capture;
2400 if (!p)
2401 p = &alc_pcm_analog_alt_capture;
2402 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002403 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2404 spec->adc_nids[1];
2405 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2406 spec->num_adc_nids - 1;
2407 } else {
2408 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2409 alc_pcm_null_stream;
2410 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002411 }
2412 }
2413
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 return 0;
2415}
2416
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002417static inline void alc_shutup(struct hda_codec *codec)
2418{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002419 struct alc_spec *spec = codec->spec;
2420
2421 if (spec && spec->shutup)
2422 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002423 snd_hda_shutup_pins(codec);
2424}
2425
Takashi Iwai603c4012008-07-30 15:01:44 +02002426static void alc_free_kctls(struct hda_codec *codec)
2427{
2428 struct alc_spec *spec = codec->spec;
2429
2430 if (spec->kctls.list) {
2431 struct snd_kcontrol_new *kctl = spec->kctls.list;
2432 int i;
2433 for (i = 0; i < spec->kctls.used; i++)
2434 kfree(kctl[i].name);
2435 }
2436 snd_array_free(&spec->kctls);
2437}
2438
Takashi Iwai23c09b02011-08-19 09:05:35 +02002439static void alc_free_bind_ctls(struct hda_codec *codec)
2440{
2441 struct alc_spec *spec = codec->spec;
2442 if (spec->bind_ctls.list) {
2443 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2444 int i;
2445 for (i = 0; i < spec->bind_ctls.used; i++)
2446 kfree(ctl[i]);
2447 }
2448 snd_array_free(&spec->bind_ctls);
2449}
2450
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451static void alc_free(struct hda_codec *codec)
2452{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002453 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002454
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002455 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002456 return;
2457
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002458 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002459 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002460 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002461 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002462 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
Hector Martinf5de24b2009-12-20 22:51:31 +01002465#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002466static void alc_power_eapd(struct hda_codec *codec)
2467{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002468 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002469}
2470
Hector Martinf5de24b2009-12-20 22:51:31 +01002471static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2472{
2473 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002474 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002475 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002476 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002477 return 0;
2478}
2479#endif
2480
Takashi Iwai2a439522011-07-26 09:52:50 +02002481#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002482static int alc_resume(struct hda_codec *codec)
2483{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002484 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002485 codec->patch_ops.init(codec);
2486 snd_hda_codec_resume_amp(codec);
2487 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002488 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002489 return 0;
2490}
Takashi Iwaie044c392008-10-27 16:56:24 +01002491#endif
2492
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493/*
2494 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002495static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 .build_controls = alc_build_controls,
2497 .build_pcms = alc_build_pcms,
2498 .init = alc_init,
2499 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002500 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002501#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002502 .resume = alc_resume,
2503#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002504#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002505 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002506 .check_power_status = alc_check_power_status,
2507#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002508 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509};
2510
Kailang Yangc027ddc2010-03-19 11:33:06 +01002511/* replace the codec chip_name with the given string */
2512static int alc_codec_rename(struct hda_codec *codec, const char *name)
2513{
2514 kfree(codec->chip_name);
2515 codec->chip_name = kstrdup(name, GFP_KERNEL);
2516 if (!codec->chip_name) {
2517 alc_free(codec);
2518 return -ENOMEM;
2519 }
2520 return 0;
2521}
2522
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002523/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002524 * Rename codecs appropriately from COEF value
2525 */
2526struct alc_codec_rename_table {
2527 unsigned int vendor_id;
2528 unsigned short coef_mask;
2529 unsigned short coef_bits;
2530 const char *name;
2531};
2532
2533static struct alc_codec_rename_table rename_tbl[] = {
2534 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2535 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2536 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2537 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2538 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2539 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2540 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2541 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2542 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2543 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2544 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2545 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2546 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2547 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2548 { } /* terminator */
2549};
2550
2551static int alc_codec_rename_from_preset(struct hda_codec *codec)
2552{
2553 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002554
2555 for (p = rename_tbl; p->vendor_id; p++) {
2556 if (p->vendor_id != codec->vendor_id)
2557 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002558 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002559 return alc_codec_rename(codec, p->name);
2560 }
2561 return 0;
2562}
2563
2564/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002565 * Automatic parse of I/O pins from the BIOS configuration
2566 */
2567
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002568enum {
2569 ALC_CTL_WIDGET_VOL,
2570 ALC_CTL_WIDGET_MUTE,
2571 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002572 ALC_CTL_BIND_VOL,
2573 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002574};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002575static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002576 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2577 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002578 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002579 HDA_BIND_VOL(NULL, 0),
2580 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002581};
2582
2583/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002584static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002585 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002586{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002587 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002588
Takashi Iwaice764ab2011-04-27 16:35:23 +02002589 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002590 if (!knew)
2591 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002592 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002593 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002594 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002595 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002596 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002597 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002598 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002599 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002600 return 0;
2601}
2602
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002603static int add_control_with_pfx(struct alc_spec *spec, int type,
2604 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002605 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002606{
2607 char name[32];
2608 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002609 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002610}
2611
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002612#define add_pb_vol_ctrl(spec, type, pfx, val) \
2613 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2614#define add_pb_sw_ctrl(spec, type, pfx, val) \
2615 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2616#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2617 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2618#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2619 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002620
Takashi Iwai23c09b02011-08-19 09:05:35 +02002621static const char * const channel_name[4] = {
2622 "Front", "Surround", "CLFE", "Side"
2623};
2624
Takashi Iwai6843ca12011-06-24 11:03:58 +02002625static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2626 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002627{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002628 struct auto_pin_cfg *cfg = &spec->autocfg;
2629
Takashi Iwai6843ca12011-06-24 11:03:58 +02002630 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002631 if (cfg->line_outs == 1 && !spec->multi_ios &&
2632 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002633 return "Master";
2634
2635 switch (cfg->line_out_type) {
2636 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002637 if (cfg->line_outs == 1)
2638 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002639 if (cfg->line_outs == 2)
2640 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002641 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002642 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002643 /* for multi-io case, only the primary out */
2644 if (ch && spec->multi_ios)
2645 break;
2646 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002647 return "Headphone";
2648 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002649 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002650 return "PCM";
2651 break;
2652 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002653 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2654 return "PCM";
2655
2656 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002657}
2658
Takashi Iwai164f73e2012-02-21 11:27:09 +01002659#ifdef CONFIG_SND_HDA_POWER_SAVE
2660/* add the powersave loopback-list entry */
2661static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2662{
2663 struct hda_amp_list *list;
2664
2665 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2666 return;
2667 list = spec->loopback_list + spec->num_loopbacks;
2668 list->nid = mix;
2669 list->dir = HDA_INPUT;
2670 list->idx = idx;
2671 spec->num_loopbacks++;
2672 spec->loopback.amplist = spec->loopback_list;
2673}
2674#else
2675#define add_loopback_list(spec, mix, idx) /* NOP */
2676#endif
2677
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002678/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002679static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002680 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002681 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002682{
Kailang Yangdf694da2005-12-05 19:42:22 +01002683 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002684
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002685 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002686 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2687 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002688 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002689 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002690 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2691 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002692 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002693 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002694 return 0;
2695}
2696
Takashi Iwai05f5f472009-08-25 13:10:18 +02002697static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002698{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002699 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2700 return (pincap & AC_PINCAP_IN) != 0;
2701}
2702
Takashi Iwai1d045db2011-07-07 18:23:21 +02002703/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002704static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002705{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002706 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002707 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002708 hda_nid_t *adc_nids = spec->private_adc_nids;
2709 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2710 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002711 int i, nums = 0;
2712
Takashi Iwai24de1832011-11-07 17:13:39 +01002713 if (spec->shared_mic_hp)
2714 max_nums = 1; /* no multi streams with the shared HP/mic */
2715
Takashi Iwaib7821702011-07-06 15:12:46 +02002716 nid = codec->start_nid;
2717 for (i = 0; i < codec->num_nodes; i++, nid++) {
2718 hda_nid_t src;
2719 const hda_nid_t *list;
2720 unsigned int caps = get_wcaps(codec, nid);
2721 int type = get_wcaps_type(caps);
2722
2723 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2724 continue;
2725 adc_nids[nums] = nid;
2726 cap_nids[nums] = nid;
2727 src = nid;
2728 for (;;) {
2729 int n;
2730 type = get_wcaps_type(get_wcaps(codec, src));
2731 if (type == AC_WID_PIN)
2732 break;
2733 if (type == AC_WID_AUD_SEL) {
2734 cap_nids[nums] = src;
2735 break;
2736 }
2737 n = snd_hda_get_conn_list(codec, src, &list);
2738 if (n > 1) {
2739 cap_nids[nums] = src;
2740 break;
2741 } else if (n != 1)
2742 break;
2743 src = *list;
2744 }
2745 if (++nums >= max_nums)
2746 break;
2747 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002748 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002749 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002750 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002751 return nums;
2752}
2753
Takashi Iwai05f5f472009-08-25 13:10:18 +02002754/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002755static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002756{
2757 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002758 const struct auto_pin_cfg *cfg = &spec->autocfg;
2759 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002760 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002761 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002762 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002763 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002764
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002765 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002766 if (num_adcs < 0)
2767 return 0;
2768
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002769 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002770 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002771 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002772
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002773 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002774 if (!alc_is_input_pin(codec, pin))
2775 continue;
2776
David Henningsson5322bf22011-01-05 11:03:56 +01002777 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002778 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2779 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002780 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002781 type_idx++;
2782 else
2783 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002784 prev_label = label;
2785
Takashi Iwai05f5f472009-08-25 13:10:18 +02002786 if (mixer) {
2787 idx = get_connection_index(codec, mixer, pin);
2788 if (idx >= 0) {
2789 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002790 label, type_idx,
2791 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002792 if (err < 0)
2793 return err;
2794 }
2795 }
2796
Takashi Iwaib7821702011-07-06 15:12:46 +02002797 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002798 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002799 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002800 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002801 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002802 snd_hda_add_imux_item(imux, label, idx, NULL);
2803 break;
2804 }
2805 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002806 }
Takashi Iwai21268962011-07-07 15:01:13 +02002807
2808 spec->num_mux_defs = 1;
2809 spec->input_mux = imux;
2810
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002811 return 0;
2812}
2813
Takashi Iwai24de1832011-11-07 17:13:39 +01002814/* create a shared input with the headphone out */
2815static int alc_auto_create_shared_input(struct hda_codec *codec)
2816{
2817 struct alc_spec *spec = codec->spec;
2818 struct auto_pin_cfg *cfg = &spec->autocfg;
2819 unsigned int defcfg;
2820 hda_nid_t nid;
2821
2822 /* only one internal input pin? */
2823 if (cfg->num_inputs != 1)
2824 return 0;
2825 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2826 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2827 return 0;
2828
2829 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2830 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2831 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2832 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2833 else
2834 return 0; /* both not available */
2835
2836 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2837 return 0; /* no input */
2838
2839 cfg->inputs[1].pin = nid;
2840 cfg->inputs[1].type = AUTO_PIN_MIC;
2841 cfg->num_inputs = 2;
2842 spec->shared_mic_hp = 1;
2843 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2844 return 0;
2845}
2846
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002847static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2848 unsigned int pin_type)
2849{
2850 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2851 pin_type);
2852 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002853 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2854 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002855 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002856}
2857
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002858static int get_pin_type(int line_out_type)
2859{
2860 if (line_out_type == AUTO_PIN_HP_OUT)
2861 return PIN_HP;
2862 else
2863 return PIN_OUT;
2864}
2865
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002866static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002867{
2868 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002869 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002870 int i;
2871
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002872 for (i = 0; i < cfg->num_inputs; i++) {
2873 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002874 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002875 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002876 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002877 snd_hda_codec_write(codec, nid, 0,
2878 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002879 AMP_OUT_MUTE);
2880 }
2881 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002882
2883 /* mute all loopback inputs */
2884 if (spec->mixer_nid) {
2885 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2886 for (i = 0; i < nums; i++)
2887 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2888 AC_VERB_SET_AMP_GAIN_MUTE,
2889 AMP_IN_MUTE(i));
2890 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002891}
2892
Takashi Iwai7085ec12009-10-02 09:03:58 +02002893/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002894static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002895{
Takashi Iwai604401a2011-04-27 15:14:23 +02002896 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002897 int i, num;
2898
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002899 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2900 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002901 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2902 for (i = 0; i < num; i++) {
2903 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2904 return list[i];
2905 }
2906 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002907}
2908
Takashi Iwai604401a2011-04-27 15:14:23 +02002909/* go down to the selector widget before the mixer */
2910static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2911{
2912 hda_nid_t srcs[5];
2913 int num = snd_hda_get_connections(codec, pin, srcs,
2914 ARRAY_SIZE(srcs));
2915 if (num != 1 ||
2916 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2917 return pin;
2918 return srcs[0];
2919}
2920
Takashi Iwai7085ec12009-10-02 09:03:58 +02002921/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002922static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002923 hda_nid_t dac)
2924{
David Henningssoncc1c4522010-11-24 14:17:47 +01002925 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002926 int i, num;
2927
Takashi Iwai604401a2011-04-27 15:14:23 +02002928 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002929 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2930 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002931 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002932 return mix[i];
2933 }
2934 return 0;
2935}
2936
Takashi Iwaice764ab2011-04-27 16:35:23 +02002937/* select the connection from pin to DAC if needed */
2938static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2939 hda_nid_t dac)
2940{
2941 hda_nid_t mix[5];
2942 int i, num;
2943
2944 pin = alc_go_down_to_selector(codec, pin);
2945 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2946 if (num < 2)
2947 return 0;
2948 for (i = 0; i < num; i++) {
2949 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2950 snd_hda_codec_update_cache(codec, pin, 0,
2951 AC_VERB_SET_CONNECT_SEL, i);
2952 return 0;
2953 }
2954 }
2955 return 0;
2956}
2957
Takashi Iwai185d99f2012-02-16 18:39:45 +01002958static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2959{
2960 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002961 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002962 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2963 ARRAY_SIZE(spec->private_dac_nids)) ||
2964 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2965 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2966 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2967 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2968 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002969 for (i = 0; i < spec->multi_ios; i++) {
2970 if (spec->multi_io[i].dac == nid)
2971 return true;
2972 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002973 return false;
2974}
2975
Takashi Iwai7085ec12009-10-02 09:03:58 +02002976/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002977static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002978{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002979 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002980 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002981
Takashi Iwai604401a2011-04-27 15:14:23 +02002982 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002983 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002984 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002985 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002986 if (!nid)
2987 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002988 if (!alc_is_dac_already_used(codec, nid))
2989 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002990 }
2991 return 0;
2992}
2993
Takashi Iwai07b18f62011-11-10 15:42:54 +01002994/* check whether the DAC is reachable from the pin */
2995static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2996 hda_nid_t pin, hda_nid_t dac)
2997{
2998 hda_nid_t srcs[5];
2999 int i, num;
3000
Takashi Iwaidc31b582012-02-17 17:27:53 +01003001 if (!pin || !dac)
3002 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003003 pin = alc_go_down_to_selector(codec, pin);
3004 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
3005 for (i = 0; i < num; i++) {
3006 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3007 if (nid == dac)
3008 return true;
3009 }
3010 return false;
3011}
3012
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003013static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3014{
Takashi Iwai140547e2012-02-16 17:23:46 +01003015 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003016 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003017 hda_nid_t nid, nid_found, srcs[5];
3018 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01003019 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01003020 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003021 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003022 nid_found = 0;
3023 for (i = 0; i < num; i++) {
3024 if (srcs[i] == spec->mixer_nid)
3025 continue;
3026 nid = alc_auto_mix_to_dac(codec, srcs[i]);
3027 if (nid && !alc_is_dac_already_used(codec, nid)) {
3028 if (nid_found)
3029 return 0;
3030 nid_found = nid;
3031 }
3032 }
3033 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003034}
3035
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003036/* mark up volume and mute control NIDs: used during badness parsing and
3037 * at creating actual controls
3038 */
3039static inline unsigned int get_ctl_pos(unsigned int data)
3040{
3041 hda_nid_t nid = get_amp_nid_(data);
3042 unsigned int dir;
3043 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3044 return 0;
3045 dir = get_amp_direction_(data);
3046 return (nid << 1) | dir;
3047}
3048
3049#define is_ctl_used(bits, data) \
3050 test_bit(get_ctl_pos(data), bits)
3051#define mark_ctl_usage(bits, data) \
3052 set_bit(get_ctl_pos(data), bits)
3053
3054static void clear_vol_marks(struct hda_codec *codec)
3055{
3056 struct alc_spec *spec = codec->spec;
3057 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3058 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3059}
3060
3061/* badness definition */
3062enum {
3063 /* No primary DAC is found for the main output */
3064 BAD_NO_PRIMARY_DAC = 0x10000,
3065 /* No DAC is found for the extra output */
3066 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003067 /* No possible multi-ios */
3068 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003069 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003070 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003071 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003072 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003073 /* Primary DAC shared with main surrounds */
3074 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003075 /* Primary DAC shared with main CLFE */
3076 BAD_SHARED_CLFE = 0x10,
3077 /* Primary DAC shared with extra surrounds */
3078 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003079 /* Volume widget is shared */
3080 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003081};
3082
3083static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3084 hda_nid_t pin, hda_nid_t dac);
3085static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3086 hda_nid_t pin, hda_nid_t dac);
3087
3088static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3089 hda_nid_t dac)
3090{
3091 struct alc_spec *spec = codec->spec;
3092 hda_nid_t nid;
3093 unsigned int val;
3094 int badness = 0;
3095
3096 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3097 if (nid) {
3098 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3099 if (is_ctl_used(spec->vol_ctls, nid))
3100 badness += BAD_SHARED_VOL;
3101 else
3102 mark_ctl_usage(spec->vol_ctls, val);
3103 } else
3104 badness += BAD_SHARED_VOL;
3105 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3106 if (nid) {
3107 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3108 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3109 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3110 else
3111 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3112 if (is_ctl_used(spec->sw_ctls, val))
3113 badness += BAD_SHARED_VOL;
3114 else
3115 mark_ctl_usage(spec->sw_ctls, val);
3116 } else
3117 badness += BAD_SHARED_VOL;
3118 return badness;
3119}
3120
Takashi Iwaidc31b582012-02-17 17:27:53 +01003121struct badness_table {
3122 int no_primary_dac; /* no primary DAC */
3123 int no_dac; /* no secondary DACs */
3124 int shared_primary; /* primary DAC is shared with main output */
3125 int shared_surr; /* secondary DAC shared with main or primary */
3126 int shared_clfe; /* third DAC shared with main or primary */
3127 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3128};
3129
3130static struct badness_table main_out_badness = {
3131 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3132 .no_dac = BAD_NO_DAC,
3133 .shared_primary = BAD_NO_PRIMARY_DAC,
3134 .shared_surr = BAD_SHARED_SURROUND,
3135 .shared_clfe = BAD_SHARED_CLFE,
3136 .shared_surr_main = BAD_SHARED_SURROUND,
3137};
3138
3139static struct badness_table extra_out_badness = {
3140 .no_primary_dac = BAD_NO_DAC,
3141 .no_dac = BAD_NO_DAC,
3142 .shared_primary = BAD_NO_EXTRA_DAC,
3143 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3144 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3145 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3146};
3147
3148/* try to assign DACs to pins and return the resultant badness */
3149static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3150 const hda_nid_t *pins, hda_nid_t *dacs,
3151 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003152{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003153 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003154 struct auto_pin_cfg *cfg = &spec->autocfg;
3155 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003156 int badness = 0;
3157 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003158
Takashi Iwai185d99f2012-02-16 18:39:45 +01003159 if (!num_outs)
3160 return 0;
3161
Takashi Iwaidc31b582012-02-17 17:27:53 +01003162 for (i = 0; i < num_outs; i++) {
3163 hda_nid_t pin = pins[i];
3164 if (!dacs[i])
3165 dacs[i] = alc_auto_look_for_dac(codec, pin);
3166 if (!dacs[i] && !i) {
3167 for (j = 1; j < num_outs; j++) {
3168 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3169 dacs[0] = dacs[j];
3170 dacs[j] = 0;
3171 break;
3172 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003173 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003174 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003175 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003176 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003177 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003178 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003179 else if (cfg->line_outs > i &&
3180 alc_auto_is_dac_reachable(codec, pin,
3181 spec->private_dac_nids[i]))
3182 dac = spec->private_dac_nids[i];
3183 if (dac) {
3184 if (!i)
3185 badness += bad->shared_primary;
3186 else if (i == 1)
3187 badness += bad->shared_surr;
3188 else
3189 badness += bad->shared_clfe;
3190 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003191 spec->private_dac_nids[0])) {
3192 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003193 badness += bad->shared_surr_main;
3194 } else if (!i)
3195 badness += bad->no_primary_dac;
3196 else
3197 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003198 }
3199 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003200 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003201 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003202
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003203 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003204}
3205
3206static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003207 hda_nid_t reference_pin,
3208 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003209
Takashi Iwai185d99f2012-02-16 18:39:45 +01003210static bool alc_map_singles(struct hda_codec *codec, int outs,
3211 const hda_nid_t *pins, hda_nid_t *dacs)
3212{
3213 int i;
3214 bool found = false;
3215 for (i = 0; i < outs; i++) {
3216 if (dacs[i])
3217 continue;
3218 dacs[i] = get_dac_if_single(codec, pins[i]);
3219 if (dacs[i])
3220 found = true;
3221 }
3222 return found;
3223}
3224
Takashi Iwai7085ec12009-10-02 09:03:58 +02003225/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003226static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003227 bool fill_hardwired,
3228 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003229{
3230 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003231 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003232 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003233
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003234 /* set num_dacs once to full for alc_auto_look_for_dac() */
3235 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003236 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003237 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3238 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3239 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003240 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003241 clear_vol_marks(codec);
3242 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003243
3244 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003245 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003246 bool mapped;
3247 do {
3248 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003249 cfg->line_out_pins,
3250 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003251 mapped |= alc_map_singles(codec, cfg->hp_outs,
3252 cfg->hp_pins,
3253 spec->multiout.hp_out_nid);
3254 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3255 cfg->speaker_pins,
3256 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003257 if (fill_mio_first && cfg->line_outs == 1 &&
3258 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3259 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3260 if (!err)
3261 mapped = true;
3262 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003263 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003264 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003265
Takashi Iwaidc31b582012-02-17 17:27:53 +01003266 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3267 spec->private_dac_nids,
3268 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003269
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003270 /* re-count num_dacs and squash invalid entries */
3271 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003272 for (i = 0; i < cfg->line_outs; i++) {
3273 if (spec->private_dac_nids[i])
3274 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003275 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003276 memmove(spec->private_dac_nids + i,
3277 spec->private_dac_nids + i + 1,
3278 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003279 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3280 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003281 }
3282
Takashi Iwai276dd702012-02-17 16:17:03 +01003283 if (fill_mio_first &&
3284 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003285 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003286 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003287 if (err < 0)
3288 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003289 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003290 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003291
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003292 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003293 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3294 spec->multiout.hp_out_nid,
3295 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003296 if (err < 0)
3297 return err;
3298 badness += err;
3299 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003300 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003301 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3302 cfg->speaker_pins,
3303 spec->multiout.extra_out_nid,
3304 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003305 if (err < 0)
3306 return err;
3307 badness += err;
3308 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003309 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3310 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003311 if (err < 0)
3312 return err;
3313 badness += err;
3314 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003315 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3316 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003317 int offset = 0;
3318 if (cfg->line_outs >= 3)
3319 offset = 1;
3320 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3321 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003322 if (err < 0)
3323 return err;
3324 badness += err;
3325 }
3326
3327 if (spec->multi_ios == 2) {
3328 for (i = 0; i < 2; i++)
3329 spec->private_dac_nids[spec->multiout.num_dacs++] =
3330 spec->multi_io[i].dac;
3331 spec->ext_channel_count = 2;
3332 } else if (spec->multi_ios) {
3333 spec->multi_ios = 0;
3334 badness += BAD_MULTI_IO;
3335 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003336
3337 return badness;
3338}
3339
3340#define DEBUG_BADNESS
3341
3342#ifdef DEBUG_BADNESS
3343#define debug_badness snd_printdd
3344#else
3345#define debug_badness(...)
3346#endif
3347
3348static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3349{
3350 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3351 cfg->line_out_pins[0], cfg->line_out_pins[1],
3352 cfg->line_out_pins[2], cfg->line_out_pins[2],
3353 spec->multiout.dac_nids[0],
3354 spec->multiout.dac_nids[1],
3355 spec->multiout.dac_nids[2],
3356 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003357 if (spec->multi_ios > 0)
3358 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3359 spec->multi_ios,
3360 spec->multi_io[0].pin, spec->multi_io[1].pin,
3361 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003362 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3363 cfg->hp_pins[0], cfg->hp_pins[1],
3364 cfg->hp_pins[2], cfg->hp_pins[2],
3365 spec->multiout.hp_out_nid[0],
3366 spec->multiout.hp_out_nid[1],
3367 spec->multiout.hp_out_nid[2],
3368 spec->multiout.hp_out_nid[3]);
3369 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3370 cfg->speaker_pins[0], cfg->speaker_pins[1],
3371 cfg->speaker_pins[2], cfg->speaker_pins[3],
3372 spec->multiout.extra_out_nid[0],
3373 spec->multiout.extra_out_nid[1],
3374 spec->multiout.extra_out_nid[2],
3375 spec->multiout.extra_out_nid[3]);
3376}
3377
3378static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3379{
3380 struct alc_spec *spec = codec->spec;
3381 struct auto_pin_cfg *cfg = &spec->autocfg;
3382 struct auto_pin_cfg *best_cfg;
3383 int best_badness = INT_MAX;
3384 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003385 bool fill_hardwired = true, fill_mio_first = true;
3386 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003387 bool hp_spk_swapped = false;
3388
3389 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3390 if (!best_cfg)
3391 return -ENOMEM;
3392 *best_cfg = *cfg;
3393
3394 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003395 badness = fill_and_eval_dacs(codec, fill_hardwired,
3396 fill_mio_first);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003397 if (badness < 0)
3398 return badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003399 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3400 cfg->line_out_type, fill_hardwired, fill_mio_first,
3401 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003402 debug_show_configs(spec, cfg);
3403 if (badness < best_badness) {
3404 best_badness = badness;
3405 *best_cfg = *cfg;
3406 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003407 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003408 }
3409 if (!badness)
3410 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003411 fill_mio_first = !fill_mio_first;
3412 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003413 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003414 fill_hardwired = !fill_hardwired;
3415 if (!fill_hardwired)
3416 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003417 if (hp_spk_swapped)
3418 break;
3419 hp_spk_swapped = true;
3420 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003421 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3422 cfg->hp_outs = cfg->line_outs;
3423 memcpy(cfg->hp_pins, cfg->line_out_pins,
3424 sizeof(cfg->hp_pins));
3425 cfg->line_outs = cfg->speaker_outs;
3426 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3427 sizeof(cfg->speaker_pins));
3428 cfg->speaker_outs = 0;
3429 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3430 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003431 fill_hardwired = true;
3432 continue;
3433 }
3434 if (cfg->hp_outs > 0 &&
3435 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3436 cfg->speaker_outs = cfg->line_outs;
3437 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3438 sizeof(cfg->speaker_pins));
3439 cfg->line_outs = cfg->hp_outs;
3440 memcpy(cfg->line_out_pins, cfg->hp_pins,
3441 sizeof(cfg->hp_pins));
3442 cfg->hp_outs = 0;
3443 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3444 cfg->line_out_type = AUTO_PIN_HP_OUT;
3445 fill_hardwired = true;
3446 continue;
3447 }
3448 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003449 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003450
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003451 if (badness) {
3452 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003453 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003454 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003455 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3456 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003457 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003458
David Henningssonfde48a12011-12-09 18:27:42 +08003459 if (cfg->line_out_pins[0])
3460 spec->vmaster_nid =
3461 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3462 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003463
3464 /* clear the bitmap flags for creating controls */
3465 clear_vol_marks(codec);
3466 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003467 return 0;
3468}
3469
Takashi Iwai343a04b2011-07-06 14:28:39 +02003470static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003471 const char *pfx, int cidx,
3472 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003473{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003474 struct alc_spec *spec = codec->spec;
3475 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003476 if (!nid)
3477 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003478 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3479 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3480 return 0;
3481 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003482 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003483 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003484}
3485
Takashi Iwaie29d3772011-11-14 17:13:23 +01003486static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3487 const char *pfx, int cidx,
3488 hda_nid_t nid)
3489{
3490 int chs = 1;
3491 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3492 chs = 3;
3493 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3494}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003495
3496/* create a mute-switch for the given mixer widget;
3497 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3498 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003499static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003500 const char *pfx, int cidx,
3501 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003502{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003503 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003504 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003505 int type;
3506 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003507 if (!nid)
3508 return 0;
3509 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3510 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3511 type = ALC_CTL_WIDGET_MUTE;
3512 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3513 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003514 type = ALC_CTL_WIDGET_MUTE;
3515 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3516 } else {
3517 type = ALC_CTL_BIND_MUTE;
3518 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3519 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003520 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3521 return 0;
3522 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003523 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003524}
3525
Takashi Iwaie29d3772011-11-14 17:13:23 +01003526static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3527 int cidx, hda_nid_t nid)
3528{
3529 int chs = 1;
3530 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3531 chs = 3;
3532 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3533}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003534
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003535static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3536 hda_nid_t pin, hda_nid_t dac)
3537{
3538 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3539 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3540 return pin;
3541 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3542 return mix;
3543 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3544 return dac;
3545 return 0;
3546}
3547
3548static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3549 hda_nid_t pin, hda_nid_t dac)
3550{
3551 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3552 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3553 return dac;
3554 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3555 return mix;
3556 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3557 return pin;
3558 return 0;
3559}
3560
Takashi Iwai7085ec12009-10-02 09:03:58 +02003561/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003562static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003563 const struct auto_pin_cfg *cfg)
3564{
3565 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003566 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003567
Takashi Iwaice764ab2011-04-27 16:35:23 +02003568 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003569 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003570 noutputs += spec->multi_ios;
3571
3572 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003573 const char *name;
3574 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003575 hda_nid_t dac, pin;
3576 hda_nid_t sw, vol;
3577
3578 dac = spec->multiout.dac_nids[i];
3579 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003580 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003581 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003582 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003583 index = 0;
3584 name = channel_name[i];
3585 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003586 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003587 name = alc_get_line_out_pfx(spec, i, true, &index);
3588 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003589
3590 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3591 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003592 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003593 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003594 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003595 if (err < 0)
3596 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003597 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003598 if (err < 0)
3599 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003600 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003601 if (err < 0)
3602 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003603 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003604 if (err < 0)
3605 return err;
3606 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003607 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003608 if (err < 0)
3609 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003610 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003611 if (err < 0)
3612 return err;
3613 }
3614 }
3615 return 0;
3616}
3617
Takashi Iwai343a04b2011-07-06 14:28:39 +02003618static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003619 hda_nid_t dac, const char *pfx,
3620 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003621{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003622 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003623 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003624 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003625
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003626 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003627 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003628 /* the corresponding DAC is already occupied */
3629 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3630 return 0; /* no way */
3631 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003632 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3633 if (is_ctl_used(spec->sw_ctls, val))
3634 return 0; /* already created */
3635 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003636 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003637 }
3638
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003639 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3640 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003641 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003642 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003643 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003644 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003645 if (err < 0)
3646 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003647 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003648}
3649
Takashi Iwai23c09b02011-08-19 09:05:35 +02003650static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3651 unsigned int nums,
3652 struct hda_ctl_ops *ops)
3653{
3654 struct alc_spec *spec = codec->spec;
3655 struct hda_bind_ctls **ctlp, *ctl;
3656 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3657 ctlp = snd_array_new(&spec->bind_ctls);
3658 if (!ctlp)
3659 return NULL;
3660 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3661 *ctlp = ctl;
3662 if (ctl)
3663 ctl->ops = ops;
3664 return ctl;
3665}
3666
3667/* add playback controls for speaker and HP outputs */
3668static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3669 const hda_nid_t *pins,
3670 const hda_nid_t *dacs,
3671 const char *pfx)
3672{
3673 struct alc_spec *spec = codec->spec;
3674 struct hda_bind_ctls *ctl;
3675 char name[32];
3676 int i, n, err;
3677
3678 if (!num_pins || !pins[0])
3679 return 0;
3680
Takashi Iwai527e4d72011-10-27 16:33:27 +02003681 if (num_pins == 1) {
3682 hda_nid_t dac = *dacs;
3683 if (!dac)
3684 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003685 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003686 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003687
Takashi Iwai23c09b02011-08-19 09:05:35 +02003688 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003689 hda_nid_t dac;
3690 if (dacs[num_pins - 1])
3691 dac = dacs[i]; /* with individual volumes */
3692 else
3693 dac = 0;
3694 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3695 err = alc_auto_create_extra_out(codec, pins[i], dac,
3696 "Bass Speaker", 0);
3697 } else if (num_pins >= 3) {
3698 snprintf(name, sizeof(name), "%s %s",
3699 pfx, channel_name[i]);
3700 err = alc_auto_create_extra_out(codec, pins[i], dac,
3701 name, 0);
3702 } else {
3703 err = alc_auto_create_extra_out(codec, pins[i], dac,
3704 pfx, i);
3705 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003706 if (err < 0)
3707 return err;
3708 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003709 if (dacs[num_pins - 1])
3710 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003711
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003712 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003713 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3714 if (!ctl)
3715 return -ENOMEM;
3716 n = 0;
3717 for (i = 0; i < num_pins; i++) {
3718 hda_nid_t vol;
3719 if (!pins[i] || !dacs[i])
3720 continue;
3721 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3722 if (vol)
3723 ctl->values[n++] =
3724 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3725 }
3726 if (n) {
3727 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3728 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3729 if (err < 0)
3730 return err;
3731 }
3732 return 0;
3733}
3734
Takashi Iwai343a04b2011-07-06 14:28:39 +02003735static int alc_auto_create_hp_out(struct hda_codec *codec)
3736{
3737 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003738 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3739 spec->autocfg.hp_pins,
3740 spec->multiout.hp_out_nid,
3741 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003742}
3743
3744static int alc_auto_create_speaker_out(struct hda_codec *codec)
3745{
3746 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003747 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3748 spec->autocfg.speaker_pins,
3749 spec->multiout.extra_out_nid,
3750 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003751}
3752
Takashi Iwai343a04b2011-07-06 14:28:39 +02003753static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003754 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003755 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003756{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003757 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003758 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003759 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003760
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003761 alc_set_pin_output(codec, pin, pin_type);
3762 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003763 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003764 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003765 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003766 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003767 mix = srcs[i];
3768 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003769 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003770 if (!mix)
3771 return;
3772
3773 /* need the manual connection? */
3774 if (num > 1)
3775 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3776 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003777 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3778 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003779 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003780 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003781 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003782 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003783 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003784 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3785 if (nid)
3786 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3787 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003788
3789 /* unmute DAC if it's not assigned to a mixer */
3790 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3791 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3792 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3793 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003794}
3795
Takashi Iwai343a04b2011-07-06 14:28:39 +02003796static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003797{
3798 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003799 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003800 int i;
3801
3802 for (i = 0; i <= HDA_SIDE; i++) {
3803 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3804 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003805 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003806 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003807 }
3808}
3809
Takashi Iwai343a04b2011-07-06 14:28:39 +02003810static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003811{
3812 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003813 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003814 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003815
David Henningsson636030e2011-10-12 19:26:03 +02003816 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003817 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3818 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003819 pin = spec->autocfg.hp_pins[i];
3820 if (!pin)
3821 break;
3822 dac = spec->multiout.hp_out_nid[i];
3823 if (!dac) {
3824 if (i > 0 && spec->multiout.hp_out_nid[0])
3825 dac = spec->multiout.hp_out_nid[0];
3826 else
3827 dac = spec->multiout.dac_nids[0];
3828 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003829 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3830 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003831 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003832 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3833 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003834 pin = spec->autocfg.speaker_pins[i];
3835 if (!pin)
3836 break;
3837 dac = spec->multiout.extra_out_nid[i];
3838 if (!dac) {
3839 if (i > 0 && spec->multiout.extra_out_nid[0])
3840 dac = spec->multiout.extra_out_nid[0];
3841 else
3842 dac = spec->multiout.dac_nids[0];
3843 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003844 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3845 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003846}
3847
Takashi Iwai276dd702012-02-17 16:17:03 +01003848/* check whether the given pin can be a multi-io pin */
3849static bool can_be_multiio_pin(struct hda_codec *codec,
3850 unsigned int location, hda_nid_t nid)
3851{
3852 unsigned int defcfg, caps;
3853
3854 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3855 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3856 return false;
3857 if (location && get_defcfg_location(defcfg) != location)
3858 return false;
3859 caps = snd_hda_query_pin_caps(codec, nid);
3860 if (!(caps & AC_PINCAP_OUT))
3861 return false;
3862 return true;
3863}
3864
Takashi Iwaice764ab2011-04-27 16:35:23 +02003865/*
3866 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003867 *
3868 * When hardwired is set, try to fill ony hardwired pins, and returns
3869 * zero if any pins are filled, non-zero if nothing found.
3870 * When hardwired is off, try to fill possible input pins, and returns
3871 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003872 */
3873static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003874 hda_nid_t reference_pin,
3875 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003876{
3877 struct alc_spec *spec = codec->spec;
3878 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003879 int type, i, j, dacs, num_pins, old_pins;
3880 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3881 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003882 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003883
Takashi Iwai276dd702012-02-17 16:17:03 +01003884 old_pins = spec->multi_ios;
3885 if (old_pins >= 2)
3886 goto end_fill;
3887
3888 num_pins = 0;
3889 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3890 for (i = 0; i < cfg->num_inputs; i++) {
3891 if (cfg->inputs[i].type != type)
3892 continue;
3893 if (can_be_multiio_pin(codec, location,
3894 cfg->inputs[i].pin))
3895 num_pins++;
3896 }
3897 }
3898 if (num_pins < 2)
3899 goto end_fill;
3900
Takashi Iwai07b18f62011-11-10 15:42:54 +01003901 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003902 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3903 for (i = 0; i < cfg->num_inputs; i++) {
3904 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003905 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003906
Takashi Iwaice764ab2011-04-27 16:35:23 +02003907 if (cfg->inputs[i].type != type)
3908 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003909 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003910 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003911 for (j = 0; j < spec->multi_ios; j++) {
3912 if (nid == spec->multi_io[j].pin)
3913 break;
3914 }
3915 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003916 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003917
3918 if (offset && offset + spec->multi_ios < dacs) {
3919 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003920 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3921 dac = 0;
3922 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003923 if (hardwired)
3924 dac = get_dac_if_single(codec, nid);
3925 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003926 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003927 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003928 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003929 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003930 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003931 spec->multi_io[spec->multi_ios].pin = nid;
3932 spec->multi_io[spec->multi_ios].dac = dac;
3933 spec->multi_ios++;
3934 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003935 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003936 }
3937 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003938 end_fill:
3939 if (badness)
3940 badness = BAD_MULTI_IO;
3941 if (old_pins == spec->multi_ios) {
3942 if (hardwired)
3943 return 1; /* nothing found */
3944 else
3945 return badness; /* no badness if nothing found */
3946 }
3947 if (!hardwired && spec->multi_ios < 2) {
3948 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003949 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003950 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003951
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003952 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003953}
3954
3955static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3956 struct snd_ctl_elem_info *uinfo)
3957{
3958 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3959 struct alc_spec *spec = codec->spec;
3960
3961 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3962 uinfo->count = 1;
3963 uinfo->value.enumerated.items = spec->multi_ios + 1;
3964 if (uinfo->value.enumerated.item > spec->multi_ios)
3965 uinfo->value.enumerated.item = spec->multi_ios;
3966 sprintf(uinfo->value.enumerated.name, "%dch",
3967 (uinfo->value.enumerated.item + 1) * 2);
3968 return 0;
3969}
3970
3971static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3972 struct snd_ctl_elem_value *ucontrol)
3973{
3974 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3975 struct alc_spec *spec = codec->spec;
3976 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3977 return 0;
3978}
3979
3980static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3981{
3982 struct alc_spec *spec = codec->spec;
3983 hda_nid_t nid = spec->multi_io[idx].pin;
3984
3985 if (!spec->multi_io[idx].ctl_in)
3986 spec->multi_io[idx].ctl_in =
3987 snd_hda_codec_read(codec, nid, 0,
3988 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3989 if (output) {
3990 snd_hda_codec_update_cache(codec, nid, 0,
3991 AC_VERB_SET_PIN_WIDGET_CONTROL,
3992 PIN_OUT);
3993 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3994 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3995 HDA_AMP_MUTE, 0);
3996 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3997 } else {
3998 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3999 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4000 HDA_AMP_MUTE, HDA_AMP_MUTE);
4001 snd_hda_codec_update_cache(codec, nid, 0,
4002 AC_VERB_SET_PIN_WIDGET_CONTROL,
4003 spec->multi_io[idx].ctl_in);
4004 }
4005 return 0;
4006}
4007
4008static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4009 struct snd_ctl_elem_value *ucontrol)
4010{
4011 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4012 struct alc_spec *spec = codec->spec;
4013 int i, ch;
4014
4015 ch = ucontrol->value.enumerated.item[0];
4016 if (ch < 0 || ch > spec->multi_ios)
4017 return -EINVAL;
4018 if (ch == (spec->ext_channel_count - 1) / 2)
4019 return 0;
4020 spec->ext_channel_count = (ch + 1) * 2;
4021 for (i = 0; i < spec->multi_ios; i++)
4022 alc_set_multi_io(codec, i, i < ch);
4023 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004024 if (spec->need_dac_fix && !spec->const_channel_count)
4025 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004026 return 1;
4027}
4028
Takashi Iwaia9111322011-05-02 11:30:18 +02004029static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004030 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4031 .name = "Channel Mode",
4032 .info = alc_auto_ch_mode_info,
4033 .get = alc_auto_ch_mode_get,
4034 .put = alc_auto_ch_mode_put,
4035};
4036
Takashi Iwai23c09b02011-08-19 09:05:35 +02004037static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004038{
4039 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004040
Takashi Iwaic2674682011-08-24 17:57:44 +02004041 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004042 struct snd_kcontrol_new *knew;
4043
4044 knew = alc_kcontrol_new(spec);
4045 if (!knew)
4046 return -ENOMEM;
4047 *knew = alc_auto_channel_mode_enum;
4048 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4049 if (!knew->name)
4050 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004051 }
4052 return 0;
4053}
4054
Takashi Iwai1d045db2011-07-07 18:23:21 +02004055/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4056 * active input pins
4057 */
4058static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4059{
4060 struct alc_spec *spec = codec->spec;
4061 const struct hda_input_mux *imux;
4062 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4063 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4064 int i, n, nums;
4065
4066 imux = spec->input_mux;
4067 if (!imux)
4068 return;
4069 if (spec->dyn_adc_switch)
4070 return;
4071
4072 nums = 0;
4073 for (n = 0; n < spec->num_adc_nids; n++) {
4074 hda_nid_t cap = spec->private_capsrc_nids[n];
4075 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4076 for (i = 0; i < imux->num_items; i++) {
4077 hda_nid_t pin = spec->imux_pins[i];
4078 if (pin) {
4079 if (get_connection_index(codec, cap, pin) < 0)
4080 break;
4081 } else if (num_conns <= imux->items[i].index)
4082 break;
4083 }
4084 if (i >= imux->num_items) {
4085 adc_nids[nums] = spec->private_adc_nids[n];
4086 capsrc_nids[nums++] = cap;
4087 }
4088 }
4089 if (!nums) {
4090 /* check whether ADC-switch is possible */
4091 if (!alc_check_dyn_adc_switch(codec)) {
4092 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4093 " using fallback 0x%x\n",
4094 codec->chip_name, spec->private_adc_nids[0]);
4095 spec->num_adc_nids = 1;
4096 spec->auto_mic = 0;
4097 return;
4098 }
4099 } else if (nums != spec->num_adc_nids) {
4100 memcpy(spec->private_adc_nids, adc_nids,
4101 nums * sizeof(hda_nid_t));
4102 memcpy(spec->private_capsrc_nids, capsrc_nids,
4103 nums * sizeof(hda_nid_t));
4104 spec->num_adc_nids = nums;
4105 }
4106
4107 if (spec->auto_mic)
4108 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4109 else if (spec->input_mux->num_items == 1)
4110 spec->num_adc_nids = 1; /* reduce to a single ADC */
4111}
4112
4113/*
4114 * initialize ADC paths
4115 */
4116static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4117{
4118 struct alc_spec *spec = codec->spec;
4119 hda_nid_t nid;
4120
4121 nid = spec->adc_nids[adc_idx];
4122 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004123 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004124 snd_hda_codec_write(codec, nid, 0,
4125 AC_VERB_SET_AMP_GAIN_MUTE,
4126 AMP_IN_MUTE(0));
4127 return;
4128 }
4129 if (!spec->capsrc_nids)
4130 return;
4131 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004132 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004133 snd_hda_codec_write(codec, nid, 0,
4134 AC_VERB_SET_AMP_GAIN_MUTE,
4135 AMP_OUT_MUTE);
4136}
4137
4138static void alc_auto_init_input_src(struct hda_codec *codec)
4139{
4140 struct alc_spec *spec = codec->spec;
4141 int c, nums;
4142
4143 for (c = 0; c < spec->num_adc_nids; c++)
4144 alc_auto_init_adc(codec, c);
4145 if (spec->dyn_adc_switch)
4146 nums = 1;
4147 else
4148 nums = spec->num_adc_nids;
4149 for (c = 0; c < nums; c++)
4150 alc_mux_select(codec, 0, spec->cur_mux[c], true);
4151}
4152
4153/* add mic boosts if needed */
4154static int alc_auto_add_mic_boost(struct hda_codec *codec)
4155{
4156 struct alc_spec *spec = codec->spec;
4157 struct auto_pin_cfg *cfg = &spec->autocfg;
4158 int i, err;
4159 int type_idx = 0;
4160 hda_nid_t nid;
4161 const char *prev_label = NULL;
4162
4163 for (i = 0; i < cfg->num_inputs; i++) {
4164 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4165 break;
4166 nid = cfg->inputs[i].pin;
4167 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4168 const char *label;
4169 char boost_label[32];
4170
4171 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004172 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4173 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004174 if (prev_label && !strcmp(label, prev_label))
4175 type_idx++;
4176 else
4177 type_idx = 0;
4178 prev_label = label;
4179
4180 snprintf(boost_label, sizeof(boost_label),
4181 "%s Boost Volume", label);
4182 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4183 boost_label, type_idx,
4184 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4185 if (err < 0)
4186 return err;
4187 }
4188 }
4189 return 0;
4190}
4191
4192/* select or unmute the given capsrc route */
4193static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4194 int idx)
4195{
4196 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4197 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4198 HDA_AMP_MUTE, 0);
4199 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4200 snd_hda_codec_write_cache(codec, cap, 0,
4201 AC_VERB_SET_CONNECT_SEL, idx);
4202 }
4203}
4204
4205/* set the default connection to that pin */
4206static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4207{
4208 struct alc_spec *spec = codec->spec;
4209 int i;
4210
4211 if (!pin)
4212 return 0;
4213 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004214 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004215 int idx;
4216
4217 idx = get_connection_index(codec, cap, pin);
4218 if (idx < 0)
4219 continue;
4220 select_or_unmute_capsrc(codec, cap, idx);
4221 return i; /* return the found index */
4222 }
4223 return -1; /* not found */
4224}
4225
4226/* initialize some special cases for input sources */
4227static void alc_init_special_input_src(struct hda_codec *codec)
4228{
4229 struct alc_spec *spec = codec->spec;
4230 int i;
4231
4232 for (i = 0; i < spec->autocfg.num_inputs; i++)
4233 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4234}
4235
4236/* assign appropriate capture mixers */
4237static void set_capture_mixer(struct hda_codec *codec)
4238{
4239 struct alc_spec *spec = codec->spec;
4240 static const struct snd_kcontrol_new *caps[2][3] = {
4241 { alc_capture_mixer_nosrc1,
4242 alc_capture_mixer_nosrc2,
4243 alc_capture_mixer_nosrc3 },
4244 { alc_capture_mixer1,
4245 alc_capture_mixer2,
4246 alc_capture_mixer3 },
4247 };
4248
4249 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004250 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004251 if (!spec->capsrc_nids)
4252 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004253 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004254 return; /* no volume in capsrc, too */
4255 spec->vol_in_capsrc = 1;
4256 }
4257
4258 if (spec->num_adc_nids > 0) {
4259 int mux = 0;
4260 int num_adcs = 0;
4261
4262 if (spec->input_mux && spec->input_mux->num_items > 1)
4263 mux = 1;
4264 if (spec->auto_mic) {
4265 num_adcs = 1;
4266 mux = 0;
4267 } else if (spec->dyn_adc_switch)
4268 num_adcs = 1;
4269 if (!num_adcs) {
4270 if (spec->num_adc_nids > 3)
4271 spec->num_adc_nids = 3;
4272 else if (!spec->num_adc_nids)
4273 return;
4274 num_adcs = spec->num_adc_nids;
4275 }
4276 spec->cap_mixer = caps[mux][num_adcs - 1];
4277 }
4278}
4279
4280/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004281 * standard auto-parser initializations
4282 */
4283static void alc_auto_init_std(struct hda_codec *codec)
4284{
4285 struct alc_spec *spec = codec->spec;
4286 alc_auto_init_multi_out(codec);
4287 alc_auto_init_extra_out(codec);
4288 alc_auto_init_analog_input(codec);
4289 alc_auto_init_input_src(codec);
4290 alc_auto_init_digital(codec);
4291 if (spec->unsol_event)
4292 alc_inithook(codec);
4293}
4294
4295/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004296 * Digital-beep handlers
4297 */
4298#ifdef CONFIG_SND_HDA_INPUT_BEEP
4299#define set_beep_amp(spec, nid, idx, dir) \
4300 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4301
4302static const struct snd_pci_quirk beep_white_list[] = {
4303 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4304 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4305 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4306 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4307 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4308 {}
4309};
4310
4311static inline int has_cdefine_beep(struct hda_codec *codec)
4312{
4313 struct alc_spec *spec = codec->spec;
4314 const struct snd_pci_quirk *q;
4315 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4316 if (q)
4317 return q->value;
4318 return spec->cdefine.enable_pcbeep;
4319}
4320#else
4321#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4322#define has_cdefine_beep(codec) 0
4323#endif
4324
4325/* parse the BIOS configuration and set up the alc_spec */
4326/* return 1 if successful, 0 if the proper config is not found,
4327 * or a negative error code
4328 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004329static int alc_parse_auto_config(struct hda_codec *codec,
4330 const hda_nid_t *ignore_nids,
4331 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004332{
4333 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004334 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004335 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004336
Takashi Iwai53c334a2011-08-23 18:27:14 +02004337 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4338 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004339 if (err < 0)
4340 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004341 if (!cfg->line_outs) {
4342 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004343 spec->multiout.max_channels = 2;
4344 spec->no_analog = 1;
4345 goto dig_only;
4346 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004347 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004348 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004349
Takashi Iwai06503672011-10-06 08:27:19 +02004350 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4351 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004352 /* use HP as primary out */
4353 cfg->speaker_outs = cfg->line_outs;
4354 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4355 sizeof(cfg->speaker_pins));
4356 cfg->line_outs = cfg->hp_outs;
4357 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4358 cfg->hp_outs = 0;
4359 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4360 cfg->line_out_type = AUTO_PIN_HP_OUT;
4361 }
4362
Takashi Iwai1d045db2011-07-07 18:23:21 +02004363 err = alc_auto_fill_dac_nids(codec);
4364 if (err < 0)
4365 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004366 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004367 if (err < 0)
4368 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004369 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004370 if (err < 0)
4371 return err;
4372 err = alc_auto_create_hp_out(codec);
4373 if (err < 0)
4374 return err;
4375 err = alc_auto_create_speaker_out(codec);
4376 if (err < 0)
4377 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004378 err = alc_auto_create_shared_input(codec);
4379 if (err < 0)
4380 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004381 err = alc_auto_create_input_ctls(codec);
4382 if (err < 0)
4383 return err;
4384
4385 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4386
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004387 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004388 alc_auto_parse_digital(codec);
4389
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004390 if (!spec->no_analog)
4391 alc_remove_invalid_adc_nids(codec);
4392
4393 if (ssid_nids)
4394 alc_ssid_check(codec, ssid_nids);
4395
4396 if (!spec->no_analog) {
4397 alc_auto_check_switches(codec);
4398 err = alc_auto_add_mic_boost(codec);
4399 if (err < 0)
4400 return err;
4401 }
4402
Takashi Iwai1d045db2011-07-07 18:23:21 +02004403 if (spec->kctls.list)
4404 add_mixer(spec, spec->kctls.list);
4405
Takashi Iwai070cff42012-02-21 12:54:17 +01004406 if (!spec->no_analog && !spec->cap_mixer)
4407 set_capture_mixer(codec);
4408
Takashi Iwai1d045db2011-07-07 18:23:21 +02004409 return 1;
4410}
4411
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004412static int alc880_parse_auto_config(struct hda_codec *codec)
4413{
4414 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4415 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4416 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4417}
4418
Takashi Iwai1d045db2011-07-07 18:23:21 +02004419/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004420 * ALC880 fix-ups
4421 */
4422enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004423 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004424 ALC880_FIXUP_GPIO2,
4425 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004426 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004427 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004428 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004429 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004430 ALC880_FIXUP_VOL_KNOB,
4431 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004432 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004433 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004434 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004435 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004436 ALC880_FIXUP_3ST_BASE,
4437 ALC880_FIXUP_3ST,
4438 ALC880_FIXUP_3ST_DIG,
4439 ALC880_FIXUP_5ST_BASE,
4440 ALC880_FIXUP_5ST,
4441 ALC880_FIXUP_5ST_DIG,
4442 ALC880_FIXUP_6ST_BASE,
4443 ALC880_FIXUP_6ST,
4444 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004445};
4446
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004447/* enable the volume-knob widget support on NID 0x21 */
4448static void alc880_fixup_vol_knob(struct hda_codec *codec,
4449 const struct alc_fixup *fix, int action)
4450{
4451 if (action == ALC_FIXUP_ACT_PROBE)
4452 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4453}
4454
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004455static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004456 [ALC880_FIXUP_GPIO1] = {
4457 .type = ALC_FIXUP_VERBS,
4458 .v.verbs = alc_gpio1_init_verbs,
4459 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004460 [ALC880_FIXUP_GPIO2] = {
4461 .type = ALC_FIXUP_VERBS,
4462 .v.verbs = alc_gpio2_init_verbs,
4463 },
4464 [ALC880_FIXUP_MEDION_RIM] = {
4465 .type = ALC_FIXUP_VERBS,
4466 .v.verbs = (const struct hda_verb[]) {
4467 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4468 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4469 { }
4470 },
4471 .chained = true,
4472 .chain_id = ALC880_FIXUP_GPIO2,
4473 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004474 [ALC880_FIXUP_LG] = {
4475 .type = ALC_FIXUP_PINS,
4476 .v.pins = (const struct alc_pincfg[]) {
4477 /* disable bogus unused pins */
4478 { 0x16, 0x411111f0 },
4479 { 0x18, 0x411111f0 },
4480 { 0x1a, 0x411111f0 },
4481 { }
4482 }
4483 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004484 [ALC880_FIXUP_W810] = {
4485 .type = ALC_FIXUP_PINS,
4486 .v.pins = (const struct alc_pincfg[]) {
4487 /* disable bogus unused pins */
4488 { 0x17, 0x411111f0 },
4489 { }
4490 },
4491 .chained = true,
4492 .chain_id = ALC880_FIXUP_GPIO2,
4493 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004494 [ALC880_FIXUP_EAPD_COEF] = {
4495 .type = ALC_FIXUP_VERBS,
4496 .v.verbs = (const struct hda_verb[]) {
4497 /* change to EAPD mode */
4498 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4499 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4500 {}
4501 },
4502 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004503 [ALC880_FIXUP_TCL_S700] = {
4504 .type = ALC_FIXUP_VERBS,
4505 .v.verbs = (const struct hda_verb[]) {
4506 /* change to EAPD mode */
4507 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4508 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4509 {}
4510 },
4511 .chained = true,
4512 .chain_id = ALC880_FIXUP_GPIO2,
4513 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004514 [ALC880_FIXUP_VOL_KNOB] = {
4515 .type = ALC_FIXUP_FUNC,
4516 .v.func = alc880_fixup_vol_knob,
4517 },
4518 [ALC880_FIXUP_FUJITSU] = {
4519 /* override all pins as BIOS on old Amilo is broken */
4520 .type = ALC_FIXUP_PINS,
4521 .v.pins = (const struct alc_pincfg[]) {
4522 { 0x14, 0x0121411f }, /* HP */
4523 { 0x15, 0x99030120 }, /* speaker */
4524 { 0x16, 0x99030130 }, /* bass speaker */
4525 { 0x17, 0x411111f0 }, /* N/A */
4526 { 0x18, 0x411111f0 }, /* N/A */
4527 { 0x19, 0x01a19950 }, /* mic-in */
4528 { 0x1a, 0x411111f0 }, /* N/A */
4529 { 0x1b, 0x411111f0 }, /* N/A */
4530 { 0x1c, 0x411111f0 }, /* N/A */
4531 { 0x1d, 0x411111f0 }, /* N/A */
4532 { 0x1e, 0x01454140 }, /* SPDIF out */
4533 { }
4534 },
4535 .chained = true,
4536 .chain_id = ALC880_FIXUP_VOL_KNOB,
4537 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004538 [ALC880_FIXUP_F1734] = {
4539 /* almost compatible with FUJITSU, but no bass and SPDIF */
4540 .type = ALC_FIXUP_PINS,
4541 .v.pins = (const struct alc_pincfg[]) {
4542 { 0x14, 0x0121411f }, /* HP */
4543 { 0x15, 0x99030120 }, /* speaker */
4544 { 0x16, 0x411111f0 }, /* N/A */
4545 { 0x17, 0x411111f0 }, /* N/A */
4546 { 0x18, 0x411111f0 }, /* N/A */
4547 { 0x19, 0x01a19950 }, /* mic-in */
4548 { 0x1a, 0x411111f0 }, /* N/A */
4549 { 0x1b, 0x411111f0 }, /* N/A */
4550 { 0x1c, 0x411111f0 }, /* N/A */
4551 { 0x1d, 0x411111f0 }, /* N/A */
4552 { 0x1e, 0x411111f0 }, /* N/A */
4553 { }
4554 },
4555 .chained = true,
4556 .chain_id = ALC880_FIXUP_VOL_KNOB,
4557 },
Takashi Iwai817de922012-02-20 17:20:48 +01004558 [ALC880_FIXUP_UNIWILL] = {
4559 /* need to fix HP and speaker pins to be parsed correctly */
4560 .type = ALC_FIXUP_PINS,
4561 .v.pins = (const struct alc_pincfg[]) {
4562 { 0x14, 0x0121411f }, /* HP */
4563 { 0x15, 0x99030120 }, /* speaker */
4564 { 0x16, 0x99030130 }, /* bass speaker */
4565 { }
4566 },
4567 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004568 [ALC880_FIXUP_UNIWILL_DIG] = {
4569 .type = ALC_FIXUP_PINS,
4570 .v.pins = (const struct alc_pincfg[]) {
4571 /* disable bogus unused pins */
4572 { 0x17, 0x411111f0 },
4573 { 0x19, 0x411111f0 },
4574 { 0x1b, 0x411111f0 },
4575 { 0x1f, 0x411111f0 },
4576 { }
4577 }
4578 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004579 [ALC880_FIXUP_Z71V] = {
4580 .type = ALC_FIXUP_PINS,
4581 .v.pins = (const struct alc_pincfg[]) {
4582 /* set up the whole pins as BIOS is utterly broken */
4583 { 0x14, 0x99030120 }, /* speaker */
4584 { 0x15, 0x0121411f }, /* HP */
4585 { 0x16, 0x411111f0 }, /* N/A */
4586 { 0x17, 0x411111f0 }, /* N/A */
4587 { 0x18, 0x01a19950 }, /* mic-in */
4588 { 0x19, 0x411111f0 }, /* N/A */
4589 { 0x1a, 0x01813031 }, /* line-in */
4590 { 0x1b, 0x411111f0 }, /* N/A */
4591 { 0x1c, 0x411111f0 }, /* N/A */
4592 { 0x1d, 0x411111f0 }, /* N/A */
4593 { 0x1e, 0x0144111e }, /* SPDIF */
4594 { }
4595 }
4596 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004597 [ALC880_FIXUP_3ST_BASE] = {
4598 .type = ALC_FIXUP_PINS,
4599 .v.pins = (const struct alc_pincfg[]) {
4600 { 0x14, 0x01014010 }, /* line-out */
4601 { 0x15, 0x411111f0 }, /* N/A */
4602 { 0x16, 0x411111f0 }, /* N/A */
4603 { 0x17, 0x411111f0 }, /* N/A */
4604 { 0x18, 0x01a19c30 }, /* mic-in */
4605 { 0x19, 0x0121411f }, /* HP */
4606 { 0x1a, 0x01813031 }, /* line-in */
4607 { 0x1b, 0x02a19c40 }, /* front-mic */
4608 { 0x1c, 0x411111f0 }, /* N/A */
4609 { 0x1d, 0x411111f0 }, /* N/A */
4610 /* 0x1e is filled in below */
4611 { 0x1f, 0x411111f0 }, /* N/A */
4612 { }
4613 }
4614 },
4615 [ALC880_FIXUP_3ST] = {
4616 .type = ALC_FIXUP_PINS,
4617 .v.pins = (const struct alc_pincfg[]) {
4618 { 0x1e, 0x411111f0 }, /* N/A */
4619 { }
4620 },
4621 .chained = true,
4622 .chain_id = ALC880_FIXUP_3ST_BASE,
4623 },
4624 [ALC880_FIXUP_3ST_DIG] = {
4625 .type = ALC_FIXUP_PINS,
4626 .v.pins = (const struct alc_pincfg[]) {
4627 { 0x1e, 0x0144111e }, /* SPDIF */
4628 { }
4629 },
4630 .chained = true,
4631 .chain_id = ALC880_FIXUP_3ST_BASE,
4632 },
4633 [ALC880_FIXUP_5ST_BASE] = {
4634 .type = ALC_FIXUP_PINS,
4635 .v.pins = (const struct alc_pincfg[]) {
4636 { 0x14, 0x01014010 }, /* front */
4637 { 0x15, 0x411111f0 }, /* N/A */
4638 { 0x16, 0x01011411 }, /* CLFE */
4639 { 0x17, 0x01016412 }, /* surr */
4640 { 0x18, 0x01a19c30 }, /* mic-in */
4641 { 0x19, 0x0121411f }, /* HP */
4642 { 0x1a, 0x01813031 }, /* line-in */
4643 { 0x1b, 0x02a19c40 }, /* front-mic */
4644 { 0x1c, 0x411111f0 }, /* N/A */
4645 { 0x1d, 0x411111f0 }, /* N/A */
4646 /* 0x1e is filled in below */
4647 { 0x1f, 0x411111f0 }, /* N/A */
4648 { }
4649 }
4650 },
4651 [ALC880_FIXUP_5ST] = {
4652 .type = ALC_FIXUP_PINS,
4653 .v.pins = (const struct alc_pincfg[]) {
4654 { 0x1e, 0x411111f0 }, /* N/A */
4655 { }
4656 },
4657 .chained = true,
4658 .chain_id = ALC880_FIXUP_5ST_BASE,
4659 },
4660 [ALC880_FIXUP_5ST_DIG] = {
4661 .type = ALC_FIXUP_PINS,
4662 .v.pins = (const struct alc_pincfg[]) {
4663 { 0x1e, 0x0144111e }, /* SPDIF */
4664 { }
4665 },
4666 .chained = true,
4667 .chain_id = ALC880_FIXUP_5ST_BASE,
4668 },
4669 [ALC880_FIXUP_6ST_BASE] = {
4670 .type = ALC_FIXUP_PINS,
4671 .v.pins = (const struct alc_pincfg[]) {
4672 { 0x14, 0x01014010 }, /* front */
4673 { 0x15, 0x01016412 }, /* surr */
4674 { 0x16, 0x01011411 }, /* CLFE */
4675 { 0x17, 0x01012414 }, /* side */
4676 { 0x18, 0x01a19c30 }, /* mic-in */
4677 { 0x19, 0x02a19c40 }, /* front-mic */
4678 { 0x1a, 0x01813031 }, /* line-in */
4679 { 0x1b, 0x0121411f }, /* HP */
4680 { 0x1c, 0x411111f0 }, /* N/A */
4681 { 0x1d, 0x411111f0 }, /* N/A */
4682 /* 0x1e is filled in below */
4683 { 0x1f, 0x411111f0 }, /* N/A */
4684 { }
4685 }
4686 },
4687 [ALC880_FIXUP_6ST] = {
4688 .type = ALC_FIXUP_PINS,
4689 .v.pins = (const struct alc_pincfg[]) {
4690 { 0x1e, 0x411111f0 }, /* N/A */
4691 { }
4692 },
4693 .chained = true,
4694 .chain_id = ALC880_FIXUP_6ST_BASE,
4695 },
4696 [ALC880_FIXUP_6ST_DIG] = {
4697 .type = ALC_FIXUP_PINS,
4698 .v.pins = (const struct alc_pincfg[]) {
4699 { 0x1e, 0x0144111e }, /* SPDIF */
4700 { }
4701 },
4702 .chained = true,
4703 .chain_id = ALC880_FIXUP_6ST_BASE,
4704 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004705};
4706
4707static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004708 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004709 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004710 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4711 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004712 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004713 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004714 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004715 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004716 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004717 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004718 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004719 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004720 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004721 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004722 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004723 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4724 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4725 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004726 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004727
4728 /* Below is the copied entries from alc880_quirks.c.
4729 * It's not quite sure whether BIOS sets the correct pin-config table
4730 * on these machines, thus they are kept to be compatible with
4731 * the old static quirks. Once when it's confirmed to work without
4732 * these overrides, it'd be better to remove.
4733 */
4734 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4735 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4736 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4737 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4738 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4739 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4740 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4741 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4742 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4743 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4744 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4745 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4746 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4747 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4748 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4749 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4750 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4751 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4752 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4753 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4754 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4755 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4756 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4757 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4758 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4759 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4760 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4761 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4762 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4763 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4764 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4765 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4766 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4767 /* default Intel */
4768 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4769 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4770 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4771 {}
4772};
4773
4774static const struct alc_model_fixup alc880_fixup_models[] = {
4775 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4776 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4777 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4778 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4779 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4780 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004781 {}
4782};
4783
4784
4785/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004786 * OK, here we have finally the patch for ALC880
4787 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004788static int patch_alc880(struct hda_codec *codec)
4789{
4790 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004791 int err;
4792
4793 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4794 if (spec == NULL)
4795 return -ENOMEM;
4796
4797 codec->spec = spec;
4798
4799 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004800 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004801
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004802 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4803 alc880_fixups);
4804 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004805
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004806 /* automatic parse from the BIOS config */
4807 err = alc880_parse_auto_config(codec);
4808 if (err < 0)
4809 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004810
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004811 if (!spec->no_analog) {
4812 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004813 if (err < 0)
4814 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004815 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4816 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004817
Takashi Iwai1d045db2011-07-07 18:23:21 +02004818 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004819
Takashi Iwai589876e2012-02-20 15:47:55 +01004820 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4821
Takashi Iwai1d045db2011-07-07 18:23:21 +02004822 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004823
4824 error:
4825 alc_free(codec);
4826 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004827}
4828
4829
4830/*
4831 * ALC260 support
4832 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004833static int alc260_parse_auto_config(struct hda_codec *codec)
4834{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004835 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004836 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4837 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004838}
4839
Takashi Iwai1d045db2011-07-07 18:23:21 +02004840/*
4841 * Pin config fixes
4842 */
4843enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004844 ALC260_FIXUP_HP_DC5750,
4845 ALC260_FIXUP_HP_PIN_0F,
4846 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004847 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004848 ALC260_FIXUP_GPIO1_TOGGLE,
4849 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004850 ALC260_FIXUP_HP_B1900,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004851};
4852
Takashi Iwai20f7d922012-02-16 12:35:16 +01004853static void alc260_gpio1_automute(struct hda_codec *codec)
4854{
4855 struct alc_spec *spec = codec->spec;
4856 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4857 spec->hp_jack_present);
4858}
4859
4860static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4861 const struct alc_fixup *fix, int action)
4862{
4863 struct alc_spec *spec = codec->spec;
4864 if (action == ALC_FIXUP_ACT_PROBE) {
4865 /* although the machine has only one output pin, we need to
4866 * toggle GPIO1 according to the jack state
4867 */
4868 spec->automute_hook = alc260_gpio1_automute;
4869 spec->detect_hp = 1;
4870 spec->automute_speaker = 1;
4871 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4872 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4873 spec->unsol_event = alc_sku_unsol_event;
4874 add_verb(codec->spec, alc_gpio1_init_verbs);
4875 }
4876}
4877
Takashi Iwai1d045db2011-07-07 18:23:21 +02004878static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004879 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004880 .type = ALC_FIXUP_PINS,
4881 .v.pins = (const struct alc_pincfg[]) {
4882 { 0x11, 0x90130110 }, /* speaker */
4883 { }
4884 }
4885 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004886 [ALC260_FIXUP_HP_PIN_0F] = {
4887 .type = ALC_FIXUP_PINS,
4888 .v.pins = (const struct alc_pincfg[]) {
4889 { 0x0f, 0x01214000 }, /* HP */
4890 { }
4891 }
4892 },
4893 [ALC260_FIXUP_COEF] = {
4894 .type = ALC_FIXUP_VERBS,
4895 .v.verbs = (const struct hda_verb[]) {
4896 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4897 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4898 { }
4899 },
4900 .chained = true,
4901 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4902 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004903 [ALC260_FIXUP_GPIO1] = {
4904 .type = ALC_FIXUP_VERBS,
4905 .v.verbs = alc_gpio1_init_verbs,
4906 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004907 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4908 .type = ALC_FIXUP_FUNC,
4909 .v.func = alc260_fixup_gpio1_toggle,
4910 .chained = true,
4911 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4912 },
4913 [ALC260_FIXUP_REPLACER] = {
4914 .type = ALC_FIXUP_VERBS,
4915 .v.verbs = (const struct hda_verb[]) {
4916 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4917 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4918 { }
4919 },
4920 .chained = true,
4921 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4922 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004923 [ALC260_FIXUP_HP_B1900] = {
4924 .type = ALC_FIXUP_FUNC,
4925 .v.func = alc260_fixup_gpio1_toggle,
4926 .chained = true,
4927 .chain_id = ALC260_FIXUP_COEF,
4928 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004929};
4930
4931static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004932 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004933 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004934 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004935 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004936 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004937 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004938 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004939 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004940 {}
4941};
4942
4943/*
4944 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004945static int patch_alc260(struct hda_codec *codec)
4946{
4947 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004948 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004949
4950 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4951 if (spec == NULL)
4952 return -ENOMEM;
4953
4954 codec->spec = spec;
4955
4956 spec->mixer_nid = 0x07;
4957
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004958 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4959 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004960
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004961 /* automatic parse from the BIOS config */
4962 err = alc260_parse_auto_config(codec);
4963 if (err < 0)
4964 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004965
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004966 if (!spec->no_analog) {
4967 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004968 if (err < 0)
4969 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004970 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4971 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004972
Takashi Iwai1d045db2011-07-07 18:23:21 +02004973 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004974 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004975
Takashi Iwai589876e2012-02-20 15:47:55 +01004976 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4977
Takashi Iwai1d045db2011-07-07 18:23:21 +02004978 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004979
4980 error:
4981 alc_free(codec);
4982 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004983}
4984
4985
4986/*
4987 * ALC882/883/885/888/889 support
4988 *
4989 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4990 * configuration. Each pin widget can choose any input DACs and a mixer.
4991 * Each ADC is connected from a mixer of all inputs. This makes possible
4992 * 6-channel independent captures.
4993 *
4994 * In addition, an independent DAC for the multi-playback (not used in this
4995 * driver yet).
4996 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004997
4998/*
4999 * Pin config fixes
5000 */
5001enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005002 ALC882_FIXUP_ABIT_AW9D_MAX,
5003 ALC882_FIXUP_LENOVO_Y530,
5004 ALC882_FIXUP_PB_M5210,
5005 ALC882_FIXUP_ACER_ASPIRE_7736,
5006 ALC882_FIXUP_ASUS_W90V,
5007 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005008 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005009 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005010 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005011 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005012 ALC882_FIXUP_GPIO1,
5013 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005014 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005015 ALC889_FIXUP_COEF,
5016 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005017 ALC882_FIXUP_ACER_ASPIRE_4930G,
5018 ALC882_FIXUP_ACER_ASPIRE_8930G,
5019 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005020 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005021 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005022 ALC889_FIXUP_MBP_VREF,
5023 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005024};
5025
Takashi Iwai68ef0562011-11-09 18:24:44 +01005026static void alc889_fixup_coef(struct hda_codec *codec,
5027 const struct alc_fixup *fix, int action)
5028{
5029 if (action != ALC_FIXUP_ACT_INIT)
5030 return;
5031 alc889_coef_init(codec);
5032}
5033
Takashi Iwai56710872011-11-14 17:42:11 +01005034/* toggle speaker-output according to the hp-jack state */
5035static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5036{
5037 unsigned int gpiostate, gpiomask, gpiodir;
5038
5039 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5040 AC_VERB_GET_GPIO_DATA, 0);
5041
5042 if (!muted)
5043 gpiostate |= (1 << pin);
5044 else
5045 gpiostate &= ~(1 << pin);
5046
5047 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5048 AC_VERB_GET_GPIO_MASK, 0);
5049 gpiomask |= (1 << pin);
5050
5051 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5052 AC_VERB_GET_GPIO_DIRECTION, 0);
5053 gpiodir |= (1 << pin);
5054
5055
5056 snd_hda_codec_write(codec, codec->afg, 0,
5057 AC_VERB_SET_GPIO_MASK, gpiomask);
5058 snd_hda_codec_write(codec, codec->afg, 0,
5059 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5060
5061 msleep(1);
5062
5063 snd_hda_codec_write(codec, codec->afg, 0,
5064 AC_VERB_SET_GPIO_DATA, gpiostate);
5065}
5066
5067/* set up GPIO at initialization */
5068static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5069 const struct alc_fixup *fix, int action)
5070{
5071 if (action != ALC_FIXUP_ACT_INIT)
5072 return;
5073 alc882_gpio_mute(codec, 0, 0);
5074 alc882_gpio_mute(codec, 1, 0);
5075}
5076
Takashi Iwai02a237b2012-02-13 15:25:07 +01005077/* Fix the connection of some pins for ALC889:
5078 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5079 * work correctly (bko#42740)
5080 */
5081static void alc889_fixup_dac_route(struct hda_codec *codec,
5082 const struct alc_fixup *fix, int action)
5083{
5084 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5085 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5086 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5087 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5088 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5089 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5090 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
5091 }
5092}
5093
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005094/* Set VREF on HP pin */
5095static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5096 const struct alc_fixup *fix, int action)
5097{
5098 struct alc_spec *spec = codec->spec;
5099 static hda_nid_t nids[2] = { 0x14, 0x15 };
5100 int i;
5101
5102 if (action != ALC_FIXUP_ACT_INIT)
5103 return;
5104 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5105 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5106 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5107 continue;
5108 val = snd_hda_codec_read(codec, nids[i], 0,
5109 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5110 val |= AC_PINCTL_VREF_80;
5111 snd_hda_codec_write(codec, nids[i], 0,
5112 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5113 spec->keep_vref_in_automute = 1;
5114 break;
5115 }
5116}
5117
5118/* Set VREF on speaker pins on imac91 */
5119static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5120 const struct alc_fixup *fix, int action)
5121{
5122 struct alc_spec *spec = codec->spec;
5123 static hda_nid_t nids[2] = { 0x18, 0x1a };
5124 int i;
5125
5126 if (action != ALC_FIXUP_ACT_INIT)
5127 return;
5128 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5129 unsigned int val;
5130 val = snd_hda_codec_read(codec, nids[i], 0,
5131 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5132 val |= AC_PINCTL_VREF_50;
5133 snd_hda_codec_write(codec, nids[i], 0,
5134 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5135 }
5136 spec->keep_vref_in_automute = 1;
5137}
5138
Takashi Iwai1d045db2011-07-07 18:23:21 +02005139static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005140 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005141 .type = ALC_FIXUP_PINS,
5142 .v.pins = (const struct alc_pincfg[]) {
5143 { 0x15, 0x01080104 }, /* side */
5144 { 0x16, 0x01011012 }, /* rear */
5145 { 0x17, 0x01016011 }, /* clfe */
5146 { }
5147 }
5148 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005149 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005150 .type = ALC_FIXUP_PINS,
5151 .v.pins = (const struct alc_pincfg[]) {
5152 { 0x15, 0x99130112 }, /* rear int speakers */
5153 { 0x16, 0x99130111 }, /* subwoofer */
5154 { }
5155 }
5156 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005157 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005158 .type = ALC_FIXUP_VERBS,
5159 .v.verbs = (const struct hda_verb[]) {
5160 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5161 {}
5162 }
5163 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005164 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005165 .type = ALC_FIXUP_SKU,
5166 .v.sku = ALC_FIXUP_SKU_IGNORE,
5167 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005168 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005169 .type = ALC_FIXUP_PINS,
5170 .v.pins = (const struct alc_pincfg[]) {
5171 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5172 { }
5173 }
5174 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005175 [ALC889_FIXUP_VAIO_TT] = {
5176 .type = ALC_FIXUP_PINS,
5177 .v.pins = (const struct alc_pincfg[]) {
5178 { 0x17, 0x90170111 }, /* hidden surround speaker */
5179 { }
5180 }
5181 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005182 [ALC888_FIXUP_EEE1601] = {
5183 .type = ALC_FIXUP_VERBS,
5184 .v.verbs = (const struct hda_verb[]) {
5185 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5186 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5187 { }
5188 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005189 },
5190 [ALC882_FIXUP_EAPD] = {
5191 .type = ALC_FIXUP_VERBS,
5192 .v.verbs = (const struct hda_verb[]) {
5193 /* change to EAPD mode */
5194 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5195 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5196 { }
5197 }
5198 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005199 [ALC883_FIXUP_EAPD] = {
5200 .type = ALC_FIXUP_VERBS,
5201 .v.verbs = (const struct hda_verb[]) {
5202 /* change to EAPD mode */
5203 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5204 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5205 { }
5206 }
5207 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005208 [ALC883_FIXUP_ACER_EAPD] = {
5209 .type = ALC_FIXUP_VERBS,
5210 .v.verbs = (const struct hda_verb[]) {
5211 /* eanable EAPD on Acer laptops */
5212 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5213 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5214 { }
5215 }
5216 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005217 [ALC882_FIXUP_GPIO1] = {
5218 .type = ALC_FIXUP_VERBS,
5219 .v.verbs = alc_gpio1_init_verbs,
5220 },
5221 [ALC882_FIXUP_GPIO2] = {
5222 .type = ALC_FIXUP_VERBS,
5223 .v.verbs = alc_gpio2_init_verbs,
5224 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005225 [ALC882_FIXUP_GPIO3] = {
5226 .type = ALC_FIXUP_VERBS,
5227 .v.verbs = alc_gpio3_init_verbs,
5228 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005229 [ALC882_FIXUP_ASUS_W2JC] = {
5230 .type = ALC_FIXUP_VERBS,
5231 .v.verbs = alc_gpio1_init_verbs,
5232 .chained = true,
5233 .chain_id = ALC882_FIXUP_EAPD,
5234 },
5235 [ALC889_FIXUP_COEF] = {
5236 .type = ALC_FIXUP_FUNC,
5237 .v.func = alc889_fixup_coef,
5238 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005239 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5240 .type = ALC_FIXUP_PINS,
5241 .v.pins = (const struct alc_pincfg[]) {
5242 { 0x16, 0x99130111 }, /* CLFE speaker */
5243 { 0x17, 0x99130112 }, /* surround speaker */
5244 { }
5245 }
5246 },
5247 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5248 .type = ALC_FIXUP_PINS,
5249 .v.pins = (const struct alc_pincfg[]) {
5250 { 0x16, 0x99130111 }, /* CLFE speaker */
5251 { 0x1b, 0x99130112 }, /* surround speaker */
5252 { }
5253 },
5254 .chained = true,
5255 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5256 },
5257 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5258 /* additional init verbs for Acer Aspire 8930G */
5259 .type = ALC_FIXUP_VERBS,
5260 .v.verbs = (const struct hda_verb[]) {
5261 /* Enable all DACs */
5262 /* DAC DISABLE/MUTE 1? */
5263 /* setting bits 1-5 disables DAC nids 0x02-0x06
5264 * apparently. Init=0x38 */
5265 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5266 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5267 /* DAC DISABLE/MUTE 2? */
5268 /* some bit here disables the other DACs.
5269 * Init=0x4900 */
5270 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5271 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5272 /* DMIC fix
5273 * This laptop has a stereo digital microphone.
5274 * The mics are only 1cm apart which makes the stereo
5275 * useless. However, either the mic or the ALC889
5276 * makes the signal become a difference/sum signal
5277 * instead of standard stereo, which is annoying.
5278 * So instead we flip this bit which makes the
5279 * codec replicate the sum signal to both channels,
5280 * turning it into a normal mono mic.
5281 */
5282 /* DMIC_CONTROL? Init value = 0x0001 */
5283 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5284 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5285 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5286 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5287 { }
5288 }
5289 },
Takashi Iwai56710872011-11-14 17:42:11 +01005290 [ALC885_FIXUP_MACPRO_GPIO] = {
5291 .type = ALC_FIXUP_FUNC,
5292 .v.func = alc885_fixup_macpro_gpio,
5293 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005294 [ALC889_FIXUP_DAC_ROUTE] = {
5295 .type = ALC_FIXUP_FUNC,
5296 .v.func = alc889_fixup_dac_route,
5297 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005298 [ALC889_FIXUP_MBP_VREF] = {
5299 .type = ALC_FIXUP_FUNC,
5300 .v.func = alc889_fixup_mbp_vref,
5301 .chained = true,
5302 .chain_id = ALC882_FIXUP_GPIO1,
5303 },
5304 [ALC889_FIXUP_IMAC91_VREF] = {
5305 .type = ALC_FIXUP_FUNC,
5306 .v.func = alc889_fixup_imac91_vref,
5307 .chained = true,
5308 .chain_id = ALC882_FIXUP_GPIO1,
5309 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005310};
5311
5312static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005313 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5314 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5315 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5316 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5317 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5318 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005319 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5320 ALC882_FIXUP_ACER_ASPIRE_4930G),
5321 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5322 ALC882_FIXUP_ACER_ASPIRE_4930G),
5323 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5324 ALC882_FIXUP_ACER_ASPIRE_8930G),
5325 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5326 ALC882_FIXUP_ACER_ASPIRE_8930G),
5327 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5328 ALC882_FIXUP_ACER_ASPIRE_4930G),
5329 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5330 ALC882_FIXUP_ACER_ASPIRE_4930G),
5331 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5332 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005333 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005334 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005335 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005336 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005337 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005338 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005339 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005340 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005341
5342 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005343 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5344 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5345 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005346 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5347 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5348 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005349 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5350 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005351 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005352 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5353 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5354 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5355 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005356 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005357 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5358 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5359 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5360 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5361 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5362 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005363
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005364 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005365 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005366 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005367 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5368 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005369 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005370 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005371 {}
5372};
5373
5374/*
5375 * BIOS auto configuration
5376 */
5377/* almost identical with ALC880 parser... */
5378static int alc882_parse_auto_config(struct hda_codec *codec)
5379{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005380 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005381 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5382 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005383}
5384
Takashi Iwai1d045db2011-07-07 18:23:21 +02005385/*
5386 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005387static int patch_alc882(struct hda_codec *codec)
5388{
5389 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005390 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005391
5392 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5393 if (spec == NULL)
5394 return -ENOMEM;
5395
5396 codec->spec = spec;
5397
5398 spec->mixer_nid = 0x0b;
5399
5400 switch (codec->vendor_id) {
5401 case 0x10ec0882:
5402 case 0x10ec0885:
5403 break;
5404 default:
5405 /* ALC883 and variants */
5406 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5407 break;
5408 }
5409
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005410 err = alc_codec_rename_from_preset(codec);
5411 if (err < 0)
5412 goto error;
5413
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005414 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
5415 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005416
5417 alc_auto_parse_customize_define(codec);
5418
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005419 /* automatic parse from the BIOS config */
5420 err = alc882_parse_auto_config(codec);
5421 if (err < 0)
5422 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005423
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005424 if (!spec->no_analog && has_cdefine_beep(codec)) {
5425 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005426 if (err < 0)
5427 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005428 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005429 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005430
Takashi Iwai1d045db2011-07-07 18:23:21 +02005431 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005432
Takashi Iwai589876e2012-02-20 15:47:55 +01005433 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5434
Takashi Iwai1d045db2011-07-07 18:23:21 +02005435 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005436
5437 error:
5438 alc_free(codec);
5439 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005440}
5441
5442
5443/*
5444 * ALC262 support
5445 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005446static int alc262_parse_auto_config(struct hda_codec *codec)
5447{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005448 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005449 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5450 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451}
5452
5453/*
5454 * Pin config fixes
5455 */
5456enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005457 ALC262_FIXUP_FSC_H270,
5458 ALC262_FIXUP_HP_Z200,
5459 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005460 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005461 ALC262_FIXUP_BENQ,
5462 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005463};
5464
5465static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005466 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005467 .type = ALC_FIXUP_PINS,
5468 .v.pins = (const struct alc_pincfg[]) {
5469 { 0x14, 0x99130110 }, /* speaker */
5470 { 0x15, 0x0221142f }, /* front HP */
5471 { 0x1b, 0x0121141f }, /* rear HP */
5472 { }
5473 }
5474 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005475 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005476 .type = ALC_FIXUP_PINS,
5477 .v.pins = (const struct alc_pincfg[]) {
5478 { 0x16, 0x99130120 }, /* internal speaker */
5479 { }
5480 }
5481 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005482 [ALC262_FIXUP_TYAN] = {
5483 .type = ALC_FIXUP_PINS,
5484 .v.pins = (const struct alc_pincfg[]) {
5485 { 0x14, 0x1993e1f0 }, /* int AUX */
5486 { }
5487 }
5488 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005489 [ALC262_FIXUP_LENOVO_3000] = {
5490 .type = ALC_FIXUP_VERBS,
5491 .v.verbs = (const struct hda_verb[]) {
5492 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005493 {}
5494 },
5495 .chained = true,
5496 .chain_id = ALC262_FIXUP_BENQ,
5497 },
5498 [ALC262_FIXUP_BENQ] = {
5499 .type = ALC_FIXUP_VERBS,
5500 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005501 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5502 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5503 {}
5504 }
5505 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005506 [ALC262_FIXUP_BENQ_T31] = {
5507 .type = ALC_FIXUP_VERBS,
5508 .v.verbs = (const struct hda_verb[]) {
5509 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5510 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5511 {}
5512 }
5513 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005514};
5515
5516static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005517 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005518 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5519 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005520 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5521 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005522 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005523 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5524 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005525 {}
5526};
5527
5528
Takashi Iwai1d045db2011-07-07 18:23:21 +02005529/*
5530 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005531static int patch_alc262(struct hda_codec *codec)
5532{
5533 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005534 int err;
5535
5536 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5537 if (spec == NULL)
5538 return -ENOMEM;
5539
5540 codec->spec = spec;
5541
5542 spec->mixer_nid = 0x0b;
5543
5544#if 0
5545 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5546 * under-run
5547 */
5548 {
5549 int tmp;
5550 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5551 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5552 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5553 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5554 }
5555#endif
5556 alc_auto_parse_customize_define(codec);
5557
5558 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5559
Takashi Iwai42399f72011-11-07 17:18:44 +01005560 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5561 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005562
Takashi Iwai42399f72011-11-07 17:18:44 +01005563 /* automatic parse from the BIOS config */
5564 err = alc262_parse_auto_config(codec);
5565 if (err < 0)
5566 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005567
Takashi Iwai1d045db2011-07-07 18:23:21 +02005568 if (!spec->no_analog && has_cdefine_beep(codec)) {
5569 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005570 if (err < 0)
5571 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005572 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005573 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005574
Takashi Iwai1d045db2011-07-07 18:23:21 +02005575 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005576 spec->shutup = alc_eapd_shutup;
5577
Takashi Iwai589876e2012-02-20 15:47:55 +01005578 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5579
Takashi Iwai1d045db2011-07-07 18:23:21 +02005580 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005581
5582 error:
5583 alc_free(codec);
5584 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005585}
5586
5587/*
5588 * ALC268
5589 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005590/* bind Beep switches of both NID 0x0f and 0x10 */
5591static const struct hda_bind_ctls alc268_bind_beep_sw = {
5592 .ops = &snd_hda_bind_sw,
5593 .values = {
5594 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5595 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5596 0
5597 },
5598};
5599
5600static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5601 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5602 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5603 { }
5604};
5605
5606/* set PCBEEP vol = 0, mute connections */
5607static const struct hda_verb alc268_beep_init_verbs[] = {
5608 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5609 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5610 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5611 { }
5612};
5613
5614/*
5615 * BIOS auto configuration
5616 */
5617static int alc268_parse_auto_config(struct hda_codec *codec)
5618{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005619 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005620 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005621 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5622 if (err > 0) {
5623 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5624 add_mixer(spec, alc268_beep_mixer);
5625 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005626 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005627 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005628 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005629}
5630
Takashi Iwai1d045db2011-07-07 18:23:21 +02005631/*
5632 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005633static int patch_alc268(struct hda_codec *codec)
5634{
5635 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005636 int i, has_beep, err;
5637
5638 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5639 if (spec == NULL)
5640 return -ENOMEM;
5641
5642 codec->spec = spec;
5643
5644 /* ALC268 has no aa-loopback mixer */
5645
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005646 /* automatic parse from the BIOS config */
5647 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005648 if (err < 0)
5649 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005650
Takashi Iwai1d045db2011-07-07 18:23:21 +02005651 has_beep = 0;
5652 for (i = 0; i < spec->num_mixers; i++) {
5653 if (spec->mixers[i] == alc268_beep_mixer) {
5654 has_beep = 1;
5655 break;
5656 }
5657 }
5658
5659 if (has_beep) {
5660 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005661 if (err < 0)
5662 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005663 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5664 /* override the amp caps for beep generator */
5665 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5666 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5667 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5668 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5669 (0 << AC_AMPCAP_MUTE_SHIFT));
5670 }
5671
Takashi Iwai1d045db2011-07-07 18:23:21 +02005672 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005673 spec->shutup = alc_eapd_shutup;
5674
Takashi Iwai1d045db2011-07-07 18:23:21 +02005675 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005676
5677 error:
5678 alc_free(codec);
5679 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005680}
5681
5682/*
5683 * ALC269
5684 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005685static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5686 .substreams = 1,
5687 .channels_min = 2,
5688 .channels_max = 8,
5689 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5690 /* NID is set in alc_build_pcms */
5691 .ops = {
5692 .open = alc_playback_pcm_open,
5693 .prepare = alc_playback_pcm_prepare,
5694 .cleanup = alc_playback_pcm_cleanup
5695 },
5696};
5697
5698static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5699 .substreams = 1,
5700 .channels_min = 2,
5701 .channels_max = 2,
5702 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5703 /* NID is set in alc_build_pcms */
5704};
5705
5706#ifdef CONFIG_SND_HDA_POWER_SAVE
5707static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5708{
5709 switch (codec->subsystem_id) {
5710 case 0x103c1586:
5711 return 1;
5712 }
5713 return 0;
5714}
5715
5716static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5717{
5718 /* update mute-LED according to the speaker mute state */
5719 if (nid == 0x01 || nid == 0x14) {
5720 int pinval;
5721 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5722 HDA_AMP_MUTE)
5723 pinval = 0x24;
5724 else
5725 pinval = 0x20;
5726 /* mic2 vref pin is used for mute LED control */
5727 snd_hda_codec_update_cache(codec, 0x19, 0,
5728 AC_VERB_SET_PIN_WIDGET_CONTROL,
5729 pinval);
5730 }
5731 return alc_check_power_status(codec, nid);
5732}
5733#endif /* CONFIG_SND_HDA_POWER_SAVE */
5734
5735/* different alc269-variants */
5736enum {
5737 ALC269_TYPE_ALC269VA,
5738 ALC269_TYPE_ALC269VB,
5739 ALC269_TYPE_ALC269VC,
5740};
5741
5742/*
5743 * BIOS auto configuration
5744 */
5745static int alc269_parse_auto_config(struct hda_codec *codec)
5746{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005747 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005748 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5749 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5750 struct alc_spec *spec = codec->spec;
5751 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5752 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005754 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005755}
5756
Takashi Iwai1d045db2011-07-07 18:23:21 +02005757static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5758{
5759 int val = alc_read_coef_idx(codec, 0x04);
5760 if (power_up)
5761 val |= 1 << 11;
5762 else
5763 val &= ~(1 << 11);
5764 alc_write_coef_idx(codec, 0x04, val);
5765}
5766
5767static void alc269_shutup(struct hda_codec *codec)
5768{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005769 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005770 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005771 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005772 alc269_toggle_power_output(codec, 0);
5773 msleep(150);
5774 }
5775}
5776
Takashi Iwai2a439522011-07-26 09:52:50 +02005777#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005778static int alc269_resume(struct hda_codec *codec)
5779{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005780 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005781 alc269_toggle_power_output(codec, 0);
5782 msleep(150);
5783 }
5784
5785 codec->patch_ops.init(codec);
5786
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005787 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005788 alc269_toggle_power_output(codec, 1);
5789 msleep(200);
5790 }
5791
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005792 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005793 alc269_toggle_power_output(codec, 1);
5794
5795 snd_hda_codec_resume_amp(codec);
5796 snd_hda_codec_resume_cache(codec);
5797 hda_call_check_power_status(codec, 0x01);
5798 return 0;
5799}
Takashi Iwai2a439522011-07-26 09:52:50 +02005800#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005801
5802static void alc269_fixup_hweq(struct hda_codec *codec,
5803 const struct alc_fixup *fix, int action)
5804{
5805 int coef;
5806
5807 if (action != ALC_FIXUP_ACT_INIT)
5808 return;
5809 coef = alc_read_coef_idx(codec, 0x1e);
5810 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5811}
5812
5813static void alc271_fixup_dmic(struct hda_codec *codec,
5814 const struct alc_fixup *fix, int action)
5815{
5816 static const struct hda_verb verbs[] = {
5817 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5818 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5819 {}
5820 };
5821 unsigned int cfg;
5822
5823 if (strcmp(codec->chip_name, "ALC271X"))
5824 return;
5825 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5826 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5827 snd_hda_sequence_write(codec, verbs);
5828}
5829
Takashi Iwai017f2a12011-07-09 14:42:25 +02005830static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5831 const struct alc_fixup *fix, int action)
5832{
5833 struct alc_spec *spec = codec->spec;
5834
5835 if (action != ALC_FIXUP_ACT_PROBE)
5836 return;
5837
5838 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5839 * fix the sample rate of analog I/O to 44.1kHz
5840 */
5841 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5842 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5843}
5844
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005845static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5846 const struct alc_fixup *fix, int action)
5847{
5848 int coef;
5849
5850 if (action != ALC_FIXUP_ACT_INIT)
5851 return;
5852 /* The digital-mic unit sends PDM (differential signal) instead of
5853 * the standard PCM, thus you can't record a valid mono stream as is.
5854 * Below is a workaround specific to ALC269 to control the dmic
5855 * signal source as mono.
5856 */
5857 coef = alc_read_coef_idx(codec, 0x07);
5858 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5859}
5860
Takashi Iwai24519912011-08-16 15:08:49 +02005861static void alc269_quanta_automute(struct hda_codec *codec)
5862{
David Henningsson42cf0d02011-09-20 12:04:56 +02005863 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005864
5865 snd_hda_codec_write(codec, 0x20, 0,
5866 AC_VERB_SET_COEF_INDEX, 0x0c);
5867 snd_hda_codec_write(codec, 0x20, 0,
5868 AC_VERB_SET_PROC_COEF, 0x680);
5869
5870 snd_hda_codec_write(codec, 0x20, 0,
5871 AC_VERB_SET_COEF_INDEX, 0x0c);
5872 snd_hda_codec_write(codec, 0x20, 0,
5873 AC_VERB_SET_PROC_COEF, 0x480);
5874}
5875
5876static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5877 const struct alc_fixup *fix, int action)
5878{
5879 struct alc_spec *spec = codec->spec;
5880 if (action != ALC_FIXUP_ACT_PROBE)
5881 return;
5882 spec->automute_hook = alc269_quanta_automute;
5883}
5884
Takashi Iwai1d045db2011-07-07 18:23:21 +02005885enum {
5886 ALC269_FIXUP_SONY_VAIO,
5887 ALC275_FIXUP_SONY_VAIO_GPIO2,
5888 ALC269_FIXUP_DELL_M101Z,
5889 ALC269_FIXUP_SKU_IGNORE,
5890 ALC269_FIXUP_ASUS_G73JW,
5891 ALC269_FIXUP_LENOVO_EAPD,
5892 ALC275_FIXUP_SONY_HWEQ,
5893 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005894 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005895 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005896 ALC269_FIXUP_QUANTA_MUTE,
5897 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005898 ALC269_FIXUP_AMIC,
5899 ALC269_FIXUP_DMIC,
5900 ALC269VB_FIXUP_AMIC,
5901 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005902};
5903
5904static const struct alc_fixup alc269_fixups[] = {
5905 [ALC269_FIXUP_SONY_VAIO] = {
5906 .type = ALC_FIXUP_VERBS,
5907 .v.verbs = (const struct hda_verb[]) {
5908 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5909 {}
5910 }
5911 },
5912 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5913 .type = ALC_FIXUP_VERBS,
5914 .v.verbs = (const struct hda_verb[]) {
5915 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5916 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5917 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5918 { }
5919 },
5920 .chained = true,
5921 .chain_id = ALC269_FIXUP_SONY_VAIO
5922 },
5923 [ALC269_FIXUP_DELL_M101Z] = {
5924 .type = ALC_FIXUP_VERBS,
5925 .v.verbs = (const struct hda_verb[]) {
5926 /* Enables internal speaker */
5927 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5928 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5929 {}
5930 }
5931 },
5932 [ALC269_FIXUP_SKU_IGNORE] = {
5933 .type = ALC_FIXUP_SKU,
5934 .v.sku = ALC_FIXUP_SKU_IGNORE,
5935 },
5936 [ALC269_FIXUP_ASUS_G73JW] = {
5937 .type = ALC_FIXUP_PINS,
5938 .v.pins = (const struct alc_pincfg[]) {
5939 { 0x17, 0x99130111 }, /* subwoofer */
5940 { }
5941 }
5942 },
5943 [ALC269_FIXUP_LENOVO_EAPD] = {
5944 .type = ALC_FIXUP_VERBS,
5945 .v.verbs = (const struct hda_verb[]) {
5946 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5947 {}
5948 }
5949 },
5950 [ALC275_FIXUP_SONY_HWEQ] = {
5951 .type = ALC_FIXUP_FUNC,
5952 .v.func = alc269_fixup_hweq,
5953 .chained = true,
5954 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5955 },
5956 [ALC271_FIXUP_DMIC] = {
5957 .type = ALC_FIXUP_FUNC,
5958 .v.func = alc271_fixup_dmic,
5959 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005960 [ALC269_FIXUP_PCM_44K] = {
5961 .type = ALC_FIXUP_FUNC,
5962 .v.func = alc269_fixup_pcm_44k,
5963 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005964 [ALC269_FIXUP_STEREO_DMIC] = {
5965 .type = ALC_FIXUP_FUNC,
5966 .v.func = alc269_fixup_stereo_dmic,
5967 },
Takashi Iwai24519912011-08-16 15:08:49 +02005968 [ALC269_FIXUP_QUANTA_MUTE] = {
5969 .type = ALC_FIXUP_FUNC,
5970 .v.func = alc269_fixup_quanta_mute,
5971 },
5972 [ALC269_FIXUP_LIFEBOOK] = {
5973 .type = ALC_FIXUP_PINS,
5974 .v.pins = (const struct alc_pincfg[]) {
5975 { 0x1a, 0x2101103f }, /* dock line-out */
5976 { 0x1b, 0x23a11040 }, /* dock mic-in */
5977 { }
5978 },
5979 .chained = true,
5980 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5981 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005982 [ALC269_FIXUP_AMIC] = {
5983 .type = ALC_FIXUP_PINS,
5984 .v.pins = (const struct alc_pincfg[]) {
5985 { 0x14, 0x99130110 }, /* speaker */
5986 { 0x15, 0x0121401f }, /* HP out */
5987 { 0x18, 0x01a19c20 }, /* mic */
5988 { 0x19, 0x99a3092f }, /* int-mic */
5989 { }
5990 },
5991 },
5992 [ALC269_FIXUP_DMIC] = {
5993 .type = ALC_FIXUP_PINS,
5994 .v.pins = (const struct alc_pincfg[]) {
5995 { 0x12, 0x99a3092f }, /* int-mic */
5996 { 0x14, 0x99130110 }, /* speaker */
5997 { 0x15, 0x0121401f }, /* HP out */
5998 { 0x18, 0x01a19c20 }, /* mic */
5999 { }
6000 },
6001 },
6002 [ALC269VB_FIXUP_AMIC] = {
6003 .type = ALC_FIXUP_PINS,
6004 .v.pins = (const struct alc_pincfg[]) {
6005 { 0x14, 0x99130110 }, /* speaker */
6006 { 0x18, 0x01a19c20 }, /* mic */
6007 { 0x19, 0x99a3092f }, /* int-mic */
6008 { 0x21, 0x0121401f }, /* HP out */
6009 { }
6010 },
6011 },
David Henningsson2267ea92012-01-03 08:45:56 +01006012 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006013 .type = ALC_FIXUP_PINS,
6014 .v.pins = (const struct alc_pincfg[]) {
6015 { 0x12, 0x99a3092f }, /* int-mic */
6016 { 0x14, 0x99130110 }, /* speaker */
6017 { 0x18, 0x01a19c20 }, /* mic */
6018 { 0x21, 0x0121401f }, /* HP out */
6019 { }
6020 },
6021 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006022};
6023
6024static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02006025 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006026 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6027 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6028 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6029 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6030 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006031 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6032 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6033 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6034 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6035 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6036 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006037 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006038 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6039 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6040 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6041 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6042 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006043 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006044 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006045 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006046
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006047#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006048 /* Below is a quirk table taken from the old code.
6049 * Basically the device should work as is without the fixup table.
6050 * If BIOS doesn't give a proper info, enable the corresponding
6051 * fixup entry.
6052 */
6053 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6054 ALC269_FIXUP_AMIC),
6055 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006056 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6057 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6058 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6059 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6060 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6061 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6062 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6063 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6064 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6065 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6066 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6067 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6068 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6069 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6070 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6071 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6072 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6073 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6074 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6075 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6076 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6077 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6078 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6079 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6080 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6081 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6082 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6083 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6084 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6085 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6086 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6087 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6088 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6089 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6090 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6091 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6092 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6093 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6094#endif
6095 {}
6096};
6097
6098static const struct alc_model_fixup alc269_fixup_models[] = {
6099 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6100 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006101 {}
6102};
6103
6104
6105static int alc269_fill_coef(struct hda_codec *codec)
6106{
6107 int val;
6108
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006109 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006110 alc_write_coef_idx(codec, 0xf, 0x960b);
6111 alc_write_coef_idx(codec, 0xe, 0x8817);
6112 }
6113
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006114 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006115 alc_write_coef_idx(codec, 0xf, 0x960b);
6116 alc_write_coef_idx(codec, 0xe, 0x8814);
6117 }
6118
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006119 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006120 val = alc_read_coef_idx(codec, 0x04);
6121 /* Power up output pin */
6122 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6123 }
6124
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006125 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006126 val = alc_read_coef_idx(codec, 0xd);
6127 if ((val & 0x0c00) >> 10 != 0x1) {
6128 /* Capless ramp up clock control */
6129 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6130 }
6131 val = alc_read_coef_idx(codec, 0x17);
6132 if ((val & 0x01c0) >> 6 != 0x4) {
6133 /* Class D power on reset */
6134 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6135 }
6136 }
6137
6138 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6139 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6140
6141 val = alc_read_coef_idx(codec, 0x4); /* HP */
6142 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6143
6144 return 0;
6145}
6146
6147/*
6148 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006149static int patch_alc269(struct hda_codec *codec)
6150{
6151 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006152 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006153
6154 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6155 if (spec == NULL)
6156 return -ENOMEM;
6157
6158 codec->spec = spec;
6159
6160 spec->mixer_nid = 0x0b;
6161
6162 alc_auto_parse_customize_define(codec);
6163
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006164 err = alc_codec_rename_from_preset(codec);
6165 if (err < 0)
6166 goto error;
6167
Takashi Iwai1d045db2011-07-07 18:23:21 +02006168 if (codec->vendor_id == 0x10ec0269) {
6169 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006170 switch (alc_get_coef0(codec) & 0x00f0) {
6171 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006172 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006173 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006174 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006175 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006176 break;
6177 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006178 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6179 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006180 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006181 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006182 break;
6183 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006184 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006185 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006186 if (err < 0)
6187 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006188 alc269_fill_coef(codec);
6189 }
6190
Takashi Iwaia4297b52011-08-23 18:40:12 +02006191 alc_pick_fixup(codec, alc269_fixup_models,
6192 alc269_fixup_tbl, alc269_fixups);
6193 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006194
Takashi Iwaia4297b52011-08-23 18:40:12 +02006195 /* automatic parse from the BIOS config */
6196 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006197 if (err < 0)
6198 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006199
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006200 if (!spec->no_analog && has_cdefine_beep(codec)) {
6201 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006202 if (err < 0)
6203 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006204 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006205 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006206
Takashi Iwai1d045db2011-07-07 18:23:21 +02006207 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006208#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006209 codec->patch_ops.resume = alc269_resume;
6210#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006211 spec->shutup = alc269_shutup;
6212
Takashi Iwai1d045db2011-07-07 18:23:21 +02006213#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwai1d045db2011-07-07 18:23:21 +02006214 if (alc269_mic2_for_mute_led(codec))
6215 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
6216#endif
6217
Takashi Iwai589876e2012-02-20 15:47:55 +01006218 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6219
Takashi Iwai1d045db2011-07-07 18:23:21 +02006220 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006221
6222 error:
6223 alc_free(codec);
6224 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006225}
6226
6227/*
6228 * ALC861
6229 */
6230
Takashi Iwai1d045db2011-07-07 18:23:21 +02006231static int alc861_parse_auto_config(struct hda_codec *codec)
6232{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006233 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006234 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6235 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006236}
6237
Takashi Iwai1d045db2011-07-07 18:23:21 +02006238/* Pin config fixes */
6239enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006240 ALC861_FIXUP_FSC_AMILO_PI1505,
6241 ALC861_FIXUP_AMP_VREF_0F,
6242 ALC861_FIXUP_NO_JACK_DETECT,
6243 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006244};
6245
Takashi Iwai31150f22012-01-30 10:54:08 +01006246/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6247static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6248 const struct alc_fixup *fix, int action)
6249{
6250 struct alc_spec *spec = codec->spec;
6251 unsigned int val;
6252
6253 if (action != ALC_FIXUP_ACT_INIT)
6254 return;
6255 val = snd_hda_codec_read(codec, 0x0f, 0,
6256 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6257 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6258 val |= AC_PINCTL_IN_EN;
6259 val |= AC_PINCTL_VREF_50;
6260 snd_hda_codec_write(codec, 0x0f, 0,
6261 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6262 spec->keep_vref_in_automute = 1;
6263}
6264
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006265/* suppress the jack-detection */
6266static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6267 const struct alc_fixup *fix, int action)
6268{
6269 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6270 codec->no_jack_detect = 1;
6271}
6272
Takashi Iwai1d045db2011-07-07 18:23:21 +02006273static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006274 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006275 .type = ALC_FIXUP_PINS,
6276 .v.pins = (const struct alc_pincfg[]) {
6277 { 0x0b, 0x0221101f }, /* HP */
6278 { 0x0f, 0x90170310 }, /* speaker */
6279 { }
6280 }
6281 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006282 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006283 .type = ALC_FIXUP_FUNC,
6284 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006285 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006286 [ALC861_FIXUP_NO_JACK_DETECT] = {
6287 .type = ALC_FIXUP_FUNC,
6288 .v.func = alc_fixup_no_jack_detect,
6289 },
6290 [ALC861_FIXUP_ASUS_A6RP] = {
6291 .type = ALC_FIXUP_FUNC,
6292 .v.func = alc861_fixup_asus_amp_vref_0f,
6293 .chained = true,
6294 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6295 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006296};
6297
6298static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006299 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6300 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6301 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6302 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6303 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6304 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006305 {}
6306};
6307
6308/*
6309 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006310static int patch_alc861(struct hda_codec *codec)
6311{
6312 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006313 int err;
6314
6315 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6316 if (spec == NULL)
6317 return -ENOMEM;
6318
6319 codec->spec = spec;
6320
6321 spec->mixer_nid = 0x15;
6322
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006323 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6324 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006325
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006326 /* automatic parse from the BIOS config */
6327 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006328 if (err < 0)
6329 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006330
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006331 if (!spec->no_analog) {
6332 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006333 if (err < 0)
6334 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006335 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6336 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006337
Takashi Iwai1d045db2011-07-07 18:23:21 +02006338 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006339#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006340 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006341#endif
6342
Takashi Iwai589876e2012-02-20 15:47:55 +01006343 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6344
Takashi Iwai1d045db2011-07-07 18:23:21 +02006345 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006346
6347 error:
6348 alc_free(codec);
6349 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006350}
6351
6352/*
6353 * ALC861-VD support
6354 *
6355 * Based on ALC882
6356 *
6357 * In addition, an independent DAC
6358 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006359static int alc861vd_parse_auto_config(struct hda_codec *codec)
6360{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006361 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006362 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6363 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006364}
6365
Takashi Iwai1d045db2011-07-07 18:23:21 +02006366enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006367 ALC660VD_FIX_ASUS_GPIO1,
6368 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006369};
6370
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006371/* exclude VREF80 */
6372static void alc861vd_fixup_dallas(struct hda_codec *codec,
6373 const struct alc_fixup *fix, int action)
6374{
6375 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6376 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6377 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6378 }
6379}
6380
Takashi Iwai1d045db2011-07-07 18:23:21 +02006381static const struct alc_fixup alc861vd_fixups[] = {
6382 [ALC660VD_FIX_ASUS_GPIO1] = {
6383 .type = ALC_FIXUP_VERBS,
6384 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006385 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006386 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6387 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6388 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6389 { }
6390 }
6391 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006392 [ALC861VD_FIX_DALLAS] = {
6393 .type = ALC_FIXUP_FUNC,
6394 .v.func = alc861vd_fixup_dallas,
6395 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006396};
6397
6398static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006399 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006400 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006401 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006402 {}
6403};
6404
6405static const struct hda_verb alc660vd_eapd_verbs[] = {
6406 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6407 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6408 { }
6409};
6410
6411/*
6412 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006413static int patch_alc861vd(struct hda_codec *codec)
6414{
6415 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006416 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006417
6418 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6419 if (spec == NULL)
6420 return -ENOMEM;
6421
6422 codec->spec = spec;
6423
6424 spec->mixer_nid = 0x0b;
6425
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006426 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6427 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006428
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006429 /* automatic parse from the BIOS config */
6430 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006431 if (err < 0)
6432 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006433
Takashi Iwai1d045db2011-07-07 18:23:21 +02006434 if (codec->vendor_id == 0x10ec0660) {
6435 /* always turn on EAPD */
6436 add_verb(spec, alc660vd_eapd_verbs);
6437 }
6438
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006439 if (!spec->no_analog) {
6440 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006441 if (err < 0)
6442 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006443 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6444 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006445
Takashi Iwai1d045db2011-07-07 18:23:21 +02006446 codec->patch_ops = alc_patch_ops;
6447
Takashi Iwai1d045db2011-07-07 18:23:21 +02006448 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006449
Takashi Iwai589876e2012-02-20 15:47:55 +01006450 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6451
Takashi Iwai1d045db2011-07-07 18:23:21 +02006452 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006453
6454 error:
6455 alc_free(codec);
6456 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006457}
6458
6459/*
6460 * ALC662 support
6461 *
6462 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6463 * configuration. Each pin widget can choose any input DACs and a mixer.
6464 * Each ADC is connected from a mixer of all inputs. This makes possible
6465 * 6-channel independent captures.
6466 *
6467 * In addition, an independent DAC for the multi-playback (not used in this
6468 * driver yet).
6469 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006470
6471/*
6472 * BIOS auto configuration
6473 */
6474
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006475static int alc662_parse_auto_config(struct hda_codec *codec)
6476{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006477 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006478 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6479 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6480 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006481
Kailang Yang6227cdc2010-02-25 08:36:52 +01006482 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6483 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006484 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006485 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006486 ssids = alc662_ssids;
6487 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006488}
6489
Todd Broch6be79482010-12-07 16:51:05 -08006490static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006491 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006492{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006493 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006494 return;
Todd Broch6be79482010-12-07 16:51:05 -08006495 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6496 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6497 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6498 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6499 (0 << AC_AMPCAP_MUTE_SHIFT)))
6500 printk(KERN_WARNING
6501 "hda_codec: failed to override amp caps for NID 0x2\n");
6502}
6503
David Henningsson6cb3b702010-09-09 08:51:44 +02006504enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006505 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006506 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006507 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006508 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006509 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006510 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006511 ALC662_FIXUP_ASUS_MODE1,
6512 ALC662_FIXUP_ASUS_MODE2,
6513 ALC662_FIXUP_ASUS_MODE3,
6514 ALC662_FIXUP_ASUS_MODE4,
6515 ALC662_FIXUP_ASUS_MODE5,
6516 ALC662_FIXUP_ASUS_MODE6,
6517 ALC662_FIXUP_ASUS_MODE7,
6518 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006519 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006520};
6521
6522static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006523 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006524 .type = ALC_FIXUP_PINS,
6525 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006526 { 0x15, 0x99130112 }, /* subwoofer */
6527 { }
6528 }
6529 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006530 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006531 .type = ALC_FIXUP_PINS,
6532 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006533 { 0x17, 0x99130112 }, /* subwoofer */
6534 { }
6535 }
6536 },
Todd Broch6be79482010-12-07 16:51:05 -08006537 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006538 .type = ALC_FIXUP_FUNC,
6539 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006540 },
6541 [ALC662_FIXUP_CZC_P10T] = {
6542 .type = ALC_FIXUP_VERBS,
6543 .v.verbs = (const struct hda_verb[]) {
6544 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6545 {}
6546 }
6547 },
David Henningsson94024cd2011-04-29 14:10:55 +02006548 [ALC662_FIXUP_SKU_IGNORE] = {
6549 .type = ALC_FIXUP_SKU,
6550 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006551 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006552 [ALC662_FIXUP_HP_RP5800] = {
6553 .type = ALC_FIXUP_PINS,
6554 .v.pins = (const struct alc_pincfg[]) {
6555 { 0x14, 0x0221201f }, /* HP out */
6556 { }
6557 },
6558 .chained = true,
6559 .chain_id = ALC662_FIXUP_SKU_IGNORE
6560 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006561 [ALC662_FIXUP_ASUS_MODE1] = {
6562 .type = ALC_FIXUP_PINS,
6563 .v.pins = (const struct alc_pincfg[]) {
6564 { 0x14, 0x99130110 }, /* speaker */
6565 { 0x18, 0x01a19c20 }, /* mic */
6566 { 0x19, 0x99a3092f }, /* int-mic */
6567 { 0x21, 0x0121401f }, /* HP out */
6568 { }
6569 },
6570 .chained = true,
6571 .chain_id = ALC662_FIXUP_SKU_IGNORE
6572 },
6573 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006574 .type = ALC_FIXUP_PINS,
6575 .v.pins = (const struct alc_pincfg[]) {
6576 { 0x14, 0x99130110 }, /* speaker */
6577 { 0x18, 0x01a19820 }, /* mic */
6578 { 0x19, 0x99a3092f }, /* int-mic */
6579 { 0x1b, 0x0121401f }, /* HP out */
6580 { }
6581 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006582 .chained = true,
6583 .chain_id = ALC662_FIXUP_SKU_IGNORE
6584 },
6585 [ALC662_FIXUP_ASUS_MODE3] = {
6586 .type = ALC_FIXUP_PINS,
6587 .v.pins = (const struct alc_pincfg[]) {
6588 { 0x14, 0x99130110 }, /* speaker */
6589 { 0x15, 0x0121441f }, /* HP */
6590 { 0x18, 0x01a19840 }, /* mic */
6591 { 0x19, 0x99a3094f }, /* int-mic */
6592 { 0x21, 0x01211420 }, /* HP2 */
6593 { }
6594 },
6595 .chained = true,
6596 .chain_id = ALC662_FIXUP_SKU_IGNORE
6597 },
6598 [ALC662_FIXUP_ASUS_MODE4] = {
6599 .type = ALC_FIXUP_PINS,
6600 .v.pins = (const struct alc_pincfg[]) {
6601 { 0x14, 0x99130110 }, /* speaker */
6602 { 0x16, 0x99130111 }, /* speaker */
6603 { 0x18, 0x01a19840 }, /* mic */
6604 { 0x19, 0x99a3094f }, /* int-mic */
6605 { 0x21, 0x0121441f }, /* HP */
6606 { }
6607 },
6608 .chained = true,
6609 .chain_id = ALC662_FIXUP_SKU_IGNORE
6610 },
6611 [ALC662_FIXUP_ASUS_MODE5] = {
6612 .type = ALC_FIXUP_PINS,
6613 .v.pins = (const struct alc_pincfg[]) {
6614 { 0x14, 0x99130110 }, /* speaker */
6615 { 0x15, 0x0121441f }, /* HP */
6616 { 0x16, 0x99130111 }, /* speaker */
6617 { 0x18, 0x01a19840 }, /* mic */
6618 { 0x19, 0x99a3094f }, /* int-mic */
6619 { }
6620 },
6621 .chained = true,
6622 .chain_id = ALC662_FIXUP_SKU_IGNORE
6623 },
6624 [ALC662_FIXUP_ASUS_MODE6] = {
6625 .type = ALC_FIXUP_PINS,
6626 .v.pins = (const struct alc_pincfg[]) {
6627 { 0x14, 0x99130110 }, /* speaker */
6628 { 0x15, 0x01211420 }, /* HP2 */
6629 { 0x18, 0x01a19840 }, /* mic */
6630 { 0x19, 0x99a3094f }, /* int-mic */
6631 { 0x1b, 0x0121441f }, /* HP */
6632 { }
6633 },
6634 .chained = true,
6635 .chain_id = ALC662_FIXUP_SKU_IGNORE
6636 },
6637 [ALC662_FIXUP_ASUS_MODE7] = {
6638 .type = ALC_FIXUP_PINS,
6639 .v.pins = (const struct alc_pincfg[]) {
6640 { 0x14, 0x99130110 }, /* speaker */
6641 { 0x17, 0x99130111 }, /* speaker */
6642 { 0x18, 0x01a19840 }, /* mic */
6643 { 0x19, 0x99a3094f }, /* int-mic */
6644 { 0x1b, 0x01214020 }, /* HP */
6645 { 0x21, 0x0121401f }, /* HP */
6646 { }
6647 },
6648 .chained = true,
6649 .chain_id = ALC662_FIXUP_SKU_IGNORE
6650 },
6651 [ALC662_FIXUP_ASUS_MODE8] = {
6652 .type = ALC_FIXUP_PINS,
6653 .v.pins = (const struct alc_pincfg[]) {
6654 { 0x14, 0x99130110 }, /* speaker */
6655 { 0x12, 0x99a30970 }, /* int-mic */
6656 { 0x15, 0x01214020 }, /* HP */
6657 { 0x17, 0x99130111 }, /* speaker */
6658 { 0x18, 0x01a19840 }, /* mic */
6659 { 0x21, 0x0121401f }, /* HP */
6660 { }
6661 },
6662 .chained = true,
6663 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006664 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006665 [ALC662_FIXUP_NO_JACK_DETECT] = {
6666 .type = ALC_FIXUP_FUNC,
6667 .v.func = alc_fixup_no_jack_detect,
6668 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006669};
6670
Takashi Iwaia9111322011-05-02 11:30:18 +02006671static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006672 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006673 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006674 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006675 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006676 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006677 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006678 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006679 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006680 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006681 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006682 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006683
6684#if 0
6685 /* Below is a quirk table taken from the old code.
6686 * Basically the device should work as is without the fixup table.
6687 * If BIOS doesn't give a proper info, enable the corresponding
6688 * fixup entry.
6689 */
6690 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6691 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6692 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6693 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6694 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6695 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6696 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6697 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6698 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6699 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6700 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6701 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6702 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6703 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6704 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6705 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6706 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6707 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6708 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6709 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6710 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6711 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6712 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6713 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6714 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6715 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6716 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6717 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6718 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6719 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6720 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6721 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6722 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6723 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6724 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6725 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6726 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6727 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6728 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6729 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6730 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6731 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6732 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6733 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6734 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6735 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6736 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6737 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6738 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6739 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6740#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006741 {}
6742};
6743
Todd Broch6be79482010-12-07 16:51:05 -08006744static const struct alc_model_fixup alc662_fixup_models[] = {
6745 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006746 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6747 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6748 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6749 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6750 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6751 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6752 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6753 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006754 {}
6755};
David Henningsson6cb3b702010-09-09 08:51:44 +02006756
6757
Takashi Iwai1d045db2011-07-07 18:23:21 +02006758/*
6759 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006760static int patch_alc662(struct hda_codec *codec)
6761{
6762 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006763 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006764
6765 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6766 if (!spec)
6767 return -ENOMEM;
6768
6769 codec->spec = spec;
6770
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006771 spec->mixer_nid = 0x0b;
6772
Takashi Iwai53c334a2011-08-23 18:27:14 +02006773 /* handle multiple HPs as is */
6774 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6775
Kailang Yangda00c242010-03-19 11:23:45 +01006776 alc_auto_parse_customize_define(codec);
6777
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006778 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6779
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006780 err = alc_codec_rename_from_preset(codec);
6781 if (err < 0)
6782 goto error;
6783
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006784 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006785 codec->bus->pci->subsystem_vendor == 0x1025 &&
6786 spec->cdefine.platform_type == 1) {
6787 if (alc_codec_rename(codec, "ALC272X") < 0)
6788 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006789 }
Kailang Yang274693f2009-12-03 10:07:50 +01006790
Takashi Iwaib9c51062011-08-24 18:08:07 +02006791 alc_pick_fixup(codec, alc662_fixup_models,
6792 alc662_fixup_tbl, alc662_fixups);
6793 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6794 /* automatic parse from the BIOS config */
6795 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006796 if (err < 0)
6797 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006798
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006799 if (!spec->no_analog && has_cdefine_beep(codec)) {
6800 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006801 if (err < 0)
6802 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006803 switch (codec->vendor_id) {
6804 case 0x10ec0662:
6805 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6806 break;
6807 case 0x10ec0272:
6808 case 0x10ec0663:
6809 case 0x10ec0665:
6810 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6811 break;
6812 case 0x10ec0273:
6813 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6814 break;
6815 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006816 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006817
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006818 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c7161532011-04-07 10:37:16 +02006819 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006820
Takashi Iwai589876e2012-02-20 15:47:55 +01006821 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6822
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006823 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006824
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006825 error:
6826 alc_free(codec);
6827 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006828}
6829
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006830/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006831 * ALC680 support
6832 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006833
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006834static int alc680_parse_auto_config(struct hda_codec *codec)
6835{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006836 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006837}
6838
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006839/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006840 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006841static int patch_alc680(struct hda_codec *codec)
6842{
6843 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006844 int err;
6845
6846 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6847 if (spec == NULL)
6848 return -ENOMEM;
6849
6850 codec->spec = spec;
6851
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006852 /* ALC680 has no aa-loopback mixer */
6853
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006854 /* automatic parse from the BIOS config */
6855 err = alc680_parse_auto_config(codec);
6856 if (err < 0) {
6857 alc_free(codec);
6858 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006859 }
6860
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006861 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006862
6863 return 0;
6864}
6865
6866/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006867 * patch entries
6868 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006869static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006870 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006871 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006872 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006873 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006874 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006875 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006876 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006877 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006878 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006879 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006880 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006881 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006882 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6883 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6884 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006885 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006886 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006887 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6888 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006889 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6890 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006891 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006892 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006893 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006894 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006895 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006896 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006897 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006898 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006899 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006900 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006901 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006902 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006903 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006904 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006905 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006906 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006907 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006908 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006909 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006910 {} /* terminator */
6911};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006912
6913MODULE_ALIAS("snd-hda-codec-id:10ec*");
6914
6915MODULE_LICENSE("GPL");
6916MODULE_DESCRIPTION("Realtek HD-audio codec");
6917
6918static struct hda_codec_preset_list realtek_list = {
6919 .preset = snd_hda_preset_realtek,
6920 .owner = THIS_MODULE,
6921};
6922
6923static int __init patch_realtek_init(void)
6924{
6925 return snd_hda_add_codec_preset(&realtek_list);
6926}
6927
6928static void __exit patch_realtek_exit(void)
6929{
6930 snd_hda_delete_codec_preset(&realtek_list);
6931}
6932
6933module_init(patch_realtek_init)
6934module_exit(patch_realtek_exit)