blob: ff4410cf75a649ad16382c4612927c44dc01b423 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e42006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Takashi Iwaic14c95f2012-02-16 16:38:07 +010083#define MAX_VOL_NIDS 0x40
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085struct alc_spec {
86 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020089 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010090 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Takashi Iwai2d9c6482009-10-13 08:06:55 +020092 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020093 * don't forget NULL
94 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020095 */
96 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Takashi Iwaiaa563af2009-07-31 10:05:11 +020098 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020099 const struct hda_pcm_stream *stream_analog_playback;
100 const struct hda_pcm_stream *stream_analog_capture;
101 const struct hda_pcm_stream *stream_analog_alt_playback;
102 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200104 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200105 const struct hda_pcm_stream *stream_digital_playback;
106 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200109 struct hda_multi_out multiout; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
112 */
Takashi Iwai63300792008-01-24 15:31:36 +0100113 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100114 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100115 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 /* capture */
118 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200119 const hda_nid_t *adc_nids;
120 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200121 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200122 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwaic14c95f2012-02-16 16:38:07 +0100123 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
124 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Takashi Iwai840b64c2010-07-13 22:49:01 +0200126 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200127 hda_nid_t cur_adc;
128 unsigned int cur_adc_stream_tag;
129 unsigned int cur_adc_format;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200132 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 const struct hda_input_mux *input_mux;
134 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200135 hda_nid_t ext_mic_pin;
136 hda_nid_t dock_mic_pin;
137 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100140 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200142 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200143 int const_channel_count;
144 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100147 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200148
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100151 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200152 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200153 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200154 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai49535502009-06-30 15:28:30 +0200155 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
156 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200157 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
158 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
159 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100160
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100161 /* hooks */
162 void (*init_hook)(struct hda_codec *codec);
163 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500165 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100166#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200167 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200168 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100169
Takashi Iwai834be882006-03-01 14:16:17 +0100170 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200171 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200172 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200173 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200174 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200175 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200176 unsigned int automute_speaker:1; /* automute speaker outputs */
177 unsigned int automute_lo:1; /* automute LO outputs */
178 unsigned int detect_hp:1; /* Headphone detection enabled */
179 unsigned int detect_lo:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100182 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200183
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100184 /* other flags */
185 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200186 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100187 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200188 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200189 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100190 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200191
192 /* auto-mute control */
193 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200194 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200195
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200196 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200197 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100198
Takashi Iwai2134ea42008-01-10 16:53:55 +0100199 /* for virtual master */
200 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200201#ifdef CONFIG_SND_HDA_POWER_SAVE
202 struct hda_loopback_check loopback;
203#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200204
205 /* for PLL fix */
206 hda_nid_t pll_nid;
207 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200208 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100209
210 /* fix-up list */
211 int fixup_id;
212 const struct alc_fixup *fixup_list;
213 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200214
215 /* multi-io */
216 int multi_ios;
217 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200218
219 /* bind volumes */
220 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100221};
222
Takashi Iwai1d045db2011-07-07 18:23:21 +0200223#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
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 Iwaicd896c32008-11-18 12:36:33 +0100303 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
304 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100305 if (!imux->num_items && mux_idx > 0)
306 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100307 if (!imux->num_items)
308 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100309
Takashi Iwai21268962011-07-07 15:01:13 +0200310 if (idx >= imux->num_items)
311 idx = imux->num_items - 1;
312 if (spec->cur_mux[adc_idx] == idx && !force)
313 return 0;
314 spec->cur_mux[adc_idx] = idx;
315
Takashi Iwai24de1832011-11-07 17:13:39 +0100316 /* for shared I/O, change the pin-control accordingly */
317 if (spec->shared_mic_hp) {
318 /* NOTE: this assumes that there are only two inputs, the
319 * first is the real internal mic and the second is HP jack.
320 */
321 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
322 AC_VERB_SET_PIN_WIDGET_CONTROL,
323 spec->cur_mux[adc_idx] ?
324 PIN_VREF80 : PIN_HP);
325 spec->automute_speaker = !spec->cur_mux[adc_idx];
326 call_update_outputs(codec);
327 }
328
Takashi Iwai21268962011-07-07 15:01:13 +0200329 if (spec->dyn_adc_switch) {
330 alc_dyn_adc_pcm_resetup(codec, idx);
331 adc_idx = spec->dyn_adc_idx[idx];
332 }
333
Takashi Iwai61071592011-11-23 07:52:15 +0100334 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200335
336 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100337 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
338 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200339 return 1;
340
Takashi Iwaia22d5432009-07-27 12:54:26 +0200341 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200342 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100343 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100344 int active = imux->items[idx].index;
345 for (i = 0; i < num_conns; i++) {
346 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
347 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100348 HDA_AMP_MUTE, v);
349 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100350 } else {
351 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200352 snd_hda_codec_write_cache(codec, nid, 0,
353 AC_VERB_SET_CONNECT_SEL,
354 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100355 }
Takashi Iwai21268962011-07-07 15:01:13 +0200356 return 1;
357}
358
359static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_value *ucontrol)
361{
362 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
363 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
364 return alc_mux_select(codec, adc_idx,
365 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100366}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200367
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100369 * set up the input pin config (depending on the given auto-pin type)
370 */
371static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
372 int auto_pin_type)
373{
374 unsigned int val = PIN_IN;
375
Takashi Iwai86e29592010-09-09 14:50:17 +0200376 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100377 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200378 unsigned int oldval;
379 oldval = snd_hda_codec_read(codec, nid, 0,
380 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100381 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100382 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200383 /* if the default pin setup is vref50, we give it priority */
384 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100385 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200386 else if (pincap & AC_PINCAP_VREF_50)
387 val = PIN_VREF50;
388 else if (pincap & AC_PINCAP_VREF_100)
389 val = PIN_VREF100;
390 else if (pincap & AC_PINCAP_VREF_GRD)
391 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100392 }
393 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
394}
395
396/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200397 * Append the given mixer and verb elements for the later use
398 * The mixer array is referred in build_controls(), and init_verbs are
399 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100400 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200401static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100402{
403 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
404 return;
405 spec->mixers[spec->num_mixers++] = mix;
406}
407
408static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
409{
410 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
411 return;
412 spec->init_verbs[spec->num_init_verbs++] = verb;
413}
414
415/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200416 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100417 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200418/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200419static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200420 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
421 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
422 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
423 { }
424};
425
Takashi Iwaia9111322011-05-02 11:30:18 +0200426static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200427 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
428 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
429 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
430 { }
431};
432
Takashi Iwaia9111322011-05-02 11:30:18 +0200433static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200434 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
435 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
436 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
437 { }
438};
439
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200440/*
441 * Fix hardware PLL issue
442 * On some codecs, the analog PLL gating control must be off while
443 * the default value is 1.
444 */
445static void alc_fix_pll(struct hda_codec *codec)
446{
447 struct alc_spec *spec = codec->spec;
448 unsigned int val;
449
450 if (!spec->pll_nid)
451 return;
452 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
453 spec->pll_coef_idx);
454 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
455 AC_VERB_GET_PROC_COEF, 0);
456 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
457 spec->pll_coef_idx);
458 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
459 val & ~(1 << spec->pll_coef_bit));
460}
461
462static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
463 unsigned int coef_idx, unsigned int coef_bit)
464{
465 struct alc_spec *spec = codec->spec;
466 spec->pll_nid = nid;
467 spec->pll_coef_idx = coef_idx;
468 spec->pll_coef_bit = coef_bit;
469 alc_fix_pll(codec);
470}
471
Takashi Iwai1d045db2011-07-07 18:23:21 +0200472/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200473 * Jack detections for HP auto-mute and mic-switch
474 */
475
476/* check each pin in the given array; returns true if any of them is plugged */
477static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200478{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200479 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200480
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200481 for (i = 0; i < num_pins; i++) {
482 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200483 if (!nid)
484 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200485 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200486 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200487 return present;
488}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200489
Takashi Iwai1d045db2011-07-07 18:23:21 +0200490/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200491static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200492 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200493{
494 struct alc_spec *spec = codec->spec;
495 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200496 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200497 int i;
498
499 for (i = 0; i < num_pins; i++) {
500 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100501 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200502 if (!nid)
503 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200504 switch (spec->automute_mode) {
505 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100506 /* don't reset VREF value in case it's controlling
507 * the amp (see alc861_fixup_asus_amp_vref_0f())
508 */
509 if (spec->keep_vref_in_automute) {
510 val = snd_hda_codec_read(codec, nid, 0,
511 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
512 val &= ~PIN_HP;
513 } else
514 val = 0;
515 val |= pin_bits;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200516 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai31150f22012-01-30 10:54:08 +0100518 val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200519 break;
520 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200521 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200522 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200523 break;
524 case ALC_AUTOMUTE_MIXER:
525 nid = spec->automute_mixer_nid[i];
526 if (!nid)
527 break;
528 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200530 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200531 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200532 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200533 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200534 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200535}
536
David Henningsson42cf0d02011-09-20 12:04:56 +0200537/* Toggle outputs muting */
538static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200539{
540 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200541 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200542
Takashi Iwaic0a20262011-06-10 15:28:15 +0200543 /* Control HP pins/amps depending on master_mute state;
544 * in general, HP pins/amps control should be enabled in all cases,
545 * but currently set only for master_mute, just to be safe
546 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100547 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
548 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200549 spec->autocfg.hp_pins, spec->master_mute, true);
550
David Henningsson42cf0d02011-09-20 12:04:56 +0200551 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200552 on = 0;
553 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200554 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200557 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558
559 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 /* if LO is a copy of either HP or Speaker, don't need to handle it */
561 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
562 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200563 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200564 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 on = 0;
566 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200567 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200568 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200569 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200570 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200571}
572
David Henningsson42cf0d02011-09-20 12:04:56 +0200573static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200574{
575 struct alc_spec *spec = codec->spec;
576 if (spec->automute_hook)
577 spec->automute_hook(codec);
578 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200579 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200580}
581
Takashi Iwai1d045db2011-07-07 18:23:21 +0200582/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583static void alc_hp_automute(struct hda_codec *codec)
584{
585 struct alc_spec *spec = codec->spec;
586
David Henningsson42cf0d02011-09-20 12:04:56 +0200587 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
589 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200590 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200591 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200592 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200593}
594
Takashi Iwai1d045db2011-07-07 18:23:21 +0200595/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200596static void alc_line_automute(struct hda_codec *codec)
597{
598 struct alc_spec *spec = codec->spec;
599
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200600 /* check LO jack only when it's different from HP */
601 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
602 return;
603
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200604 spec->line_jack_present =
605 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
606 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200607 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200608 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200609 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200610}
611
Takashi Iwai8d087c72011-06-28 12:45:47 +0200612#define get_connection_index(codec, mux, nid) \
613 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200614
Takashi Iwai1d045db2011-07-07 18:23:21 +0200615/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200616static void alc_mic_automute(struct hda_codec *codec)
617{
618 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200619 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200620
Takashi Iwai21268962011-07-07 15:01:13 +0200621 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200622 return;
623 if (snd_BUG_ON(!spec->adc_nids))
624 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200625 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200626 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200627
Takashi Iwai21268962011-07-07 15:01:13 +0200628 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
629 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
630 else if (spec->dock_mic_idx >= 0 &&
631 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
632 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
633 else
634 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200635}
636
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100637/* handle the specified unsol action (ALC_XXX_EVENT) */
638static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200639{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100640 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200641 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200642 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200643 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200644 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200645 alc_line_automute(codec);
646 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200647 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200648 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200649 break;
650 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200651 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200652}
653
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100654/* update the master volume per volume-knob's unsol event */
655static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
656{
657 unsigned int val;
658 struct snd_kcontrol *kctl;
659 struct snd_ctl_elem_value *uctl;
660
661 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
662 if (!kctl)
663 return;
664 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
665 if (!uctl)
666 return;
667 val = snd_hda_codec_read(codec, nid, 0,
668 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
669 val &= HDA_AMP_VOLMASK;
670 uctl->value.integer.value[0] = val;
671 uctl->value.integer.value[1] = val;
672 kctl->put(kctl, uctl);
673 kfree(uctl);
674}
675
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100676/* unsolicited event for HP jack sensing */
677static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
678{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100679 int action;
680
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100681 if (codec->vendor_id == 0x10ec0880)
682 res >>= 28;
683 else
684 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100685 action = snd_hda_jack_get_action(codec, res);
686 if (res == ALC_DCVOL_EVENT) {
687 /* Execute the dc-vol event here as it requires the NID
688 * but we don't pass NID to alc_exec_unsol_event().
689 * Once when we convert all static quirks to the auto-parser,
690 * this can be integerated into there.
691 */
692 struct hda_jack_tbl *jack;
693 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
694 if (jack)
695 alc_update_knob_master(codec, jack->nid);
696 return;
697 }
698 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100699}
700
Takashi Iwai1d045db2011-07-07 18:23:21 +0200701/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200702static void alc_inithook(struct hda_codec *codec)
703{
Takashi Iwaid922b512011-04-28 12:18:53 +0200704 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200705 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200706 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200707}
708
Kailang Yangf9423e72008-05-27 12:32:25 +0200709/* additional initialization for ALC888 variants */
710static void alc888_coef_init(struct hda_codec *codec)
711{
712 unsigned int tmp;
713
714 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
715 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
716 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100717 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200718 /* alc888S-VC */
719 snd_hda_codec_read(codec, 0x20, 0,
720 AC_VERB_SET_PROC_COEF, 0x830);
721 else
722 /* alc888-VB */
723 snd_hda_codec_read(codec, 0x20, 0,
724 AC_VERB_SET_PROC_COEF, 0x3030);
725}
726
Takashi Iwai1d045db2011-07-07 18:23:21 +0200727/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200728static void alc889_coef_init(struct hda_codec *codec)
729{
730 unsigned int tmp;
731
732 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
733 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
734 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
735 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
736}
737
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100738/* turn on/off EAPD control (only if available) */
739static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
740{
741 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
742 return;
743 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
744 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
745 on ? 2 : 0);
746}
747
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200748/* turn on/off EAPD controls of the codec */
749static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
750{
751 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200752 static hda_nid_t pins[] = {
753 0x0f, 0x10, 0x14, 0x15, 0
754 };
755 hda_nid_t *p;
756 for (p = pins; *p; p++)
757 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200758}
759
Takashi Iwai1c716152011-04-07 10:37:16 +0200760/* generic shutup callback;
761 * just turning off EPAD and a little pause for avoiding pop-noise
762 */
763static void alc_eapd_shutup(struct hda_codec *codec)
764{
765 alc_auto_setup_eapd(codec, false);
766 msleep(200);
767}
768
Takashi Iwai1d045db2011-07-07 18:23:21 +0200769/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200771{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200772 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200773
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200774 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200775 switch (type) {
776 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200777 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
778 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200779 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200780 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
781 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200782 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200783 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
784 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200785 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200786 switch (codec->vendor_id) {
787 case 0x10ec0260:
788 snd_hda_codec_write(codec, 0x1a, 0,
789 AC_VERB_SET_COEF_INDEX, 7);
790 tmp = snd_hda_codec_read(codec, 0x1a, 0,
791 AC_VERB_GET_PROC_COEF, 0);
792 snd_hda_codec_write(codec, 0x1a, 0,
793 AC_VERB_SET_COEF_INDEX, 7);
794 snd_hda_codec_write(codec, 0x1a, 0,
795 AC_VERB_SET_PROC_COEF,
796 tmp | 0x2010);
797 break;
798 case 0x10ec0262:
799 case 0x10ec0880:
800 case 0x10ec0882:
801 case 0x10ec0883:
802 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100803 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100804 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200805 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200806 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200807 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200808 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200809 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100810#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200811 case 0x10ec0267:
812 case 0x10ec0268:
813 snd_hda_codec_write(codec, 0x20, 0,
814 AC_VERB_SET_COEF_INDEX, 7);
815 tmp = snd_hda_codec_read(codec, 0x20, 0,
816 AC_VERB_GET_PROC_COEF, 0);
817 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200818 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200819 snd_hda_codec_write(codec, 0x20, 0,
820 AC_VERB_SET_PROC_COEF,
821 tmp | 0x3000);
822 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100823#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200824 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200825 break;
826 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200827}
Kailang Yangea1fb292008-08-26 12:58:38 +0200828
Takashi Iwai1d045db2011-07-07 18:23:21 +0200829/*
830 * Auto-Mute mode mixer enum support
831 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200832static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
833 struct snd_ctl_elem_info *uinfo)
834{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200835 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
836 struct alc_spec *spec = codec->spec;
837 static const char * const texts2[] = {
838 "Disabled", "Enabled"
839 };
840 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200841 "Disabled", "Speaker Only", "Line-Out+Speaker"
842 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200843 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200844
845 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
846 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200847 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200848 uinfo->value.enumerated.items = 3;
849 texts = texts3;
850 } else {
851 uinfo->value.enumerated.items = 2;
852 texts = texts2;
853 }
854 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
855 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200856 strcpy(uinfo->value.enumerated.name,
857 texts[uinfo->value.enumerated.item]);
858 return 0;
859}
860
861static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
862 struct snd_ctl_elem_value *ucontrol)
863{
864 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
865 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200866 unsigned int val = 0;
867 if (spec->automute_speaker)
868 val++;
869 if (spec->automute_lo)
870 val++;
871
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200872 ucontrol->value.enumerated.item[0] = val;
873 return 0;
874}
875
876static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
877 struct snd_ctl_elem_value *ucontrol)
878{
879 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
880 struct alc_spec *spec = codec->spec;
881
882 switch (ucontrol->value.enumerated.item[0]) {
883 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200886 spec->automute_speaker = 0;
887 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200888 break;
889 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200890 if (spec->automute_speaker_possible) {
891 if (!spec->automute_lo && spec->automute_speaker)
892 return 0;
893 spec->automute_speaker = 1;
894 spec->automute_lo = 0;
895 } else if (spec->automute_lo_possible) {
896 if (spec->automute_lo)
897 return 0;
898 spec->automute_lo = 1;
899 } else
900 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200901 break;
902 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200903 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200904 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200905 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200906 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200907 spec->automute_speaker = 1;
908 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909 break;
910 default:
911 return -EINVAL;
912 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200913 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200914 return 1;
915}
916
Takashi Iwaia9111322011-05-02 11:30:18 +0200917static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200918 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
919 .name = "Auto-Mute Mode",
920 .info = alc_automute_mode_info,
921 .get = alc_automute_mode_get,
922 .put = alc_automute_mode_put,
923};
924
Takashi Iwai1d045db2011-07-07 18:23:21 +0200925static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
926{
927 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
928 return snd_array_new(&spec->kctls);
929}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200930
931static int alc_add_automute_mode_enum(struct hda_codec *codec)
932{
933 struct alc_spec *spec = codec->spec;
934 struct snd_kcontrol_new *knew;
935
936 knew = alc_kcontrol_new(spec);
937 if (!knew)
938 return -ENOMEM;
939 *knew = alc_automute_mode_enum;
940 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
941 if (!knew->name)
942 return -ENOMEM;
943 return 0;
944}
945
Takashi Iwai1d045db2011-07-07 18:23:21 +0200946/*
947 * Check the availability of HP/line-out auto-mute;
948 * Set up appropriately if really supported
949 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200950static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200951{
952 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200953 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200954 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200955 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200956
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200957 if (cfg->hp_pins[0])
958 present++;
959 if (cfg->line_out_pins[0])
960 present++;
961 if (cfg->speaker_pins[0])
962 present++;
963 if (present < 2) /* need two different output types */
964 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200965
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200966 if (!cfg->speaker_pins[0] &&
967 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200968 memcpy(cfg->speaker_pins, cfg->line_out_pins,
969 sizeof(cfg->speaker_pins));
970 cfg->speaker_outs = cfg->line_outs;
971 }
972
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200973 if (!cfg->hp_pins[0] &&
974 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200975 memcpy(cfg->hp_pins, cfg->line_out_pins,
976 sizeof(cfg->hp_pins));
977 cfg->hp_outs = cfg->line_outs;
978 }
979
David Henningsson42cf0d02011-09-20 12:04:56 +0200980 spec->automute_mode = ALC_AUTOMUTE_PIN;
981
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200982 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200983 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200984 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200985 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200986 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200987 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200988 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200989 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200990 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200991
David Henningsson42cf0d02011-09-20 12:04:56 +0200992 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
993 if (cfg->speaker_outs)
994 for (i = 0; i < cfg->line_outs; i++) {
995 hda_nid_t nid = cfg->line_out_pins[i];
996 if (!is_jack_detectable(codec, nid))
997 continue;
998 snd_printdd("realtek: Enable Line-Out "
999 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001000 snd_hda_jack_detect_enable(codec, nid,
1001 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001002 spec->detect_lo = 1;
1003 }
1004 spec->automute_lo_possible = spec->detect_hp;
1005 }
1006
1007 spec->automute_speaker_possible = cfg->speaker_outs &&
1008 (spec->detect_hp || spec->detect_lo);
1009
1010 spec->automute_lo = spec->automute_lo_possible;
1011 spec->automute_speaker = spec->automute_speaker_possible;
1012
1013 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001014 /* create a control for automute mode */
1015 alc_add_automute_mode_enum(codec);
1016 spec->unsol_event = alc_sku_unsol_event;
1017 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001018}
1019
Takashi Iwai1d045db2011-07-07 18:23:21 +02001020/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001021static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1022{
1023 int i;
1024 for (i = 0; i < nums; i++)
1025 if (list[i] == nid)
1026 return i;
1027 return -1;
1028}
1029
Takashi Iwai1d045db2011-07-07 18:23:21 +02001030/* check whether dynamic ADC-switching is available */
1031static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1032{
1033 struct alc_spec *spec = codec->spec;
1034 struct hda_input_mux *imux = &spec->private_imux[0];
1035 int i, n, idx;
1036 hda_nid_t cap, pin;
1037
1038 if (imux != spec->input_mux) /* no dynamic imux? */
1039 return false;
1040
1041 for (n = 0; n < spec->num_adc_nids; n++) {
1042 cap = spec->private_capsrc_nids[n];
1043 for (i = 0; i < imux->num_items; i++) {
1044 pin = spec->imux_pins[i];
1045 if (!pin)
1046 return false;
1047 if (get_connection_index(codec, cap, pin) < 0)
1048 break;
1049 }
1050 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001051 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001052 }
1053
1054 for (i = 0; i < imux->num_items; i++) {
1055 pin = spec->imux_pins[i];
1056 for (n = 0; n < spec->num_adc_nids; n++) {
1057 cap = spec->private_capsrc_nids[n];
1058 idx = get_connection_index(codec, cap, pin);
1059 if (idx >= 0) {
1060 imux->items[i].index = idx;
1061 spec->dyn_adc_idx[i] = n;
1062 break;
1063 }
1064 }
1065 }
1066
1067 snd_printdd("realtek: enabling ADC switching\n");
1068 spec->dyn_adc_switch = 1;
1069 return true;
1070}
Takashi Iwai21268962011-07-07 15:01:13 +02001071
1072/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1073static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1074{
1075 struct alc_spec *spec = codec->spec;
1076 struct hda_input_mux *imux;
1077 static char * const texts[3] = {
1078 "Mic", "Internal Mic", "Dock Mic"
1079 };
1080 int i;
1081
1082 if (!spec->auto_mic)
1083 return false;
1084 imux = &spec->private_imux[0];
1085 if (spec->input_mux == imux)
1086 return true;
1087 spec->imux_pins[0] = spec->ext_mic_pin;
1088 spec->imux_pins[1] = spec->int_mic_pin;
1089 spec->imux_pins[2] = spec->dock_mic_pin;
1090 for (i = 0; i < 3; i++) {
1091 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001092 if (spec->imux_pins[i]) {
1093 hda_nid_t pin = spec->imux_pins[i];
1094 int c;
1095 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001096 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001097 int idx = get_connection_index(codec, cap, pin);
1098 if (idx >= 0) {
1099 imux->items[i].index = idx;
1100 break;
1101 }
1102 }
Takashi Iwai21268962011-07-07 15:01:13 +02001103 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001104 }
Takashi Iwai21268962011-07-07 15:01:13 +02001105 }
1106 spec->num_mux_defs = 1;
1107 spec->input_mux = imux;
1108 return true;
1109}
1110
1111/* check whether all auto-mic pins are valid; setup indices if OK */
1112static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1113{
1114 struct alc_spec *spec = codec->spec;
1115 const struct hda_input_mux *imux;
1116
1117 if (!spec->auto_mic)
1118 return false;
1119 if (spec->auto_mic_valid_imux)
1120 return true; /* already checked */
1121
1122 /* fill up imux indices */
1123 if (!alc_check_dyn_adc_switch(codec)) {
1124 spec->auto_mic = 0;
1125 return false;
1126 }
1127
1128 imux = spec->input_mux;
1129 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1130 spec->imux_pins, imux->num_items);
1131 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1132 spec->imux_pins, imux->num_items);
1133 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1134 spec->imux_pins, imux->num_items);
1135 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1136 spec->auto_mic = 0;
1137 return false; /* no corresponding imux */
1138 }
1139
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001140 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001141 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001142 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1143 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001144
1145 spec->auto_mic_valid_imux = 1;
1146 spec->auto_mic = 1;
1147 return true;
1148}
1149
Takashi Iwai1d045db2011-07-07 18:23:21 +02001150/*
1151 * Check the availability of auto-mic switch;
1152 * Set up if really supported
1153 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001154static void alc_init_auto_mic(struct hda_codec *codec)
1155{
1156 struct alc_spec *spec = codec->spec;
1157 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001158 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001159 int i;
1160
Takashi Iwai24de1832011-11-07 17:13:39 +01001161 if (spec->shared_mic_hp)
1162 return; /* no auto-mic for the shared I/O */
1163
Takashi Iwai21268962011-07-07 15:01:13 +02001164 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1165
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001166 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001167 for (i = 0; i < cfg->num_inputs; i++) {
1168 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001169 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001170 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001171 switch (snd_hda_get_input_pin_attr(defcfg)) {
1172 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001173 if (fixed)
1174 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001175 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1176 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001177 fixed = nid;
1178 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001179 case INPUT_PIN_ATTR_UNUSED:
1180 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001181 case INPUT_PIN_ATTR_DOCK:
1182 if (dock)
1183 return; /* already occupied */
1184 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1185 return; /* invalid type */
1186 dock = nid;
1187 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001188 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001189 if (ext)
1190 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001191 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1192 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001193 ext = nid;
1194 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001195 }
1196 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001197 if (!ext && dock) {
1198 ext = dock;
1199 dock = 0;
1200 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001201 if (!ext || !fixed)
1202 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001203 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001204 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001205 if (dock && !is_jack_detectable(codec, dock))
1206 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001207
1208 /* check imux indices */
1209 spec->ext_mic_pin = ext;
1210 spec->int_mic_pin = fixed;
1211 spec->dock_mic_pin = dock;
1212
1213 spec->auto_mic = 1;
1214 if (!alc_auto_mic_check_imux(codec))
1215 return;
1216
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001217 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1218 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001219 spec->unsol_event = alc_sku_unsol_event;
1220}
1221
Takashi Iwai1d045db2011-07-07 18:23:21 +02001222/* check the availabilities of auto-mute and auto-mic switches */
1223static void alc_auto_check_switches(struct hda_codec *codec)
1224{
David Henningsson42cf0d02011-09-20 12:04:56 +02001225 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001226 alc_init_auto_mic(codec);
1227}
1228
1229/*
1230 * Realtek SSID verification
1231 */
1232
David Henningsson90622912010-10-14 14:50:18 +02001233/* Could be any non-zero and even value. When used as fixup, tells
1234 * the driver to ignore any present sku defines.
1235 */
1236#define ALC_FIXUP_SKU_IGNORE (2)
1237
Kailang Yangda00c242010-03-19 11:23:45 +01001238static int alc_auto_parse_customize_define(struct hda_codec *codec)
1239{
1240 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001241 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001242 struct alc_spec *spec = codec->spec;
1243
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001244 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1245
David Henningsson90622912010-10-14 14:50:18 +02001246 if (spec->cdefine.fixup) {
1247 ass = spec->cdefine.sku_cfg;
1248 if (ass == ALC_FIXUP_SKU_IGNORE)
1249 return -1;
1250 goto do_sku;
1251 }
1252
Kailang Yangda00c242010-03-19 11:23:45 +01001253 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001254 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001255 goto do_sku;
1256
1257 nid = 0x1d;
1258 if (codec->vendor_id == 0x10ec0260)
1259 nid = 0x17;
1260 ass = snd_hda_codec_get_pincfg(codec, nid);
1261
1262 if (!(ass & 1)) {
1263 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1264 codec->chip_name, ass);
1265 return -1;
1266 }
1267
1268 /* check sum */
1269 tmp = 0;
1270 for (i = 1; i < 16; i++) {
1271 if ((ass >> i) & 1)
1272 tmp++;
1273 }
1274 if (((ass >> 16) & 0xf) != tmp)
1275 return -1;
1276
1277 spec->cdefine.port_connectivity = ass >> 30;
1278 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1279 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1280 spec->cdefine.customization = ass >> 8;
1281do_sku:
1282 spec->cdefine.sku_cfg = ass;
1283 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1284 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1285 spec->cdefine.swap = (ass & 0x2) >> 1;
1286 spec->cdefine.override = ass & 0x1;
1287
1288 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1289 nid, spec->cdefine.sku_cfg);
1290 snd_printd("SKU: port_connectivity=0x%x\n",
1291 spec->cdefine.port_connectivity);
1292 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1293 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1294 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1295 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1296 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1297 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1298 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1299
1300 return 0;
1301}
1302
Takashi Iwai1d045db2011-07-07 18:23:21 +02001303/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001304static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1305{
Takashi Iwai21268962011-07-07 15:01:13 +02001306 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001307}
1308
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001309/* check subsystem ID and set up device-specific initialization;
1310 * return 1 if initialized, 0 if invalid SSID
1311 */
1312/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1313 * 31 ~ 16 : Manufacture ID
1314 * 15 ~ 8 : SKU ID
1315 * 7 ~ 0 : Assembly ID
1316 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1317 */
1318static int alc_subsystem_id(struct hda_codec *codec,
1319 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001320 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001321{
1322 unsigned int ass, tmp, i;
1323 unsigned nid;
1324 struct alc_spec *spec = codec->spec;
1325
David Henningsson90622912010-10-14 14:50:18 +02001326 if (spec->cdefine.fixup) {
1327 ass = spec->cdefine.sku_cfg;
1328 if (ass == ALC_FIXUP_SKU_IGNORE)
1329 return 0;
1330 goto do_sku;
1331 }
1332
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001333 ass = codec->subsystem_id & 0xffff;
1334 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1335 goto do_sku;
1336
1337 /* invalid SSID, check the special NID pin defcfg instead */
1338 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001339 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001340 * 29~21 : reserve
1341 * 20 : PCBEEP input
1342 * 19~16 : Check sum (15:1)
1343 * 15~1 : Custom
1344 * 0 : override
1345 */
1346 nid = 0x1d;
1347 if (codec->vendor_id == 0x10ec0260)
1348 nid = 0x17;
1349 ass = snd_hda_codec_get_pincfg(codec, nid);
1350 snd_printd("realtek: No valid SSID, "
1351 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001352 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001353 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001354 return 0;
1355 if ((ass >> 30) != 1) /* no physical connection */
1356 return 0;
1357
1358 /* check sum */
1359 tmp = 0;
1360 for (i = 1; i < 16; i++) {
1361 if ((ass >> i) & 1)
1362 tmp++;
1363 }
1364 if (((ass >> 16) & 0xf) != tmp)
1365 return 0;
1366do_sku:
1367 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1368 ass & 0xffff, codec->vendor_id);
1369 /*
1370 * 0 : override
1371 * 1 : Swap Jack
1372 * 2 : 0 --> Desktop, 1 --> Laptop
1373 * 3~5 : External Amplifier control
1374 * 7~6 : Reserved
1375 */
1376 tmp = (ass & 0x38) >> 3; /* external Amp control */
1377 switch (tmp) {
1378 case 1:
1379 spec->init_amp = ALC_INIT_GPIO1;
1380 break;
1381 case 3:
1382 spec->init_amp = ALC_INIT_GPIO2;
1383 break;
1384 case 7:
1385 spec->init_amp = ALC_INIT_GPIO3;
1386 break;
1387 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001388 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001389 spec->init_amp = ALC_INIT_DEFAULT;
1390 break;
1391 }
1392
1393 /* is laptop or Desktop and enable the function "Mute internal speaker
1394 * when the external headphone out jack is plugged"
1395 */
1396 if (!(ass & 0x8000))
1397 return 1;
1398 /*
1399 * 10~8 : Jack location
1400 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1401 * 14~13: Resvered
1402 * 15 : 1 --> enable the function "Mute internal speaker
1403 * when the external headphone out jack is plugged"
1404 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001405 if (!spec->autocfg.hp_pins[0] &&
1406 !(spec->autocfg.line_out_pins[0] &&
1407 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001408 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001409 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1410 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001411 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001412 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001413 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001414 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001415 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001416 else if (tmp == 3)
1417 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001418 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001419 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001420 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1421 spec->autocfg.line_outs))
1422 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001423 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001424 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001425 return 1;
1426}
Kailang Yangea1fb292008-08-26 12:58:38 +02001427
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001428/* Check the validity of ALC subsystem-id
1429 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1430static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001431{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001432 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001433 struct alc_spec *spec = codec->spec;
1434 snd_printd("realtek: "
1435 "Enable default setup for auto mode as fallback\n");
1436 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001437 }
Takashi Iwai21268962011-07-07 15:01:13 +02001438}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001439
Takashi Iwai41e41f12005-06-08 14:48:49 +02001440/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001441 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001442 */
1443
1444struct alc_pincfg {
1445 hda_nid_t nid;
1446 u32 val;
1447};
1448
Todd Broche1eb5f12010-12-06 11:19:51 -08001449struct alc_model_fixup {
1450 const int id;
1451 const char *name;
1452};
1453
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001454struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001455 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001456 bool chained;
1457 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001458 union {
1459 unsigned int sku;
1460 const struct alc_pincfg *pins;
1461 const struct hda_verb *verbs;
1462 void (*func)(struct hda_codec *codec,
1463 const struct alc_fixup *fix,
1464 int action);
1465 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001466};
1467
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001468enum {
1469 ALC_FIXUP_INVALID,
1470 ALC_FIXUP_SKU,
1471 ALC_FIXUP_PINS,
1472 ALC_FIXUP_VERBS,
1473 ALC_FIXUP_FUNC,
1474};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001475
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001476enum {
1477 ALC_FIXUP_ACT_PRE_PROBE,
1478 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001479 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001480};
1481
1482static void alc_apply_fixup(struct hda_codec *codec, int action)
1483{
1484 struct alc_spec *spec = codec->spec;
1485 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001486#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001487 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001488#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001489 int depth = 0;
1490
1491 if (!spec->fixup_list)
1492 return;
1493
1494 while (id >= 0) {
1495 const struct alc_fixup *fix = spec->fixup_list + id;
1496 const struct alc_pincfg *cfg;
1497
1498 switch (fix->type) {
1499 case ALC_FIXUP_SKU:
1500 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001501 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001502 snd_printdd(KERN_INFO "hda_codec: %s: "
1503 "Apply sku override for %s\n",
1504 codec->chip_name, modelname);
1505 spec->cdefine.sku_cfg = fix->v.sku;
1506 spec->cdefine.fixup = 1;
1507 break;
1508 case ALC_FIXUP_PINS:
1509 cfg = fix->v.pins;
1510 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1511 break;
1512 snd_printdd(KERN_INFO "hda_codec: %s: "
1513 "Apply pincfg for %s\n",
1514 codec->chip_name, modelname);
1515 for (; cfg->nid; cfg++)
1516 snd_hda_codec_set_pincfg(codec, cfg->nid,
1517 cfg->val);
1518 break;
1519 case ALC_FIXUP_VERBS:
1520 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1521 break;
1522 snd_printdd(KERN_INFO "hda_codec: %s: "
1523 "Apply fix-verbs for %s\n",
1524 codec->chip_name, modelname);
1525 add_verb(codec->spec, fix->v.verbs);
1526 break;
1527 case ALC_FIXUP_FUNC:
1528 if (!fix->v.func)
1529 break;
1530 snd_printdd(KERN_INFO "hda_codec: %s: "
1531 "Apply fix-func for %s\n",
1532 codec->chip_name, modelname);
1533 fix->v.func(codec, fix, action);
1534 break;
1535 default:
1536 snd_printk(KERN_ERR "hda_codec: %s: "
1537 "Invalid fixup type %d\n",
1538 codec->chip_name, fix->type);
1539 break;
1540 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001541 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001542 break;
1543 if (++depth > 10)
1544 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001545 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001546 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001547}
1548
Todd Broche1eb5f12010-12-06 11:19:51 -08001549static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001550 const struct alc_model_fixup *models,
1551 const struct snd_pci_quirk *quirk,
1552 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001553{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001554 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001555 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001556 int id = -1;
1557 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001558
Todd Broche1eb5f12010-12-06 11:19:51 -08001559 if (codec->modelname && models) {
1560 while (models->name) {
1561 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001562 id = models->id;
1563 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001564 break;
1565 }
1566 models++;
1567 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001568 }
1569 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001570 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1571 if (q) {
1572 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001573#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001574 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001575#endif
1576 }
1577 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001578 if (id < 0) {
1579 for (q = quirk; q->subvendor; q++) {
1580 unsigned int vendorid =
1581 q->subdevice | (q->subvendor << 16);
1582 if (vendorid == codec->subsystem_id) {
1583 id = q->value;
1584#ifdef CONFIG_SND_DEBUG_VERBOSE
1585 name = q->name;
1586#endif
1587 break;
1588 }
1589 }
1590 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001591
1592 spec->fixup_id = id;
1593 if (id >= 0) {
1594 spec->fixup_list = fixlist;
1595 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001596 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001597}
1598
Takashi Iwai1d045db2011-07-07 18:23:21 +02001599/*
1600 * COEF access helper functions
1601 */
Kailang Yang274693f2009-12-03 10:07:50 +01001602static int alc_read_coef_idx(struct hda_codec *codec,
1603 unsigned int coef_idx)
1604{
1605 unsigned int val;
1606 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1607 coef_idx);
1608 val = snd_hda_codec_read(codec, 0x20, 0,
1609 AC_VERB_GET_PROC_COEF, 0);
1610 return val;
1611}
1612
Kailang Yang977ddd62010-09-15 10:02:29 +02001613static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1614 unsigned int coef_val)
1615{
1616 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1617 coef_idx);
1618 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1619 coef_val);
1620}
1621
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001622/* a special bypass for COEF 0; read the cached value at the second time */
1623static unsigned int alc_get_coef0(struct hda_codec *codec)
1624{
1625 struct alc_spec *spec = codec->spec;
1626 if (!spec->coef0)
1627 spec->coef0 = alc_read_coef_idx(codec, 0);
1628 return spec->coef0;
1629}
1630
Takashi Iwai1d045db2011-07-07 18:23:21 +02001631/*
1632 * Digital I/O handling
1633 */
1634
Takashi Iwai757899a2010-07-30 10:48:14 +02001635/* set right pin controls for digital I/O */
1636static void alc_auto_init_digital(struct hda_codec *codec)
1637{
1638 struct alc_spec *spec = codec->spec;
1639 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001640 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001641
1642 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1643 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001644 if (!pin)
1645 continue;
1646 snd_hda_codec_write(codec, pin, 0,
1647 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1648 if (!i)
1649 dac = spec->multiout.dig_out_nid;
1650 else
1651 dac = spec->slave_dig_outs[i - 1];
1652 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1653 continue;
1654 snd_hda_codec_write(codec, dac, 0,
1655 AC_VERB_SET_AMP_GAIN_MUTE,
1656 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001657 }
1658 pin = spec->autocfg.dig_in_pin;
1659 if (pin)
1660 snd_hda_codec_write(codec, pin, 0,
1661 AC_VERB_SET_PIN_WIDGET_CONTROL,
1662 PIN_IN);
1663}
1664
1665/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1666static void alc_auto_parse_digital(struct hda_codec *codec)
1667{
1668 struct alc_spec *spec = codec->spec;
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001669 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001670 hda_nid_t dig_nid;
1671
1672 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001673 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001674 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001675 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001676 err = snd_hda_get_connections(codec,
1677 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001678 conn, ARRAY_SIZE(conn));
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001679 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001680 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001681 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001682 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001683 spec->multiout.dig_out_nid = dig_nid;
1684 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1685 } else {
1686 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001687 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001688 break;
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001689 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001690 }
Takashi Iwai51e4152a2011-11-03 16:54:06 +01001691 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001692 }
1693
1694 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001695 dig_nid = codec->start_nid;
1696 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1697 unsigned int wcaps = get_wcaps(codec, dig_nid);
1698 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1699 continue;
1700 if (!(wcaps & AC_WCAP_DIGITAL))
1701 continue;
1702 if (!(wcaps & AC_WCAP_CONN_LIST))
1703 continue;
1704 err = get_connection_index(codec, dig_nid,
1705 spec->autocfg.dig_in_pin);
1706 if (err >= 0) {
1707 spec->dig_in_nid = dig_nid;
1708 break;
1709 }
1710 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001711 }
1712}
1713
Takashi Iwaif95474e2007-07-10 00:47:43 +02001714/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001715 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001716 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001717static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1718 struct snd_ctl_elem_info *uinfo)
1719{
1720 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1721 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001722 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001723 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001724
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001725 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001726 if (spec->vol_in_capsrc)
1727 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1728 else
1729 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1730 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001731 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001732 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001733 return err;
1734}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001736static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1737 unsigned int size, unsigned int __user *tlv)
1738{
1739 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1740 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001741 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001742 int err;
1743
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001744 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001745 if (spec->vol_in_capsrc)
1746 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1747 else
1748 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1749 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001750 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001751 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001752 return err;
1753}
1754
1755typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol);
1757
1758static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1759 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001760 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001761{
1762 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1763 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001764 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001765
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001766 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001767 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001768 for (i = 0; i < spec->num_adc_nids; i++) {
1769 kcontrol->private_value =
1770 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1771 3, 0, HDA_INPUT);
1772 err = func(kcontrol, ucontrol);
1773 if (err < 0)
1774 goto error;
1775 }
1776 } else {
1777 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001778 if (spec->vol_in_capsrc)
1779 kcontrol->private_value =
1780 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1781 3, 0, HDA_OUTPUT);
1782 else
1783 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001784 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1785 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001786 err = func(kcontrol, ucontrol);
1787 }
1788 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001789 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001790 return err;
1791}
1792
1793static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1794 struct snd_ctl_elem_value *ucontrol)
1795{
1796 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001797 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001798}
1799
1800static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1801 struct snd_ctl_elem_value *ucontrol)
1802{
1803 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001804 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001805}
1806
1807/* capture mixer elements */
1808#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1809
1810static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1811 struct snd_ctl_elem_value *ucontrol)
1812{
1813 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001814 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001815}
1816
1817static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1818 struct snd_ctl_elem_value *ucontrol)
1819{
1820 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001821 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001822}
1823
Takashi Iwaia23b6882009-03-23 15:21:36 +01001824#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001825 { \
1826 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1827 .name = "Capture Switch", \
1828 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1829 .count = num, \
1830 .info = alc_cap_sw_info, \
1831 .get = alc_cap_sw_get, \
1832 .put = alc_cap_sw_put, \
1833 }, \
1834 { \
1835 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1836 .name = "Capture Volume", \
1837 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1838 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1839 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1840 .count = num, \
1841 .info = alc_cap_vol_info, \
1842 .get = alc_cap_vol_get, \
1843 .put = alc_cap_vol_put, \
1844 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001845 }
1846
1847#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001848 { \
1849 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1850 /* .name = "Capture Source", */ \
1851 .name = "Input Source", \
1852 .count = num, \
1853 .info = alc_mux_enum_info, \
1854 .get = alc_mux_enum_get, \
1855 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001856 }
1857
1858#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001859static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001860 _DEFINE_CAPMIX(num), \
1861 _DEFINE_CAPSRC(num), \
1862 { } /* end */ \
1863}
1864
1865#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001866static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001867 _DEFINE_CAPMIX(num), \
1868 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001869}
1870
1871/* up to three ADCs */
1872DEFINE_CAPMIX(1);
1873DEFINE_CAPMIX(2);
1874DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001875DEFINE_CAPMIX_NOSRC(1);
1876DEFINE_CAPMIX_NOSRC(2);
1877DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001878
1879/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001880 * virtual master controls
1881 */
1882
1883/*
1884 * slave controls for virtual master
1885 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001886static const char * const alc_slave_pfxs[] = {
1887 "Front", "Surround", "Center", "LFE", "Side",
1888 "Headphone", "Speaker", "Mono", "Line-Out",
1889 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001890 NULL,
1891};
1892
1893/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001894 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001896
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001897#define NID_MAPPING (-1)
1898
1899#define SUBDEV_SPEAKER_ (0 << 6)
1900#define SUBDEV_HP_ (1 << 6)
1901#define SUBDEV_LINE_ (2 << 6)
1902#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1903#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1904#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1905
Takashi Iwai603c4012008-07-30 15:01:44 +02001906static void alc_free_kctls(struct hda_codec *codec);
1907
Takashi Iwai67d634c2009-11-16 15:35:59 +01001908#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001909/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001910static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001911 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001912 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001913 { } /* end */
1914};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001915#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001916
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001917static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918{
1919 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001920 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001921 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001922 int i, j, err;
1923 unsigned int u;
1924 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
1926 for (i = 0; i < spec->num_mixers; i++) {
1927 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1928 if (err < 0)
1929 return err;
1930 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001931 if (spec->cap_mixer) {
1932 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1933 if (err < 0)
1934 return err;
1935 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001937 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001938 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001939 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 if (err < 0)
1941 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001942 if (!spec->no_analog) {
1943 err = snd_hda_create_spdif_share_sw(codec,
1944 &spec->multiout);
1945 if (err < 0)
1946 return err;
1947 spec->multiout.share_spdif = 1;
1948 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 }
1950 if (spec->dig_in_nid) {
1951 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1952 if (err < 0)
1953 return err;
1954 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001955
Takashi Iwai67d634c2009-11-16 15:35:59 +01001956#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001957 /* create beep controls if needed */
1958 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001959 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001960 for (knew = alc_beep_mixer; knew->name; knew++) {
1961 struct snd_kcontrol *kctl;
1962 kctl = snd_ctl_new1(knew, codec);
1963 if (!kctl)
1964 return -ENOMEM;
1965 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001966 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001967 if (err < 0)
1968 return err;
1969 }
1970 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001971#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001972
Takashi Iwai2134ea42008-01-10 16:53:55 +01001973 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001974 if (!spec->no_analog &&
1975 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001976 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001977 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001978 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001979 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001980 vmaster_tlv, alc_slave_pfxs,
1981 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001982 if (err < 0)
1983 return err;
1984 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001985 if (!spec->no_analog &&
1986 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001987 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001988 NULL, alc_slave_pfxs,
1989 "Playback Switch");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001990 if (err < 0)
1991 return err;
1992 }
1993
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001994 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001995 if (spec->capsrc_nids || spec->adc_nids) {
1996 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1997 if (!kctl)
1998 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1999 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002000 err = snd_hda_add_nid(codec, kctl, i,
2001 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02002002 if (err < 0)
2003 return err;
2004 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002005 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02002006 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002007 const char *kname = kctl ? kctl->id.name : NULL;
2008 for (knew = spec->cap_mixer; knew->name; knew++) {
2009 if (kname && strcmp(knew->name, kname) == 0)
2010 continue;
2011 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2012 for (i = 0; kctl && i < kctl->count; i++) {
2013 err = snd_hda_add_nid(codec, kctl, i,
2014 spec->adc_nids[i]);
2015 if (err < 0)
2016 return err;
2017 }
2018 }
2019 }
2020
2021 /* other nid->control mapping */
2022 for (i = 0; i < spec->num_mixers; i++) {
2023 for (knew = spec->mixers[i]; knew->name; knew++) {
2024 if (knew->iface != NID_MAPPING)
2025 continue;
2026 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2027 if (kctl == NULL)
2028 continue;
2029 u = knew->subdevice;
2030 for (j = 0; j < 4; j++, u >>= 8) {
2031 nid = u & 0x3f;
2032 if (nid == 0)
2033 continue;
2034 switch (u & 0xc0) {
2035 case SUBDEV_SPEAKER_:
2036 nid = spec->autocfg.speaker_pins[nid];
2037 break;
2038 case SUBDEV_LINE_:
2039 nid = spec->autocfg.line_out_pins[nid];
2040 break;
2041 case SUBDEV_HP_:
2042 nid = spec->autocfg.hp_pins[nid];
2043 break;
2044 default:
2045 continue;
2046 }
2047 err = snd_hda_add_nid(codec, kctl, 0, nid);
2048 if (err < 0)
2049 return err;
2050 }
2051 u = knew->private_value;
2052 for (j = 0; j < 4; j++, u >>= 8) {
2053 nid = u & 0xff;
2054 if (nid == 0)
2055 continue;
2056 err = snd_hda_add_nid(codec, kctl, 0, nid);
2057 if (err < 0)
2058 return err;
2059 }
2060 }
2061 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002062
2063 alc_free_kctls(codec); /* no longer needed */
2064
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002065 return 0;
2066}
2067
2068static int alc_build_controls(struct hda_codec *codec)
2069{
2070 struct alc_spec *spec = codec->spec;
2071 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002072 if (err < 0)
2073 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002074 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075}
2076
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002077
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002079 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002080 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002081
Takashi Iwai584c0c42011-03-10 12:51:11 +01002082static void alc_init_special_input_src(struct hda_codec *codec);
2083
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084static int alc_init(struct hda_codec *codec)
2085{
2086 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002087 unsigned int i;
2088
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002089 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002090 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002091
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002092 for (i = 0; i < spec->num_init_verbs; i++)
2093 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002094 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002095
2096 if (spec->init_hook)
2097 spec->init_hook(codec);
2098
Takashi Iwai58701122011-01-13 15:41:45 +01002099 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2100
Takashi Iwai01a61e12011-10-28 00:03:22 +02002101 snd_hda_jack_report_sync(codec);
2102
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002103 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 return 0;
2105}
2106
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002107static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2108{
2109 struct alc_spec *spec = codec->spec;
2110
2111 if (spec->unsol_event)
2112 spec->unsol_event(codec, res);
2113}
2114
Takashi Iwaicb53c622007-08-10 17:21:45 +02002115#ifdef CONFIG_SND_HDA_POWER_SAVE
2116static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2117{
2118 struct alc_spec *spec = codec->spec;
2119 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2120}
2121#endif
2122
Linus Torvalds1da177e2005-04-16 15:20:36 -07002123/*
2124 * Analog playback callbacks
2125 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002126static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002128 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
2130 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002131 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2132 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133}
2134
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002135static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 struct hda_codec *codec,
2137 unsigned int stream_tag,
2138 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002139 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
2141 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002142 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2143 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144}
2145
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002146static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002148 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149{
2150 struct alc_spec *spec = codec->spec;
2151 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2152}
2153
2154/*
2155 * Digital out
2156 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002157static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-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_open(codec, &spec->multiout);
2163}
2164
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002165static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002166 struct hda_codec *codec,
2167 unsigned int stream_tag,
2168 unsigned int format,
2169 struct snd_pcm_substream *substream)
2170{
2171 struct alc_spec *spec = codec->spec;
2172 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2173 stream_tag, format, substream);
2174}
2175
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002176static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002177 struct hda_codec *codec,
2178 struct snd_pcm_substream *substream)
2179{
2180 struct alc_spec *spec = codec->spec;
2181 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2182}
2183
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002184static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002186 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187{
2188 struct alc_spec *spec = codec->spec;
2189 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2190}
2191
2192/*
2193 * Analog capture
2194 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002195static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 struct hda_codec *codec,
2197 unsigned int stream_tag,
2198 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002199 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
2201 struct alc_spec *spec = codec->spec;
2202
Takashi Iwai63300792008-01-24 15:31:36 +01002203 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 stream_tag, 0, format);
2205 return 0;
2206}
2207
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002208static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002210 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211{
2212 struct alc_spec *spec = codec->spec;
2213
Takashi Iwai888afa12008-03-18 09:57:50 +01002214 snd_hda_codec_cleanup_stream(codec,
2215 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 return 0;
2217}
2218
Takashi Iwai840b64c2010-07-13 22:49:01 +02002219/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002220static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002221 struct hda_codec *codec,
2222 unsigned int stream_tag,
2223 unsigned int format,
2224 struct snd_pcm_substream *substream)
2225{
2226 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002227 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002228 spec->cur_adc_stream_tag = stream_tag;
2229 spec->cur_adc_format = format;
2230 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2231 return 0;
2232}
2233
Takashi Iwai21268962011-07-07 15:01:13 +02002234static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002235 struct hda_codec *codec,
2236 struct snd_pcm_substream *substream)
2237{
2238 struct alc_spec *spec = codec->spec;
2239 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2240 spec->cur_adc = 0;
2241 return 0;
2242}
2243
Takashi Iwai21268962011-07-07 15:01:13 +02002244static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002245 .substreams = 1,
2246 .channels_min = 2,
2247 .channels_max = 2,
2248 .nid = 0, /* fill later */
2249 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002250 .prepare = dyn_adc_capture_pcm_prepare,
2251 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002252 },
2253};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
2255/*
2256 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002257static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 .substreams = 1,
2259 .channels_min = 2,
2260 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002261 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002263 .open = alc_playback_pcm_open,
2264 .prepare = alc_playback_pcm_prepare,
2265 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 },
2267};
2268
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002269static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002270 .substreams = 1,
2271 .channels_min = 2,
2272 .channels_max = 2,
2273 /* NID is set in alc_build_pcms */
2274};
2275
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002276static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002277 .substreams = 1,
2278 .channels_min = 2,
2279 .channels_max = 2,
2280 /* NID is set in alc_build_pcms */
2281};
2282
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002283static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002284 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 .channels_min = 2,
2286 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002287 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002289 .prepare = alc_alt_capture_pcm_prepare,
2290 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 },
2292};
2293
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002294static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 .substreams = 1,
2296 .channels_min = 2,
2297 .channels_max = 2,
2298 /* NID is set in alc_build_pcms */
2299 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002300 .open = alc_dig_playback_pcm_open,
2301 .close = alc_dig_playback_pcm_close,
2302 .prepare = alc_dig_playback_pcm_prepare,
2303 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304 },
2305};
2306
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002307static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 .substreams = 1,
2309 .channels_min = 2,
2310 .channels_max = 2,
2311 /* NID is set in alc_build_pcms */
2312};
2313
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002314/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002315static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002316 .substreams = 0,
2317 .channels_min = 0,
2318 .channels_max = 0,
2319};
2320
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321static int alc_build_pcms(struct hda_codec *codec)
2322{
2323 struct alc_spec *spec = codec->spec;
2324 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002325 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002326 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 int i;
2328
2329 codec->num_pcms = 1;
2330 codec->pcm_info = info;
2331
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002332 if (spec->no_analog)
2333 goto skip_analog;
2334
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002335 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2336 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002338
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002339 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002340 p = spec->stream_analog_playback;
2341 if (!p)
2342 p = &alc_pcm_analog_playback;
2343 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2345 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002346 if (spec->adc_nids) {
2347 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002348 if (!p) {
2349 if (spec->dyn_adc_switch)
2350 p = &dyn_adc_pcm_analog_capture;
2351 else
2352 p = &alc_pcm_analog_capture;
2353 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002354 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002355 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357
Takashi Iwai4a471b72005-12-07 13:56:29 +01002358 if (spec->channel_mode) {
2359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2360 for (i = 0; i < spec->num_channel_mode; i++) {
2361 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2362 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2363 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 }
2365 }
2366
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002367 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002368 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002370 snprintf(spec->stream_name_digital,
2371 sizeof(spec->stream_name_digital),
2372 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002373 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002374 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002375 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002377 if (spec->dig_out_type)
2378 info->pcm_type = spec->dig_out_type;
2379 else
2380 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002381 if (spec->multiout.dig_out_nid) {
2382 p = spec->stream_digital_playback;
2383 if (!p)
2384 p = &alc_pcm_digital_playback;
2385 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2387 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002388 if (spec->dig_in_nid) {
2389 p = spec->stream_digital_capture;
2390 if (!p)
2391 p = &alc_pcm_digital_capture;
2392 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2394 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002395 /* FIXME: do we need this for all Realtek codec models? */
2396 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 }
2398
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002399 if (spec->no_analog)
2400 return 0;
2401
Takashi Iwaie08a0072006-09-07 17:52:14 +02002402 /* If the use of more than one ADC is requested for the current
2403 * model, configure a second analog capture-only PCM.
2404 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002405 have_multi_adcs = (spec->num_adc_nids > 1) &&
2406 !spec->dyn_adc_switch && !spec->auto_mic &&
2407 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002408 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002409 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002410 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002411 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002412 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002413 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002414 p = spec->stream_analog_alt_playback;
2415 if (!p)
2416 p = &alc_pcm_analog_alt_playback;
2417 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002418 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2419 spec->alt_dac_nid;
2420 } else {
2421 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2422 alc_pcm_null_stream;
2423 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2424 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002425 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002426 p = spec->stream_analog_alt_capture;
2427 if (!p)
2428 p = &alc_pcm_analog_alt_capture;
2429 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002430 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2431 spec->adc_nids[1];
2432 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2433 spec->num_adc_nids - 1;
2434 } else {
2435 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2436 alc_pcm_null_stream;
2437 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002438 }
2439 }
2440
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 return 0;
2442}
2443
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002444static inline void alc_shutup(struct hda_codec *codec)
2445{
Takashi Iwai1c716152011-04-07 10:37:16 +02002446 struct alc_spec *spec = codec->spec;
2447
2448 if (spec && spec->shutup)
2449 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002450 snd_hda_shutup_pins(codec);
2451}
2452
Takashi Iwai603c4012008-07-30 15:01:44 +02002453static void alc_free_kctls(struct hda_codec *codec)
2454{
2455 struct alc_spec *spec = codec->spec;
2456
2457 if (spec->kctls.list) {
2458 struct snd_kcontrol_new *kctl = spec->kctls.list;
2459 int i;
2460 for (i = 0; i < spec->kctls.used; i++)
2461 kfree(kctl[i].name);
2462 }
2463 snd_array_free(&spec->kctls);
2464}
2465
Takashi Iwai23c09b02011-08-19 09:05:35 +02002466static void alc_free_bind_ctls(struct hda_codec *codec)
2467{
2468 struct alc_spec *spec = codec->spec;
2469 if (spec->bind_ctls.list) {
2470 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2471 int i;
2472 for (i = 0; i < spec->bind_ctls.used; i++)
2473 kfree(ctl[i]);
2474 }
2475 snd_array_free(&spec->bind_ctls);
2476}
2477
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478static void alc_free(struct hda_codec *codec)
2479{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002480 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002481
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002482 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002483 return;
2484
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002485 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002486 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002487 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002488 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002489 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490}
2491
Hector Martinf5de24b2009-12-20 22:51:31 +01002492#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002493static void alc_power_eapd(struct hda_codec *codec)
2494{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002495 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002496}
2497
Hector Martinf5de24b2009-12-20 22:51:31 +01002498static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2499{
2500 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002501 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002502 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002503 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002504 return 0;
2505}
2506#endif
2507
Takashi Iwai2a439522011-07-26 09:52:50 +02002508#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002509static int alc_resume(struct hda_codec *codec)
2510{
Takashi Iwai1c716152011-04-07 10:37:16 +02002511 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002512 codec->patch_ops.init(codec);
2513 snd_hda_codec_resume_amp(codec);
2514 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002515 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002516 return 0;
2517}
Takashi Iwaie044c392008-10-27 16:56:24 +01002518#endif
2519
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520/*
2521 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002522static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 .build_controls = alc_build_controls,
2524 .build_pcms = alc_build_pcms,
2525 .init = alc_init,
2526 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002527 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002528#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002529 .resume = alc_resume,
2530#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002531#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002532 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002533 .check_power_status = alc_check_power_status,
2534#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002535 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536};
2537
Kailang Yangc027ddc2010-03-19 11:33:06 +01002538/* replace the codec chip_name with the given string */
2539static int alc_codec_rename(struct hda_codec *codec, const char *name)
2540{
2541 kfree(codec->chip_name);
2542 codec->chip_name = kstrdup(name, GFP_KERNEL);
2543 if (!codec->chip_name) {
2544 alc_free(codec);
2545 return -ENOMEM;
2546 }
2547 return 0;
2548}
2549
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002550/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002551 * Rename codecs appropriately from COEF value
2552 */
2553struct alc_codec_rename_table {
2554 unsigned int vendor_id;
2555 unsigned short coef_mask;
2556 unsigned short coef_bits;
2557 const char *name;
2558};
2559
2560static struct alc_codec_rename_table rename_tbl[] = {
2561 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2562 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2563 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2564 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2565 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2566 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2567 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2568 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2569 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2570 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2571 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2572 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2573 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2574 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2575 { } /* terminator */
2576};
2577
2578static int alc_codec_rename_from_preset(struct hda_codec *codec)
2579{
2580 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002581
2582 for (p = rename_tbl; p->vendor_id; p++) {
2583 if (p->vendor_id != codec->vendor_id)
2584 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002585 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002586 return alc_codec_rename(codec, p->name);
2587 }
2588 return 0;
2589}
2590
2591/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002592 * Automatic parse of I/O pins from the BIOS configuration
2593 */
2594
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002595enum {
2596 ALC_CTL_WIDGET_VOL,
2597 ALC_CTL_WIDGET_MUTE,
2598 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002599 ALC_CTL_BIND_VOL,
2600 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002601};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002602static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002603 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2604 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002605 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002606 HDA_BIND_VOL(NULL, 0),
2607 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002608};
2609
2610/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002611static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002612 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002613{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002614 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002615
Takashi Iwaice764ab2011-04-27 16:35:23 +02002616 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002617 if (!knew)
2618 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002619 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002620 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002621 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002622 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002623 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002624 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002625 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002626 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002627 return 0;
2628}
2629
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002630static int add_control_with_pfx(struct alc_spec *spec, int type,
2631 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002632 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002633{
2634 char name[32];
2635 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002636 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002637}
2638
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002639#define add_pb_vol_ctrl(spec, type, pfx, val) \
2640 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2641#define add_pb_sw_ctrl(spec, type, pfx, val) \
2642 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2643#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2644 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2645#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2646 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002647
Takashi Iwai23c09b02011-08-19 09:05:35 +02002648static const char * const channel_name[4] = {
2649 "Front", "Surround", "CLFE", "Side"
2650};
2651
Takashi Iwai6843ca12011-06-24 11:03:58 +02002652static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2653 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002654{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002655 struct auto_pin_cfg *cfg = &spec->autocfg;
2656
Takashi Iwai6843ca12011-06-24 11:03:58 +02002657 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002658 if (cfg->line_outs == 1 && !spec->multi_ios &&
2659 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002660 return "Master";
2661
2662 switch (cfg->line_out_type) {
2663 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002664 if (cfg->line_outs == 1)
2665 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002666 if (cfg->line_outs == 2)
2667 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002668 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002669 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002670 /* for multi-io case, only the primary out */
2671 if (ch && spec->multi_ios)
2672 break;
2673 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002674 return "Headphone";
2675 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002676 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002677 return "PCM";
2678 break;
2679 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002680 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2681 return "PCM";
2682
2683 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002684}
2685
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002686/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002687static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002688 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002689 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002690{
Kailang Yangdf694da2005-12-05 19:42:22 +01002691 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002692
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002693 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002694 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2695 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002696 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002697 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002698 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2699 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002700 return err;
2701 return 0;
2702}
2703
Takashi Iwai05f5f472009-08-25 13:10:18 +02002704static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002705{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002706 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2707 return (pincap & AC_PINCAP_IN) != 0;
2708}
2709
Takashi Iwai1d045db2011-07-07 18:23:21 +02002710/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002711static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002712{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002713 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002714 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002715 hda_nid_t *adc_nids = spec->private_adc_nids;
2716 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2717 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002718 int i, nums = 0;
2719
Takashi Iwai24de1832011-11-07 17:13:39 +01002720 if (spec->shared_mic_hp)
2721 max_nums = 1; /* no multi streams with the shared HP/mic */
2722
Takashi Iwaib7821702011-07-06 15:12:46 +02002723 nid = codec->start_nid;
2724 for (i = 0; i < codec->num_nodes; i++, nid++) {
2725 hda_nid_t src;
2726 const hda_nid_t *list;
2727 unsigned int caps = get_wcaps(codec, nid);
2728 int type = get_wcaps_type(caps);
2729
2730 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2731 continue;
2732 adc_nids[nums] = nid;
2733 cap_nids[nums] = nid;
2734 src = nid;
2735 for (;;) {
2736 int n;
2737 type = get_wcaps_type(get_wcaps(codec, src));
2738 if (type == AC_WID_PIN)
2739 break;
2740 if (type == AC_WID_AUD_SEL) {
2741 cap_nids[nums] = src;
2742 break;
2743 }
2744 n = snd_hda_get_conn_list(codec, src, &list);
2745 if (n > 1) {
2746 cap_nids[nums] = src;
2747 break;
2748 } else if (n != 1)
2749 break;
2750 src = *list;
2751 }
2752 if (++nums >= max_nums)
2753 break;
2754 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002755 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002756 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002757 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002758 return nums;
2759}
2760
Takashi Iwai05f5f472009-08-25 13:10:18 +02002761/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002762static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002763{
2764 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002765 const struct auto_pin_cfg *cfg = &spec->autocfg;
2766 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002767 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002768 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002769 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002770 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002771
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002772 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002773 if (num_adcs < 0)
2774 return 0;
2775
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002776 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002777 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002778 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002779
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002780 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002781 if (!alc_is_input_pin(codec, pin))
2782 continue;
2783
David Henningsson5322bf22011-01-05 11:03:56 +01002784 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002785 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2786 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002787 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002788 type_idx++;
2789 else
2790 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002791 prev_label = label;
2792
Takashi Iwai05f5f472009-08-25 13:10:18 +02002793 if (mixer) {
2794 idx = get_connection_index(codec, mixer, pin);
2795 if (idx >= 0) {
2796 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002797 label, type_idx,
2798 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002799 if (err < 0)
2800 return err;
2801 }
2802 }
2803
Takashi Iwaib7821702011-07-06 15:12:46 +02002804 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002805 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002806 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002807 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002808 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002809 snd_hda_add_imux_item(imux, label, idx, NULL);
2810 break;
2811 }
2812 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002813 }
Takashi Iwai21268962011-07-07 15:01:13 +02002814
2815 spec->num_mux_defs = 1;
2816 spec->input_mux = imux;
2817
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002818 return 0;
2819}
2820
Takashi Iwai24de1832011-11-07 17:13:39 +01002821/* create a shared input with the headphone out */
2822static int alc_auto_create_shared_input(struct hda_codec *codec)
2823{
2824 struct alc_spec *spec = codec->spec;
2825 struct auto_pin_cfg *cfg = &spec->autocfg;
2826 unsigned int defcfg;
2827 hda_nid_t nid;
2828
2829 /* only one internal input pin? */
2830 if (cfg->num_inputs != 1)
2831 return 0;
2832 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2833 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2834 return 0;
2835
2836 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2837 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2838 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2839 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2840 else
2841 return 0; /* both not available */
2842
2843 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2844 return 0; /* no input */
2845
2846 cfg->inputs[1].pin = nid;
2847 cfg->inputs[1].type = AUTO_PIN_MIC;
2848 cfg->num_inputs = 2;
2849 spec->shared_mic_hp = 1;
2850 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2851 return 0;
2852}
2853
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002854static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2855 unsigned int pin_type)
2856{
2857 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2858 pin_type);
2859 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002860 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2861 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002862 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002863}
2864
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002865static int get_pin_type(int line_out_type)
2866{
2867 if (line_out_type == AUTO_PIN_HP_OUT)
2868 return PIN_HP;
2869 else
2870 return PIN_OUT;
2871}
2872
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002873static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002874{
2875 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002876 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002877 int i;
2878
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002879 for (i = 0; i < cfg->num_inputs; i++) {
2880 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002881 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002882 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002883 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002884 snd_hda_codec_write(codec, nid, 0,
2885 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002886 AMP_OUT_MUTE);
2887 }
2888 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002889
2890 /* mute all loopback inputs */
2891 if (spec->mixer_nid) {
2892 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2893 for (i = 0; i < nums; i++)
2894 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2895 AC_VERB_SET_AMP_GAIN_MUTE,
2896 AMP_IN_MUTE(i));
2897 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002898}
2899
Takashi Iwai7085ec12009-10-02 09:03:58 +02002900/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002901static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002902{
Takashi Iwai604401a2011-04-27 15:14:23 +02002903 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002904 int i, num;
2905
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002906 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2907 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002908 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2909 for (i = 0; i < num; i++) {
2910 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2911 return list[i];
2912 }
2913 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002914}
2915
Takashi Iwai604401a2011-04-27 15:14:23 +02002916/* go down to the selector widget before the mixer */
2917static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2918{
2919 hda_nid_t srcs[5];
2920 int num = snd_hda_get_connections(codec, pin, srcs,
2921 ARRAY_SIZE(srcs));
2922 if (num != 1 ||
2923 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2924 return pin;
2925 return srcs[0];
2926}
2927
Takashi Iwai7085ec12009-10-02 09:03:58 +02002928/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002929static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002930 hda_nid_t dac)
2931{
David Henningssoncc1c4522010-11-24 14:17:47 +01002932 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002933 int i, num;
2934
Takashi Iwai604401a2011-04-27 15:14:23 +02002935 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002936 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2937 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002938 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002939 return mix[i];
2940 }
2941 return 0;
2942}
2943
Takashi Iwaice764ab2011-04-27 16:35:23 +02002944/* select the connection from pin to DAC if needed */
2945static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2946 hda_nid_t dac)
2947{
2948 hda_nid_t mix[5];
2949 int i, num;
2950
2951 pin = alc_go_down_to_selector(codec, pin);
2952 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2953 if (num < 2)
2954 return 0;
2955 for (i = 0; i < num; i++) {
2956 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2957 snd_hda_codec_update_cache(codec, pin, 0,
2958 AC_VERB_SET_CONNECT_SEL, i);
2959 return 0;
2960 }
2961 }
2962 return 0;
2963}
2964
Takashi Iwai185d99f2012-02-16 18:39:45 +01002965static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2966{
2967 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002968 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002969 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2970 ARRAY_SIZE(spec->private_dac_nids)) ||
2971 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2972 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2973 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2974 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2975 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002976 for (i = 0; i < spec->multi_ios; i++) {
2977 if (spec->multi_io[i].dac == nid)
2978 return true;
2979 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002980 return false;
2981}
2982
Takashi Iwai7085ec12009-10-02 09:03:58 +02002983/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002984static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002985{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002986 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002987 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002988
Takashi Iwai604401a2011-04-27 15:14:23 +02002989 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002990 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002991 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002992 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002993 if (!nid)
2994 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002995 if (!alc_is_dac_already_used(codec, nid))
2996 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002997 }
2998 return 0;
2999}
3000
Takashi Iwai07b18f692011-11-10 15:42:54 +01003001/* check whether the DAC is reachable from the pin */
3002static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
3003 hda_nid_t pin, hda_nid_t dac)
3004{
3005 hda_nid_t srcs[5];
3006 int i, num;
3007
Takashi Iwaidc31b582012-02-17 17:27:53 +01003008 if (!pin || !dac)
3009 return false;
Takashi Iwai07b18f692011-11-10 15:42:54 +01003010 pin = alc_go_down_to_selector(codec, pin);
3011 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
3012 for (i = 0; i < num; i++) {
3013 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3014 if (nid == dac)
3015 return true;
3016 }
3017 return false;
3018}
3019
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003020static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3021{
Takashi Iwai140547e2012-02-16 17:23:46 +01003022 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003023 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003024 hda_nid_t nid, nid_found, srcs[5];
3025 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01003026 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01003027 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003028 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003029 nid_found = 0;
3030 for (i = 0; i < num; i++) {
3031 if (srcs[i] == spec->mixer_nid)
3032 continue;
3033 nid = alc_auto_mix_to_dac(codec, srcs[i]);
3034 if (nid && !alc_is_dac_already_used(codec, nid)) {
3035 if (nid_found)
3036 return 0;
3037 nid_found = nid;
3038 }
3039 }
3040 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003041}
3042
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003043/* mark up volume and mute control NIDs: used during badness parsing and
3044 * at creating actual controls
3045 */
3046static inline unsigned int get_ctl_pos(unsigned int data)
3047{
3048 hda_nid_t nid = get_amp_nid_(data);
3049 unsigned int dir;
3050 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3051 return 0;
3052 dir = get_amp_direction_(data);
3053 return (nid << 1) | dir;
3054}
3055
3056#define is_ctl_used(bits, data) \
3057 test_bit(get_ctl_pos(data), bits)
3058#define mark_ctl_usage(bits, data) \
3059 set_bit(get_ctl_pos(data), bits)
3060
3061static void clear_vol_marks(struct hda_codec *codec)
3062{
3063 struct alc_spec *spec = codec->spec;
3064 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3065 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3066}
3067
3068/* badness definition */
3069enum {
3070 /* No primary DAC is found for the main output */
3071 BAD_NO_PRIMARY_DAC = 0x10000,
3072 /* No DAC is found for the extra output */
3073 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003074 /* No possible multi-ios */
3075 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003076 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003077 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003078 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003079 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003080 /* Primary DAC shared with main surrounds */
3081 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003082 /* Primary DAC shared with main CLFE */
3083 BAD_SHARED_CLFE = 0x10,
3084 /* Primary DAC shared with extra surrounds */
3085 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003086 /* Volume widget is shared */
3087 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003088};
3089
3090static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3091 hda_nid_t pin, hda_nid_t dac);
3092static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3093 hda_nid_t pin, hda_nid_t dac);
3094
3095static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3096 hda_nid_t dac)
3097{
3098 struct alc_spec *spec = codec->spec;
3099 hda_nid_t nid;
3100 unsigned int val;
3101 int badness = 0;
3102
3103 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3104 if (nid) {
3105 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3106 if (is_ctl_used(spec->vol_ctls, nid))
3107 badness += BAD_SHARED_VOL;
3108 else
3109 mark_ctl_usage(spec->vol_ctls, val);
3110 } else
3111 badness += BAD_SHARED_VOL;
3112 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3113 if (nid) {
3114 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3115 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3116 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3117 else
3118 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3119 if (is_ctl_used(spec->sw_ctls, val))
3120 badness += BAD_SHARED_VOL;
3121 else
3122 mark_ctl_usage(spec->sw_ctls, val);
3123 } else
3124 badness += BAD_SHARED_VOL;
3125 return badness;
3126}
3127
Takashi Iwaidc31b582012-02-17 17:27:53 +01003128struct badness_table {
3129 int no_primary_dac; /* no primary DAC */
3130 int no_dac; /* no secondary DACs */
3131 int shared_primary; /* primary DAC is shared with main output */
3132 int shared_surr; /* secondary DAC shared with main or primary */
3133 int shared_clfe; /* third DAC shared with main or primary */
3134 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3135};
3136
3137static struct badness_table main_out_badness = {
3138 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3139 .no_dac = BAD_NO_DAC,
3140 .shared_primary = BAD_NO_PRIMARY_DAC,
3141 .shared_surr = BAD_SHARED_SURROUND,
3142 .shared_clfe = BAD_SHARED_CLFE,
3143 .shared_surr_main = BAD_SHARED_SURROUND,
3144};
3145
3146static struct badness_table extra_out_badness = {
3147 .no_primary_dac = BAD_NO_DAC,
3148 .no_dac = BAD_NO_DAC,
3149 .shared_primary = BAD_NO_EXTRA_DAC,
3150 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3151 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3152 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3153};
3154
3155/* try to assign DACs to pins and return the resultant badness */
3156static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3157 const hda_nid_t *pins, hda_nid_t *dacs,
3158 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003159{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003160 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003161 struct auto_pin_cfg *cfg = &spec->autocfg;
3162 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003163 int badness = 0;
3164 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003165
Takashi Iwai185d99f2012-02-16 18:39:45 +01003166 if (!num_outs)
3167 return 0;
3168
Takashi Iwaidc31b582012-02-17 17:27:53 +01003169 for (i = 0; i < num_outs; i++) {
3170 hda_nid_t pin = pins[i];
3171 if (!dacs[i])
3172 dacs[i] = alc_auto_look_for_dac(codec, pin);
3173 if (!dacs[i] && !i) {
3174 for (j = 1; j < num_outs; j++) {
3175 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3176 dacs[0] = dacs[j];
3177 dacs[j] = 0;
3178 break;
3179 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003180 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003181 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003182 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003183 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003184 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003185 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003186 else if (cfg->line_outs > i &&
3187 alc_auto_is_dac_reachable(codec, pin,
3188 spec->private_dac_nids[i]))
3189 dac = spec->private_dac_nids[i];
3190 if (dac) {
3191 if (!i)
3192 badness += bad->shared_primary;
3193 else if (i == 1)
3194 badness += bad->shared_surr;
3195 else
3196 badness += bad->shared_clfe;
3197 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003198 spec->private_dac_nids[0])) {
3199 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003200 badness += bad->shared_surr_main;
3201 } else if (!i)
3202 badness += bad->no_primary_dac;
3203 else
3204 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003205 }
3206 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003207 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003208 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003209
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003210 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003211}
3212
3213static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003214 hda_nid_t reference_pin,
3215 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003216
Takashi Iwai185d99f2012-02-16 18:39:45 +01003217static bool alc_map_singles(struct hda_codec *codec, int outs,
3218 const hda_nid_t *pins, hda_nid_t *dacs)
3219{
3220 int i;
3221 bool found = false;
3222 for (i = 0; i < outs; i++) {
3223 if (dacs[i])
3224 continue;
3225 dacs[i] = get_dac_if_single(codec, pins[i]);
3226 if (dacs[i])
3227 found = true;
3228 }
3229 return found;
3230}
3231
Takashi Iwai7085ec12009-10-02 09:03:58 +02003232/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003233static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003234 bool fill_hardwired,
3235 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003236{
3237 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003238 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003239 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003240
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003241 /* set num_dacs once to full for alc_auto_look_for_dac() */
3242 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003243 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003244 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3245 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3246 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003247 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003248 clear_vol_marks(codec);
3249 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003250
3251 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003252 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003253 bool mapped;
3254 do {
3255 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003256 cfg->line_out_pins,
3257 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003258 mapped |= alc_map_singles(codec, cfg->hp_outs,
3259 cfg->hp_pins,
3260 spec->multiout.hp_out_nid);
3261 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3262 cfg->speaker_pins,
3263 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003264 if (fill_mio_first && cfg->line_outs == 1 &&
3265 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3266 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3267 if (!err)
3268 mapped = true;
3269 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003270 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003271 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003272
Takashi Iwaidc31b582012-02-17 17:27:53 +01003273 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3274 spec->private_dac_nids,
3275 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003276
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003277 /* re-count num_dacs and squash invalid entries */
3278 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003279 for (i = 0; i < cfg->line_outs; i++) {
3280 if (spec->private_dac_nids[i])
3281 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003282 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003283 memmove(spec->private_dac_nids + i,
3284 spec->private_dac_nids + i + 1,
3285 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003286 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3287 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003288 }
3289
Takashi Iwai276dd702012-02-17 16:17:03 +01003290 if (fill_mio_first &&
3291 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003292 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003293 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003294 if (err < 0)
3295 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003296 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003297 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003298
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003299 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003300 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3301 spec->multiout.hp_out_nid,
3302 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003303 if (err < 0)
3304 return err;
3305 badness += err;
3306 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003307 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003308 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3309 cfg->speaker_pins,
3310 spec->multiout.extra_out_nid,
3311 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003312 if (err < 0)
3313 return err;
3314 badness += err;
3315 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003316 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3317 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003318 if (err < 0)
3319 return err;
3320 badness += err;
3321 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003322 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3323 /* try multi-ios with HP + inputs */
3324 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false, 1);
3325 if (err < 0)
3326 return err;
3327 badness += err;
3328 }
3329
3330 if (spec->multi_ios == 2) {
3331 for (i = 0; i < 2; i++)
3332 spec->private_dac_nids[spec->multiout.num_dacs++] =
3333 spec->multi_io[i].dac;
3334 spec->ext_channel_count = 2;
3335 } else if (spec->multi_ios) {
3336 spec->multi_ios = 0;
3337 badness += BAD_MULTI_IO;
3338 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003339
3340 return badness;
3341}
3342
3343#define DEBUG_BADNESS
3344
3345#ifdef DEBUG_BADNESS
3346#define debug_badness snd_printdd
3347#else
3348#define debug_badness(...)
3349#endif
3350
3351static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3352{
3353 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3354 cfg->line_out_pins[0], cfg->line_out_pins[1],
3355 cfg->line_out_pins[2], cfg->line_out_pins[2],
3356 spec->multiout.dac_nids[0],
3357 spec->multiout.dac_nids[1],
3358 spec->multiout.dac_nids[2],
3359 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003360 if (spec->multi_ios > 0)
3361 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3362 spec->multi_ios,
3363 spec->multi_io[0].pin, spec->multi_io[1].pin,
3364 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003365 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3366 cfg->hp_pins[0], cfg->hp_pins[1],
3367 cfg->hp_pins[2], cfg->hp_pins[2],
3368 spec->multiout.hp_out_nid[0],
3369 spec->multiout.hp_out_nid[1],
3370 spec->multiout.hp_out_nid[2],
3371 spec->multiout.hp_out_nid[3]);
3372 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3373 cfg->speaker_pins[0], cfg->speaker_pins[1],
3374 cfg->speaker_pins[2], cfg->speaker_pins[3],
3375 spec->multiout.extra_out_nid[0],
3376 spec->multiout.extra_out_nid[1],
3377 spec->multiout.extra_out_nid[2],
3378 spec->multiout.extra_out_nid[3]);
3379}
3380
3381static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3382{
3383 struct alc_spec *spec = codec->spec;
3384 struct auto_pin_cfg *cfg = &spec->autocfg;
3385 struct auto_pin_cfg *best_cfg;
3386 int best_badness = INT_MAX;
3387 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003388 bool fill_hardwired = true, fill_mio_first = true;
3389 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003390 bool hp_spk_swapped = false;
3391
3392 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3393 if (!best_cfg)
3394 return -ENOMEM;
3395 *best_cfg = *cfg;
3396
3397 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003398 badness = fill_and_eval_dacs(codec, fill_hardwired,
3399 fill_mio_first);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003400 if (badness < 0)
3401 return badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003402 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3403 cfg->line_out_type, fill_hardwired, fill_mio_first,
3404 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003405 debug_show_configs(spec, cfg);
3406 if (badness < best_badness) {
3407 best_badness = badness;
3408 *best_cfg = *cfg;
3409 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003410 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003411 }
3412 if (!badness)
3413 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003414 fill_mio_first = !fill_mio_first;
3415 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003416 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003417 fill_hardwired = !fill_hardwired;
3418 if (!fill_hardwired)
3419 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003420 if (hp_spk_swapped)
3421 break;
3422 hp_spk_swapped = true;
3423 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003424 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3425 cfg->hp_outs = cfg->line_outs;
3426 memcpy(cfg->hp_pins, cfg->line_out_pins,
3427 sizeof(cfg->hp_pins));
3428 cfg->line_outs = cfg->speaker_outs;
3429 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3430 sizeof(cfg->speaker_pins));
3431 cfg->speaker_outs = 0;
3432 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3433 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003434 fill_hardwired = true;
3435 continue;
3436 }
3437 if (cfg->hp_outs > 0 &&
3438 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3439 cfg->speaker_outs = cfg->line_outs;
3440 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3441 sizeof(cfg->speaker_pins));
3442 cfg->line_outs = cfg->hp_outs;
3443 memcpy(cfg->line_out_pins, cfg->hp_pins,
3444 sizeof(cfg->hp_pins));
3445 cfg->hp_outs = 0;
3446 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3447 cfg->line_out_type = AUTO_PIN_HP_OUT;
3448 fill_hardwired = true;
3449 continue;
3450 }
3451 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003452 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003453
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003454 if (badness) {
3455 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003456 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f692011-11-10 15:42:54 +01003457 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003458 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3459 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003460 debug_show_configs(spec, cfg);
Takashi Iwai07b18f692011-11-10 15:42:54 +01003461
David Henningssonfde48a12011-12-09 18:27:42 +08003462 if (cfg->line_out_pins[0])
3463 spec->vmaster_nid =
3464 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3465 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003466
3467 /* clear the bitmap flags for creating controls */
3468 clear_vol_marks(codec);
3469 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003470 return 0;
3471}
3472
Takashi Iwai343a04b2011-07-06 14:28:39 +02003473static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003474 const char *pfx, int cidx,
3475 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003476{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003477 struct alc_spec *spec = codec->spec;
3478 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003479 if (!nid)
3480 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003481 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3482 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3483 return 0;
3484 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003485 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003486 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003487}
3488
Takashi Iwaie29d3772011-11-14 17:13:23 +01003489static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3490 const char *pfx, int cidx,
3491 hda_nid_t nid)
3492{
3493 int chs = 1;
3494 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3495 chs = 3;
3496 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3497}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003498
3499/* create a mute-switch for the given mixer widget;
3500 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3501 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003502static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003503 const char *pfx, int cidx,
3504 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003505{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003506 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003507 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003508 int type;
3509 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003510 if (!nid)
3511 return 0;
3512 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3513 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3514 type = ALC_CTL_WIDGET_MUTE;
3515 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3516 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003517 type = ALC_CTL_WIDGET_MUTE;
3518 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3519 } else {
3520 type = ALC_CTL_BIND_MUTE;
3521 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3522 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003523 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3524 return 0;
3525 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003526 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003527}
3528
Takashi Iwaie29d3772011-11-14 17:13:23 +01003529static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3530 int cidx, hda_nid_t nid)
3531{
3532 int chs = 1;
3533 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3534 chs = 3;
3535 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3536}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003537
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003538static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3539 hda_nid_t pin, hda_nid_t dac)
3540{
3541 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3542 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3543 return pin;
3544 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3545 return mix;
3546 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3547 return dac;
3548 return 0;
3549}
3550
3551static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3552 hda_nid_t pin, hda_nid_t dac)
3553{
3554 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3555 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3556 return dac;
3557 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3558 return mix;
3559 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3560 return pin;
3561 return 0;
3562}
3563
Takashi Iwai7085ec12009-10-02 09:03:58 +02003564/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003565static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003566 const struct auto_pin_cfg *cfg)
3567{
3568 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003569 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003570
Takashi Iwaice764ab2011-04-27 16:35:23 +02003571 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003572 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003573 noutputs += spec->multi_ios;
3574
3575 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003576 const char *name;
3577 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003578 hda_nid_t dac, pin;
3579 hda_nid_t sw, vol;
3580
3581 dac = spec->multiout.dac_nids[i];
3582 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003583 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003584 if (i >= cfg->line_outs)
3585 pin = spec->multi_io[i - 1].pin;
3586 else
3587 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003588
3589 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3590 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003591 name = alc_get_line_out_pfx(spec, i, true, &index);
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
3688 if (dacs[num_pins - 1]) {
3689 /* OK, we have a multi-output system with individual volumes */
3690 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003691 if (num_pins >= 3) {
3692 snprintf(name, sizeof(name), "%s %s",
3693 pfx, channel_name[i]);
3694 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3695 name, 0);
3696 } else {
3697 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3698 pfx, i);
3699 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003700 if (err < 0)
3701 return err;
3702 }
3703 return 0;
3704 }
3705
3706 /* Let's create a bind-controls */
3707 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3708 if (!ctl)
3709 return -ENOMEM;
3710 n = 0;
3711 for (i = 0; i < num_pins; i++) {
3712 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3713 ctl->values[n++] =
3714 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3715 }
3716 if (n) {
3717 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3718 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3719 if (err < 0)
3720 return err;
3721 }
3722
3723 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3724 if (!ctl)
3725 return -ENOMEM;
3726 n = 0;
3727 for (i = 0; i < num_pins; i++) {
3728 hda_nid_t vol;
3729 if (!pins[i] || !dacs[i])
3730 continue;
3731 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3732 if (vol)
3733 ctl->values[n++] =
3734 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3735 }
3736 if (n) {
3737 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3738 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3739 if (err < 0)
3740 return err;
3741 }
3742 return 0;
3743}
3744
Takashi Iwai343a04b2011-07-06 14:28:39 +02003745static int alc_auto_create_hp_out(struct hda_codec *codec)
3746{
3747 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003748 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3749 spec->autocfg.hp_pins,
3750 spec->multiout.hp_out_nid,
3751 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003752}
3753
3754static int alc_auto_create_speaker_out(struct hda_codec *codec)
3755{
3756 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003757 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3758 spec->autocfg.speaker_pins,
3759 spec->multiout.extra_out_nid,
3760 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003761}
3762
Takashi Iwai343a04b2011-07-06 14:28:39 +02003763static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003764 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003765 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003766{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003767 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003768 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003769 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003770
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003771 alc_set_pin_output(codec, pin, pin_type);
3772 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003773 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003774 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003775 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003776 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003777 mix = srcs[i];
3778 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003779 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003780 if (!mix)
3781 return;
3782
3783 /* need the manual connection? */
3784 if (num > 1)
3785 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3786 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003787 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3788 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003789 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003790 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003791 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003792 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003793 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003794 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3795 if (nid)
3796 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3797 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003798
3799 /* unmute DAC if it's not assigned to a mixer */
3800 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3801 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3802 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3803 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003804}
3805
Takashi Iwai343a04b2011-07-06 14:28:39 +02003806static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003807{
3808 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003809 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003810 int i;
3811
3812 for (i = 0; i <= HDA_SIDE; i++) {
3813 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3814 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003815 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003816 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003817 }
3818}
3819
Takashi Iwai343a04b2011-07-06 14:28:39 +02003820static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003821{
3822 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003823 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003824 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003825
David Henningsson636030e2011-10-12 19:26:03 +02003826 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003827 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3828 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003829 pin = spec->autocfg.hp_pins[i];
3830 if (!pin)
3831 break;
3832 dac = spec->multiout.hp_out_nid[i];
3833 if (!dac) {
3834 if (i > 0 && spec->multiout.hp_out_nid[0])
3835 dac = spec->multiout.hp_out_nid[0];
3836 else
3837 dac = spec->multiout.dac_nids[0];
3838 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003839 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3840 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003841 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003842 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3843 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003844 pin = spec->autocfg.speaker_pins[i];
3845 if (!pin)
3846 break;
3847 dac = spec->multiout.extra_out_nid[i];
3848 if (!dac) {
3849 if (i > 0 && spec->multiout.extra_out_nid[0])
3850 dac = spec->multiout.extra_out_nid[0];
3851 else
3852 dac = spec->multiout.dac_nids[0];
3853 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003854 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3855 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003856}
3857
Takashi Iwai276dd702012-02-17 16:17:03 +01003858/* check whether the given pin can be a multi-io pin */
3859static bool can_be_multiio_pin(struct hda_codec *codec,
3860 unsigned int location, hda_nid_t nid)
3861{
3862 unsigned int defcfg, caps;
3863
3864 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3865 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3866 return false;
3867 if (location && get_defcfg_location(defcfg) != location)
3868 return false;
3869 caps = snd_hda_query_pin_caps(codec, nid);
3870 if (!(caps & AC_PINCAP_OUT))
3871 return false;
3872 return true;
3873}
3874
Takashi Iwaice764ab2011-04-27 16:35:23 +02003875/*
3876 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003877 *
3878 * When hardwired is set, try to fill ony hardwired pins, and returns
3879 * zero if any pins are filled, non-zero if nothing found.
3880 * When hardwired is off, try to fill possible input pins, and returns
3881 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003882 */
3883static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003884 hda_nid_t reference_pin,
3885 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003886{
3887 struct alc_spec *spec = codec->spec;
3888 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003889 int type, i, j, dacs, num_pins, old_pins;
3890 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3891 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003892 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003893
Takashi Iwai276dd702012-02-17 16:17:03 +01003894 old_pins = spec->multi_ios;
3895 if (old_pins >= 2)
3896 goto end_fill;
3897
3898 num_pins = 0;
3899 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3900 for (i = 0; i < cfg->num_inputs; i++) {
3901 if (cfg->inputs[i].type != type)
3902 continue;
3903 if (can_be_multiio_pin(codec, location,
3904 cfg->inputs[i].pin))
3905 num_pins++;
3906 }
3907 }
3908 if (num_pins < 2)
3909 goto end_fill;
3910
Takashi Iwai07b18f692011-11-10 15:42:54 +01003911 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003912 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3913 for (i = 0; i < cfg->num_inputs; i++) {
3914 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f692011-11-10 15:42:54 +01003915 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003916
Takashi Iwaice764ab2011-04-27 16:35:23 +02003917 if (cfg->inputs[i].type != type)
3918 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003919 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003920 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003921 for (j = 0; j < spec->multi_ios; j++) {
3922 if (nid == spec->multi_io[j].pin)
3923 break;
3924 }
3925 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003926 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003927
3928 if (offset && offset + spec->multi_ios < dacs) {
3929 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f692011-11-10 15:42:54 +01003930 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3931 dac = 0;
3932 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003933 if (hardwired)
3934 dac = get_dac_if_single(codec, nid);
3935 else if (!dac)
Takashi Iwai07b18f692011-11-10 15:42:54 +01003936 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003937 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003938 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003939 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003940 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003941 spec->multi_io[spec->multi_ios].pin = nid;
3942 spec->multi_io[spec->multi_ios].dac = dac;
3943 spec->multi_ios++;
3944 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003945 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003946 }
3947 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003948 end_fill:
3949 if (badness)
3950 badness = BAD_MULTI_IO;
3951 if (old_pins == spec->multi_ios) {
3952 if (hardwired)
3953 return 1; /* nothing found */
3954 else
3955 return badness; /* no badness if nothing found */
3956 }
3957 if (!hardwired && spec->multi_ios < 2) {
3958 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003959 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003960 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003961
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003962 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003963}
3964
3965static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3966 struct snd_ctl_elem_info *uinfo)
3967{
3968 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3969 struct alc_spec *spec = codec->spec;
3970
3971 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3972 uinfo->count = 1;
3973 uinfo->value.enumerated.items = spec->multi_ios + 1;
3974 if (uinfo->value.enumerated.item > spec->multi_ios)
3975 uinfo->value.enumerated.item = spec->multi_ios;
3976 sprintf(uinfo->value.enumerated.name, "%dch",
3977 (uinfo->value.enumerated.item + 1) * 2);
3978 return 0;
3979}
3980
3981static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3982 struct snd_ctl_elem_value *ucontrol)
3983{
3984 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3985 struct alc_spec *spec = codec->spec;
3986 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3987 return 0;
3988}
3989
3990static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3991{
3992 struct alc_spec *spec = codec->spec;
3993 hda_nid_t nid = spec->multi_io[idx].pin;
3994
3995 if (!spec->multi_io[idx].ctl_in)
3996 spec->multi_io[idx].ctl_in =
3997 snd_hda_codec_read(codec, nid, 0,
3998 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3999 if (output) {
4000 snd_hda_codec_update_cache(codec, nid, 0,
4001 AC_VERB_SET_PIN_WIDGET_CONTROL,
4002 PIN_OUT);
4003 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4004 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4005 HDA_AMP_MUTE, 0);
4006 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
4007 } else {
4008 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4009 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4010 HDA_AMP_MUTE, HDA_AMP_MUTE);
4011 snd_hda_codec_update_cache(codec, nid, 0,
4012 AC_VERB_SET_PIN_WIDGET_CONTROL,
4013 spec->multi_io[idx].ctl_in);
4014 }
4015 return 0;
4016}
4017
4018static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4019 struct snd_ctl_elem_value *ucontrol)
4020{
4021 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4022 struct alc_spec *spec = codec->spec;
4023 int i, ch;
4024
4025 ch = ucontrol->value.enumerated.item[0];
4026 if (ch < 0 || ch > spec->multi_ios)
4027 return -EINVAL;
4028 if (ch == (spec->ext_channel_count - 1) / 2)
4029 return 0;
4030 spec->ext_channel_count = (ch + 1) * 2;
4031 for (i = 0; i < spec->multi_ios; i++)
4032 alc_set_multi_io(codec, i, i < ch);
4033 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004034 if (spec->need_dac_fix && !spec->const_channel_count)
4035 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004036 return 1;
4037}
4038
Takashi Iwaia9111322011-05-02 11:30:18 +02004039static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004040 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4041 .name = "Channel Mode",
4042 .info = alc_auto_ch_mode_info,
4043 .get = alc_auto_ch_mode_get,
4044 .put = alc_auto_ch_mode_put,
4045};
4046
Takashi Iwai23c09b02011-08-19 09:05:35 +02004047static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004048{
4049 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004050
Takashi Iwaic2674682011-08-24 17:57:44 +02004051 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004052 struct snd_kcontrol_new *knew;
4053
4054 knew = alc_kcontrol_new(spec);
4055 if (!knew)
4056 return -ENOMEM;
4057 *knew = alc_auto_channel_mode_enum;
4058 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4059 if (!knew->name)
4060 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004061 }
4062 return 0;
4063}
4064
Takashi Iwai1d045db2011-07-07 18:23:21 +02004065/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4066 * active input pins
4067 */
4068static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4069{
4070 struct alc_spec *spec = codec->spec;
4071 const struct hda_input_mux *imux;
4072 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4073 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4074 int i, n, nums;
4075
4076 imux = spec->input_mux;
4077 if (!imux)
4078 return;
4079 if (spec->dyn_adc_switch)
4080 return;
4081
4082 nums = 0;
4083 for (n = 0; n < spec->num_adc_nids; n++) {
4084 hda_nid_t cap = spec->private_capsrc_nids[n];
4085 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4086 for (i = 0; i < imux->num_items; i++) {
4087 hda_nid_t pin = spec->imux_pins[i];
4088 if (pin) {
4089 if (get_connection_index(codec, cap, pin) < 0)
4090 break;
4091 } else if (num_conns <= imux->items[i].index)
4092 break;
4093 }
4094 if (i >= imux->num_items) {
4095 adc_nids[nums] = spec->private_adc_nids[n];
4096 capsrc_nids[nums++] = cap;
4097 }
4098 }
4099 if (!nums) {
4100 /* check whether ADC-switch is possible */
4101 if (!alc_check_dyn_adc_switch(codec)) {
4102 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4103 " using fallback 0x%x\n",
4104 codec->chip_name, spec->private_adc_nids[0]);
4105 spec->num_adc_nids = 1;
4106 spec->auto_mic = 0;
4107 return;
4108 }
4109 } else if (nums != spec->num_adc_nids) {
4110 memcpy(spec->private_adc_nids, adc_nids,
4111 nums * sizeof(hda_nid_t));
4112 memcpy(spec->private_capsrc_nids, capsrc_nids,
4113 nums * sizeof(hda_nid_t));
4114 spec->num_adc_nids = nums;
4115 }
4116
4117 if (spec->auto_mic)
4118 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
4119 else if (spec->input_mux->num_items == 1)
4120 spec->num_adc_nids = 1; /* reduce to a single ADC */
4121}
4122
4123/*
4124 * initialize ADC paths
4125 */
4126static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4127{
4128 struct alc_spec *spec = codec->spec;
4129 hda_nid_t nid;
4130
4131 nid = spec->adc_nids[adc_idx];
4132 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004133 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004134 snd_hda_codec_write(codec, nid, 0,
4135 AC_VERB_SET_AMP_GAIN_MUTE,
4136 AMP_IN_MUTE(0));
4137 return;
4138 }
4139 if (!spec->capsrc_nids)
4140 return;
4141 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004142 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004143 snd_hda_codec_write(codec, nid, 0,
4144 AC_VERB_SET_AMP_GAIN_MUTE,
4145 AMP_OUT_MUTE);
4146}
4147
4148static void alc_auto_init_input_src(struct hda_codec *codec)
4149{
4150 struct alc_spec *spec = codec->spec;
4151 int c, nums;
4152
4153 for (c = 0; c < spec->num_adc_nids; c++)
4154 alc_auto_init_adc(codec, c);
4155 if (spec->dyn_adc_switch)
4156 nums = 1;
4157 else
4158 nums = spec->num_adc_nids;
4159 for (c = 0; c < nums; c++)
4160 alc_mux_select(codec, 0, spec->cur_mux[c], true);
4161}
4162
4163/* add mic boosts if needed */
4164static int alc_auto_add_mic_boost(struct hda_codec *codec)
4165{
4166 struct alc_spec *spec = codec->spec;
4167 struct auto_pin_cfg *cfg = &spec->autocfg;
4168 int i, err;
4169 int type_idx = 0;
4170 hda_nid_t nid;
4171 const char *prev_label = NULL;
4172
4173 for (i = 0; i < cfg->num_inputs; i++) {
4174 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4175 break;
4176 nid = cfg->inputs[i].pin;
4177 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4178 const char *label;
4179 char boost_label[32];
4180
4181 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004182 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4183 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004184 if (prev_label && !strcmp(label, prev_label))
4185 type_idx++;
4186 else
4187 type_idx = 0;
4188 prev_label = label;
4189
4190 snprintf(boost_label, sizeof(boost_label),
4191 "%s Boost Volume", label);
4192 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4193 boost_label, type_idx,
4194 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4195 if (err < 0)
4196 return err;
4197 }
4198 }
4199 return 0;
4200}
4201
4202/* select or unmute the given capsrc route */
4203static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4204 int idx)
4205{
4206 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4207 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4208 HDA_AMP_MUTE, 0);
4209 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4210 snd_hda_codec_write_cache(codec, cap, 0,
4211 AC_VERB_SET_CONNECT_SEL, idx);
4212 }
4213}
4214
4215/* set the default connection to that pin */
4216static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4217{
4218 struct alc_spec *spec = codec->spec;
4219 int i;
4220
4221 if (!pin)
4222 return 0;
4223 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004224 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004225 int idx;
4226
4227 idx = get_connection_index(codec, cap, pin);
4228 if (idx < 0)
4229 continue;
4230 select_or_unmute_capsrc(codec, cap, idx);
4231 return i; /* return the found index */
4232 }
4233 return -1; /* not found */
4234}
4235
4236/* initialize some special cases for input sources */
4237static void alc_init_special_input_src(struct hda_codec *codec)
4238{
4239 struct alc_spec *spec = codec->spec;
4240 int i;
4241
4242 for (i = 0; i < spec->autocfg.num_inputs; i++)
4243 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4244}
4245
4246/* assign appropriate capture mixers */
4247static void set_capture_mixer(struct hda_codec *codec)
4248{
4249 struct alc_spec *spec = codec->spec;
4250 static const struct snd_kcontrol_new *caps[2][3] = {
4251 { alc_capture_mixer_nosrc1,
4252 alc_capture_mixer_nosrc2,
4253 alc_capture_mixer_nosrc3 },
4254 { alc_capture_mixer1,
4255 alc_capture_mixer2,
4256 alc_capture_mixer3 },
4257 };
4258
4259 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004260 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004261 if (!spec->capsrc_nids)
4262 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004263 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004264 return; /* no volume in capsrc, too */
4265 spec->vol_in_capsrc = 1;
4266 }
4267
4268 if (spec->num_adc_nids > 0) {
4269 int mux = 0;
4270 int num_adcs = 0;
4271
4272 if (spec->input_mux && spec->input_mux->num_items > 1)
4273 mux = 1;
4274 if (spec->auto_mic) {
4275 num_adcs = 1;
4276 mux = 0;
4277 } else if (spec->dyn_adc_switch)
4278 num_adcs = 1;
4279 if (!num_adcs) {
4280 if (spec->num_adc_nids > 3)
4281 spec->num_adc_nids = 3;
4282 else if (!spec->num_adc_nids)
4283 return;
4284 num_adcs = spec->num_adc_nids;
4285 }
4286 spec->cap_mixer = caps[mux][num_adcs - 1];
4287 }
4288}
4289
4290/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004291 * standard auto-parser initializations
4292 */
4293static void alc_auto_init_std(struct hda_codec *codec)
4294{
4295 struct alc_spec *spec = codec->spec;
4296 alc_auto_init_multi_out(codec);
4297 alc_auto_init_extra_out(codec);
4298 alc_auto_init_analog_input(codec);
4299 alc_auto_init_input_src(codec);
4300 alc_auto_init_digital(codec);
4301 if (spec->unsol_event)
4302 alc_inithook(codec);
4303}
4304
4305/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004306 * Digital-beep handlers
4307 */
4308#ifdef CONFIG_SND_HDA_INPUT_BEEP
4309#define set_beep_amp(spec, nid, idx, dir) \
4310 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4311
4312static const struct snd_pci_quirk beep_white_list[] = {
4313 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4314 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4315 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4316 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
4317 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4318 {}
4319};
4320
4321static inline int has_cdefine_beep(struct hda_codec *codec)
4322{
4323 struct alc_spec *spec = codec->spec;
4324 const struct snd_pci_quirk *q;
4325 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4326 if (q)
4327 return q->value;
4328 return spec->cdefine.enable_pcbeep;
4329}
4330#else
4331#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4332#define has_cdefine_beep(codec) 0
4333#endif
4334
4335/* parse the BIOS configuration and set up the alc_spec */
4336/* return 1 if successful, 0 if the proper config is not found,
4337 * or a negative error code
4338 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004339static int alc_parse_auto_config(struct hda_codec *codec,
4340 const hda_nid_t *ignore_nids,
4341 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004342{
4343 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004344 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004345 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004346
Takashi Iwai53c334a2011-08-23 18:27:14 +02004347 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4348 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004349 if (err < 0)
4350 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004351 if (!cfg->line_outs) {
4352 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004353 spec->multiout.max_channels = 2;
4354 spec->no_analog = 1;
4355 goto dig_only;
4356 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004357 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004358 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004359
Takashi Iwai06503672011-10-06 08:27:19 +02004360 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4361 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004362 /* use HP as primary out */
4363 cfg->speaker_outs = cfg->line_outs;
4364 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4365 sizeof(cfg->speaker_pins));
4366 cfg->line_outs = cfg->hp_outs;
4367 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4368 cfg->hp_outs = 0;
4369 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4370 cfg->line_out_type = AUTO_PIN_HP_OUT;
4371 }
4372
Takashi Iwai1d045db2011-07-07 18:23:21 +02004373 err = alc_auto_fill_dac_nids(codec);
4374 if (err < 0)
4375 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004376 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004377 if (err < 0)
4378 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004379 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004380 if (err < 0)
4381 return err;
4382 err = alc_auto_create_hp_out(codec);
4383 if (err < 0)
4384 return err;
4385 err = alc_auto_create_speaker_out(codec);
4386 if (err < 0)
4387 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004388 err = alc_auto_create_shared_input(codec);
4389 if (err < 0)
4390 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004391 err = alc_auto_create_input_ctls(codec);
4392 if (err < 0)
4393 return err;
4394
4395 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4396
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004397 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004398 alc_auto_parse_digital(codec);
4399
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004400 if (!spec->no_analog)
4401 alc_remove_invalid_adc_nids(codec);
4402
4403 if (ssid_nids)
4404 alc_ssid_check(codec, ssid_nids);
4405
4406 if (!spec->no_analog) {
4407 alc_auto_check_switches(codec);
4408 err = alc_auto_add_mic_boost(codec);
4409 if (err < 0)
4410 return err;
4411 }
4412
Takashi Iwai1d045db2011-07-07 18:23:21 +02004413 if (spec->kctls.list)
4414 add_mixer(spec, spec->kctls.list);
4415
Takashi Iwai1d045db2011-07-07 18:23:21 +02004416 return 1;
4417}
4418
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004419static int alc880_parse_auto_config(struct hda_codec *codec)
4420{
4421 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4422 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4423 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4424}
4425
Takashi Iwai1d045db2011-07-07 18:23:21 +02004426#ifdef CONFIG_SND_HDA_POWER_SAVE
4427static const struct hda_amp_list alc880_loopbacks[] = {
4428 { 0x0b, HDA_INPUT, 0 },
4429 { 0x0b, HDA_INPUT, 1 },
4430 { 0x0b, HDA_INPUT, 2 },
4431 { 0x0b, HDA_INPUT, 3 },
4432 { 0x0b, HDA_INPUT, 4 },
4433 { } /* end */
4434};
4435#endif
4436
4437/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004438 * ALC880 fix-ups
4439 */
4440enum {
4441 ALC880_FIXUP_GPIO2,
4442 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004443 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004444 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004445 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004446 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004447 ALC880_FIXUP_VOL_KNOB,
4448 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004449 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004450 ALC880_FIXUP_UNIWILL,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004451};
4452
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004453/* enable the volume-knob widget support on NID 0x21 */
4454static void alc880_fixup_vol_knob(struct hda_codec *codec,
4455 const struct alc_fixup *fix, int action)
4456{
4457 if (action == ALC_FIXUP_ACT_PROBE)
4458 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4459}
4460
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004461static const struct alc_fixup alc880_fixups[] = {
4462 [ALC880_FIXUP_GPIO2] = {
4463 .type = ALC_FIXUP_VERBS,
4464 .v.verbs = alc_gpio2_init_verbs,
4465 },
4466 [ALC880_FIXUP_MEDION_RIM] = {
4467 .type = ALC_FIXUP_VERBS,
4468 .v.verbs = (const struct hda_verb[]) {
4469 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4470 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4471 { }
4472 },
4473 .chained = true,
4474 .chain_id = ALC880_FIXUP_GPIO2,
4475 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004476 [ALC880_FIXUP_LG] = {
4477 .type = ALC_FIXUP_PINS,
4478 .v.pins = (const struct alc_pincfg[]) {
4479 /* disable bogus unused pins */
4480 { 0x16, 0x411111f0 },
4481 { 0x18, 0x411111f0 },
4482 { 0x1a, 0x411111f0 },
4483 { }
4484 }
4485 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004486 [ALC880_FIXUP_W810] = {
4487 .type = ALC_FIXUP_PINS,
4488 .v.pins = (const struct alc_pincfg[]) {
4489 /* disable bogus unused pins */
4490 { 0x17, 0x411111f0 },
4491 { }
4492 },
4493 .chained = true,
4494 .chain_id = ALC880_FIXUP_GPIO2,
4495 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004496 [ALC880_FIXUP_EAPD_COEF] = {
4497 .type = ALC_FIXUP_VERBS,
4498 .v.verbs = (const struct hda_verb[]) {
4499 /* change to EAPD mode */
4500 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4501 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4502 {}
4503 },
4504 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004505 [ALC880_FIXUP_TCL_S700] = {
4506 .type = ALC_FIXUP_VERBS,
4507 .v.verbs = (const struct hda_verb[]) {
4508 /* change to EAPD mode */
4509 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4510 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4511 {}
4512 },
4513 .chained = true,
4514 .chain_id = ALC880_FIXUP_GPIO2,
4515 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004516 [ALC880_FIXUP_VOL_KNOB] = {
4517 .type = ALC_FIXUP_FUNC,
4518 .v.func = alc880_fixup_vol_knob,
4519 },
4520 [ALC880_FIXUP_FUJITSU] = {
4521 /* override all pins as BIOS on old Amilo is broken */
4522 .type = ALC_FIXUP_PINS,
4523 .v.pins = (const struct alc_pincfg[]) {
4524 { 0x14, 0x0121411f }, /* HP */
4525 { 0x15, 0x99030120 }, /* speaker */
4526 { 0x16, 0x99030130 }, /* bass speaker */
4527 { 0x17, 0x411111f0 }, /* N/A */
4528 { 0x18, 0x411111f0 }, /* N/A */
4529 { 0x19, 0x01a19950 }, /* mic-in */
4530 { 0x1a, 0x411111f0 }, /* N/A */
4531 { 0x1b, 0x411111f0 }, /* N/A */
4532 { 0x1c, 0x411111f0 }, /* N/A */
4533 { 0x1d, 0x411111f0 }, /* N/A */
4534 { 0x1e, 0x01454140 }, /* SPDIF out */
4535 { }
4536 },
4537 .chained = true,
4538 .chain_id = ALC880_FIXUP_VOL_KNOB,
4539 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004540 [ALC880_FIXUP_F1734] = {
4541 /* almost compatible with FUJITSU, but no bass and SPDIF */
4542 .type = ALC_FIXUP_PINS,
4543 .v.pins = (const struct alc_pincfg[]) {
4544 { 0x14, 0x0121411f }, /* HP */
4545 { 0x15, 0x99030120 }, /* speaker */
4546 { 0x16, 0x411111f0 }, /* N/A */
4547 { 0x17, 0x411111f0 }, /* N/A */
4548 { 0x18, 0x411111f0 }, /* N/A */
4549 { 0x19, 0x01a19950 }, /* mic-in */
4550 { 0x1a, 0x411111f0 }, /* N/A */
4551 { 0x1b, 0x411111f0 }, /* N/A */
4552 { 0x1c, 0x411111f0 }, /* N/A */
4553 { 0x1d, 0x411111f0 }, /* N/A */
4554 { 0x1e, 0x411111f0 }, /* N/A */
4555 { }
4556 },
4557 .chained = true,
4558 .chain_id = ALC880_FIXUP_VOL_KNOB,
4559 },
Takashi Iwai817de922012-02-20 17:20:48 +01004560 [ALC880_FIXUP_UNIWILL] = {
4561 /* need to fix HP and speaker pins to be parsed correctly */
4562 .type = ALC_FIXUP_PINS,
4563 .v.pins = (const struct alc_pincfg[]) {
4564 { 0x14, 0x0121411f }, /* HP */
4565 { 0x15, 0x99030120 }, /* speaker */
4566 { 0x16, 0x99030130 }, /* bass speaker */
4567 { }
4568 },
4569 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004570};
4571
4572static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004573 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004574 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwaiba533812012-02-20 16:36:52 +01004575 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004576 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004577 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004578 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004579 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004580 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004581 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004582 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004583 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004584 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4585 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4586 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004587 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004588 {}
4589};
4590
4591
4592/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004593 * board setups
4594 */
4595#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4596#define alc_board_config \
4597 snd_hda_check_board_config
4598#define alc_board_codec_sid_config \
4599 snd_hda_check_board_codec_sid_config
4600#include "alc_quirks.c"
4601#else
4602#define alc_board_config(codec, nums, models, tbl) -1
4603#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4604#define setup_preset(codec, x) /* NOP */
4605#endif
4606
4607/*
4608 * OK, here we have finally the patch for ALC880
4609 */
4610#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4611#include "alc880_quirks.c"
4612#endif
4613
4614static int patch_alc880(struct hda_codec *codec)
4615{
4616 struct alc_spec *spec;
4617 int board_config;
4618 int err;
4619
4620 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4621 if (spec == NULL)
4622 return -ENOMEM;
4623
4624 codec->spec = spec;
4625
4626 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004627 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004628
4629 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4630 alc880_models, alc880_cfg_tbl);
4631 if (board_config < 0) {
4632 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4633 codec->chip_name);
4634 board_config = ALC_MODEL_AUTO;
4635 }
4636
4637 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004638 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4639 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4640 }
4641
4642 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004643 /* automatic parse from the BIOS config */
4644 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004645 if (err < 0)
4646 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004647#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4648 else if (!err) {
4649 printk(KERN_INFO
4650 "hda_codec: Cannot set up configuration "
4651 "from BIOS. Using 3-stack mode...\n");
4652 board_config = ALC880_3ST;
4653 }
4654#endif
4655 }
4656
David Henningssonfde48a12011-12-09 18:27:42 +08004657 if (board_config != ALC_MODEL_AUTO) {
4658 spec->vmaster_nid = 0x0c;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004659 setup_preset(codec, &alc880_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004660 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004661
Takashi Iwai60a6a842011-07-27 14:01:24 +02004662 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004663 alc_auto_fill_adc_caps(codec);
4664 alc_rebuild_imux_for_auto_mic(codec);
4665 alc_remove_invalid_adc_nids(codec);
4666 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004667
4668 if (!spec->no_analog && !spec->cap_mixer)
4669 set_capture_mixer(codec);
4670
4671 if (!spec->no_analog) {
4672 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004673 if (err < 0)
4674 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004675 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4676 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004677
Takashi Iwai1d045db2011-07-07 18:23:21 +02004678 codec->patch_ops = alc_patch_ops;
4679 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004680 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004681 else
4682 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004683#ifdef CONFIG_SND_HDA_POWER_SAVE
4684 if (!spec->loopback.amplist)
4685 spec->loopback.amplist = alc880_loopbacks;
4686#endif
4687
Takashi Iwai589876e2012-02-20 15:47:55 +01004688 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4689
Takashi Iwai1d045db2011-07-07 18:23:21 +02004690 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004691
4692 error:
4693 alc_free(codec);
4694 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004695}
4696
4697
4698/*
4699 * ALC260 support
4700 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004701static int alc260_parse_auto_config(struct hda_codec *codec)
4702{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004703 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004704 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4705 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004706}
4707
Takashi Iwai1d045db2011-07-07 18:23:21 +02004708#ifdef CONFIG_SND_HDA_POWER_SAVE
4709static const struct hda_amp_list alc260_loopbacks[] = {
4710 { 0x07, HDA_INPUT, 0 },
4711 { 0x07, HDA_INPUT, 1 },
4712 { 0x07, HDA_INPUT, 2 },
4713 { 0x07, HDA_INPUT, 3 },
4714 { 0x07, HDA_INPUT, 4 },
4715 { } /* end */
4716};
4717#endif
4718
4719/*
4720 * Pin config fixes
4721 */
4722enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004723 ALC260_FIXUP_HP_DC5750,
4724 ALC260_FIXUP_HP_PIN_0F,
4725 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004726 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004727 ALC260_FIXUP_GPIO1_TOGGLE,
4728 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004729 ALC260_FIXUP_HP_B1900,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004730};
4731
Takashi Iwai20f7d922012-02-16 12:35:16 +01004732static void alc260_gpio1_automute(struct hda_codec *codec)
4733{
4734 struct alc_spec *spec = codec->spec;
4735 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4736 spec->hp_jack_present);
4737}
4738
4739static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4740 const struct alc_fixup *fix, int action)
4741{
4742 struct alc_spec *spec = codec->spec;
4743 if (action == ALC_FIXUP_ACT_PROBE) {
4744 /* although the machine has only one output pin, we need to
4745 * toggle GPIO1 according to the jack state
4746 */
4747 spec->automute_hook = alc260_gpio1_automute;
4748 spec->detect_hp = 1;
4749 spec->automute_speaker = 1;
4750 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4751 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4752 spec->unsol_event = alc_sku_unsol_event;
4753 add_verb(codec->spec, alc_gpio1_init_verbs);
4754 }
4755}
4756
Takashi Iwai1d045db2011-07-07 18:23:21 +02004757static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004758 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004759 .type = ALC_FIXUP_PINS,
4760 .v.pins = (const struct alc_pincfg[]) {
4761 { 0x11, 0x90130110 }, /* speaker */
4762 { }
4763 }
4764 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004765 [ALC260_FIXUP_HP_PIN_0F] = {
4766 .type = ALC_FIXUP_PINS,
4767 .v.pins = (const struct alc_pincfg[]) {
4768 { 0x0f, 0x01214000 }, /* HP */
4769 { }
4770 }
4771 },
4772 [ALC260_FIXUP_COEF] = {
4773 .type = ALC_FIXUP_VERBS,
4774 .v.verbs = (const struct hda_verb[]) {
4775 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4776 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4777 { }
4778 },
4779 .chained = true,
4780 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4781 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004782 [ALC260_FIXUP_GPIO1] = {
4783 .type = ALC_FIXUP_VERBS,
4784 .v.verbs = alc_gpio1_init_verbs,
4785 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004786 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4787 .type = ALC_FIXUP_FUNC,
4788 .v.func = alc260_fixup_gpio1_toggle,
4789 .chained = true,
4790 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4791 },
4792 [ALC260_FIXUP_REPLACER] = {
4793 .type = ALC_FIXUP_VERBS,
4794 .v.verbs = (const struct hda_verb[]) {
4795 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4796 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4797 { }
4798 },
4799 .chained = true,
4800 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4801 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004802 [ALC260_FIXUP_HP_B1900] = {
4803 .type = ALC_FIXUP_FUNC,
4804 .v.func = alc260_fixup_gpio1_toggle,
4805 .chained = true,
4806 .chain_id = ALC260_FIXUP_COEF,
4807 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004808};
4809
4810static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004811 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004812 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004813 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004814 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004815 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004816 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004817 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004818 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004819 {}
4820};
4821
4822/*
4823 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004824static int patch_alc260(struct hda_codec *codec)
4825{
4826 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004827 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004828
4829 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4830 if (spec == NULL)
4831 return -ENOMEM;
4832
4833 codec->spec = spec;
4834
4835 spec->mixer_nid = 0x07;
4836
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004837 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4838 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004839
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004840 /* automatic parse from the BIOS config */
4841 err = alc260_parse_auto_config(codec);
4842 if (err < 0)
4843 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004844
Takashi Iwai60a6a842011-07-27 14:01:24 +02004845 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004846 alc_auto_fill_adc_caps(codec);
4847 alc_rebuild_imux_for_auto_mic(codec);
4848 alc_remove_invalid_adc_nids(codec);
4849 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004850
4851 if (!spec->no_analog && !spec->cap_mixer)
4852 set_capture_mixer(codec);
4853
4854 if (!spec->no_analog) {
4855 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004856 if (err < 0)
4857 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004858 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4859 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004860
Takashi Iwai1d045db2011-07-07 18:23:21 +02004861 codec->patch_ops = alc_patch_ops;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004862 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004863 spec->shutup = alc_eapd_shutup;
4864#ifdef CONFIG_SND_HDA_POWER_SAVE
4865 if (!spec->loopback.amplist)
4866 spec->loopback.amplist = alc260_loopbacks;
4867#endif
4868
Takashi Iwai589876e2012-02-20 15:47:55 +01004869 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4870
Takashi Iwai1d045db2011-07-07 18:23:21 +02004871 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004872
4873 error:
4874 alc_free(codec);
4875 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004876}
4877
4878
4879/*
4880 * ALC882/883/885/888/889 support
4881 *
4882 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4883 * configuration. Each pin widget can choose any input DACs and a mixer.
4884 * Each ADC is connected from a mixer of all inputs. This makes possible
4885 * 6-channel independent captures.
4886 *
4887 * In addition, an independent DAC for the multi-playback (not used in this
4888 * driver yet).
4889 */
4890#ifdef CONFIG_SND_HDA_POWER_SAVE
4891#define alc882_loopbacks alc880_loopbacks
4892#endif
4893
4894/*
4895 * Pin config fixes
4896 */
4897enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004898 ALC882_FIXUP_ABIT_AW9D_MAX,
4899 ALC882_FIXUP_LENOVO_Y530,
4900 ALC882_FIXUP_PB_M5210,
4901 ALC882_FIXUP_ACER_ASPIRE_7736,
4902 ALC882_FIXUP_ASUS_W90V,
4903 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004904 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004905 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004906 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004907 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004908 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004909 ALC889_FIXUP_COEF,
4910 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004911 ALC882_FIXUP_ACER_ASPIRE_4930G,
4912 ALC882_FIXUP_ACER_ASPIRE_8930G,
4913 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004914 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01004915 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004916};
4917
Takashi Iwai68ef0562011-11-09 18:24:44 +01004918static void alc889_fixup_coef(struct hda_codec *codec,
4919 const struct alc_fixup *fix, int action)
4920{
4921 if (action != ALC_FIXUP_ACT_INIT)
4922 return;
4923 alc889_coef_init(codec);
4924}
4925
Takashi Iwai56710872011-11-14 17:42:11 +01004926/* toggle speaker-output according to the hp-jack state */
4927static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4928{
4929 unsigned int gpiostate, gpiomask, gpiodir;
4930
4931 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4932 AC_VERB_GET_GPIO_DATA, 0);
4933
4934 if (!muted)
4935 gpiostate |= (1 << pin);
4936 else
4937 gpiostate &= ~(1 << pin);
4938
4939 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4940 AC_VERB_GET_GPIO_MASK, 0);
4941 gpiomask |= (1 << pin);
4942
4943 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4944 AC_VERB_GET_GPIO_DIRECTION, 0);
4945 gpiodir |= (1 << pin);
4946
4947
4948 snd_hda_codec_write(codec, codec->afg, 0,
4949 AC_VERB_SET_GPIO_MASK, gpiomask);
4950 snd_hda_codec_write(codec, codec->afg, 0,
4951 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4952
4953 msleep(1);
4954
4955 snd_hda_codec_write(codec, codec->afg, 0,
4956 AC_VERB_SET_GPIO_DATA, gpiostate);
4957}
4958
4959/* set up GPIO at initialization */
4960static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4961 const struct alc_fixup *fix, int action)
4962{
4963 if (action != ALC_FIXUP_ACT_INIT)
4964 return;
4965 alc882_gpio_mute(codec, 0, 0);
4966 alc882_gpio_mute(codec, 1, 0);
4967}
4968
Takashi Iwai02a237b2012-02-13 15:25:07 +01004969/* Fix the connection of some pins for ALC889:
4970 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4971 * work correctly (bko#42740)
4972 */
4973static void alc889_fixup_dac_route(struct hda_codec *codec,
4974 const struct alc_fixup *fix, int action)
4975{
4976 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
4977 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4978 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4979 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4980 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4981 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4982 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
4983 }
4984}
4985
Takashi Iwai1d045db2011-07-07 18:23:21 +02004986static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004987 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004988 .type = ALC_FIXUP_PINS,
4989 .v.pins = (const struct alc_pincfg[]) {
4990 { 0x15, 0x01080104 }, /* side */
4991 { 0x16, 0x01011012 }, /* rear */
4992 { 0x17, 0x01016011 }, /* clfe */
4993 { }
4994 }
4995 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004996 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004997 .type = ALC_FIXUP_PINS,
4998 .v.pins = (const struct alc_pincfg[]) {
4999 { 0x15, 0x99130112 }, /* rear int speakers */
5000 { 0x16, 0x99130111 }, /* subwoofer */
5001 { }
5002 }
5003 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005004 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005 .type = ALC_FIXUP_VERBS,
5006 .v.verbs = (const struct hda_verb[]) {
5007 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5008 {}
5009 }
5010 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005011 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005012 .type = ALC_FIXUP_SKU,
5013 .v.sku = ALC_FIXUP_SKU_IGNORE,
5014 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005015 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005016 .type = ALC_FIXUP_PINS,
5017 .v.pins = (const struct alc_pincfg[]) {
5018 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5019 { }
5020 }
5021 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005022 [ALC889_FIXUP_VAIO_TT] = {
5023 .type = ALC_FIXUP_PINS,
5024 .v.pins = (const struct alc_pincfg[]) {
5025 { 0x17, 0x90170111 }, /* hidden surround speaker */
5026 { }
5027 }
5028 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005029 [ALC888_FIXUP_EEE1601] = {
5030 .type = ALC_FIXUP_VERBS,
5031 .v.verbs = (const struct hda_verb[]) {
5032 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5033 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5034 { }
5035 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005036 },
5037 [ALC882_FIXUP_EAPD] = {
5038 .type = ALC_FIXUP_VERBS,
5039 .v.verbs = (const struct hda_verb[]) {
5040 /* change to EAPD mode */
5041 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5042 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5043 { }
5044 }
5045 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005046 [ALC883_FIXUP_EAPD] = {
5047 .type = ALC_FIXUP_VERBS,
5048 .v.verbs = (const struct hda_verb[]) {
5049 /* change to EAPD mode */
5050 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5051 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5052 { }
5053 }
5054 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005055 [ALC883_FIXUP_ACER_EAPD] = {
5056 .type = ALC_FIXUP_VERBS,
5057 .v.verbs = (const struct hda_verb[]) {
5058 /* eanable EAPD on Acer laptops */
5059 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5060 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5061 { }
5062 }
5063 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005064 [ALC882_FIXUP_GPIO3] = {
5065 .type = ALC_FIXUP_VERBS,
5066 .v.verbs = alc_gpio3_init_verbs,
5067 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005068 [ALC882_FIXUP_ASUS_W2JC] = {
5069 .type = ALC_FIXUP_VERBS,
5070 .v.verbs = alc_gpio1_init_verbs,
5071 .chained = true,
5072 .chain_id = ALC882_FIXUP_EAPD,
5073 },
5074 [ALC889_FIXUP_COEF] = {
5075 .type = ALC_FIXUP_FUNC,
5076 .v.func = alc889_fixup_coef,
5077 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005078 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5079 .type = ALC_FIXUP_PINS,
5080 .v.pins = (const struct alc_pincfg[]) {
5081 { 0x16, 0x99130111 }, /* CLFE speaker */
5082 { 0x17, 0x99130112 }, /* surround speaker */
5083 { }
5084 }
5085 },
5086 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5087 .type = ALC_FIXUP_PINS,
5088 .v.pins = (const struct alc_pincfg[]) {
5089 { 0x16, 0x99130111 }, /* CLFE speaker */
5090 { 0x1b, 0x99130112 }, /* surround speaker */
5091 { }
5092 },
5093 .chained = true,
5094 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5095 },
5096 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5097 /* additional init verbs for Acer Aspire 8930G */
5098 .type = ALC_FIXUP_VERBS,
5099 .v.verbs = (const struct hda_verb[]) {
5100 /* Enable all DACs */
5101 /* DAC DISABLE/MUTE 1? */
5102 /* setting bits 1-5 disables DAC nids 0x02-0x06
5103 * apparently. Init=0x38 */
5104 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5105 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5106 /* DAC DISABLE/MUTE 2? */
5107 /* some bit here disables the other DACs.
5108 * Init=0x4900 */
5109 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5110 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5111 /* DMIC fix
5112 * This laptop has a stereo digital microphone.
5113 * The mics are only 1cm apart which makes the stereo
5114 * useless. However, either the mic or the ALC889
5115 * makes the signal become a difference/sum signal
5116 * instead of standard stereo, which is annoying.
5117 * So instead we flip this bit which makes the
5118 * codec replicate the sum signal to both channels,
5119 * turning it into a normal mono mic.
5120 */
5121 /* DMIC_CONTROL? Init value = 0x0001 */
5122 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5123 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5124 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5125 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5126 { }
5127 }
5128 },
Takashi Iwai56710872011-11-14 17:42:11 +01005129 [ALC885_FIXUP_MACPRO_GPIO] = {
5130 .type = ALC_FIXUP_FUNC,
5131 .v.func = alc885_fixup_macpro_gpio,
5132 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005133 [ALC889_FIXUP_DAC_ROUTE] = {
5134 .type = ALC_FIXUP_FUNC,
5135 .v.func = alc889_fixup_dac_route,
5136 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005137};
5138
5139static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005140 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5141 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5142 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5143 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5144 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5145 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005146 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5147 ALC882_FIXUP_ACER_ASPIRE_4930G),
5148 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5149 ALC882_FIXUP_ACER_ASPIRE_4930G),
5150 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5151 ALC882_FIXUP_ACER_ASPIRE_8930G),
5152 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5153 ALC882_FIXUP_ACER_ASPIRE_8930G),
5154 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5155 ALC882_FIXUP_ACER_ASPIRE_4930G),
5156 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5157 ALC882_FIXUP_ACER_ASPIRE_4930G),
5158 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5159 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005160 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005161 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005162 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005163 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005164 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005165 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005166 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005167 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005168
5169 /* All Apple entries are in codec SSIDs */
5170 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5171 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5172 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
5173 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
5174 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
5175
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005176 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005177 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005178 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005179 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5180 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005181 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005182 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005183 {}
5184};
5185
5186/*
5187 * BIOS auto configuration
5188 */
5189/* almost identical with ALC880 parser... */
5190static int alc882_parse_auto_config(struct hda_codec *codec)
5191{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005192 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005193 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5194 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005195}
5196
Takashi Iwai1d045db2011-07-07 18:23:21 +02005197/*
5198 */
5199#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5200#include "alc882_quirks.c"
5201#endif
5202
5203static int patch_alc882(struct hda_codec *codec)
5204{
5205 struct alc_spec *spec;
5206 int err, board_config;
5207
5208 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5209 if (spec == NULL)
5210 return -ENOMEM;
5211
5212 codec->spec = spec;
5213
5214 spec->mixer_nid = 0x0b;
5215
5216 switch (codec->vendor_id) {
5217 case 0x10ec0882:
5218 case 0x10ec0885:
5219 break;
5220 default:
5221 /* ALC883 and variants */
5222 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5223 break;
5224 }
5225
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005226 err = alc_codec_rename_from_preset(codec);
5227 if (err < 0)
5228 goto error;
5229
Takashi Iwaib2539692011-11-14 17:32:17 +01005230 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
5231 alc882_models, NULL);
5232 if (board_config < 0)
5233 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005234 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
5235
5236 if (board_config < 0) {
5237 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5238 codec->chip_name);
5239 board_config = ALC_MODEL_AUTO;
5240 }
5241
5242 if (board_config == ALC_MODEL_AUTO) {
5243 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
5244 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5245 }
5246
5247 alc_auto_parse_customize_define(codec);
5248
5249 if (board_config == ALC_MODEL_AUTO) {
5250 /* automatic parse from the BIOS config */
5251 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005252 if (err < 0)
5253 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005254 }
5255
David Henningssonfde48a12011-12-09 18:27:42 +08005256 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005257 setup_preset(codec, &alc882_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08005258 spec->vmaster_nid = 0x0c;
5259 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005260
Takashi Iwai60a6a842011-07-27 14:01:24 +02005261 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005262 alc_auto_fill_adc_caps(codec);
5263 alc_rebuild_imux_for_auto_mic(codec);
5264 alc_remove_invalid_adc_nids(codec);
5265 }
5266
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005267 if (!spec->no_analog && !spec->cap_mixer)
5268 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005269
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005270 if (!spec->no_analog && has_cdefine_beep(codec)) {
5271 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005272 if (err < 0)
5273 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005274 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005275 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005276
Takashi Iwai1d045db2011-07-07 18:23:21 +02005277 codec->patch_ops = alc_patch_ops;
5278 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02005279 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01005280 else
5281 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005282
Takashi Iwai1d045db2011-07-07 18:23:21 +02005283#ifdef CONFIG_SND_HDA_POWER_SAVE
5284 if (!spec->loopback.amplist)
5285 spec->loopback.amplist = alc882_loopbacks;
5286#endif
5287
Takashi Iwai589876e2012-02-20 15:47:55 +01005288 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5289
Takashi Iwai1d045db2011-07-07 18:23:21 +02005290 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005291
5292 error:
5293 alc_free(codec);
5294 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005295}
5296
5297
5298/*
5299 * ALC262 support
5300 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005301static int alc262_parse_auto_config(struct hda_codec *codec)
5302{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005303 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005304 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5305 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005306}
5307
5308/*
5309 * Pin config fixes
5310 */
5311enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005312 ALC262_FIXUP_FSC_H270,
5313 ALC262_FIXUP_HP_Z200,
5314 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005315 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005316 ALC262_FIXUP_BENQ,
5317 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005318};
5319
5320static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005321 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005322 .type = ALC_FIXUP_PINS,
5323 .v.pins = (const struct alc_pincfg[]) {
5324 { 0x14, 0x99130110 }, /* speaker */
5325 { 0x15, 0x0221142f }, /* front HP */
5326 { 0x1b, 0x0121141f }, /* rear HP */
5327 { }
5328 }
5329 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005330 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005331 .type = ALC_FIXUP_PINS,
5332 .v.pins = (const struct alc_pincfg[]) {
5333 { 0x16, 0x99130120 }, /* internal speaker */
5334 { }
5335 }
5336 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005337 [ALC262_FIXUP_TYAN] = {
5338 .type = ALC_FIXUP_PINS,
5339 .v.pins = (const struct alc_pincfg[]) {
5340 { 0x14, 0x1993e1f0 }, /* int AUX */
5341 { }
5342 }
5343 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005344 [ALC262_FIXUP_LENOVO_3000] = {
5345 .type = ALC_FIXUP_VERBS,
5346 .v.verbs = (const struct hda_verb[]) {
5347 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005348 {}
5349 },
5350 .chained = true,
5351 .chain_id = ALC262_FIXUP_BENQ,
5352 },
5353 [ALC262_FIXUP_BENQ] = {
5354 .type = ALC_FIXUP_VERBS,
5355 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005356 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5357 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5358 {}
5359 }
5360 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005361 [ALC262_FIXUP_BENQ_T31] = {
5362 .type = ALC_FIXUP_VERBS,
5363 .v.verbs = (const struct hda_verb[]) {
5364 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5365 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5366 {}
5367 }
5368 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005369};
5370
5371static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005372 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005373 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5374 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005375 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5376 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005377 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005378 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5379 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005380 {}
5381};
5382
5383
5384#ifdef CONFIG_SND_HDA_POWER_SAVE
5385#define alc262_loopbacks alc880_loopbacks
5386#endif
5387
Takashi Iwai1d045db2011-07-07 18:23:21 +02005388/*
5389 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005390static int patch_alc262(struct hda_codec *codec)
5391{
5392 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005393 int err;
5394
5395 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5396 if (spec == NULL)
5397 return -ENOMEM;
5398
5399 codec->spec = spec;
5400
5401 spec->mixer_nid = 0x0b;
5402
5403#if 0
5404 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5405 * under-run
5406 */
5407 {
5408 int tmp;
5409 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5410 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5411 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5412 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5413 }
5414#endif
5415 alc_auto_parse_customize_define(codec);
5416
5417 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5418
Takashi Iwai42399f72011-11-07 17:18:44 +01005419 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5420 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005421
Takashi Iwai42399f72011-11-07 17:18:44 +01005422 /* automatic parse from the BIOS config */
5423 err = alc262_parse_auto_config(codec);
5424 if (err < 0)
5425 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005426
Takashi Iwai60a6a842011-07-27 14:01:24 +02005427 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005428 alc_auto_fill_adc_caps(codec);
5429 alc_rebuild_imux_for_auto_mic(codec);
5430 alc_remove_invalid_adc_nids(codec);
5431 }
5432
5433 if (!spec->no_analog && !spec->cap_mixer)
5434 set_capture_mixer(codec);
5435
Takashi Iwai1d045db2011-07-07 18:23:21 +02005436 if (!spec->no_analog && has_cdefine_beep(codec)) {
5437 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005438 if (err < 0)
5439 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005440 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005441 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005442
Takashi Iwai1d045db2011-07-07 18:23:21 +02005443 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01005444 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005445 spec->shutup = alc_eapd_shutup;
5446
Takashi Iwai1d045db2011-07-07 18:23:21 +02005447#ifdef CONFIG_SND_HDA_POWER_SAVE
5448 if (!spec->loopback.amplist)
5449 spec->loopback.amplist = alc262_loopbacks;
5450#endif
5451
Takashi Iwai589876e2012-02-20 15:47:55 +01005452 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5453
Takashi Iwai1d045db2011-07-07 18:23:21 +02005454 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005455
5456 error:
5457 alc_free(codec);
5458 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005459}
5460
5461/*
5462 * ALC268
5463 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005464/* bind Beep switches of both NID 0x0f and 0x10 */
5465static const struct hda_bind_ctls alc268_bind_beep_sw = {
5466 .ops = &snd_hda_bind_sw,
5467 .values = {
5468 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5469 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5470 0
5471 },
5472};
5473
5474static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5475 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5476 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5477 { }
5478};
5479
5480/* set PCBEEP vol = 0, mute connections */
5481static const struct hda_verb alc268_beep_init_verbs[] = {
5482 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5483 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5484 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5485 { }
5486};
5487
5488/*
5489 * BIOS auto configuration
5490 */
5491static int alc268_parse_auto_config(struct hda_codec *codec)
5492{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005493 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005494 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005495 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5496 if (err > 0) {
5497 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5498 add_mixer(spec, alc268_beep_mixer);
5499 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005500 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005501 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005502 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005503}
5504
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505/*
5506 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005507static int patch_alc268(struct hda_codec *codec)
5508{
5509 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005510 int i, has_beep, err;
5511
5512 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5513 if (spec == NULL)
5514 return -ENOMEM;
5515
5516 codec->spec = spec;
5517
5518 /* ALC268 has no aa-loopback mixer */
5519
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005520 /* automatic parse from the BIOS config */
5521 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005522 if (err < 0)
5523 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005524
Takashi Iwai1d045db2011-07-07 18:23:21 +02005525 has_beep = 0;
5526 for (i = 0; i < spec->num_mixers; i++) {
5527 if (spec->mixers[i] == alc268_beep_mixer) {
5528 has_beep = 1;
5529 break;
5530 }
5531 }
5532
5533 if (has_beep) {
5534 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005535 if (err < 0)
5536 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005537 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5538 /* override the amp caps for beep generator */
5539 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5540 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5541 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5542 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5543 (0 << AC_AMPCAP_MUTE_SHIFT));
5544 }
5545
Takashi Iwai60a6a842011-07-27 14:01:24 +02005546 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005547 alc_auto_fill_adc_caps(codec);
5548 alc_rebuild_imux_for_auto_mic(codec);
5549 alc_remove_invalid_adc_nids(codec);
5550 }
5551
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005552 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005553 set_capture_mixer(codec);
5554
Takashi Iwai1d045db2011-07-07 18:23:21 +02005555 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005556 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005557 spec->shutup = alc_eapd_shutup;
5558
Takashi Iwai1d045db2011-07-07 18:23:21 +02005559 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005560
5561 error:
5562 alc_free(codec);
5563 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005564}
5565
5566/*
5567 * ALC269
5568 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005569#ifdef CONFIG_SND_HDA_POWER_SAVE
5570#define alc269_loopbacks alc880_loopbacks
5571#endif
5572
5573static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5574 .substreams = 1,
5575 .channels_min = 2,
5576 .channels_max = 8,
5577 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5578 /* NID is set in alc_build_pcms */
5579 .ops = {
5580 .open = alc_playback_pcm_open,
5581 .prepare = alc_playback_pcm_prepare,
5582 .cleanup = alc_playback_pcm_cleanup
5583 },
5584};
5585
5586static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5587 .substreams = 1,
5588 .channels_min = 2,
5589 .channels_max = 2,
5590 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5591 /* NID is set in alc_build_pcms */
5592};
5593
5594#ifdef CONFIG_SND_HDA_POWER_SAVE
5595static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5596{
5597 switch (codec->subsystem_id) {
5598 case 0x103c1586:
5599 return 1;
5600 }
5601 return 0;
5602}
5603
5604static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5605{
5606 /* update mute-LED according to the speaker mute state */
5607 if (nid == 0x01 || nid == 0x14) {
5608 int pinval;
5609 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5610 HDA_AMP_MUTE)
5611 pinval = 0x24;
5612 else
5613 pinval = 0x20;
5614 /* mic2 vref pin is used for mute LED control */
5615 snd_hda_codec_update_cache(codec, 0x19, 0,
5616 AC_VERB_SET_PIN_WIDGET_CONTROL,
5617 pinval);
5618 }
5619 return alc_check_power_status(codec, nid);
5620}
5621#endif /* CONFIG_SND_HDA_POWER_SAVE */
5622
5623/* different alc269-variants */
5624enum {
5625 ALC269_TYPE_ALC269VA,
5626 ALC269_TYPE_ALC269VB,
5627 ALC269_TYPE_ALC269VC,
5628};
5629
5630/*
5631 * BIOS auto configuration
5632 */
5633static int alc269_parse_auto_config(struct hda_codec *codec)
5634{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005635 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005636 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5637 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5638 struct alc_spec *spec = codec->spec;
5639 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5640 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005641
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005642 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643}
5644
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5646{
5647 int val = alc_read_coef_idx(codec, 0x04);
5648 if (power_up)
5649 val |= 1 << 11;
5650 else
5651 val &= ~(1 << 11);
5652 alc_write_coef_idx(codec, 0x04, val);
5653}
5654
5655static void alc269_shutup(struct hda_codec *codec)
5656{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005657 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005658 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005659 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005660 alc269_toggle_power_output(codec, 0);
5661 msleep(150);
5662 }
5663}
5664
Takashi Iwai2a439522011-07-26 09:52:50 +02005665#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005666static int alc269_resume(struct hda_codec *codec)
5667{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005668 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005669 alc269_toggle_power_output(codec, 0);
5670 msleep(150);
5671 }
5672
5673 codec->patch_ops.init(codec);
5674
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005675 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005676 alc269_toggle_power_output(codec, 1);
5677 msleep(200);
5678 }
5679
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005680 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005681 alc269_toggle_power_output(codec, 1);
5682
5683 snd_hda_codec_resume_amp(codec);
5684 snd_hda_codec_resume_cache(codec);
5685 hda_call_check_power_status(codec, 0x01);
5686 return 0;
5687}
Takashi Iwai2a439522011-07-26 09:52:50 +02005688#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005689
5690static void alc269_fixup_hweq(struct hda_codec *codec,
5691 const struct alc_fixup *fix, int action)
5692{
5693 int coef;
5694
5695 if (action != ALC_FIXUP_ACT_INIT)
5696 return;
5697 coef = alc_read_coef_idx(codec, 0x1e);
5698 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5699}
5700
5701static void alc271_fixup_dmic(struct hda_codec *codec,
5702 const struct alc_fixup *fix, int action)
5703{
5704 static const struct hda_verb verbs[] = {
5705 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5706 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5707 {}
5708 };
5709 unsigned int cfg;
5710
5711 if (strcmp(codec->chip_name, "ALC271X"))
5712 return;
5713 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5714 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5715 snd_hda_sequence_write(codec, verbs);
5716}
5717
Takashi Iwai017f2a12011-07-09 14:42:25 +02005718static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5719 const struct alc_fixup *fix, int action)
5720{
5721 struct alc_spec *spec = codec->spec;
5722
5723 if (action != ALC_FIXUP_ACT_PROBE)
5724 return;
5725
5726 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5727 * fix the sample rate of analog I/O to 44.1kHz
5728 */
5729 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5730 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5731}
5732
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005733static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5734 const struct alc_fixup *fix, int action)
5735{
5736 int coef;
5737
5738 if (action != ALC_FIXUP_ACT_INIT)
5739 return;
5740 /* The digital-mic unit sends PDM (differential signal) instead of
5741 * the standard PCM, thus you can't record a valid mono stream as is.
5742 * Below is a workaround specific to ALC269 to control the dmic
5743 * signal source as mono.
5744 */
5745 coef = alc_read_coef_idx(codec, 0x07);
5746 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5747}
5748
Takashi Iwai24519912011-08-16 15:08:49 +02005749static void alc269_quanta_automute(struct hda_codec *codec)
5750{
David Henningsson42cf0d02011-09-20 12:04:56 +02005751 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005752
5753 snd_hda_codec_write(codec, 0x20, 0,
5754 AC_VERB_SET_COEF_INDEX, 0x0c);
5755 snd_hda_codec_write(codec, 0x20, 0,
5756 AC_VERB_SET_PROC_COEF, 0x680);
5757
5758 snd_hda_codec_write(codec, 0x20, 0,
5759 AC_VERB_SET_COEF_INDEX, 0x0c);
5760 snd_hda_codec_write(codec, 0x20, 0,
5761 AC_VERB_SET_PROC_COEF, 0x480);
5762}
5763
5764static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5765 const struct alc_fixup *fix, int action)
5766{
5767 struct alc_spec *spec = codec->spec;
5768 if (action != ALC_FIXUP_ACT_PROBE)
5769 return;
5770 spec->automute_hook = alc269_quanta_automute;
5771}
5772
Takashi Iwai1d045db2011-07-07 18:23:21 +02005773enum {
5774 ALC269_FIXUP_SONY_VAIO,
5775 ALC275_FIXUP_SONY_VAIO_GPIO2,
5776 ALC269_FIXUP_DELL_M101Z,
5777 ALC269_FIXUP_SKU_IGNORE,
5778 ALC269_FIXUP_ASUS_G73JW,
5779 ALC269_FIXUP_LENOVO_EAPD,
5780 ALC275_FIXUP_SONY_HWEQ,
5781 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005782 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005783 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005784 ALC269_FIXUP_QUANTA_MUTE,
5785 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005786 ALC269_FIXUP_AMIC,
5787 ALC269_FIXUP_DMIC,
5788 ALC269VB_FIXUP_AMIC,
5789 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005790};
5791
5792static const struct alc_fixup alc269_fixups[] = {
5793 [ALC269_FIXUP_SONY_VAIO] = {
5794 .type = ALC_FIXUP_VERBS,
5795 .v.verbs = (const struct hda_verb[]) {
5796 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5797 {}
5798 }
5799 },
5800 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5801 .type = ALC_FIXUP_VERBS,
5802 .v.verbs = (const struct hda_verb[]) {
5803 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5804 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5805 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5806 { }
5807 },
5808 .chained = true,
5809 .chain_id = ALC269_FIXUP_SONY_VAIO
5810 },
5811 [ALC269_FIXUP_DELL_M101Z] = {
5812 .type = ALC_FIXUP_VERBS,
5813 .v.verbs = (const struct hda_verb[]) {
5814 /* Enables internal speaker */
5815 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5816 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5817 {}
5818 }
5819 },
5820 [ALC269_FIXUP_SKU_IGNORE] = {
5821 .type = ALC_FIXUP_SKU,
5822 .v.sku = ALC_FIXUP_SKU_IGNORE,
5823 },
5824 [ALC269_FIXUP_ASUS_G73JW] = {
5825 .type = ALC_FIXUP_PINS,
5826 .v.pins = (const struct alc_pincfg[]) {
5827 { 0x17, 0x99130111 }, /* subwoofer */
5828 { }
5829 }
5830 },
5831 [ALC269_FIXUP_LENOVO_EAPD] = {
5832 .type = ALC_FIXUP_VERBS,
5833 .v.verbs = (const struct hda_verb[]) {
5834 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5835 {}
5836 }
5837 },
5838 [ALC275_FIXUP_SONY_HWEQ] = {
5839 .type = ALC_FIXUP_FUNC,
5840 .v.func = alc269_fixup_hweq,
5841 .chained = true,
5842 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5843 },
5844 [ALC271_FIXUP_DMIC] = {
5845 .type = ALC_FIXUP_FUNC,
5846 .v.func = alc271_fixup_dmic,
5847 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005848 [ALC269_FIXUP_PCM_44K] = {
5849 .type = ALC_FIXUP_FUNC,
5850 .v.func = alc269_fixup_pcm_44k,
5851 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005852 [ALC269_FIXUP_STEREO_DMIC] = {
5853 .type = ALC_FIXUP_FUNC,
5854 .v.func = alc269_fixup_stereo_dmic,
5855 },
Takashi Iwai24519912011-08-16 15:08:49 +02005856 [ALC269_FIXUP_QUANTA_MUTE] = {
5857 .type = ALC_FIXUP_FUNC,
5858 .v.func = alc269_fixup_quanta_mute,
5859 },
5860 [ALC269_FIXUP_LIFEBOOK] = {
5861 .type = ALC_FIXUP_PINS,
5862 .v.pins = (const struct alc_pincfg[]) {
5863 { 0x1a, 0x2101103f }, /* dock line-out */
5864 { 0x1b, 0x23a11040 }, /* dock mic-in */
5865 { }
5866 },
5867 .chained = true,
5868 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5869 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005870 [ALC269_FIXUP_AMIC] = {
5871 .type = ALC_FIXUP_PINS,
5872 .v.pins = (const struct alc_pincfg[]) {
5873 { 0x14, 0x99130110 }, /* speaker */
5874 { 0x15, 0x0121401f }, /* HP out */
5875 { 0x18, 0x01a19c20 }, /* mic */
5876 { 0x19, 0x99a3092f }, /* int-mic */
5877 { }
5878 },
5879 },
5880 [ALC269_FIXUP_DMIC] = {
5881 .type = ALC_FIXUP_PINS,
5882 .v.pins = (const struct alc_pincfg[]) {
5883 { 0x12, 0x99a3092f }, /* int-mic */
5884 { 0x14, 0x99130110 }, /* speaker */
5885 { 0x15, 0x0121401f }, /* HP out */
5886 { 0x18, 0x01a19c20 }, /* mic */
5887 { }
5888 },
5889 },
5890 [ALC269VB_FIXUP_AMIC] = {
5891 .type = ALC_FIXUP_PINS,
5892 .v.pins = (const struct alc_pincfg[]) {
5893 { 0x14, 0x99130110 }, /* speaker */
5894 { 0x18, 0x01a19c20 }, /* mic */
5895 { 0x19, 0x99a3092f }, /* int-mic */
5896 { 0x21, 0x0121401f }, /* HP out */
5897 { }
5898 },
5899 },
David Henningsson2267ea92012-01-03 08:45:56 +01005900 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02005901 .type = ALC_FIXUP_PINS,
5902 .v.pins = (const struct alc_pincfg[]) {
5903 { 0x12, 0x99a3092f }, /* int-mic */
5904 { 0x14, 0x99130110 }, /* speaker */
5905 { 0x18, 0x01a19c20 }, /* mic */
5906 { 0x21, 0x0121401f }, /* HP out */
5907 { }
5908 },
5909 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005910};
5911
5912static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005913 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005914 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5915 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5916 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5917 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5918 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005919 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5920 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5921 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5922 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5923 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5924 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005925 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005926 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5927 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5928 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5929 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5930 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005931 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005932 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005933 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005934
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01005935#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02005936 /* Below is a quirk table taken from the old code.
5937 * Basically the device should work as is without the fixup table.
5938 * If BIOS doesn't give a proper info, enable the corresponding
5939 * fixup entry.
5940 */
5941 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5942 ALC269_FIXUP_AMIC),
5943 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005944 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5945 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5946 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5947 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5948 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5949 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5950 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5951 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5952 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5953 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5954 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5955 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5956 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5957 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5958 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5959 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5960 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5961 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5962 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5963 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5964 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5965 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5966 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5967 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5968 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5969 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5970 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5971 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5972 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5973 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5974 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5975 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5976 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5977 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5978 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5979 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5980 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5981 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5982#endif
5983 {}
5984};
5985
5986static const struct alc_model_fixup alc269_fixup_models[] = {
5987 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5988 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005989 {}
5990};
5991
5992
5993static int alc269_fill_coef(struct hda_codec *codec)
5994{
5995 int val;
5996
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005997 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005998 alc_write_coef_idx(codec, 0xf, 0x960b);
5999 alc_write_coef_idx(codec, 0xe, 0x8817);
6000 }
6001
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006002 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006003 alc_write_coef_idx(codec, 0xf, 0x960b);
6004 alc_write_coef_idx(codec, 0xe, 0x8814);
6005 }
6006
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006007 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006008 val = alc_read_coef_idx(codec, 0x04);
6009 /* Power up output pin */
6010 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6011 }
6012
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006013 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006014 val = alc_read_coef_idx(codec, 0xd);
6015 if ((val & 0x0c00) >> 10 != 0x1) {
6016 /* Capless ramp up clock control */
6017 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6018 }
6019 val = alc_read_coef_idx(codec, 0x17);
6020 if ((val & 0x01c0) >> 6 != 0x4) {
6021 /* Class D power on reset */
6022 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6023 }
6024 }
6025
6026 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6027 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6028
6029 val = alc_read_coef_idx(codec, 0x4); /* HP */
6030 alc_write_coef_idx(codec, 0x4, val | (1<<11));
6031
6032 return 0;
6033}
6034
6035/*
6036 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006037static int patch_alc269(struct hda_codec *codec)
6038{
6039 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006040 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006041
6042 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6043 if (spec == NULL)
6044 return -ENOMEM;
6045
6046 codec->spec = spec;
6047
6048 spec->mixer_nid = 0x0b;
6049
6050 alc_auto_parse_customize_define(codec);
6051
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006052 err = alc_codec_rename_from_preset(codec);
6053 if (err < 0)
6054 goto error;
6055
Takashi Iwai1d045db2011-07-07 18:23:21 +02006056 if (codec->vendor_id == 0x10ec0269) {
6057 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006058 switch (alc_get_coef0(codec) & 0x00f0) {
6059 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006060 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006061 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006062 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006063 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006064 break;
6065 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006066 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6067 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006068 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006069 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006070 break;
6071 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006072 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006073 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006074 if (err < 0)
6075 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006076 alc269_fill_coef(codec);
6077 }
6078
Takashi Iwaia4297b52011-08-23 18:40:12 +02006079 alc_pick_fixup(codec, alc269_fixup_models,
6080 alc269_fixup_tbl, alc269_fixups);
6081 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006082
Takashi Iwaia4297b52011-08-23 18:40:12 +02006083 /* automatic parse from the BIOS config */
6084 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006085 if (err < 0)
6086 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006087
Takashi Iwai60a6a842011-07-27 14:01:24 +02006088 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006089 alc_auto_fill_adc_caps(codec);
6090 alc_rebuild_imux_for_auto_mic(codec);
6091 alc_remove_invalid_adc_nids(codec);
6092 }
6093
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006094 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006095 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006096
6097 if (!spec->no_analog && has_cdefine_beep(codec)) {
6098 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006099 if (err < 0)
6100 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006101 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006102 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006103
Takashi Iwai1d045db2011-07-07 18:23:21 +02006104 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006105#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006106 codec->patch_ops.resume = alc269_resume;
6107#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02006108 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006109 spec->shutup = alc269_shutup;
6110
Takashi Iwai1d045db2011-07-07 18:23:21 +02006111#ifdef CONFIG_SND_HDA_POWER_SAVE
6112 if (!spec->loopback.amplist)
6113 spec->loopback.amplist = alc269_loopbacks;
6114 if (alc269_mic2_for_mute_led(codec))
6115 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
6116#endif
6117
Takashi Iwai589876e2012-02-20 15:47:55 +01006118 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6119
Takashi Iwai1d045db2011-07-07 18:23:21 +02006120 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006121
6122 error:
6123 alc_free(codec);
6124 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006125}
6126
6127/*
6128 * ALC861
6129 */
6130
Takashi Iwai1d045db2011-07-07 18:23:21 +02006131static int alc861_parse_auto_config(struct hda_codec *codec)
6132{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006133 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006134 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6135 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006136}
6137
Takashi Iwai1d045db2011-07-07 18:23:21 +02006138#ifdef CONFIG_SND_HDA_POWER_SAVE
6139static const struct hda_amp_list alc861_loopbacks[] = {
6140 { 0x15, HDA_INPUT, 0 },
6141 { 0x15, HDA_INPUT, 1 },
6142 { 0x15, HDA_INPUT, 2 },
6143 { 0x15, HDA_INPUT, 3 },
6144 { } /* end */
6145};
6146#endif
6147
6148
6149/* Pin config fixes */
6150enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006151 ALC861_FIXUP_FSC_AMILO_PI1505,
6152 ALC861_FIXUP_AMP_VREF_0F,
6153 ALC861_FIXUP_NO_JACK_DETECT,
6154 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006155};
6156
Takashi Iwai31150f22012-01-30 10:54:08 +01006157/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6158static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6159 const struct alc_fixup *fix, int action)
6160{
6161 struct alc_spec *spec = codec->spec;
6162 unsigned int val;
6163
6164 if (action != ALC_FIXUP_ACT_INIT)
6165 return;
6166 val = snd_hda_codec_read(codec, 0x0f, 0,
6167 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6168 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6169 val |= AC_PINCTL_IN_EN;
6170 val |= AC_PINCTL_VREF_50;
6171 snd_hda_codec_write(codec, 0x0f, 0,
6172 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6173 spec->keep_vref_in_automute = 1;
6174}
6175
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006176/* suppress the jack-detection */
6177static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6178 const struct alc_fixup *fix, int action)
6179{
6180 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6181 codec->no_jack_detect = 1;
6182}
6183
Takashi Iwai1d045db2011-07-07 18:23:21 +02006184static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006185 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006186 .type = ALC_FIXUP_PINS,
6187 .v.pins = (const struct alc_pincfg[]) {
6188 { 0x0b, 0x0221101f }, /* HP */
6189 { 0x0f, 0x90170310 }, /* speaker */
6190 { }
6191 }
6192 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006193 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006194 .type = ALC_FIXUP_FUNC,
6195 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006196 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006197 [ALC861_FIXUP_NO_JACK_DETECT] = {
6198 .type = ALC_FIXUP_FUNC,
6199 .v.func = alc_fixup_no_jack_detect,
6200 },
6201 [ALC861_FIXUP_ASUS_A6RP] = {
6202 .type = ALC_FIXUP_FUNC,
6203 .v.func = alc861_fixup_asus_amp_vref_0f,
6204 .chained = true,
6205 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6206 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006207};
6208
6209static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006210 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6211 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6212 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6213 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6214 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6215 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006216 {}
6217};
6218
6219/*
6220 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006221static int patch_alc861(struct hda_codec *codec)
6222{
6223 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006224 int err;
6225
6226 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6227 if (spec == NULL)
6228 return -ENOMEM;
6229
6230 codec->spec = spec;
6231
6232 spec->mixer_nid = 0x15;
6233
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006234 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6235 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006236
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006237 /* automatic parse from the BIOS config */
6238 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006239 if (err < 0)
6240 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006241
Takashi Iwai60a6a842011-07-27 14:01:24 +02006242 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006243 alc_auto_fill_adc_caps(codec);
6244 alc_rebuild_imux_for_auto_mic(codec);
6245 alc_remove_invalid_adc_nids(codec);
6246 }
6247
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006248 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006249 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006250
6251 if (!spec->no_analog) {
6252 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006253 if (err < 0)
6254 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006255 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6256 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006257
Takashi Iwai1d045db2011-07-07 18:23:21 +02006258 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006259 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006260#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006261 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006262 if (!spec->loopback.amplist)
6263 spec->loopback.amplist = alc861_loopbacks;
6264#endif
6265
Takashi Iwai589876e2012-02-20 15:47:55 +01006266 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6267
Takashi Iwai1d045db2011-07-07 18:23:21 +02006268 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006269
6270 error:
6271 alc_free(codec);
6272 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006273}
6274
6275/*
6276 * ALC861-VD support
6277 *
6278 * Based on ALC882
6279 *
6280 * In addition, an independent DAC
6281 */
6282#ifdef CONFIG_SND_HDA_POWER_SAVE
6283#define alc861vd_loopbacks alc880_loopbacks
6284#endif
6285
Takashi Iwai1d045db2011-07-07 18:23:21 +02006286static int alc861vd_parse_auto_config(struct hda_codec *codec)
6287{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006288 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006289 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6290 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006291}
6292
Takashi Iwai1d045db2011-07-07 18:23:21 +02006293enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006294 ALC660VD_FIX_ASUS_GPIO1,
6295 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006296};
6297
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006298/* exclude VREF80 */
6299static void alc861vd_fixup_dallas(struct hda_codec *codec,
6300 const struct alc_fixup *fix, int action)
6301{
6302 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6303 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6304 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6305 }
6306}
6307
Takashi Iwai1d045db2011-07-07 18:23:21 +02006308static const struct alc_fixup alc861vd_fixups[] = {
6309 [ALC660VD_FIX_ASUS_GPIO1] = {
6310 .type = ALC_FIXUP_VERBS,
6311 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006312 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006313 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6314 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6315 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6316 { }
6317 }
6318 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006319 [ALC861VD_FIX_DALLAS] = {
6320 .type = ALC_FIXUP_FUNC,
6321 .v.func = alc861vd_fixup_dallas,
6322 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006323};
6324
6325static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006326 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006327 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006328 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006329 {}
6330};
6331
6332static const struct hda_verb alc660vd_eapd_verbs[] = {
6333 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6334 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6335 { }
6336};
6337
6338/*
6339 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006340static int patch_alc861vd(struct hda_codec *codec)
6341{
6342 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006343 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006344
6345 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6346 if (spec == NULL)
6347 return -ENOMEM;
6348
6349 codec->spec = spec;
6350
6351 spec->mixer_nid = 0x0b;
6352
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006353 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6354 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006355
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006356 /* automatic parse from the BIOS config */
6357 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006358 if (err < 0)
6359 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006360
Takashi Iwai1d045db2011-07-07 18:23:21 +02006361 if (codec->vendor_id == 0x10ec0660) {
6362 /* always turn on EAPD */
6363 add_verb(spec, alc660vd_eapd_verbs);
6364 }
6365
Takashi Iwai60a6a842011-07-27 14:01:24 +02006366 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006367 alc_auto_fill_adc_caps(codec);
6368 alc_rebuild_imux_for_auto_mic(codec);
6369 alc_remove_invalid_adc_nids(codec);
6370 }
6371
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006372 if (!spec->no_analog && !spec->cap_mixer)
6373 set_capture_mixer(codec);
6374
6375 if (!spec->no_analog) {
6376 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006377 if (err < 0)
6378 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006379 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6380 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006381
Takashi Iwai1d045db2011-07-07 18:23:21 +02006382 codec->patch_ops = alc_patch_ops;
6383
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006384 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006385 spec->shutup = alc_eapd_shutup;
6386#ifdef CONFIG_SND_HDA_POWER_SAVE
6387 if (!spec->loopback.amplist)
6388 spec->loopback.amplist = alc861vd_loopbacks;
6389#endif
6390
Takashi Iwai589876e2012-02-20 15:47:55 +01006391 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6392
Takashi Iwai1d045db2011-07-07 18:23:21 +02006393 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006394
6395 error:
6396 alc_free(codec);
6397 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006398}
6399
6400/*
6401 * ALC662 support
6402 *
6403 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6404 * configuration. Each pin widget can choose any input DACs and a mixer.
6405 * Each ADC is connected from a mixer of all inputs. This makes possible
6406 * 6-channel independent captures.
6407 *
6408 * In addition, an independent DAC for the multi-playback (not used in this
6409 * driver yet).
6410 */
6411#ifdef CONFIG_SND_HDA_POWER_SAVE
6412#define alc662_loopbacks alc880_loopbacks
6413#endif
6414
6415/*
6416 * BIOS auto configuration
6417 */
6418
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006419static int alc662_parse_auto_config(struct hda_codec *codec)
6420{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006421 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006422 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6423 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6424 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006425
Kailang Yang6227cdc2010-02-25 08:36:52 +01006426 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6427 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006428 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006429 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006430 ssids = alc662_ssids;
6431 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006432}
6433
Todd Broch6be79482010-12-07 16:51:05 -08006434static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006435 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006436{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006437 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006438 return;
Todd Broch6be79482010-12-07 16:51:05 -08006439 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6440 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6441 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6442 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6443 (0 << AC_AMPCAP_MUTE_SHIFT)))
6444 printk(KERN_WARNING
6445 "hda_codec: failed to override amp caps for NID 0x2\n");
6446}
6447
David Henningsson6cb3b702010-09-09 08:51:44 +02006448enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006449 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006450 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006451 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006452 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006453 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006454 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006455 ALC662_FIXUP_ASUS_MODE1,
6456 ALC662_FIXUP_ASUS_MODE2,
6457 ALC662_FIXUP_ASUS_MODE3,
6458 ALC662_FIXUP_ASUS_MODE4,
6459 ALC662_FIXUP_ASUS_MODE5,
6460 ALC662_FIXUP_ASUS_MODE6,
6461 ALC662_FIXUP_ASUS_MODE7,
6462 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006463 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006464};
6465
6466static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006467 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006468 .type = ALC_FIXUP_PINS,
6469 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006470 { 0x15, 0x99130112 }, /* subwoofer */
6471 { }
6472 }
6473 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006474 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006475 .type = ALC_FIXUP_PINS,
6476 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006477 { 0x17, 0x99130112 }, /* subwoofer */
6478 { }
6479 }
6480 },
Todd Broch6be79482010-12-07 16:51:05 -08006481 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006482 .type = ALC_FIXUP_FUNC,
6483 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006484 },
6485 [ALC662_FIXUP_CZC_P10T] = {
6486 .type = ALC_FIXUP_VERBS,
6487 .v.verbs = (const struct hda_verb[]) {
6488 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6489 {}
6490 }
6491 },
David Henningsson94024cd2011-04-29 14:10:55 +02006492 [ALC662_FIXUP_SKU_IGNORE] = {
6493 .type = ALC_FIXUP_SKU,
6494 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006495 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006496 [ALC662_FIXUP_HP_RP5800] = {
6497 .type = ALC_FIXUP_PINS,
6498 .v.pins = (const struct alc_pincfg[]) {
6499 { 0x14, 0x0221201f }, /* HP out */
6500 { }
6501 },
6502 .chained = true,
6503 .chain_id = ALC662_FIXUP_SKU_IGNORE
6504 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006505 [ALC662_FIXUP_ASUS_MODE1] = {
6506 .type = ALC_FIXUP_PINS,
6507 .v.pins = (const struct alc_pincfg[]) {
6508 { 0x14, 0x99130110 }, /* speaker */
6509 { 0x18, 0x01a19c20 }, /* mic */
6510 { 0x19, 0x99a3092f }, /* int-mic */
6511 { 0x21, 0x0121401f }, /* HP out */
6512 { }
6513 },
6514 .chained = true,
6515 .chain_id = ALC662_FIXUP_SKU_IGNORE
6516 },
6517 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006518 .type = ALC_FIXUP_PINS,
6519 .v.pins = (const struct alc_pincfg[]) {
6520 { 0x14, 0x99130110 }, /* speaker */
6521 { 0x18, 0x01a19820 }, /* mic */
6522 { 0x19, 0x99a3092f }, /* int-mic */
6523 { 0x1b, 0x0121401f }, /* HP out */
6524 { }
6525 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006526 .chained = true,
6527 .chain_id = ALC662_FIXUP_SKU_IGNORE
6528 },
6529 [ALC662_FIXUP_ASUS_MODE3] = {
6530 .type = ALC_FIXUP_PINS,
6531 .v.pins = (const struct alc_pincfg[]) {
6532 { 0x14, 0x99130110 }, /* speaker */
6533 { 0x15, 0x0121441f }, /* HP */
6534 { 0x18, 0x01a19840 }, /* mic */
6535 { 0x19, 0x99a3094f }, /* int-mic */
6536 { 0x21, 0x01211420 }, /* HP2 */
6537 { }
6538 },
6539 .chained = true,
6540 .chain_id = ALC662_FIXUP_SKU_IGNORE
6541 },
6542 [ALC662_FIXUP_ASUS_MODE4] = {
6543 .type = ALC_FIXUP_PINS,
6544 .v.pins = (const struct alc_pincfg[]) {
6545 { 0x14, 0x99130110 }, /* speaker */
6546 { 0x16, 0x99130111 }, /* speaker */
6547 { 0x18, 0x01a19840 }, /* mic */
6548 { 0x19, 0x99a3094f }, /* int-mic */
6549 { 0x21, 0x0121441f }, /* HP */
6550 { }
6551 },
6552 .chained = true,
6553 .chain_id = ALC662_FIXUP_SKU_IGNORE
6554 },
6555 [ALC662_FIXUP_ASUS_MODE5] = {
6556 .type = ALC_FIXUP_PINS,
6557 .v.pins = (const struct alc_pincfg[]) {
6558 { 0x14, 0x99130110 }, /* speaker */
6559 { 0x15, 0x0121441f }, /* HP */
6560 { 0x16, 0x99130111 }, /* speaker */
6561 { 0x18, 0x01a19840 }, /* mic */
6562 { 0x19, 0x99a3094f }, /* int-mic */
6563 { }
6564 },
6565 .chained = true,
6566 .chain_id = ALC662_FIXUP_SKU_IGNORE
6567 },
6568 [ALC662_FIXUP_ASUS_MODE6] = {
6569 .type = ALC_FIXUP_PINS,
6570 .v.pins = (const struct alc_pincfg[]) {
6571 { 0x14, 0x99130110 }, /* speaker */
6572 { 0x15, 0x01211420 }, /* HP2 */
6573 { 0x18, 0x01a19840 }, /* mic */
6574 { 0x19, 0x99a3094f }, /* int-mic */
6575 { 0x1b, 0x0121441f }, /* HP */
6576 { }
6577 },
6578 .chained = true,
6579 .chain_id = ALC662_FIXUP_SKU_IGNORE
6580 },
6581 [ALC662_FIXUP_ASUS_MODE7] = {
6582 .type = ALC_FIXUP_PINS,
6583 .v.pins = (const struct alc_pincfg[]) {
6584 { 0x14, 0x99130110 }, /* speaker */
6585 { 0x17, 0x99130111 }, /* speaker */
6586 { 0x18, 0x01a19840 }, /* mic */
6587 { 0x19, 0x99a3094f }, /* int-mic */
6588 { 0x1b, 0x01214020 }, /* HP */
6589 { 0x21, 0x0121401f }, /* HP */
6590 { }
6591 },
6592 .chained = true,
6593 .chain_id = ALC662_FIXUP_SKU_IGNORE
6594 },
6595 [ALC662_FIXUP_ASUS_MODE8] = {
6596 .type = ALC_FIXUP_PINS,
6597 .v.pins = (const struct alc_pincfg[]) {
6598 { 0x14, 0x99130110 }, /* speaker */
6599 { 0x12, 0x99a30970 }, /* int-mic */
6600 { 0x15, 0x01214020 }, /* HP */
6601 { 0x17, 0x99130111 }, /* speaker */
6602 { 0x18, 0x01a19840 }, /* mic */
6603 { 0x21, 0x0121401f }, /* HP */
6604 { }
6605 },
6606 .chained = true,
6607 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006608 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006609 [ALC662_FIXUP_NO_JACK_DETECT] = {
6610 .type = ALC_FIXUP_FUNC,
6611 .v.func = alc_fixup_no_jack_detect,
6612 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006613};
6614
Takashi Iwaia9111322011-05-02 11:30:18 +02006615static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006616 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006617 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006618 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006619 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006620 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006621 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006622 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006623 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006624 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006625 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006626 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006627
6628#if 0
6629 /* Below is a quirk table taken from the old code.
6630 * Basically the device should work as is without the fixup table.
6631 * If BIOS doesn't give a proper info, enable the corresponding
6632 * fixup entry.
6633 */
6634 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6635 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6636 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6637 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6638 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6639 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6640 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6641 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6642 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6643 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6644 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6645 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6646 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6647 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6648 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6649 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6650 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6651 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6652 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6653 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6654 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6655 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6656 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6657 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6658 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6659 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6660 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6661 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6662 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6663 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6664 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6665 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6666 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6667 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6668 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6669 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6670 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6671 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6672 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6673 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6674 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6675 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6676 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6677 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6678 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6679 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6680 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6681 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6682 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6683 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6684#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006685 {}
6686};
6687
Todd Broch6be79482010-12-07 16:51:05 -08006688static const struct alc_model_fixup alc662_fixup_models[] = {
6689 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006690 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6691 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6692 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6693 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6694 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6695 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6696 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6697 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006698 {}
6699};
David Henningsson6cb3b702010-09-09 08:51:44 +02006700
6701
Takashi Iwai1d045db2011-07-07 18:23:21 +02006702/*
6703 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006704static int patch_alc662(struct hda_codec *codec)
6705{
6706 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006707 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006708
6709 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6710 if (!spec)
6711 return -ENOMEM;
6712
6713 codec->spec = spec;
6714
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006715 spec->mixer_nid = 0x0b;
6716
Takashi Iwai53c334a2011-08-23 18:27:14 +02006717 /* handle multiple HPs as is */
6718 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6719
Kailang Yangda00c242010-03-19 11:23:45 +01006720 alc_auto_parse_customize_define(codec);
6721
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006722 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6723
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006724 err = alc_codec_rename_from_preset(codec);
6725 if (err < 0)
6726 goto error;
6727
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006728 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006729 codec->bus->pci->subsystem_vendor == 0x1025 &&
6730 spec->cdefine.platform_type == 1) {
6731 if (alc_codec_rename(codec, "ALC272X") < 0)
6732 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006733 }
Kailang Yang274693f2009-12-03 10:07:50 +01006734
Takashi Iwaib9c51062011-08-24 18:08:07 +02006735 alc_pick_fixup(codec, alc662_fixup_models,
6736 alc662_fixup_tbl, alc662_fixups);
6737 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6738 /* automatic parse from the BIOS config */
6739 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006740 if (err < 0)
6741 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006742
Takashi Iwai60a6a842011-07-27 14:01:24 +02006743 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006744 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006745 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006746 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006747 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006748
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006749 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006750 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006751
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006752 if (!spec->no_analog && has_cdefine_beep(codec)) {
6753 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006754 if (err < 0)
6755 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006756 switch (codec->vendor_id) {
6757 case 0x10ec0662:
6758 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6759 break;
6760 case 0x10ec0272:
6761 case 0x10ec0663:
6762 case 0x10ec0665:
6763 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6764 break;
6765 case 0x10ec0273:
6766 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6767 break;
6768 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006769 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006770
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006771 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006772 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006773 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006774
Takashi Iwaicb53c622007-08-10 17:21:45 +02006775#ifdef CONFIG_SND_HDA_POWER_SAVE
6776 if (!spec->loopback.amplist)
6777 spec->loopback.amplist = alc662_loopbacks;
6778#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006779
Takashi Iwai589876e2012-02-20 15:47:55 +01006780 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6781
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006782 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006783
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006784 error:
6785 alc_free(codec);
6786 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006787}
6788
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006789/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006790 * ALC680 support
6791 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006792
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006793static int alc680_parse_auto_config(struct hda_codec *codec)
6794{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006795 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006796}
6797
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006798/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006799 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006800static int patch_alc680(struct hda_codec *codec)
6801{
6802 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006803 int err;
6804
6805 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6806 if (spec == NULL)
6807 return -ENOMEM;
6808
6809 codec->spec = spec;
6810
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006811 /* ALC680 has no aa-loopback mixer */
6812
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006813 /* automatic parse from the BIOS config */
6814 err = alc680_parse_auto_config(codec);
6815 if (err < 0) {
6816 alc_free(codec);
6817 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006818 }
6819
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006820 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006821 set_capture_mixer(codec);
6822
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006823 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006824 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006825
6826 return 0;
6827}
6828
6829/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006830 * patch entries
6831 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006832static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006833 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006834 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006835 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006836 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006837 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006838 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006839 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006840 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006841 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006842 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006843 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006844 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006845 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6846 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6847 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006848 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02006849 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006850 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6851 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006852 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6853 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006854 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006855 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006856 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006857 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006858 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006859 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006860 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006861 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006862 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006863 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006864 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006865 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006866 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006867 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02006868 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006869 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006870 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006871 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006872 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006873 {} /* terminator */
6874};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006875
6876MODULE_ALIAS("snd-hda-codec-id:10ec*");
6877
6878MODULE_LICENSE("GPL");
6879MODULE_DESCRIPTION("Realtek HD-audio codec");
6880
6881static struct hda_codec_preset_list realtek_list = {
6882 .preset = snd_hda_preset_realtek,
6883 .owner = THIS_MODULE,
6884};
6885
6886static int __init patch_realtek_init(void)
6887{
6888 return snd_hda_add_codec_preset(&realtek_list);
6889}
6890
6891static void __exit patch_realtek_exit(void)
6892{
6893 snd_hda_delete_codec_preset(&realtek_list);
6894}
6895
6896module_init(patch_realtek_init)
6897module_exit(patch_realtek_exit)