blob: a23479926f894e62963f7be05b199611aeb9331b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e482006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083struct alc_spec {
84 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020085 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010088 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Takashi Iwai2d9c6482009-10-13 08:06:55 +020090 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020091 * don't forget NULL
92 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020093 */
94 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Takashi Iwaiaa563af2009-07-31 10:05:11 +020096 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020097 const struct hda_pcm_stream *stream_analog_playback;
98 const struct hda_pcm_stream *stream_analog_capture;
99 const struct hda_pcm_stream *stream_analog_alt_playback;
100 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200102 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200103 const struct hda_pcm_stream *stream_digital_playback;
104 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200107 struct hda_multi_out multiout; /* playback set-up
108 * max_channels, dacs must be set
109 * dig_out_nid and hp_nid are optional
110 */
Takashi Iwai63300792008-01-24 15:31:36 +0100111 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100112 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100113 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* capture */
116 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200117 const hda_nid_t *adc_nids;
118 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200119 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200120 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwai527e4d72011-10-27 16:33:27 +0200121 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
122 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Takashi Iwai840b64c2010-07-13 22:49:01 +0200124 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200125 hda_nid_t cur_adc;
126 unsigned int cur_adc_stream_tag;
127 unsigned int cur_adc_format;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200130 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 const struct hda_input_mux *input_mux;
132 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200133 hda_nid_t ext_mic_pin;
134 hda_nid_t dock_mic_pin;
135 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100138 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200140 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200141 int const_channel_count;
142 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100145 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200146
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200147 /* dynamic controls, init_verbs and input_mux */
148 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100149 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200150 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200151 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200152 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200153 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200155 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
156 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
157 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100158
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100159 /* hooks */
160 void (*init_hook)(struct hda_codec *codec);
161 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100162#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500163 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200165 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200166 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100167
Takashi Iwai834be882006-03-01 14:16:17 +0100168 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200169 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200170 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200171 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200172 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200173 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200174 unsigned int automute_speaker:1; /* automute speaker outputs */
175 unsigned int automute_lo:1; /* automute LO outputs */
176 unsigned int detect_hp:1; /* Headphone detection enabled */
177 unsigned int detect_lo:1; /* Line-out detection enabled */
178 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
179 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200180
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100181 /* other flags */
182 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200183 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100184 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200185 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200186 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100187 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200188
189 /* auto-mute control */
190 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200191 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200192
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200193 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200194 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100195
Takashi Iwai2134ea42008-01-10 16:53:55 +0100196 /* for virtual master */
197 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200198#ifdef CONFIG_SND_HDA_POWER_SAVE
199 struct hda_loopback_check loopback;
200#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200201
202 /* for PLL fix */
203 hda_nid_t pll_nid;
204 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200205 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100206
207 /* fix-up list */
208 int fixup_id;
209 const struct alc_fixup *fixup_list;
210 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200211
212 /* multi-io */
213 int multi_ios;
214 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200215
216 /* bind volumes */
217 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100218};
219
Takashi Iwai1d045db2011-07-07 18:23:21 +0200220#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Takashi Iwai44c02402011-07-08 15:14:19 +0200222static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
223 int dir, unsigned int bits)
224{
225 if (!nid)
226 return false;
227 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
228 if (query_amp_caps(codec, nid, dir) & bits)
229 return true;
230 return false;
231}
232
233#define nid_has_mute(codec, nid, dir) \
234 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
235#define nid_has_volume(codec, nid, dir) \
236 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238/*
239 * input MUX handling
240 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200241static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
242 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
245 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200246 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
247 if (mux_idx >= spec->num_mux_defs)
248 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100249 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
250 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200251 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252}
253
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200254static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
258 struct alc_spec *spec = codec->spec;
259 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
260
261 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
262 return 0;
263}
264
Takashi Iwai21268962011-07-07 15:01:13 +0200265static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Takashi Iwai21268962011-07-07 15:01:13 +0200267 struct alc_spec *spec = codec->spec;
268 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
269
270 if (spec->cur_adc && spec->cur_adc != new_adc) {
271 /* stream is running, let's swap the current ADC */
272 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
273 spec->cur_adc = new_adc;
274 snd_hda_codec_setup_stream(codec, new_adc,
275 spec->cur_adc_stream_tag, 0,
276 spec->cur_adc_format);
277 return true;
278 }
279 return false;
280}
281
Takashi Iwai61071592011-11-23 07:52:15 +0100282static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
283{
284 return spec->capsrc_nids ?
285 spec->capsrc_nids[idx] : spec->adc_nids[idx];
286}
287
Takashi Iwai24de1832011-11-07 17:13:39 +0100288static void call_update_outputs(struct hda_codec *codec);
289
Takashi Iwai21268962011-07-07 15:01:13 +0200290/* select the given imux item; either unmute exclusively or select the route */
291static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
292 unsigned int idx, bool force)
293{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100295 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100296 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100297 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200298 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299
Takashi Iwaicd896c32008-11-18 12:36:33 +0100300 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
301 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100302 if (!imux->num_items && mux_idx > 0)
303 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100304 if (!imux->num_items)
305 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100306
Takashi Iwai21268962011-07-07 15:01:13 +0200307 if (idx >= imux->num_items)
308 idx = imux->num_items - 1;
309 if (spec->cur_mux[adc_idx] == idx && !force)
310 return 0;
311 spec->cur_mux[adc_idx] = idx;
312
Takashi Iwai24de1832011-11-07 17:13:39 +0100313 /* for shared I/O, change the pin-control accordingly */
314 if (spec->shared_mic_hp) {
315 /* NOTE: this assumes that there are only two inputs, the
316 * first is the real internal mic and the second is HP jack.
317 */
318 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
319 AC_VERB_SET_PIN_WIDGET_CONTROL,
320 spec->cur_mux[adc_idx] ?
321 PIN_VREF80 : PIN_HP);
322 spec->automute_speaker = !spec->cur_mux[adc_idx];
323 call_update_outputs(codec);
324 }
325
Takashi Iwai21268962011-07-07 15:01:13 +0200326 if (spec->dyn_adc_switch) {
327 alc_dyn_adc_pcm_resetup(codec, idx);
328 adc_idx = spec->dyn_adc_idx[idx];
329 }
330
Takashi Iwai61071592011-11-23 07:52:15 +0100331 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200332
333 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100334 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
335 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200336 return 1;
337
Takashi Iwaia22d5432009-07-27 12:54:26 +0200338 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200339 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100340 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100341 int active = imux->items[idx].index;
342 for (i = 0; i < num_conns; i++) {
343 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
344 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100345 HDA_AMP_MUTE, v);
346 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100347 } else {
348 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200349 snd_hda_codec_write_cache(codec, nid, 0,
350 AC_VERB_SET_CONNECT_SEL,
351 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100352 }
Takashi Iwai21268962011-07-07 15:01:13 +0200353 return 1;
354}
355
356static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
357 struct snd_ctl_elem_value *ucontrol)
358{
359 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
360 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
361 return alc_mux_select(codec, adc_idx,
362 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100363}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200364
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100366 * set up the input pin config (depending on the given auto-pin type)
367 */
368static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
369 int auto_pin_type)
370{
371 unsigned int val = PIN_IN;
372
Takashi Iwai86e29592010-09-09 14:50:17 +0200373 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100374 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200375 unsigned int oldval;
376 oldval = snd_hda_codec_read(codec, nid, 0,
377 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100378 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100379 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200380 /* if the default pin setup is vref50, we give it priority */
381 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100382 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200383 else if (pincap & AC_PINCAP_VREF_50)
384 val = PIN_VREF50;
385 else if (pincap & AC_PINCAP_VREF_100)
386 val = PIN_VREF100;
387 else if (pincap & AC_PINCAP_VREF_GRD)
388 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100389 }
390 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
391}
392
393/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200394 * Append the given mixer and verb elements for the later use
395 * The mixer array is referred in build_controls(), and init_verbs are
396 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100397 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200398static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100399{
400 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
401 return;
402 spec->mixers[spec->num_mixers++] = mix;
403}
404
405static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
406{
407 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
408 return;
409 spec->init_verbs[spec->num_init_verbs++] = verb;
410}
411
412/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200413 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100414 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200415/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200416static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200417 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
418 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
419 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
420 { }
421};
422
Takashi Iwaia9111322011-05-02 11:30:18 +0200423static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200424 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
425 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
426 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
427 { }
428};
429
Takashi Iwaia9111322011-05-02 11:30:18 +0200430static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200431 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
432 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
433 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
434 { }
435};
436
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200437/*
438 * Fix hardware PLL issue
439 * On some codecs, the analog PLL gating control must be off while
440 * the default value is 1.
441 */
442static void alc_fix_pll(struct hda_codec *codec)
443{
444 struct alc_spec *spec = codec->spec;
445 unsigned int val;
446
447 if (!spec->pll_nid)
448 return;
449 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
450 spec->pll_coef_idx);
451 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
452 AC_VERB_GET_PROC_COEF, 0);
453 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
454 spec->pll_coef_idx);
455 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
456 val & ~(1 << spec->pll_coef_bit));
457}
458
459static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
460 unsigned int coef_idx, unsigned int coef_bit)
461{
462 struct alc_spec *spec = codec->spec;
463 spec->pll_nid = nid;
464 spec->pll_coef_idx = coef_idx;
465 spec->pll_coef_bit = coef_bit;
466 alc_fix_pll(codec);
467}
468
Takashi Iwai1d045db2011-07-07 18:23:21 +0200469/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200470 * Jack detections for HP auto-mute and mic-switch
471 */
472
473/* check each pin in the given array; returns true if any of them is plugged */
474static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200475{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200476 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200477
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200478 for (i = 0; i < num_pins; i++) {
479 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200480 if (!nid)
481 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200482 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200483 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200484 return present;
485}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200486
Takashi Iwai1d045db2011-07-07 18:23:21 +0200487/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200488static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200489 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200490{
491 struct alc_spec *spec = codec->spec;
492 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200493 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200494 int i;
495
496 for (i = 0; i < num_pins; i++) {
497 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200498 if (!nid)
499 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200500 switch (spec->automute_mode) {
501 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200502 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200503 AC_VERB_SET_PIN_WIDGET_CONTROL,
504 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200505 break;
506 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200507 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200508 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200509 break;
510 case ALC_AUTOMUTE_MIXER:
511 nid = spec->automute_mixer_nid[i];
512 if (!nid)
513 break;
514 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200515 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200516 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200518 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200519 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200520 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200521}
522
David Henningsson42cf0d02011-09-20 12:04:56 +0200523/* Toggle outputs muting */
524static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200525{
526 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200527 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200528
Takashi Iwaic0a20262011-06-10 15:28:15 +0200529 /* Control HP pins/amps depending on master_mute state;
530 * in general, HP pins/amps control should be enabled in all cases,
531 * but currently set only for master_mute, just to be safe
532 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100533 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
534 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200535 spec->autocfg.hp_pins, spec->master_mute, true);
536
David Henningsson42cf0d02011-09-20 12:04:56 +0200537 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200538 on = 0;
539 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200540 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200541 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200542 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200543 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200544
545 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200546 /* if LO is a copy of either HP or Speaker, don't need to handle it */
547 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
548 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200549 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200550 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200551 on = 0;
552 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200553 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200554 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200555 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200556 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200557}
558
David Henningsson42cf0d02011-09-20 12:04:56 +0200559static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200560{
561 struct alc_spec *spec = codec->spec;
562 if (spec->automute_hook)
563 spec->automute_hook(codec);
564 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200565 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200566}
567
Takashi Iwai1d045db2011-07-07 18:23:21 +0200568/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200569static void alc_hp_automute(struct hda_codec *codec)
570{
571 struct alc_spec *spec = codec->spec;
572
David Henningsson42cf0d02011-09-20 12:04:56 +0200573 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200574 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
575 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200576 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200577 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200578 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200579}
580
Takashi Iwai1d045db2011-07-07 18:23:21 +0200581/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582static void alc_line_automute(struct hda_codec *codec)
583{
584 struct alc_spec *spec = codec->spec;
585
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200586 /* check LO jack only when it's different from HP */
587 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
588 return;
589
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590 spec->line_jack_present =
591 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
592 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200593 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200594 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200595 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200596}
597
Takashi Iwai8d087c72011-06-28 12:45:47 +0200598#define get_connection_index(codec, mux, nid) \
599 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200600
Takashi Iwai1d045db2011-07-07 18:23:21 +0200601/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200602static void alc_mic_automute(struct hda_codec *codec)
603{
604 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200605 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200606
Takashi Iwai21268962011-07-07 15:01:13 +0200607 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200608 return;
609 if (snd_BUG_ON(!spec->adc_nids))
610 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200611 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200612 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200613
Takashi Iwai21268962011-07-07 15:01:13 +0200614 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
615 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
616 else if (spec->dock_mic_idx >= 0 &&
617 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
618 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
619 else
620 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200621}
622
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100623/* handle the specified unsol action (ALC_XXX_EVENT) */
624static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200625{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100626 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200627 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200628 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200629 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200630 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200631 alc_line_automute(codec);
632 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200633 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200634 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200635 break;
636 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200637 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200638}
639
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100640/* unsolicited event for HP jack sensing */
641static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
642{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100643 if (codec->vendor_id == 0x10ec0880)
644 res >>= 28;
645 else
646 res >>= 26;
Takashi Iwaia7309792012-01-19 15:03:48 +0100647 res = snd_hda_jack_get_action(codec, res);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100648 alc_exec_unsol_event(codec, res);
649}
650
Takashi Iwai1d045db2011-07-07 18:23:21 +0200651/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200652static void alc_inithook(struct hda_codec *codec)
653{
Takashi Iwaid922b512011-04-28 12:18:53 +0200654 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200655 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200656 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200657}
658
Kailang Yangf9423e72008-05-27 12:32:25 +0200659/* additional initialization for ALC888 variants */
660static void alc888_coef_init(struct hda_codec *codec)
661{
662 unsigned int tmp;
663
664 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
665 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
666 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100667 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200668 /* alc888S-VC */
669 snd_hda_codec_read(codec, 0x20, 0,
670 AC_VERB_SET_PROC_COEF, 0x830);
671 else
672 /* alc888-VB */
673 snd_hda_codec_read(codec, 0x20, 0,
674 AC_VERB_SET_PROC_COEF, 0x3030);
675}
676
Takashi Iwai1d045db2011-07-07 18:23:21 +0200677/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200678static void alc889_coef_init(struct hda_codec *codec)
679{
680 unsigned int tmp;
681
682 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
683 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
684 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
685 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
686}
687
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100688/* turn on/off EAPD control (only if available) */
689static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
690{
691 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
692 return;
693 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
694 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
695 on ? 2 : 0);
696}
697
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200698/* turn on/off EAPD controls of the codec */
699static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
700{
701 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200702 static hda_nid_t pins[] = {
703 0x0f, 0x10, 0x14, 0x15, 0
704 };
705 hda_nid_t *p;
706 for (p = pins; *p; p++)
707 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200708}
709
Takashi Iwai1c7161532011-04-07 10:37:16 +0200710/* generic shutup callback;
711 * just turning off EPAD and a little pause for avoiding pop-noise
712 */
713static void alc_eapd_shutup(struct hda_codec *codec)
714{
715 alc_auto_setup_eapd(codec, false);
716 msleep(200);
717}
718
Takashi Iwai1d045db2011-07-07 18:23:21 +0200719/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200720static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200721{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200722 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200723
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200724 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200725 switch (type) {
726 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200727 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
728 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200729 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200730 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
731 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200732 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200733 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
734 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200735 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200736 switch (codec->vendor_id) {
737 case 0x10ec0260:
738 snd_hda_codec_write(codec, 0x1a, 0,
739 AC_VERB_SET_COEF_INDEX, 7);
740 tmp = snd_hda_codec_read(codec, 0x1a, 0,
741 AC_VERB_GET_PROC_COEF, 0);
742 snd_hda_codec_write(codec, 0x1a, 0,
743 AC_VERB_SET_COEF_INDEX, 7);
744 snd_hda_codec_write(codec, 0x1a, 0,
745 AC_VERB_SET_PROC_COEF,
746 tmp | 0x2010);
747 break;
748 case 0x10ec0262:
749 case 0x10ec0880:
750 case 0x10ec0882:
751 case 0x10ec0883:
752 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100753 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100754 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200755 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200756 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200757 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200758 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200759 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100760#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200761 case 0x10ec0267:
762 case 0x10ec0268:
763 snd_hda_codec_write(codec, 0x20, 0,
764 AC_VERB_SET_COEF_INDEX, 7);
765 tmp = snd_hda_codec_read(codec, 0x20, 0,
766 AC_VERB_GET_PROC_COEF, 0);
767 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200768 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200769 snd_hda_codec_write(codec, 0x20, 0,
770 AC_VERB_SET_PROC_COEF,
771 tmp | 0x3000);
772 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100773#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200774 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200775 break;
776 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777}
Kailang Yangea1fb292008-08-26 12:58:38 +0200778
Takashi Iwai1d045db2011-07-07 18:23:21 +0200779/*
780 * Auto-Mute mode mixer enum support
781 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200782static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
783 struct snd_ctl_elem_info *uinfo)
784{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200785 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
786 struct alc_spec *spec = codec->spec;
787 static const char * const texts2[] = {
788 "Disabled", "Enabled"
789 };
790 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200791 "Disabled", "Speaker Only", "Line-Out+Speaker"
792 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200793 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200794
795 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
796 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200797 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200798 uinfo->value.enumerated.items = 3;
799 texts = texts3;
800 } else {
801 uinfo->value.enumerated.items = 2;
802 texts = texts2;
803 }
804 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
805 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200806 strcpy(uinfo->value.enumerated.name,
807 texts[uinfo->value.enumerated.item]);
808 return 0;
809}
810
811static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_value *ucontrol)
813{
814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200816 unsigned int val = 0;
817 if (spec->automute_speaker)
818 val++;
819 if (spec->automute_lo)
820 val++;
821
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200822 ucontrol->value.enumerated.item[0] = val;
823 return 0;
824}
825
826static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
827 struct snd_ctl_elem_value *ucontrol)
828{
829 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
830 struct alc_spec *spec = codec->spec;
831
832 switch (ucontrol->value.enumerated.item[0]) {
833 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200834 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200835 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200836 spec->automute_speaker = 0;
837 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200838 break;
839 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200840 if (spec->automute_speaker_possible) {
841 if (!spec->automute_lo && spec->automute_speaker)
842 return 0;
843 spec->automute_speaker = 1;
844 spec->automute_lo = 0;
845 } else if (spec->automute_lo_possible) {
846 if (spec->automute_lo)
847 return 0;
848 spec->automute_lo = 1;
849 } else
850 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200851 break;
852 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200853 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200854 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200855 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200856 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200857 spec->automute_speaker = 1;
858 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200859 break;
860 default:
861 return -EINVAL;
862 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200863 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200864 return 1;
865}
866
Takashi Iwaia9111322011-05-02 11:30:18 +0200867static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200868 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
869 .name = "Auto-Mute Mode",
870 .info = alc_automute_mode_info,
871 .get = alc_automute_mode_get,
872 .put = alc_automute_mode_put,
873};
874
Takashi Iwai1d045db2011-07-07 18:23:21 +0200875static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
876{
877 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
878 return snd_array_new(&spec->kctls);
879}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880
881static int alc_add_automute_mode_enum(struct hda_codec *codec)
882{
883 struct alc_spec *spec = codec->spec;
884 struct snd_kcontrol_new *knew;
885
886 knew = alc_kcontrol_new(spec);
887 if (!knew)
888 return -ENOMEM;
889 *knew = alc_automute_mode_enum;
890 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
891 if (!knew->name)
892 return -ENOMEM;
893 return 0;
894}
895
Takashi Iwai1d045db2011-07-07 18:23:21 +0200896/*
897 * Check the availability of HP/line-out auto-mute;
898 * Set up appropriately if really supported
899 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200900static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200901{
902 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200903 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200904 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200905 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200906
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200907 if (cfg->hp_pins[0])
908 present++;
909 if (cfg->line_out_pins[0])
910 present++;
911 if (cfg->speaker_pins[0])
912 present++;
913 if (present < 2) /* need two different output types */
914 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200915
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200916 if (!cfg->speaker_pins[0] &&
917 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200918 memcpy(cfg->speaker_pins, cfg->line_out_pins,
919 sizeof(cfg->speaker_pins));
920 cfg->speaker_outs = cfg->line_outs;
921 }
922
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200923 if (!cfg->hp_pins[0] &&
924 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200925 memcpy(cfg->hp_pins, cfg->line_out_pins,
926 sizeof(cfg->hp_pins));
927 cfg->hp_outs = cfg->line_outs;
928 }
929
David Henningsson42cf0d02011-09-20 12:04:56 +0200930 spec->automute_mode = ALC_AUTOMUTE_PIN;
931
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200932 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200933 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200934 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200935 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200936 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200937 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200938 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200939 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200940 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200941
David Henningsson42cf0d02011-09-20 12:04:56 +0200942 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
943 if (cfg->speaker_outs)
944 for (i = 0; i < cfg->line_outs; i++) {
945 hda_nid_t nid = cfg->line_out_pins[i];
946 if (!is_jack_detectable(codec, nid))
947 continue;
948 snd_printdd("realtek: Enable Line-Out "
949 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200950 snd_hda_jack_detect_enable(codec, nid,
951 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200952 spec->detect_lo = 1;
953 }
954 spec->automute_lo_possible = spec->detect_hp;
955 }
956
957 spec->automute_speaker_possible = cfg->speaker_outs &&
958 (spec->detect_hp || spec->detect_lo);
959
960 spec->automute_lo = spec->automute_lo_possible;
961 spec->automute_speaker = spec->automute_speaker_possible;
962
963 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200964 /* create a control for automute mode */
965 alc_add_automute_mode_enum(codec);
966 spec->unsol_event = alc_sku_unsol_event;
967 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200968}
969
Takashi Iwai1d045db2011-07-07 18:23:21 +0200970/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200971static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
972{
973 int i;
974 for (i = 0; i < nums; i++)
975 if (list[i] == nid)
976 return i;
977 return -1;
978}
979
Takashi Iwai1d045db2011-07-07 18:23:21 +0200980/* check whether dynamic ADC-switching is available */
981static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
982{
983 struct alc_spec *spec = codec->spec;
984 struct hda_input_mux *imux = &spec->private_imux[0];
985 int i, n, idx;
986 hda_nid_t cap, pin;
987
988 if (imux != spec->input_mux) /* no dynamic imux? */
989 return false;
990
991 for (n = 0; n < spec->num_adc_nids; n++) {
992 cap = spec->private_capsrc_nids[n];
993 for (i = 0; i < imux->num_items; i++) {
994 pin = spec->imux_pins[i];
995 if (!pin)
996 return false;
997 if (get_connection_index(codec, cap, pin) < 0)
998 break;
999 }
1000 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001001 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001002 }
1003
1004 for (i = 0; i < imux->num_items; i++) {
1005 pin = spec->imux_pins[i];
1006 for (n = 0; n < spec->num_adc_nids; n++) {
1007 cap = spec->private_capsrc_nids[n];
1008 idx = get_connection_index(codec, cap, pin);
1009 if (idx >= 0) {
1010 imux->items[i].index = idx;
1011 spec->dyn_adc_idx[i] = n;
1012 break;
1013 }
1014 }
1015 }
1016
1017 snd_printdd("realtek: enabling ADC switching\n");
1018 spec->dyn_adc_switch = 1;
1019 return true;
1020}
Takashi Iwai21268962011-07-07 15:01:13 +02001021
1022/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1023static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1024{
1025 struct alc_spec *spec = codec->spec;
1026 struct hda_input_mux *imux;
1027 static char * const texts[3] = {
1028 "Mic", "Internal Mic", "Dock Mic"
1029 };
1030 int i;
1031
1032 if (!spec->auto_mic)
1033 return false;
1034 imux = &spec->private_imux[0];
1035 if (spec->input_mux == imux)
1036 return true;
1037 spec->imux_pins[0] = spec->ext_mic_pin;
1038 spec->imux_pins[1] = spec->int_mic_pin;
1039 spec->imux_pins[2] = spec->dock_mic_pin;
1040 for (i = 0; i < 3; i++) {
1041 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001042 if (spec->imux_pins[i]) {
1043 hda_nid_t pin = spec->imux_pins[i];
1044 int c;
1045 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001046 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001047 int idx = get_connection_index(codec, cap, pin);
1048 if (idx >= 0) {
1049 imux->items[i].index = idx;
1050 break;
1051 }
1052 }
Takashi Iwai21268962011-07-07 15:01:13 +02001053 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001054 }
Takashi Iwai21268962011-07-07 15:01:13 +02001055 }
1056 spec->num_mux_defs = 1;
1057 spec->input_mux = imux;
1058 return true;
1059}
1060
1061/* check whether all auto-mic pins are valid; setup indices if OK */
1062static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1063{
1064 struct alc_spec *spec = codec->spec;
1065 const struct hda_input_mux *imux;
1066
1067 if (!spec->auto_mic)
1068 return false;
1069 if (spec->auto_mic_valid_imux)
1070 return true; /* already checked */
1071
1072 /* fill up imux indices */
1073 if (!alc_check_dyn_adc_switch(codec)) {
1074 spec->auto_mic = 0;
1075 return false;
1076 }
1077
1078 imux = spec->input_mux;
1079 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1080 spec->imux_pins, imux->num_items);
1081 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1082 spec->imux_pins, imux->num_items);
1083 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1084 spec->imux_pins, imux->num_items);
1085 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1086 spec->auto_mic = 0;
1087 return false; /* no corresponding imux */
1088 }
1089
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001090 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001091 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001092 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1093 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001094
1095 spec->auto_mic_valid_imux = 1;
1096 spec->auto_mic = 1;
1097 return true;
1098}
1099
Takashi Iwai1d045db2011-07-07 18:23:21 +02001100/*
1101 * Check the availability of auto-mic switch;
1102 * Set up if really supported
1103 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001104static void alc_init_auto_mic(struct hda_codec *codec)
1105{
1106 struct alc_spec *spec = codec->spec;
1107 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001108 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001109 int i;
1110
Takashi Iwai24de1832011-11-07 17:13:39 +01001111 if (spec->shared_mic_hp)
1112 return; /* no auto-mic for the shared I/O */
1113
Takashi Iwai21268962011-07-07 15:01:13 +02001114 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1115
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001116 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001117 for (i = 0; i < cfg->num_inputs; i++) {
1118 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001119 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001120 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001121 switch (snd_hda_get_input_pin_attr(defcfg)) {
1122 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001123 if (fixed)
1124 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001125 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1126 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001127 fixed = nid;
1128 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001129 case INPUT_PIN_ATTR_UNUSED:
1130 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001131 case INPUT_PIN_ATTR_DOCK:
1132 if (dock)
1133 return; /* already occupied */
1134 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1135 return; /* invalid type */
1136 dock = nid;
1137 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001138 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001139 if (ext)
1140 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001141 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1142 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001143 ext = nid;
1144 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 }
1146 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001147 if (!ext && dock) {
1148 ext = dock;
1149 dock = 0;
1150 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001151 if (!ext || !fixed)
1152 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001153 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001154 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001155 if (dock && !is_jack_detectable(codec, dock))
1156 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001157
1158 /* check imux indices */
1159 spec->ext_mic_pin = ext;
1160 spec->int_mic_pin = fixed;
1161 spec->dock_mic_pin = dock;
1162
1163 spec->auto_mic = 1;
1164 if (!alc_auto_mic_check_imux(codec))
1165 return;
1166
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001167 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1168 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001169 spec->unsol_event = alc_sku_unsol_event;
1170}
1171
Takashi Iwai1d045db2011-07-07 18:23:21 +02001172/* check the availabilities of auto-mute and auto-mic switches */
1173static void alc_auto_check_switches(struct hda_codec *codec)
1174{
David Henningsson42cf0d02011-09-20 12:04:56 +02001175 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001176 alc_init_auto_mic(codec);
1177}
1178
1179/*
1180 * Realtek SSID verification
1181 */
1182
David Henningsson90622912010-10-14 14:50:18 +02001183/* Could be any non-zero and even value. When used as fixup, tells
1184 * the driver to ignore any present sku defines.
1185 */
1186#define ALC_FIXUP_SKU_IGNORE (2)
1187
Kailang Yangda00c242010-03-19 11:23:45 +01001188static int alc_auto_parse_customize_define(struct hda_codec *codec)
1189{
1190 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001191 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001192 struct alc_spec *spec = codec->spec;
1193
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001194 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1195
David Henningsson90622912010-10-14 14:50:18 +02001196 if (spec->cdefine.fixup) {
1197 ass = spec->cdefine.sku_cfg;
1198 if (ass == ALC_FIXUP_SKU_IGNORE)
1199 return -1;
1200 goto do_sku;
1201 }
1202
Kailang Yangda00c242010-03-19 11:23:45 +01001203 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001204 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001205 goto do_sku;
1206
1207 nid = 0x1d;
1208 if (codec->vendor_id == 0x10ec0260)
1209 nid = 0x17;
1210 ass = snd_hda_codec_get_pincfg(codec, nid);
1211
1212 if (!(ass & 1)) {
1213 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1214 codec->chip_name, ass);
1215 return -1;
1216 }
1217
1218 /* check sum */
1219 tmp = 0;
1220 for (i = 1; i < 16; i++) {
1221 if ((ass >> i) & 1)
1222 tmp++;
1223 }
1224 if (((ass >> 16) & 0xf) != tmp)
1225 return -1;
1226
1227 spec->cdefine.port_connectivity = ass >> 30;
1228 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1229 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1230 spec->cdefine.customization = ass >> 8;
1231do_sku:
1232 spec->cdefine.sku_cfg = ass;
1233 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1234 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1235 spec->cdefine.swap = (ass & 0x2) >> 1;
1236 spec->cdefine.override = ass & 0x1;
1237
1238 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1239 nid, spec->cdefine.sku_cfg);
1240 snd_printd("SKU: port_connectivity=0x%x\n",
1241 spec->cdefine.port_connectivity);
1242 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1243 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1244 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1245 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1246 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1247 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1248 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1249
1250 return 0;
1251}
1252
Takashi Iwai1d045db2011-07-07 18:23:21 +02001253/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001254static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1255{
Takashi Iwai21268962011-07-07 15:01:13 +02001256 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001257}
1258
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001259/* check subsystem ID and set up device-specific initialization;
1260 * return 1 if initialized, 0 if invalid SSID
1261 */
1262/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1263 * 31 ~ 16 : Manufacture ID
1264 * 15 ~ 8 : SKU ID
1265 * 7 ~ 0 : Assembly ID
1266 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1267 */
1268static int alc_subsystem_id(struct hda_codec *codec,
1269 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001270 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001271{
1272 unsigned int ass, tmp, i;
1273 unsigned nid;
1274 struct alc_spec *spec = codec->spec;
1275
David Henningsson90622912010-10-14 14:50:18 +02001276 if (spec->cdefine.fixup) {
1277 ass = spec->cdefine.sku_cfg;
1278 if (ass == ALC_FIXUP_SKU_IGNORE)
1279 return 0;
1280 goto do_sku;
1281 }
1282
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001283 ass = codec->subsystem_id & 0xffff;
1284 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1285 goto do_sku;
1286
1287 /* invalid SSID, check the special NID pin defcfg instead */
1288 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001289 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001290 * 29~21 : reserve
1291 * 20 : PCBEEP input
1292 * 19~16 : Check sum (15:1)
1293 * 15~1 : Custom
1294 * 0 : override
1295 */
1296 nid = 0x1d;
1297 if (codec->vendor_id == 0x10ec0260)
1298 nid = 0x17;
1299 ass = snd_hda_codec_get_pincfg(codec, nid);
1300 snd_printd("realtek: No valid SSID, "
1301 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001302 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001303 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001304 return 0;
1305 if ((ass >> 30) != 1) /* no physical connection */
1306 return 0;
1307
1308 /* check sum */
1309 tmp = 0;
1310 for (i = 1; i < 16; i++) {
1311 if ((ass >> i) & 1)
1312 tmp++;
1313 }
1314 if (((ass >> 16) & 0xf) != tmp)
1315 return 0;
1316do_sku:
1317 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1318 ass & 0xffff, codec->vendor_id);
1319 /*
1320 * 0 : override
1321 * 1 : Swap Jack
1322 * 2 : 0 --> Desktop, 1 --> Laptop
1323 * 3~5 : External Amplifier control
1324 * 7~6 : Reserved
1325 */
1326 tmp = (ass & 0x38) >> 3; /* external Amp control */
1327 switch (tmp) {
1328 case 1:
1329 spec->init_amp = ALC_INIT_GPIO1;
1330 break;
1331 case 3:
1332 spec->init_amp = ALC_INIT_GPIO2;
1333 break;
1334 case 7:
1335 spec->init_amp = ALC_INIT_GPIO3;
1336 break;
1337 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001338 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001339 spec->init_amp = ALC_INIT_DEFAULT;
1340 break;
1341 }
1342
1343 /* is laptop or Desktop and enable the function "Mute internal speaker
1344 * when the external headphone out jack is plugged"
1345 */
1346 if (!(ass & 0x8000))
1347 return 1;
1348 /*
1349 * 10~8 : Jack location
1350 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1351 * 14~13: Resvered
1352 * 15 : 1 --> enable the function "Mute internal speaker
1353 * when the external headphone out jack is plugged"
1354 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001355 if (!spec->autocfg.hp_pins[0] &&
1356 !(spec->autocfg.line_out_pins[0] &&
1357 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001358 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001359 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1360 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001361 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001362 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001363 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001364 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001365 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001366 else if (tmp == 3)
1367 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001368 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001369 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001370 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1371 spec->autocfg.line_outs))
1372 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001373 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001374 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001375 return 1;
1376}
Kailang Yangea1fb292008-08-26 12:58:38 +02001377
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001378/* Check the validity of ALC subsystem-id
1379 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1380static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001381{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001382 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001383 struct alc_spec *spec = codec->spec;
1384 snd_printd("realtek: "
1385 "Enable default setup for auto mode as fallback\n");
1386 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001387 }
Takashi Iwai21268962011-07-07 15:01:13 +02001388}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001389
Takashi Iwai41e41f12005-06-08 14:48:49 +02001390/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001391 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001392 */
1393
1394struct alc_pincfg {
1395 hda_nid_t nid;
1396 u32 val;
1397};
1398
Todd Broche1eb5f12010-12-06 11:19:51 -08001399struct alc_model_fixup {
1400 const int id;
1401 const char *name;
1402};
1403
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001404struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001405 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001406 bool chained;
1407 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001408 union {
1409 unsigned int sku;
1410 const struct alc_pincfg *pins;
1411 const struct hda_verb *verbs;
1412 void (*func)(struct hda_codec *codec,
1413 const struct alc_fixup *fix,
1414 int action);
1415 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001416};
1417
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001418enum {
1419 ALC_FIXUP_INVALID,
1420 ALC_FIXUP_SKU,
1421 ALC_FIXUP_PINS,
1422 ALC_FIXUP_VERBS,
1423 ALC_FIXUP_FUNC,
1424};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001425
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001426enum {
1427 ALC_FIXUP_ACT_PRE_PROBE,
1428 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001429 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001430};
1431
1432static void alc_apply_fixup(struct hda_codec *codec, int action)
1433{
1434 struct alc_spec *spec = codec->spec;
1435 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001436#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001437 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001438#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001439 int depth = 0;
1440
1441 if (!spec->fixup_list)
1442 return;
1443
1444 while (id >= 0) {
1445 const struct alc_fixup *fix = spec->fixup_list + id;
1446 const struct alc_pincfg *cfg;
1447
1448 switch (fix->type) {
1449 case ALC_FIXUP_SKU:
1450 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001451 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001452 snd_printdd(KERN_INFO "hda_codec: %s: "
1453 "Apply sku override for %s\n",
1454 codec->chip_name, modelname);
1455 spec->cdefine.sku_cfg = fix->v.sku;
1456 spec->cdefine.fixup = 1;
1457 break;
1458 case ALC_FIXUP_PINS:
1459 cfg = fix->v.pins;
1460 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1461 break;
1462 snd_printdd(KERN_INFO "hda_codec: %s: "
1463 "Apply pincfg for %s\n",
1464 codec->chip_name, modelname);
1465 for (; cfg->nid; cfg++)
1466 snd_hda_codec_set_pincfg(codec, cfg->nid,
1467 cfg->val);
1468 break;
1469 case ALC_FIXUP_VERBS:
1470 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1471 break;
1472 snd_printdd(KERN_INFO "hda_codec: %s: "
1473 "Apply fix-verbs for %s\n",
1474 codec->chip_name, modelname);
1475 add_verb(codec->spec, fix->v.verbs);
1476 break;
1477 case ALC_FIXUP_FUNC:
1478 if (!fix->v.func)
1479 break;
1480 snd_printdd(KERN_INFO "hda_codec: %s: "
1481 "Apply fix-func for %s\n",
1482 codec->chip_name, modelname);
1483 fix->v.func(codec, fix, action);
1484 break;
1485 default:
1486 snd_printk(KERN_ERR "hda_codec: %s: "
1487 "Invalid fixup type %d\n",
1488 codec->chip_name, fix->type);
1489 break;
1490 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001491 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001492 break;
1493 if (++depth > 10)
1494 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001495 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001496 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001497}
1498
Todd Broche1eb5f12010-12-06 11:19:51 -08001499static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001500 const struct alc_model_fixup *models,
1501 const struct snd_pci_quirk *quirk,
1502 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001503{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001504 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001505 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001506 int id = -1;
1507 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001508
Todd Broche1eb5f12010-12-06 11:19:51 -08001509 if (codec->modelname && models) {
1510 while (models->name) {
1511 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001512 id = models->id;
1513 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001514 break;
1515 }
1516 models++;
1517 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001518 }
1519 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001520 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1521 if (q) {
1522 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001523#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001524 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001525#endif
1526 }
1527 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001528 if (id < 0) {
1529 for (q = quirk; q->subvendor; q++) {
1530 unsigned int vendorid =
1531 q->subdevice | (q->subvendor << 16);
1532 if (vendorid == codec->subsystem_id) {
1533 id = q->value;
1534#ifdef CONFIG_SND_DEBUG_VERBOSE
1535 name = q->name;
1536#endif
1537 break;
1538 }
1539 }
1540 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001541
1542 spec->fixup_id = id;
1543 if (id >= 0) {
1544 spec->fixup_list = fixlist;
1545 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001546 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001547}
1548
Takashi Iwai1d045db2011-07-07 18:23:21 +02001549/*
1550 * COEF access helper functions
1551 */
Kailang Yang274693f2009-12-03 10:07:50 +01001552static int alc_read_coef_idx(struct hda_codec *codec,
1553 unsigned int coef_idx)
1554{
1555 unsigned int val;
1556 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1557 coef_idx);
1558 val = snd_hda_codec_read(codec, 0x20, 0,
1559 AC_VERB_GET_PROC_COEF, 0);
1560 return val;
1561}
1562
Kailang Yang977ddd62010-09-15 10:02:29 +02001563static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1564 unsigned int coef_val)
1565{
1566 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1567 coef_idx);
1568 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1569 coef_val);
1570}
1571
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001572/* a special bypass for COEF 0; read the cached value at the second time */
1573static unsigned int alc_get_coef0(struct hda_codec *codec)
1574{
1575 struct alc_spec *spec = codec->spec;
1576 if (!spec->coef0)
1577 spec->coef0 = alc_read_coef_idx(codec, 0);
1578 return spec->coef0;
1579}
1580
Takashi Iwai1d045db2011-07-07 18:23:21 +02001581/*
1582 * Digital I/O handling
1583 */
1584
Takashi Iwai757899a2010-07-30 10:48:14 +02001585/* set right pin controls for digital I/O */
1586static void alc_auto_init_digital(struct hda_codec *codec)
1587{
1588 struct alc_spec *spec = codec->spec;
1589 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001590 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001591
1592 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1593 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001594 if (!pin)
1595 continue;
1596 snd_hda_codec_write(codec, pin, 0,
1597 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1598 if (!i)
1599 dac = spec->multiout.dig_out_nid;
1600 else
1601 dac = spec->slave_dig_outs[i - 1];
1602 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1603 continue;
1604 snd_hda_codec_write(codec, dac, 0,
1605 AC_VERB_SET_AMP_GAIN_MUTE,
1606 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001607 }
1608 pin = spec->autocfg.dig_in_pin;
1609 if (pin)
1610 snd_hda_codec_write(codec, pin, 0,
1611 AC_VERB_SET_PIN_WIDGET_CONTROL,
1612 PIN_IN);
1613}
1614
1615/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1616static void alc_auto_parse_digital(struct hda_codec *codec)
1617{
1618 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001619 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001620 hda_nid_t dig_nid;
1621
1622 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001623 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001624 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001625 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001626 err = snd_hda_get_connections(codec,
1627 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001628 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001629 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001630 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001631 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001632 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001633 spec->multiout.dig_out_nid = dig_nid;
1634 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1635 } else {
1636 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001637 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001638 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001639 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001640 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001641 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001642 }
1643
1644 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001645 dig_nid = codec->start_nid;
1646 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1647 unsigned int wcaps = get_wcaps(codec, dig_nid);
1648 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1649 continue;
1650 if (!(wcaps & AC_WCAP_DIGITAL))
1651 continue;
1652 if (!(wcaps & AC_WCAP_CONN_LIST))
1653 continue;
1654 err = get_connection_index(codec, dig_nid,
1655 spec->autocfg.dig_in_pin);
1656 if (err >= 0) {
1657 spec->dig_in_nid = dig_nid;
1658 break;
1659 }
1660 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001661 }
1662}
1663
Takashi Iwaif95474e2007-07-10 00:47:43 +02001664/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001665 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001666 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001667static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1668 struct snd_ctl_elem_info *uinfo)
1669{
1670 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1671 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001672 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001673 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001674
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001675 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001676 if (spec->vol_in_capsrc)
1677 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1678 else
1679 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1680 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001681 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001682 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001683 return err;
1684}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001686static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1687 unsigned int size, unsigned int __user *tlv)
1688{
1689 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1690 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001691 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001692 int err;
1693
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001694 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001695 if (spec->vol_in_capsrc)
1696 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1697 else
1698 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1699 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001700 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001701 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001702 return err;
1703}
1704
1705typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol);
1707
1708static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1709 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001710 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001711{
1712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1713 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001714 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001715
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001716 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001717 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001718 for (i = 0; i < spec->num_adc_nids; i++) {
1719 kcontrol->private_value =
1720 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1721 3, 0, HDA_INPUT);
1722 err = func(kcontrol, ucontrol);
1723 if (err < 0)
1724 goto error;
1725 }
1726 } else {
1727 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001728 if (spec->vol_in_capsrc)
1729 kcontrol->private_value =
1730 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1731 3, 0, HDA_OUTPUT);
1732 else
1733 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001734 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1735 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001736 err = func(kcontrol, ucontrol);
1737 }
1738 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001739 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001740 return err;
1741}
1742
1743static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1744 struct snd_ctl_elem_value *ucontrol)
1745{
1746 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001747 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001748}
1749
1750static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1751 struct snd_ctl_elem_value *ucontrol)
1752{
1753 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001754 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001755}
1756
1757/* capture mixer elements */
1758#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1759
1760static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1761 struct snd_ctl_elem_value *ucontrol)
1762{
1763 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001764 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001765}
1766
1767static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1768 struct snd_ctl_elem_value *ucontrol)
1769{
1770 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001771 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001772}
1773
Takashi Iwaia23b6882009-03-23 15:21:36 +01001774#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001775 { \
1776 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1777 .name = "Capture Switch", \
1778 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1779 .count = num, \
1780 .info = alc_cap_sw_info, \
1781 .get = alc_cap_sw_get, \
1782 .put = alc_cap_sw_put, \
1783 }, \
1784 { \
1785 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1786 .name = "Capture Volume", \
1787 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1788 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1789 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1790 .count = num, \
1791 .info = alc_cap_vol_info, \
1792 .get = alc_cap_vol_get, \
1793 .put = alc_cap_vol_put, \
1794 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001795 }
1796
1797#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001798 { \
1799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1800 /* .name = "Capture Source", */ \
1801 .name = "Input Source", \
1802 .count = num, \
1803 .info = alc_mux_enum_info, \
1804 .get = alc_mux_enum_get, \
1805 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001806 }
1807
1808#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001809static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001810 _DEFINE_CAPMIX(num), \
1811 _DEFINE_CAPSRC(num), \
1812 { } /* end */ \
1813}
1814
1815#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001816static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001817 _DEFINE_CAPMIX(num), \
1818 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001819}
1820
1821/* up to three ADCs */
1822DEFINE_CAPMIX(1);
1823DEFINE_CAPMIX(2);
1824DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001825DEFINE_CAPMIX_NOSRC(1);
1826DEFINE_CAPMIX_NOSRC(2);
1827DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001828
1829/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001830 * virtual master controls
1831 */
1832
1833/*
1834 * slave controls for virtual master
1835 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001836static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001837 "Front Playback Volume",
1838 "Surround Playback Volume",
1839 "Center Playback Volume",
1840 "LFE Playback Volume",
1841 "Side Playback Volume",
1842 "Headphone Playback Volume",
1843 "Speaker Playback Volume",
1844 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001845 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001846 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001847 NULL,
1848};
1849
Takashi Iwaiea734962011-01-17 11:29:34 +01001850static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001851 "Front Playback Switch",
1852 "Surround Playback Switch",
1853 "Center Playback Switch",
1854 "LFE Playback Switch",
1855 "Side Playback Switch",
1856 "Headphone Playback Switch",
1857 "Speaker Playback Switch",
1858 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001859 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001860 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001861 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001862 NULL,
1863};
1864
1865/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001866 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001868
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001869#define NID_MAPPING (-1)
1870
1871#define SUBDEV_SPEAKER_ (0 << 6)
1872#define SUBDEV_HP_ (1 << 6)
1873#define SUBDEV_LINE_ (2 << 6)
1874#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1875#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1876#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1877
Takashi Iwai603c4012008-07-30 15:01:44 +02001878static void alc_free_kctls(struct hda_codec *codec);
1879
Takashi Iwai67d634c2009-11-16 15:35:59 +01001880#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001881/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001882static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001883 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001884 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001885 { } /* end */
1886};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001887#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001888
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001889static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
1891 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001892 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001893 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001894 int i, j, err;
1895 unsigned int u;
1896 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897
1898 for (i = 0; i < spec->num_mixers; i++) {
1899 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1900 if (err < 0)
1901 return err;
1902 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001903 if (spec->cap_mixer) {
1904 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1905 if (err < 0)
1906 return err;
1907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001909 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001910 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001911 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 if (err < 0)
1913 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001914 if (!spec->no_analog) {
1915 err = snd_hda_create_spdif_share_sw(codec,
1916 &spec->multiout);
1917 if (err < 0)
1918 return err;
1919 spec->multiout.share_spdif = 1;
1920 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 }
1922 if (spec->dig_in_nid) {
1923 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1924 if (err < 0)
1925 return err;
1926 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001927
Takashi Iwai67d634c2009-11-16 15:35:59 +01001928#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001929 /* create beep controls if needed */
1930 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001931 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001932 for (knew = alc_beep_mixer; knew->name; knew++) {
1933 struct snd_kcontrol *kctl;
1934 kctl = snd_ctl_new1(knew, codec);
1935 if (!kctl)
1936 return -ENOMEM;
1937 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001938 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001939 if (err < 0)
1940 return err;
1941 }
1942 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001943#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001944
Takashi Iwai2134ea42008-01-10 16:53:55 +01001945 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001946 if (!spec->no_analog &&
1947 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001948 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001949 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001950 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001951 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001952 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001953 if (err < 0)
1954 return err;
1955 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001956 if (!spec->no_analog &&
1957 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001958 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1959 NULL, alc_slave_sws);
1960 if (err < 0)
1961 return err;
1962 }
1963
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001964 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001965 if (spec->capsrc_nids || spec->adc_nids) {
1966 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1967 if (!kctl)
1968 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1969 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001970 err = snd_hda_add_nid(codec, kctl, i,
1971 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001972 if (err < 0)
1973 return err;
1974 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001975 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001976 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001977 const char *kname = kctl ? kctl->id.name : NULL;
1978 for (knew = spec->cap_mixer; knew->name; knew++) {
1979 if (kname && strcmp(knew->name, kname) == 0)
1980 continue;
1981 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1982 for (i = 0; kctl && i < kctl->count; i++) {
1983 err = snd_hda_add_nid(codec, kctl, i,
1984 spec->adc_nids[i]);
1985 if (err < 0)
1986 return err;
1987 }
1988 }
1989 }
1990
1991 /* other nid->control mapping */
1992 for (i = 0; i < spec->num_mixers; i++) {
1993 for (knew = spec->mixers[i]; knew->name; knew++) {
1994 if (knew->iface != NID_MAPPING)
1995 continue;
1996 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1997 if (kctl == NULL)
1998 continue;
1999 u = knew->subdevice;
2000 for (j = 0; j < 4; j++, u >>= 8) {
2001 nid = u & 0x3f;
2002 if (nid == 0)
2003 continue;
2004 switch (u & 0xc0) {
2005 case SUBDEV_SPEAKER_:
2006 nid = spec->autocfg.speaker_pins[nid];
2007 break;
2008 case SUBDEV_LINE_:
2009 nid = spec->autocfg.line_out_pins[nid];
2010 break;
2011 case SUBDEV_HP_:
2012 nid = spec->autocfg.hp_pins[nid];
2013 break;
2014 default:
2015 continue;
2016 }
2017 err = snd_hda_add_nid(codec, kctl, 0, nid);
2018 if (err < 0)
2019 return err;
2020 }
2021 u = knew->private_value;
2022 for (j = 0; j < 4; j++, u >>= 8) {
2023 nid = u & 0xff;
2024 if (nid == 0)
2025 continue;
2026 err = snd_hda_add_nid(codec, kctl, 0, nid);
2027 if (err < 0)
2028 return err;
2029 }
2030 }
2031 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002032
2033 alc_free_kctls(codec); /* no longer needed */
2034
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002035 return 0;
2036}
2037
2038static int alc_build_controls(struct hda_codec *codec)
2039{
2040 struct alc_spec *spec = codec->spec;
2041 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002042 if (err < 0)
2043 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002044 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
2046
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002047
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002049 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002050 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002051
Takashi Iwai584c0c42011-03-10 12:51:11 +01002052static void alc_init_special_input_src(struct hda_codec *codec);
2053
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054static int alc_init(struct hda_codec *codec)
2055{
2056 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002057 unsigned int i;
2058
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002059 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002060 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002061
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002062 for (i = 0; i < spec->num_init_verbs; i++)
2063 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002064 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002065
2066 if (spec->init_hook)
2067 spec->init_hook(codec);
2068
Takashi Iwai58701122011-01-13 15:41:45 +01002069 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2070
Takashi Iwai01a61e12011-10-28 00:03:22 +02002071 snd_hda_jack_report_sync(codec);
2072
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002073 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 return 0;
2075}
2076
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002077static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2078{
2079 struct alc_spec *spec = codec->spec;
2080
2081 if (spec->unsol_event)
2082 spec->unsol_event(codec, res);
2083}
2084
Takashi Iwaicb53c622007-08-10 17:21:45 +02002085#ifdef CONFIG_SND_HDA_POWER_SAVE
2086static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2087{
2088 struct alc_spec *spec = codec->spec;
2089 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2090}
2091#endif
2092
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093/*
2094 * Analog playback callbacks
2095 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002096static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002098 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099{
2100 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002101 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2102 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103}
2104
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002105static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 struct hda_codec *codec,
2107 unsigned int stream_tag,
2108 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002109 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
2111 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002112 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2113 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114}
2115
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002116static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002118 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119{
2120 struct alc_spec *spec = codec->spec;
2121 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2122}
2123
2124/*
2125 * Digital out
2126 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002127static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002129 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130{
2131 struct alc_spec *spec = codec->spec;
2132 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2133}
2134
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002135static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002136 struct hda_codec *codec,
2137 unsigned int stream_tag,
2138 unsigned int format,
2139 struct snd_pcm_substream *substream)
2140{
2141 struct alc_spec *spec = codec->spec;
2142 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2143 stream_tag, format, substream);
2144}
2145
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002146static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002147 struct hda_codec *codec,
2148 struct snd_pcm_substream *substream)
2149{
2150 struct alc_spec *spec = codec->spec;
2151 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2152}
2153
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002154static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002156 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157{
2158 struct alc_spec *spec = codec->spec;
2159 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2160}
2161
2162/*
2163 * Analog capture
2164 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002165static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 struct hda_codec *codec,
2167 unsigned int stream_tag,
2168 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002169 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170{
2171 struct alc_spec *spec = codec->spec;
2172
Takashi Iwai63300792008-01-24 15:31:36 +01002173 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 stream_tag, 0, format);
2175 return 0;
2176}
2177
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002178static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002180 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181{
2182 struct alc_spec *spec = codec->spec;
2183
Takashi Iwai888afa12008-03-18 09:57:50 +01002184 snd_hda_codec_cleanup_stream(codec,
2185 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 return 0;
2187}
2188
Takashi Iwai840b64c2010-07-13 22:49:01 +02002189/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002190static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002191 struct hda_codec *codec,
2192 unsigned int stream_tag,
2193 unsigned int format,
2194 struct snd_pcm_substream *substream)
2195{
2196 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002197 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002198 spec->cur_adc_stream_tag = stream_tag;
2199 spec->cur_adc_format = format;
2200 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2201 return 0;
2202}
2203
Takashi Iwai21268962011-07-07 15:01:13 +02002204static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002205 struct hda_codec *codec,
2206 struct snd_pcm_substream *substream)
2207{
2208 struct alc_spec *spec = codec->spec;
2209 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2210 spec->cur_adc = 0;
2211 return 0;
2212}
2213
Takashi Iwai21268962011-07-07 15:01:13 +02002214static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002215 .substreams = 1,
2216 .channels_min = 2,
2217 .channels_max = 2,
2218 .nid = 0, /* fill later */
2219 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002220 .prepare = dyn_adc_capture_pcm_prepare,
2221 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002222 },
2223};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
2225/*
2226 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002227static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 .substreams = 1,
2229 .channels_min = 2,
2230 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002231 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002233 .open = alc_playback_pcm_open,
2234 .prepare = alc_playback_pcm_prepare,
2235 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 },
2237};
2238
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002239static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002240 .substreams = 1,
2241 .channels_min = 2,
2242 .channels_max = 2,
2243 /* NID is set in alc_build_pcms */
2244};
2245
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002246static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002247 .substreams = 1,
2248 .channels_min = 2,
2249 .channels_max = 2,
2250 /* NID is set in alc_build_pcms */
2251};
2252
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002253static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002254 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 .channels_min = 2,
2256 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002257 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002259 .prepare = alc_alt_capture_pcm_prepare,
2260 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 },
2262};
2263
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002264static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 .substreams = 1,
2266 .channels_min = 2,
2267 .channels_max = 2,
2268 /* NID is set in alc_build_pcms */
2269 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002270 .open = alc_dig_playback_pcm_open,
2271 .close = alc_dig_playback_pcm_close,
2272 .prepare = alc_dig_playback_pcm_prepare,
2273 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274 },
2275};
2276
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002277static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 .substreams = 1,
2279 .channels_min = 2,
2280 .channels_max = 2,
2281 /* NID is set in alc_build_pcms */
2282};
2283
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002284/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002285static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002286 .substreams = 0,
2287 .channels_min = 0,
2288 .channels_max = 0,
2289};
2290
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291static int alc_build_pcms(struct hda_codec *codec)
2292{
2293 struct alc_spec *spec = codec->spec;
2294 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002295 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002296 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 int i;
2298
2299 codec->num_pcms = 1;
2300 codec->pcm_info = info;
2301
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002302 if (spec->no_analog)
2303 goto skip_analog;
2304
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002305 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2306 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002308
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002309 if (spec->multiout.dac_nids > 0) {
2310 p = spec->stream_analog_playback;
2311 if (!p)
2312 p = &alc_pcm_analog_playback;
2313 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002314 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2315 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002316 if (spec->adc_nids) {
2317 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002318 if (!p) {
2319 if (spec->dyn_adc_switch)
2320 p = &dyn_adc_pcm_analog_capture;
2321 else
2322 p = &alc_pcm_analog_capture;
2323 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002324 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002325 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327
Takashi Iwai4a471b72005-12-07 13:56:29 +01002328 if (spec->channel_mode) {
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2330 for (i = 0; i < spec->num_channel_mode; i++) {
2331 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2332 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2333 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 }
2335 }
2336
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002337 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002338 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002340 snprintf(spec->stream_name_digital,
2341 sizeof(spec->stream_name_digital),
2342 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002343 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002344 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002345 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002347 if (spec->dig_out_type)
2348 info->pcm_type = spec->dig_out_type;
2349 else
2350 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002351 if (spec->multiout.dig_out_nid) {
2352 p = spec->stream_digital_playback;
2353 if (!p)
2354 p = &alc_pcm_digital_playback;
2355 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2357 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002358 if (spec->dig_in_nid) {
2359 p = spec->stream_digital_capture;
2360 if (!p)
2361 p = &alc_pcm_digital_capture;
2362 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2364 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002365 /* FIXME: do we need this for all Realtek codec models? */
2366 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 }
2368
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002369 if (spec->no_analog)
2370 return 0;
2371
Takashi Iwaie08a0072006-09-07 17:52:14 +02002372 /* If the use of more than one ADC is requested for the current
2373 * model, configure a second analog capture-only PCM.
2374 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002375 have_multi_adcs = (spec->num_adc_nids > 1) &&
2376 !spec->dyn_adc_switch && !spec->auto_mic &&
2377 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002378 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002379 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002380 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002381 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002382 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002383 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002384 p = spec->stream_analog_alt_playback;
2385 if (!p)
2386 p = &alc_pcm_analog_alt_playback;
2387 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002388 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2389 spec->alt_dac_nid;
2390 } else {
2391 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2392 alc_pcm_null_stream;
2393 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2394 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002395 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002396 p = spec->stream_analog_alt_capture;
2397 if (!p)
2398 p = &alc_pcm_analog_alt_capture;
2399 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002400 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2401 spec->adc_nids[1];
2402 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2403 spec->num_adc_nids - 1;
2404 } else {
2405 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2406 alc_pcm_null_stream;
2407 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002408 }
2409 }
2410
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 return 0;
2412}
2413
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002414static inline void alc_shutup(struct hda_codec *codec)
2415{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002416 struct alc_spec *spec = codec->spec;
2417
2418 if (spec && spec->shutup)
2419 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002420 snd_hda_shutup_pins(codec);
2421}
2422
Takashi Iwai603c4012008-07-30 15:01:44 +02002423static void alc_free_kctls(struct hda_codec *codec)
2424{
2425 struct alc_spec *spec = codec->spec;
2426
2427 if (spec->kctls.list) {
2428 struct snd_kcontrol_new *kctl = spec->kctls.list;
2429 int i;
2430 for (i = 0; i < spec->kctls.used; i++)
2431 kfree(kctl[i].name);
2432 }
2433 snd_array_free(&spec->kctls);
2434}
2435
Takashi Iwai23c09b02011-08-19 09:05:35 +02002436static void alc_free_bind_ctls(struct hda_codec *codec)
2437{
2438 struct alc_spec *spec = codec->spec;
2439 if (spec->bind_ctls.list) {
2440 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2441 int i;
2442 for (i = 0; i < spec->bind_ctls.used; i++)
2443 kfree(ctl[i]);
2444 }
2445 snd_array_free(&spec->bind_ctls);
2446}
2447
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448static void alc_free(struct hda_codec *codec)
2449{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002450 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002451
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002452 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002453 return;
2454
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002455 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002456 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002457 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002458 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002459 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460}
2461
Hector Martinf5de24b2009-12-20 22:51:31 +01002462#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002463static void alc_power_eapd(struct hda_codec *codec)
2464{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002465 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002466}
2467
Hector Martinf5de24b2009-12-20 22:51:31 +01002468static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2469{
2470 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002471 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002472 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002473 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002474 return 0;
2475}
2476#endif
2477
Takashi Iwai2a439522011-07-26 09:52:50 +02002478#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002479static int alc_resume(struct hda_codec *codec)
2480{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002481 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002482 codec->patch_ops.init(codec);
2483 snd_hda_codec_resume_amp(codec);
2484 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002485 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002486 return 0;
2487}
Takashi Iwaie044c392008-10-27 16:56:24 +01002488#endif
2489
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490/*
2491 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002492static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 .build_controls = alc_build_controls,
2494 .build_pcms = alc_build_pcms,
2495 .init = alc_init,
2496 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002497 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002498#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002499 .resume = alc_resume,
2500#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002501#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002502 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002503 .check_power_status = alc_check_power_status,
2504#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002505 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506};
2507
Kailang Yangc027ddc2010-03-19 11:33:06 +01002508/* replace the codec chip_name with the given string */
2509static int alc_codec_rename(struct hda_codec *codec, const char *name)
2510{
2511 kfree(codec->chip_name);
2512 codec->chip_name = kstrdup(name, GFP_KERNEL);
2513 if (!codec->chip_name) {
2514 alc_free(codec);
2515 return -ENOMEM;
2516 }
2517 return 0;
2518}
2519
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002520/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002521 * Rename codecs appropriately from COEF value
2522 */
2523struct alc_codec_rename_table {
2524 unsigned int vendor_id;
2525 unsigned short coef_mask;
2526 unsigned short coef_bits;
2527 const char *name;
2528};
2529
2530static struct alc_codec_rename_table rename_tbl[] = {
2531 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2532 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2533 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2534 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2535 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2536 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2537 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2538 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2539 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2540 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2541 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2542 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2543 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2544 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2545 { } /* terminator */
2546};
2547
2548static int alc_codec_rename_from_preset(struct hda_codec *codec)
2549{
2550 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002551
2552 for (p = rename_tbl; p->vendor_id; p++) {
2553 if (p->vendor_id != codec->vendor_id)
2554 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002555 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002556 return alc_codec_rename(codec, p->name);
2557 }
2558 return 0;
2559}
2560
2561/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002562 * Automatic parse of I/O pins from the BIOS configuration
2563 */
2564
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002565enum {
2566 ALC_CTL_WIDGET_VOL,
2567 ALC_CTL_WIDGET_MUTE,
2568 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002569 ALC_CTL_BIND_VOL,
2570 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002571};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002572static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002573 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2574 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002575 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002576 HDA_BIND_VOL(NULL, 0),
2577 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002578};
2579
2580/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002581static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002582 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002583{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002584 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002585
Takashi Iwaice764ab2011-04-27 16:35:23 +02002586 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002587 if (!knew)
2588 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002589 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002590 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002591 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002592 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002593 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002594 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002595 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002596 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002597 return 0;
2598}
2599
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002600static int add_control_with_pfx(struct alc_spec *spec, int type,
2601 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002602 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002603{
2604 char name[32];
2605 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002606 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002607}
2608
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002609#define add_pb_vol_ctrl(spec, type, pfx, val) \
2610 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2611#define add_pb_sw_ctrl(spec, type, pfx, val) \
2612 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2613#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2614 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2615#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2616 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002617
Takashi Iwai23c09b02011-08-19 09:05:35 +02002618static const char * const channel_name[4] = {
2619 "Front", "Surround", "CLFE", "Side"
2620};
2621
Takashi Iwai6843ca12011-06-24 11:03:58 +02002622static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2623 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002624{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002625 struct auto_pin_cfg *cfg = &spec->autocfg;
2626
Takashi Iwai6843ca12011-06-24 11:03:58 +02002627 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002628 if (cfg->line_outs == 1 && !spec->multi_ios &&
2629 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002630 return "Master";
2631
2632 switch (cfg->line_out_type) {
2633 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002634 if (cfg->line_outs == 1)
2635 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002636 if (cfg->line_outs == 2)
2637 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002638 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002639 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002640 /* for multi-io case, only the primary out */
2641 if (ch && spec->multi_ios)
2642 break;
2643 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002644 return "Headphone";
2645 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002646 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002647 return "PCM";
2648 break;
2649 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002650 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2651 return "PCM";
2652
2653 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002654}
2655
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002656/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002657static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002658 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002659 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002660{
Kailang Yangdf694da2005-12-05 19:42:22 +01002661 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002662
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002663 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002664 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2665 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002666 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002667 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002668 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2669 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002670 return err;
2671 return 0;
2672}
2673
Takashi Iwai05f5f472009-08-25 13:10:18 +02002674static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002675{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002676 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2677 return (pincap & AC_PINCAP_IN) != 0;
2678}
2679
Takashi Iwai1d045db2011-07-07 18:23:21 +02002680/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002681static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002682{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002683 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002684 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002685 hda_nid_t *adc_nids = spec->private_adc_nids;
2686 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2687 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002688 int i, nums = 0;
2689
Takashi Iwai24de1832011-11-07 17:13:39 +01002690 if (spec->shared_mic_hp)
2691 max_nums = 1; /* no multi streams with the shared HP/mic */
2692
Takashi Iwaib7821702011-07-06 15:12:46 +02002693 nid = codec->start_nid;
2694 for (i = 0; i < codec->num_nodes; i++, nid++) {
2695 hda_nid_t src;
2696 const hda_nid_t *list;
2697 unsigned int caps = get_wcaps(codec, nid);
2698 int type = get_wcaps_type(caps);
2699
2700 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2701 continue;
2702 adc_nids[nums] = nid;
2703 cap_nids[nums] = nid;
2704 src = nid;
2705 for (;;) {
2706 int n;
2707 type = get_wcaps_type(get_wcaps(codec, src));
2708 if (type == AC_WID_PIN)
2709 break;
2710 if (type == AC_WID_AUD_SEL) {
2711 cap_nids[nums] = src;
2712 break;
2713 }
2714 n = snd_hda_get_conn_list(codec, src, &list);
2715 if (n > 1) {
2716 cap_nids[nums] = src;
2717 break;
2718 } else if (n != 1)
2719 break;
2720 src = *list;
2721 }
2722 if (++nums >= max_nums)
2723 break;
2724 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002725 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002726 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002727 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002728 return nums;
2729}
2730
Takashi Iwai05f5f472009-08-25 13:10:18 +02002731/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002732static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002733{
2734 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002735 const struct auto_pin_cfg *cfg = &spec->autocfg;
2736 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002737 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002738 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002739 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002740 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002741
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002742 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002743 if (num_adcs < 0)
2744 return 0;
2745
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002746 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002747 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002748 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002749
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002750 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002751 if (!alc_is_input_pin(codec, pin))
2752 continue;
2753
David Henningsson5322bf22011-01-05 11:03:56 +01002754 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002755 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2756 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002757 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002758 type_idx++;
2759 else
2760 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002761 prev_label = label;
2762
Takashi Iwai05f5f472009-08-25 13:10:18 +02002763 if (mixer) {
2764 idx = get_connection_index(codec, mixer, pin);
2765 if (idx >= 0) {
2766 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002767 label, type_idx,
2768 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002769 if (err < 0)
2770 return err;
2771 }
2772 }
2773
Takashi Iwaib7821702011-07-06 15:12:46 +02002774 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002775 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002776 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002777 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002778 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002779 snd_hda_add_imux_item(imux, label, idx, NULL);
2780 break;
2781 }
2782 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002783 }
Takashi Iwai21268962011-07-07 15:01:13 +02002784
2785 spec->num_mux_defs = 1;
2786 spec->input_mux = imux;
2787
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002788 return 0;
2789}
2790
Takashi Iwai24de1832011-11-07 17:13:39 +01002791/* create a shared input with the headphone out */
2792static int alc_auto_create_shared_input(struct hda_codec *codec)
2793{
2794 struct alc_spec *spec = codec->spec;
2795 struct auto_pin_cfg *cfg = &spec->autocfg;
2796 unsigned int defcfg;
2797 hda_nid_t nid;
2798
2799 /* only one internal input pin? */
2800 if (cfg->num_inputs != 1)
2801 return 0;
2802 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2803 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2804 return 0;
2805
2806 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2807 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2808 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2809 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2810 else
2811 return 0; /* both not available */
2812
2813 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2814 return 0; /* no input */
2815
2816 cfg->inputs[1].pin = nid;
2817 cfg->inputs[1].type = AUTO_PIN_MIC;
2818 cfg->num_inputs = 2;
2819 spec->shared_mic_hp = 1;
2820 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2821 return 0;
2822}
2823
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002824static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2825 unsigned int pin_type)
2826{
2827 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2828 pin_type);
2829 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002830 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2831 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002832 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002833}
2834
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002835static int get_pin_type(int line_out_type)
2836{
2837 if (line_out_type == AUTO_PIN_HP_OUT)
2838 return PIN_HP;
2839 else
2840 return PIN_OUT;
2841}
2842
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002843static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002844{
2845 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002846 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002847 int i;
2848
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002849 for (i = 0; i < cfg->num_inputs; i++) {
2850 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002851 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002852 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002853 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002854 snd_hda_codec_write(codec, nid, 0,
2855 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002856 AMP_OUT_MUTE);
2857 }
2858 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002859
2860 /* mute all loopback inputs */
2861 if (spec->mixer_nid) {
2862 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2863 for (i = 0; i < nums; i++)
2864 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2865 AC_VERB_SET_AMP_GAIN_MUTE,
2866 AMP_IN_MUTE(i));
2867 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002868}
2869
Takashi Iwai7085ec12009-10-02 09:03:58 +02002870/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002871static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002872{
Takashi Iwai604401a2011-04-27 15:14:23 +02002873 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002874 int i, num;
2875
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002876 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2877 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002878 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2879 for (i = 0; i < num; i++) {
2880 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2881 return list[i];
2882 }
2883 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002884}
2885
Takashi Iwai604401a2011-04-27 15:14:23 +02002886/* go down to the selector widget before the mixer */
2887static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2888{
2889 hda_nid_t srcs[5];
2890 int num = snd_hda_get_connections(codec, pin, srcs,
2891 ARRAY_SIZE(srcs));
2892 if (num != 1 ||
2893 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2894 return pin;
2895 return srcs[0];
2896}
2897
Takashi Iwai7085ec12009-10-02 09:03:58 +02002898/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002899static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002900 hda_nid_t dac)
2901{
David Henningssoncc1c4522010-11-24 14:17:47 +01002902 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002903 int i, num;
2904
Takashi Iwai604401a2011-04-27 15:14:23 +02002905 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002906 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2907 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002908 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002909 return mix[i];
2910 }
2911 return 0;
2912}
2913
Takashi Iwaice764ab2011-04-27 16:35:23 +02002914/* select the connection from pin to DAC if needed */
2915static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2916 hda_nid_t dac)
2917{
2918 hda_nid_t mix[5];
2919 int i, num;
2920
2921 pin = alc_go_down_to_selector(codec, pin);
2922 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2923 if (num < 2)
2924 return 0;
2925 for (i = 0; i < num; i++) {
2926 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2927 snd_hda_codec_update_cache(codec, pin, 0,
2928 AC_VERB_SET_CONNECT_SEL, i);
2929 return 0;
2930 }
2931 }
2932 return 0;
2933}
2934
Takashi Iwai7085ec12009-10-02 09:03:58 +02002935/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002936static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002937{
2938 struct alc_spec *spec = codec->spec;
2939 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002940 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002941
Takashi Iwai604401a2011-04-27 15:14:23 +02002942 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002943 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002944 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002945 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002946 if (!nid)
2947 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002948 if (found_in_nid_list(nid, spec->multiout.dac_nids,
Takashi Iwai0a34b422011-12-07 17:20:30 +01002949 ARRAY_SIZE(spec->private_dac_nids)))
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002950 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002951 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2952 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2953 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002954 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2955 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2956 continue;
2957 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002958 }
2959 return 0;
2960}
2961
Takashi Iwai07b18f62011-11-10 15:42:54 +01002962/* check whether the DAC is reachable from the pin */
2963static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2964 hda_nid_t pin, hda_nid_t dac)
2965{
2966 hda_nid_t srcs[5];
2967 int i, num;
2968
2969 pin = alc_go_down_to_selector(codec, pin);
2970 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2971 for (i = 0; i < num; i++) {
2972 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2973 if (nid == dac)
2974 return true;
2975 }
2976 return false;
2977}
2978
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002979static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2980{
2981 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2982 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2983 return alc_auto_look_for_dac(codec, pin);
2984 return 0;
2985}
2986
Takashi Iwai0a34b422011-12-07 17:20:30 +01002987/* return 0 if no possible DAC is found, 1 if one or more found */
Takashi Iwaic2674682011-08-24 17:57:44 +02002988static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2989 const hda_nid_t *pins, hda_nid_t *dacs)
2990{
2991 int i;
2992
2993 if (num_outs && !dacs[0]) {
2994 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2995 if (!dacs[0])
2996 return 0;
2997 }
2998
2999 for (i = 1; i < num_outs; i++)
3000 dacs[i] = get_dac_if_single(codec, pins[i]);
3001 for (i = 1; i < num_outs; i++) {
3002 if (!dacs[i])
3003 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3004 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003005 return 1;
Takashi Iwaic2674682011-08-24 17:57:44 +02003006}
3007
3008static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003009 unsigned int location, int offset);
David Henningssonfde48a12011-12-09 18:27:42 +08003010static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3011 hda_nid_t pin, hda_nid_t dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003012
Takashi Iwai7085ec12009-10-02 09:03:58 +02003013/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003014static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003015{
3016 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003017 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003018 unsigned int location, defcfg;
3019 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003020 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003021 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003022
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003023 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003024 /* set num_dacs once to full for alc_auto_look_for_dac() */
3025 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003026 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003027 spec->multiout.extra_out_nid[0] = 0;
3028 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3029 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003030 spec->multi_ios = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003031
3032 /* fill hard-wired DACs first */
3033 if (!redone) {
3034 for (i = 0; i < cfg->line_outs; i++)
3035 spec->private_dac_nids[i] =
3036 get_dac_if_single(codec, cfg->line_out_pins[i]);
3037 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003038 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003039 get_dac_if_single(codec, cfg->hp_pins[0]);
3040 if (cfg->speaker_outs)
3041 spec->multiout.extra_out_nid[0] =
3042 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003043 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003044
3045 for (i = 0; i < cfg->line_outs; i++) {
3046 hda_nid_t pin = cfg->line_out_pins[i];
3047 if (spec->private_dac_nids[i])
3048 continue;
3049 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3050 if (!spec->private_dac_nids[i] && !redone) {
3051 /* if we can't find primary DACs, re-probe without
3052 * checking the hard-wired DACs
3053 */
3054 redone = true;
3055 goto again;
3056 }
3057 }
3058
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003059 /* re-count num_dacs and squash invalid entries */
3060 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003061 for (i = 0; i < cfg->line_outs; i++) {
3062 if (spec->private_dac_nids[i])
3063 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003064 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003065 memmove(spec->private_dac_nids + i,
3066 spec->private_dac_nids + i + 1,
3067 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003068 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3069 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003070 }
3071
Takashi Iwaic2674682011-08-24 17:57:44 +02003072 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3073 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003074 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3075 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003076
Takashi Iwai07b18f62011-11-10 15:42:54 +01003077 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003078 if (num_pins > 0) {
3079 spec->multi_ios = num_pins;
3080 spec->ext_channel_count = 2;
3081 spec->multiout.num_dacs = num_pins + 1;
3082 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003083 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003084
Takashi Iwai716eef02011-10-21 15:07:42 +02003085 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3086 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003087 spec->multiout.hp_out_nid);
Takashi Iwai0a34b422011-12-07 17:20:30 +01003088 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3089 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3090 cfg->speaker_pins,
3091 spec->multiout.extra_out_nid);
3092 /* if no speaker volume is assigned, try again as the primary
3093 * output
3094 */
3095 if (!err && cfg->speaker_outs > 0 &&
3096 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3097 cfg->hp_outs = cfg->line_outs;
3098 memcpy(cfg->hp_pins, cfg->line_out_pins,
3099 sizeof(cfg->hp_pins));
3100 cfg->line_outs = cfg->speaker_outs;
3101 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3102 sizeof(cfg->speaker_pins));
3103 cfg->speaker_outs = 0;
3104 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3105 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3106 redone = false;
3107 goto again;
3108 }
3109 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003110
Takashi Iwai07b18f62011-11-10 15:42:54 +01003111 if (!spec->multi_ios &&
3112 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3113 cfg->hp_outs) {
3114 /* try multi-ios with HP + inputs */
3115 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3116 location = get_defcfg_location(defcfg);
3117
3118 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3119 if (num_pins > 0) {
3120 spec->multi_ios = num_pins;
3121 spec->ext_channel_count = 2;
3122 spec->multiout.num_dacs = num_pins + 1;
3123 }
3124 }
3125
David Henningssonfde48a12011-12-09 18:27:42 +08003126 if (cfg->line_out_pins[0])
3127 spec->vmaster_nid =
3128 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3129 spec->multiout.dac_nids[0]);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003130 return 0;
3131}
3132
Takashi Iwai527e4d72011-10-27 16:33:27 +02003133static inline unsigned int get_ctl_pos(unsigned int data)
3134{
3135 hda_nid_t nid = get_amp_nid_(data);
3136 unsigned int dir = get_amp_direction_(data);
3137 return (nid << 1) | dir;
3138}
3139
3140#define is_ctl_used(bits, data) \
3141 test_bit(get_ctl_pos(data), bits)
3142#define mark_ctl_usage(bits, data) \
3143 set_bit(get_ctl_pos(data), bits)
3144
Takashi Iwai343a04b2011-07-06 14:28:39 +02003145static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003146 const char *pfx, int cidx,
3147 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003148{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003149 struct alc_spec *spec = codec->spec;
3150 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003151 if (!nid)
3152 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003153 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3154 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3155 return 0;
3156 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003157 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003158 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003159}
3160
Takashi Iwaie29d3772011-11-14 17:13:23 +01003161static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3162 const char *pfx, int cidx,
3163 hda_nid_t nid)
3164{
3165 int chs = 1;
3166 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3167 chs = 3;
3168 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3169}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003170
3171/* create a mute-switch for the given mixer widget;
3172 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3173 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003174static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003175 const char *pfx, int cidx,
3176 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003177{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003178 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003179 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003180 int type;
3181 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003182 if (!nid)
3183 return 0;
3184 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3185 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3186 type = ALC_CTL_WIDGET_MUTE;
3187 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3188 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003189 type = ALC_CTL_WIDGET_MUTE;
3190 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3191 } else {
3192 type = ALC_CTL_BIND_MUTE;
3193 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3194 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003195 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3196 return 0;
3197 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003198 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003199}
3200
Takashi Iwaie29d3772011-11-14 17:13:23 +01003201static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3202 int cidx, hda_nid_t nid)
3203{
3204 int chs = 1;
3205 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3206 chs = 3;
3207 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3208}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003209
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003210static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3211 hda_nid_t pin, hda_nid_t dac)
3212{
3213 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3214 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3215 return pin;
3216 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3217 return mix;
3218 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3219 return dac;
3220 return 0;
3221}
3222
3223static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3224 hda_nid_t pin, hda_nid_t dac)
3225{
3226 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3227 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3228 return dac;
3229 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3230 return mix;
3231 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3232 return pin;
3233 return 0;
3234}
3235
Takashi Iwai7085ec12009-10-02 09:03:58 +02003236/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003237static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003238 const struct auto_pin_cfg *cfg)
3239{
3240 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003241 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003242
Takashi Iwaice764ab2011-04-27 16:35:23 +02003243 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003244 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003245 noutputs += spec->multi_ios;
3246
3247 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003248 const char *name;
3249 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003250 hda_nid_t dac, pin;
3251 hda_nid_t sw, vol;
3252
3253 dac = spec->multiout.dac_nids[i];
3254 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003255 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003256 if (i >= cfg->line_outs)
3257 pin = spec->multi_io[i - 1].pin;
3258 else
3259 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003260
3261 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3262 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003263 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003264 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003265 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003266 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003267 if (err < 0)
3268 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003269 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003270 if (err < 0)
3271 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003272 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003273 if (err < 0)
3274 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003275 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003276 if (err < 0)
3277 return err;
3278 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003279 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003280 if (err < 0)
3281 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003282 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003283 if (err < 0)
3284 return err;
3285 }
3286 }
3287 return 0;
3288}
3289
Takashi Iwai343a04b2011-07-06 14:28:39 +02003290static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003291 hda_nid_t dac, const char *pfx,
3292 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003293{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003294 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003295 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003296 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003297
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003298 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003299 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003300 /* the corresponding DAC is already occupied */
3301 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3302 return 0; /* no way */
3303 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003304 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3305 if (is_ctl_used(spec->sw_ctls, val))
3306 return 0; /* already created */
3307 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003308 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003309 }
3310
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003311 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3312 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003313 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003314 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003315 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003316 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003317 if (err < 0)
3318 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003319 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003320}
3321
Takashi Iwai23c09b02011-08-19 09:05:35 +02003322static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3323 unsigned int nums,
3324 struct hda_ctl_ops *ops)
3325{
3326 struct alc_spec *spec = codec->spec;
3327 struct hda_bind_ctls **ctlp, *ctl;
3328 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3329 ctlp = snd_array_new(&spec->bind_ctls);
3330 if (!ctlp)
3331 return NULL;
3332 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3333 *ctlp = ctl;
3334 if (ctl)
3335 ctl->ops = ops;
3336 return ctl;
3337}
3338
3339/* add playback controls for speaker and HP outputs */
3340static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3341 const hda_nid_t *pins,
3342 const hda_nid_t *dacs,
3343 const char *pfx)
3344{
3345 struct alc_spec *spec = codec->spec;
3346 struct hda_bind_ctls *ctl;
3347 char name[32];
3348 int i, n, err;
3349
3350 if (!num_pins || !pins[0])
3351 return 0;
3352
Takashi Iwai527e4d72011-10-27 16:33:27 +02003353 if (num_pins == 1) {
3354 hda_nid_t dac = *dacs;
3355 if (!dac)
3356 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003357 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003358 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003359
3360 if (dacs[num_pins - 1]) {
3361 /* OK, we have a multi-output system with individual volumes */
3362 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003363 if (num_pins >= 3) {
3364 snprintf(name, sizeof(name), "%s %s",
3365 pfx, channel_name[i]);
3366 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3367 name, 0);
3368 } else {
3369 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3370 pfx, i);
3371 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003372 if (err < 0)
3373 return err;
3374 }
3375 return 0;
3376 }
3377
3378 /* Let's create a bind-controls */
3379 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3380 if (!ctl)
3381 return -ENOMEM;
3382 n = 0;
3383 for (i = 0; i < num_pins; i++) {
3384 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3385 ctl->values[n++] =
3386 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3387 }
3388 if (n) {
3389 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3390 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3391 if (err < 0)
3392 return err;
3393 }
3394
3395 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3396 if (!ctl)
3397 return -ENOMEM;
3398 n = 0;
3399 for (i = 0; i < num_pins; i++) {
3400 hda_nid_t vol;
3401 if (!pins[i] || !dacs[i])
3402 continue;
3403 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3404 if (vol)
3405 ctl->values[n++] =
3406 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3407 }
3408 if (n) {
3409 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3410 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3411 if (err < 0)
3412 return err;
3413 }
3414 return 0;
3415}
3416
Takashi Iwai343a04b2011-07-06 14:28:39 +02003417static int alc_auto_create_hp_out(struct hda_codec *codec)
3418{
3419 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003420 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3421 spec->autocfg.hp_pins,
3422 spec->multiout.hp_out_nid,
3423 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003424}
3425
3426static int alc_auto_create_speaker_out(struct hda_codec *codec)
3427{
3428 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003429 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3430 spec->autocfg.speaker_pins,
3431 spec->multiout.extra_out_nid,
3432 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003433}
3434
Takashi Iwai343a04b2011-07-06 14:28:39 +02003435static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003436 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003437 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003438{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003439 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003440 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003441 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003442
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003443 alc_set_pin_output(codec, pin, pin_type);
3444 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003445 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003446 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003447 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003448 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003449 mix = srcs[i];
3450 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003451 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003452 if (!mix)
3453 return;
3454
3455 /* need the manual connection? */
3456 if (num > 1)
3457 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3458 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003459 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3460 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003461 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003462 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003463 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003464 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003465 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003466 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3467 if (nid)
3468 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3469 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003470
3471 /* unmute DAC if it's not assigned to a mixer */
3472 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3473 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3474 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3475 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003476}
3477
Takashi Iwai343a04b2011-07-06 14:28:39 +02003478static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003479{
3480 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003481 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003482 int i;
3483
3484 for (i = 0; i <= HDA_SIDE; i++) {
3485 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3486 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003487 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003488 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003489 }
3490}
3491
Takashi Iwai343a04b2011-07-06 14:28:39 +02003492static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003493{
3494 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003495 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003496 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003497
David Henningsson636030e2011-10-12 19:26:03 +02003498 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003499 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3500 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003501 pin = spec->autocfg.hp_pins[i];
3502 if (!pin)
3503 break;
3504 dac = spec->multiout.hp_out_nid[i];
3505 if (!dac) {
3506 if (i > 0 && spec->multiout.hp_out_nid[0])
3507 dac = spec->multiout.hp_out_nid[0];
3508 else
3509 dac = spec->multiout.dac_nids[0];
3510 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003511 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3512 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003513 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003514 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3515 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003516 pin = spec->autocfg.speaker_pins[i];
3517 if (!pin)
3518 break;
3519 dac = spec->multiout.extra_out_nid[i];
3520 if (!dac) {
3521 if (i > 0 && spec->multiout.extra_out_nid[0])
3522 dac = spec->multiout.extra_out_nid[0];
3523 else
3524 dac = spec->multiout.dac_nids[0];
3525 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003526 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3527 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003528}
3529
Takashi Iwaice764ab2011-04-27 16:35:23 +02003530/*
3531 * multi-io helper
3532 */
3533static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003534 unsigned int location,
3535 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003536{
3537 struct alc_spec *spec = codec->spec;
3538 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003539 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003540 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003541
Takashi Iwai07b18f62011-11-10 15:42:54 +01003542 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003543 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3544 for (i = 0; i < cfg->num_inputs; i++) {
3545 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003546 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003547 unsigned int defcfg, caps;
3548 if (cfg->inputs[i].type != type)
3549 continue;
3550 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3551 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3552 continue;
3553 if (location && get_defcfg_location(defcfg) != location)
3554 continue;
3555 caps = snd_hda_query_pin_caps(codec, nid);
3556 if (!(caps & AC_PINCAP_OUT))
3557 continue;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003558 if (offset && offset + num_pins < dacs) {
3559 dac = spec->private_dac_nids[offset + num_pins];
3560 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3561 dac = 0;
3562 }
3563 if (!dac)
3564 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003565 if (!dac)
3566 continue;
3567 spec->multi_io[num_pins].pin = nid;
3568 spec->multi_io[num_pins].dac = dac;
3569 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003570 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003571 }
3572 }
Takashi Iwai07b18f62011-11-10 15:42:54 +01003573 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003574 if (num_pins < 2) {
3575 /* clear up again */
Takashi Iwai07b18f62011-11-10 15:42:54 +01003576 memset(spec->private_dac_nids + dacs, 0,
3577 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003578 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003579 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003580 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003581 return num_pins;
3582}
3583
3584static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3585 struct snd_ctl_elem_info *uinfo)
3586{
3587 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3588 struct alc_spec *spec = codec->spec;
3589
3590 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3591 uinfo->count = 1;
3592 uinfo->value.enumerated.items = spec->multi_ios + 1;
3593 if (uinfo->value.enumerated.item > spec->multi_ios)
3594 uinfo->value.enumerated.item = spec->multi_ios;
3595 sprintf(uinfo->value.enumerated.name, "%dch",
3596 (uinfo->value.enumerated.item + 1) * 2);
3597 return 0;
3598}
3599
3600static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3601 struct snd_ctl_elem_value *ucontrol)
3602{
3603 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3604 struct alc_spec *spec = codec->spec;
3605 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3606 return 0;
3607}
3608
3609static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3610{
3611 struct alc_spec *spec = codec->spec;
3612 hda_nid_t nid = spec->multi_io[idx].pin;
3613
3614 if (!spec->multi_io[idx].ctl_in)
3615 spec->multi_io[idx].ctl_in =
3616 snd_hda_codec_read(codec, nid, 0,
3617 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3618 if (output) {
3619 snd_hda_codec_update_cache(codec, nid, 0,
3620 AC_VERB_SET_PIN_WIDGET_CONTROL,
3621 PIN_OUT);
3622 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3623 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3624 HDA_AMP_MUTE, 0);
3625 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3626 } else {
3627 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3628 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3629 HDA_AMP_MUTE, HDA_AMP_MUTE);
3630 snd_hda_codec_update_cache(codec, nid, 0,
3631 AC_VERB_SET_PIN_WIDGET_CONTROL,
3632 spec->multi_io[idx].ctl_in);
3633 }
3634 return 0;
3635}
3636
3637static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3638 struct snd_ctl_elem_value *ucontrol)
3639{
3640 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3641 struct alc_spec *spec = codec->spec;
3642 int i, ch;
3643
3644 ch = ucontrol->value.enumerated.item[0];
3645 if (ch < 0 || ch > spec->multi_ios)
3646 return -EINVAL;
3647 if (ch == (spec->ext_channel_count - 1) / 2)
3648 return 0;
3649 spec->ext_channel_count = (ch + 1) * 2;
3650 for (i = 0; i < spec->multi_ios; i++)
3651 alc_set_multi_io(codec, i, i < ch);
3652 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003653 if (spec->need_dac_fix && !spec->const_channel_count)
3654 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003655 return 1;
3656}
3657
Takashi Iwaia9111322011-05-02 11:30:18 +02003658static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3660 .name = "Channel Mode",
3661 .info = alc_auto_ch_mode_info,
3662 .get = alc_auto_ch_mode_get,
3663 .put = alc_auto_ch_mode_put,
3664};
3665
Takashi Iwai23c09b02011-08-19 09:05:35 +02003666static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003667{
3668 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003669
Takashi Iwaic2674682011-08-24 17:57:44 +02003670 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003671 struct snd_kcontrol_new *knew;
3672
3673 knew = alc_kcontrol_new(spec);
3674 if (!knew)
3675 return -ENOMEM;
3676 *knew = alc_auto_channel_mode_enum;
3677 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3678 if (!knew->name)
3679 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003680 }
3681 return 0;
3682}
3683
Takashi Iwai1d045db2011-07-07 18:23:21 +02003684/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3685 * active input pins
3686 */
3687static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3688{
3689 struct alc_spec *spec = codec->spec;
3690 const struct hda_input_mux *imux;
3691 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3692 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3693 int i, n, nums;
3694
3695 imux = spec->input_mux;
3696 if (!imux)
3697 return;
3698 if (spec->dyn_adc_switch)
3699 return;
3700
3701 nums = 0;
3702 for (n = 0; n < spec->num_adc_nids; n++) {
3703 hda_nid_t cap = spec->private_capsrc_nids[n];
3704 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3705 for (i = 0; i < imux->num_items; i++) {
3706 hda_nid_t pin = spec->imux_pins[i];
3707 if (pin) {
3708 if (get_connection_index(codec, cap, pin) < 0)
3709 break;
3710 } else if (num_conns <= imux->items[i].index)
3711 break;
3712 }
3713 if (i >= imux->num_items) {
3714 adc_nids[nums] = spec->private_adc_nids[n];
3715 capsrc_nids[nums++] = cap;
3716 }
3717 }
3718 if (!nums) {
3719 /* check whether ADC-switch is possible */
3720 if (!alc_check_dyn_adc_switch(codec)) {
3721 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3722 " using fallback 0x%x\n",
3723 codec->chip_name, spec->private_adc_nids[0]);
3724 spec->num_adc_nids = 1;
3725 spec->auto_mic = 0;
3726 return;
3727 }
3728 } else if (nums != spec->num_adc_nids) {
3729 memcpy(spec->private_adc_nids, adc_nids,
3730 nums * sizeof(hda_nid_t));
3731 memcpy(spec->private_capsrc_nids, capsrc_nids,
3732 nums * sizeof(hda_nid_t));
3733 spec->num_adc_nids = nums;
3734 }
3735
3736 if (spec->auto_mic)
3737 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3738 else if (spec->input_mux->num_items == 1)
3739 spec->num_adc_nids = 1; /* reduce to a single ADC */
3740}
3741
3742/*
3743 * initialize ADC paths
3744 */
3745static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3746{
3747 struct alc_spec *spec = codec->spec;
3748 hda_nid_t nid;
3749
3750 nid = spec->adc_nids[adc_idx];
3751 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003752 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003753 snd_hda_codec_write(codec, nid, 0,
3754 AC_VERB_SET_AMP_GAIN_MUTE,
3755 AMP_IN_MUTE(0));
3756 return;
3757 }
3758 if (!spec->capsrc_nids)
3759 return;
3760 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003761 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003762 snd_hda_codec_write(codec, nid, 0,
3763 AC_VERB_SET_AMP_GAIN_MUTE,
3764 AMP_OUT_MUTE);
3765}
3766
3767static void alc_auto_init_input_src(struct hda_codec *codec)
3768{
3769 struct alc_spec *spec = codec->spec;
3770 int c, nums;
3771
3772 for (c = 0; c < spec->num_adc_nids; c++)
3773 alc_auto_init_adc(codec, c);
3774 if (spec->dyn_adc_switch)
3775 nums = 1;
3776 else
3777 nums = spec->num_adc_nids;
3778 for (c = 0; c < nums; c++)
3779 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3780}
3781
3782/* add mic boosts if needed */
3783static int alc_auto_add_mic_boost(struct hda_codec *codec)
3784{
3785 struct alc_spec *spec = codec->spec;
3786 struct auto_pin_cfg *cfg = &spec->autocfg;
3787 int i, err;
3788 int type_idx = 0;
3789 hda_nid_t nid;
3790 const char *prev_label = NULL;
3791
3792 for (i = 0; i < cfg->num_inputs; i++) {
3793 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3794 break;
3795 nid = cfg->inputs[i].pin;
3796 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3797 const char *label;
3798 char boost_label[32];
3799
3800 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003801 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3802 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003803 if (prev_label && !strcmp(label, prev_label))
3804 type_idx++;
3805 else
3806 type_idx = 0;
3807 prev_label = label;
3808
3809 snprintf(boost_label, sizeof(boost_label),
3810 "%s Boost Volume", label);
3811 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3812 boost_label, type_idx,
3813 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3814 if (err < 0)
3815 return err;
3816 }
3817 }
3818 return 0;
3819}
3820
3821/* select or unmute the given capsrc route */
3822static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3823 int idx)
3824{
3825 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3826 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3827 HDA_AMP_MUTE, 0);
3828 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3829 snd_hda_codec_write_cache(codec, cap, 0,
3830 AC_VERB_SET_CONNECT_SEL, idx);
3831 }
3832}
3833
3834/* set the default connection to that pin */
3835static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3836{
3837 struct alc_spec *spec = codec->spec;
3838 int i;
3839
3840 if (!pin)
3841 return 0;
3842 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01003843 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003844 int idx;
3845
3846 idx = get_connection_index(codec, cap, pin);
3847 if (idx < 0)
3848 continue;
3849 select_or_unmute_capsrc(codec, cap, idx);
3850 return i; /* return the found index */
3851 }
3852 return -1; /* not found */
3853}
3854
3855/* initialize some special cases for input sources */
3856static void alc_init_special_input_src(struct hda_codec *codec)
3857{
3858 struct alc_spec *spec = codec->spec;
3859 int i;
3860
3861 for (i = 0; i < spec->autocfg.num_inputs; i++)
3862 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3863}
3864
3865/* assign appropriate capture mixers */
3866static void set_capture_mixer(struct hda_codec *codec)
3867{
3868 struct alc_spec *spec = codec->spec;
3869 static const struct snd_kcontrol_new *caps[2][3] = {
3870 { alc_capture_mixer_nosrc1,
3871 alc_capture_mixer_nosrc2,
3872 alc_capture_mixer_nosrc3 },
3873 { alc_capture_mixer1,
3874 alc_capture_mixer2,
3875 alc_capture_mixer3 },
3876 };
3877
3878 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003879 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003880 if (!spec->capsrc_nids)
3881 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003882 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003883 return; /* no volume in capsrc, too */
3884 spec->vol_in_capsrc = 1;
3885 }
3886
3887 if (spec->num_adc_nids > 0) {
3888 int mux = 0;
3889 int num_adcs = 0;
3890
3891 if (spec->input_mux && spec->input_mux->num_items > 1)
3892 mux = 1;
3893 if (spec->auto_mic) {
3894 num_adcs = 1;
3895 mux = 0;
3896 } else if (spec->dyn_adc_switch)
3897 num_adcs = 1;
3898 if (!num_adcs) {
3899 if (spec->num_adc_nids > 3)
3900 spec->num_adc_nids = 3;
3901 else if (!spec->num_adc_nids)
3902 return;
3903 num_adcs = spec->num_adc_nids;
3904 }
3905 spec->cap_mixer = caps[mux][num_adcs - 1];
3906 }
3907}
3908
3909/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003910 * standard auto-parser initializations
3911 */
3912static void alc_auto_init_std(struct hda_codec *codec)
3913{
3914 struct alc_spec *spec = codec->spec;
3915 alc_auto_init_multi_out(codec);
3916 alc_auto_init_extra_out(codec);
3917 alc_auto_init_analog_input(codec);
3918 alc_auto_init_input_src(codec);
3919 alc_auto_init_digital(codec);
3920 if (spec->unsol_event)
3921 alc_inithook(codec);
3922}
3923
3924/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003925 * Digital-beep handlers
3926 */
3927#ifdef CONFIG_SND_HDA_INPUT_BEEP
3928#define set_beep_amp(spec, nid, idx, dir) \
3929 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3930
3931static const struct snd_pci_quirk beep_white_list[] = {
3932 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3933 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3934 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3935 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3936 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3937 {}
3938};
3939
3940static inline int has_cdefine_beep(struct hda_codec *codec)
3941{
3942 struct alc_spec *spec = codec->spec;
3943 const struct snd_pci_quirk *q;
3944 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3945 if (q)
3946 return q->value;
3947 return spec->cdefine.enable_pcbeep;
3948}
3949#else
3950#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3951#define has_cdefine_beep(codec) 0
3952#endif
3953
3954/* parse the BIOS configuration and set up the alc_spec */
3955/* return 1 if successful, 0 if the proper config is not found,
3956 * or a negative error code
3957 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003958static int alc_parse_auto_config(struct hda_codec *codec,
3959 const hda_nid_t *ignore_nids,
3960 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003961{
3962 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003963 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003964 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003965
Takashi Iwai53c334a2011-08-23 18:27:14 +02003966 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3967 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003968 if (err < 0)
3969 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003970 if (!cfg->line_outs) {
3971 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003972 spec->multiout.max_channels = 2;
3973 spec->no_analog = 1;
3974 goto dig_only;
3975 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003976 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003977 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003978
Takashi Iwai06503672011-10-06 08:27:19 +02003979 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3980 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003981 /* use HP as primary out */
3982 cfg->speaker_outs = cfg->line_outs;
3983 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3984 sizeof(cfg->speaker_pins));
3985 cfg->line_outs = cfg->hp_outs;
3986 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3987 cfg->hp_outs = 0;
3988 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3989 cfg->line_out_type = AUTO_PIN_HP_OUT;
3990 }
3991
Takashi Iwai1d045db2011-07-07 18:23:21 +02003992 err = alc_auto_fill_dac_nids(codec);
3993 if (err < 0)
3994 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003995 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003996 if (err < 0)
3997 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003998 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003999 if (err < 0)
4000 return err;
4001 err = alc_auto_create_hp_out(codec);
4002 if (err < 0)
4003 return err;
4004 err = alc_auto_create_speaker_out(codec);
4005 if (err < 0)
4006 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004007 err = alc_auto_create_shared_input(codec);
4008 if (err < 0)
4009 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004010 err = alc_auto_create_input_ctls(codec);
4011 if (err < 0)
4012 return err;
4013
4014 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4015
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004016 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004017 alc_auto_parse_digital(codec);
4018
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004019 if (!spec->no_analog)
4020 alc_remove_invalid_adc_nids(codec);
4021
4022 if (ssid_nids)
4023 alc_ssid_check(codec, ssid_nids);
4024
4025 if (!spec->no_analog) {
4026 alc_auto_check_switches(codec);
4027 err = alc_auto_add_mic_boost(codec);
4028 if (err < 0)
4029 return err;
4030 }
4031
Takashi Iwai1d045db2011-07-07 18:23:21 +02004032 if (spec->kctls.list)
4033 add_mixer(spec, spec->kctls.list);
4034
Takashi Iwai1d045db2011-07-07 18:23:21 +02004035 return 1;
4036}
4037
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004038static int alc880_parse_auto_config(struct hda_codec *codec)
4039{
4040 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4041 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4042 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4043}
4044
Takashi Iwai1d045db2011-07-07 18:23:21 +02004045#ifdef CONFIG_SND_HDA_POWER_SAVE
4046static const struct hda_amp_list alc880_loopbacks[] = {
4047 { 0x0b, HDA_INPUT, 0 },
4048 { 0x0b, HDA_INPUT, 1 },
4049 { 0x0b, HDA_INPUT, 2 },
4050 { 0x0b, HDA_INPUT, 3 },
4051 { 0x0b, HDA_INPUT, 4 },
4052 { } /* end */
4053};
4054#endif
4055
4056/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004057 * ALC880 fix-ups
4058 */
4059enum {
4060 ALC880_FIXUP_GPIO2,
4061 ALC880_FIXUP_MEDION_RIM,
4062};
4063
4064static const struct alc_fixup alc880_fixups[] = {
4065 [ALC880_FIXUP_GPIO2] = {
4066 .type = ALC_FIXUP_VERBS,
4067 .v.verbs = alc_gpio2_init_verbs,
4068 },
4069 [ALC880_FIXUP_MEDION_RIM] = {
4070 .type = ALC_FIXUP_VERBS,
4071 .v.verbs = (const struct hda_verb[]) {
4072 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4073 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4074 { }
4075 },
4076 .chained = true,
4077 .chain_id = ALC880_FIXUP_GPIO2,
4078 },
4079};
4080
4081static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4082 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4083 {}
4084};
4085
4086
4087/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004088 * board setups
4089 */
4090#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4091#define alc_board_config \
4092 snd_hda_check_board_config
4093#define alc_board_codec_sid_config \
4094 snd_hda_check_board_codec_sid_config
4095#include "alc_quirks.c"
4096#else
4097#define alc_board_config(codec, nums, models, tbl) -1
4098#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4099#define setup_preset(codec, x) /* NOP */
4100#endif
4101
4102/*
4103 * OK, here we have finally the patch for ALC880
4104 */
4105#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4106#include "alc880_quirks.c"
4107#endif
4108
4109static int patch_alc880(struct hda_codec *codec)
4110{
4111 struct alc_spec *spec;
4112 int board_config;
4113 int err;
4114
4115 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4116 if (spec == NULL)
4117 return -ENOMEM;
4118
4119 codec->spec = spec;
4120
4121 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004122 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004123
4124 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4125 alc880_models, alc880_cfg_tbl);
4126 if (board_config < 0) {
4127 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4128 codec->chip_name);
4129 board_config = ALC_MODEL_AUTO;
4130 }
4131
4132 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004133 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4134 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4135 }
4136
4137 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004138 /* automatic parse from the BIOS config */
4139 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004140 if (err < 0)
4141 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004142#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4143 else if (!err) {
4144 printk(KERN_INFO
4145 "hda_codec: Cannot set up configuration "
4146 "from BIOS. Using 3-stack mode...\n");
4147 board_config = ALC880_3ST;
4148 }
4149#endif
4150 }
4151
David Henningssonfde48a12011-12-09 18:27:42 +08004152 if (board_config != ALC_MODEL_AUTO) {
4153 spec->vmaster_nid = 0x0c;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004154 setup_preset(codec, &alc880_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004155 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004156
Takashi Iwai60a6a842011-07-27 14:01:24 +02004157 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004158 alc_auto_fill_adc_caps(codec);
4159 alc_rebuild_imux_for_auto_mic(codec);
4160 alc_remove_invalid_adc_nids(codec);
4161 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004162
4163 if (!spec->no_analog && !spec->cap_mixer)
4164 set_capture_mixer(codec);
4165
4166 if (!spec->no_analog) {
4167 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004168 if (err < 0)
4169 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004170 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4171 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004172
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004173 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4174
Takashi Iwai1d045db2011-07-07 18:23:21 +02004175 codec->patch_ops = alc_patch_ops;
4176 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004177 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004178 else
4179 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004180#ifdef CONFIG_SND_HDA_POWER_SAVE
4181 if (!spec->loopback.amplist)
4182 spec->loopback.amplist = alc880_loopbacks;
4183#endif
4184
4185 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004186
4187 error:
4188 alc_free(codec);
4189 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004190}
4191
4192
4193/*
4194 * ALC260 support
4195 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004196static int alc260_parse_auto_config(struct hda_codec *codec)
4197{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004198 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004199 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4200 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004201}
4202
Takashi Iwai1d045db2011-07-07 18:23:21 +02004203#ifdef CONFIG_SND_HDA_POWER_SAVE
4204static const struct hda_amp_list alc260_loopbacks[] = {
4205 { 0x07, HDA_INPUT, 0 },
4206 { 0x07, HDA_INPUT, 1 },
4207 { 0x07, HDA_INPUT, 2 },
4208 { 0x07, HDA_INPUT, 3 },
4209 { 0x07, HDA_INPUT, 4 },
4210 { } /* end */
4211};
4212#endif
4213
4214/*
4215 * Pin config fixes
4216 */
4217enum {
4218 PINFIX_HP_DC5750,
4219};
4220
4221static const struct alc_fixup alc260_fixups[] = {
4222 [PINFIX_HP_DC5750] = {
4223 .type = ALC_FIXUP_PINS,
4224 .v.pins = (const struct alc_pincfg[]) {
4225 { 0x11, 0x90130110 }, /* speaker */
4226 { }
4227 }
4228 },
4229};
4230
4231static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4232 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4233 {}
4234};
4235
4236/*
4237 */
4238#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4239#include "alc260_quirks.c"
4240#endif
4241
4242static int patch_alc260(struct hda_codec *codec)
4243{
4244 struct alc_spec *spec;
4245 int err, board_config;
4246
4247 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4248 if (spec == NULL)
4249 return -ENOMEM;
4250
4251 codec->spec = spec;
4252
4253 spec->mixer_nid = 0x07;
4254
4255 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4256 alc260_models, alc260_cfg_tbl);
4257 if (board_config < 0) {
4258 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4259 codec->chip_name);
4260 board_config = ALC_MODEL_AUTO;
4261 }
4262
4263 if (board_config == ALC_MODEL_AUTO) {
4264 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4265 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4266 }
4267
4268 if (board_config == ALC_MODEL_AUTO) {
4269 /* automatic parse from the BIOS config */
4270 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004271 if (err < 0)
4272 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004273#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4274 else if (!err) {
4275 printk(KERN_INFO
4276 "hda_codec: Cannot set up configuration "
4277 "from BIOS. Using base mode...\n");
4278 board_config = ALC260_BASIC;
4279 }
4280#endif
4281 }
4282
David Henningssonfde48a12011-12-09 18:27:42 +08004283 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004284 setup_preset(codec, &alc260_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004285 spec->vmaster_nid = 0x08;
4286 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004287
Takashi Iwai60a6a842011-07-27 14:01:24 +02004288 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004289 alc_auto_fill_adc_caps(codec);
4290 alc_rebuild_imux_for_auto_mic(codec);
4291 alc_remove_invalid_adc_nids(codec);
4292 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004293
4294 if (!spec->no_analog && !spec->cap_mixer)
4295 set_capture_mixer(codec);
4296
4297 if (!spec->no_analog) {
4298 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004299 if (err < 0)
4300 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004301 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4302 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004303
4304 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4305
Takashi Iwai1d045db2011-07-07 18:23:21 +02004306 codec->patch_ops = alc_patch_ops;
4307 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004308 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004309 else
4310 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004311 spec->shutup = alc_eapd_shutup;
4312#ifdef CONFIG_SND_HDA_POWER_SAVE
4313 if (!spec->loopback.amplist)
4314 spec->loopback.amplist = alc260_loopbacks;
4315#endif
4316
4317 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004318
4319 error:
4320 alc_free(codec);
4321 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004322}
4323
4324
4325/*
4326 * ALC882/883/885/888/889 support
4327 *
4328 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4329 * configuration. Each pin widget can choose any input DACs and a mixer.
4330 * Each ADC is connected from a mixer of all inputs. This makes possible
4331 * 6-channel independent captures.
4332 *
4333 * In addition, an independent DAC for the multi-playback (not used in this
4334 * driver yet).
4335 */
4336#ifdef CONFIG_SND_HDA_POWER_SAVE
4337#define alc882_loopbacks alc880_loopbacks
4338#endif
4339
4340/*
4341 * Pin config fixes
4342 */
4343enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004344 ALC882_FIXUP_ABIT_AW9D_MAX,
4345 ALC882_FIXUP_LENOVO_Y530,
4346 ALC882_FIXUP_PB_M5210,
4347 ALC882_FIXUP_ACER_ASPIRE_7736,
4348 ALC882_FIXUP_ASUS_W90V,
4349 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004350 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a32011-11-09 12:55:18 +01004351 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004352 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004353 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004354 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004355 ALC889_FIXUP_COEF,
4356 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004357 ALC882_FIXUP_ACER_ASPIRE_4930G,
4358 ALC882_FIXUP_ACER_ASPIRE_8930G,
4359 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004360 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004361};
4362
Takashi Iwai68ef0562011-11-09 18:24:44 +01004363static void alc889_fixup_coef(struct hda_codec *codec,
4364 const struct alc_fixup *fix, int action)
4365{
4366 if (action != ALC_FIXUP_ACT_INIT)
4367 return;
4368 alc889_coef_init(codec);
4369}
4370
Takashi Iwai56710872011-11-14 17:42:11 +01004371/* toggle speaker-output according to the hp-jack state */
4372static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4373{
4374 unsigned int gpiostate, gpiomask, gpiodir;
4375
4376 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4377 AC_VERB_GET_GPIO_DATA, 0);
4378
4379 if (!muted)
4380 gpiostate |= (1 << pin);
4381 else
4382 gpiostate &= ~(1 << pin);
4383
4384 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4385 AC_VERB_GET_GPIO_MASK, 0);
4386 gpiomask |= (1 << pin);
4387
4388 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4389 AC_VERB_GET_GPIO_DIRECTION, 0);
4390 gpiodir |= (1 << pin);
4391
4392
4393 snd_hda_codec_write(codec, codec->afg, 0,
4394 AC_VERB_SET_GPIO_MASK, gpiomask);
4395 snd_hda_codec_write(codec, codec->afg, 0,
4396 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4397
4398 msleep(1);
4399
4400 snd_hda_codec_write(codec, codec->afg, 0,
4401 AC_VERB_SET_GPIO_DATA, gpiostate);
4402}
4403
4404/* set up GPIO at initialization */
4405static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4406 const struct alc_fixup *fix, int action)
4407{
4408 if (action != ALC_FIXUP_ACT_INIT)
4409 return;
4410 alc882_gpio_mute(codec, 0, 0);
4411 alc882_gpio_mute(codec, 1, 0);
4412}
4413
Takashi Iwai1d045db2011-07-07 18:23:21 +02004414static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004415 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004416 .type = ALC_FIXUP_PINS,
4417 .v.pins = (const struct alc_pincfg[]) {
4418 { 0x15, 0x01080104 }, /* side */
4419 { 0x16, 0x01011012 }, /* rear */
4420 { 0x17, 0x01016011 }, /* clfe */
4421 { }
4422 }
4423 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004424 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004425 .type = ALC_FIXUP_PINS,
4426 .v.pins = (const struct alc_pincfg[]) {
4427 { 0x15, 0x99130112 }, /* rear int speakers */
4428 { 0x16, 0x99130111 }, /* subwoofer */
4429 { }
4430 }
4431 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004432 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004433 .type = ALC_FIXUP_VERBS,
4434 .v.verbs = (const struct hda_verb[]) {
4435 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4436 {}
4437 }
4438 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004439 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004440 .type = ALC_FIXUP_SKU,
4441 .v.sku = ALC_FIXUP_SKU_IGNORE,
4442 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004443 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004444 .type = ALC_FIXUP_PINS,
4445 .v.pins = (const struct alc_pincfg[]) {
4446 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4447 { }
4448 }
4449 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004450 [ALC889_FIXUP_VAIO_TT] = {
4451 .type = ALC_FIXUP_PINS,
4452 .v.pins = (const struct alc_pincfg[]) {
4453 { 0x17, 0x90170111 }, /* hidden surround speaker */
4454 { }
4455 }
4456 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004457 [ALC888_FIXUP_EEE1601] = {
4458 .type = ALC_FIXUP_VERBS,
4459 .v.verbs = (const struct hda_verb[]) {
4460 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4461 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4462 { }
4463 }
Takashi Iwai177943a32011-11-09 12:55:18 +01004464 },
4465 [ALC882_FIXUP_EAPD] = {
4466 .type = ALC_FIXUP_VERBS,
4467 .v.verbs = (const struct hda_verb[]) {
4468 /* change to EAPD mode */
4469 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4470 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4471 { }
4472 }
4473 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004474 [ALC883_FIXUP_EAPD] = {
4475 .type = ALC_FIXUP_VERBS,
4476 .v.verbs = (const struct hda_verb[]) {
4477 /* change to EAPD mode */
4478 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4479 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4480 { }
4481 }
4482 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004483 [ALC883_FIXUP_ACER_EAPD] = {
4484 .type = ALC_FIXUP_VERBS,
4485 .v.verbs = (const struct hda_verb[]) {
4486 /* eanable EAPD on Acer laptops */
4487 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4488 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4489 { }
4490 }
4491 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004492 [ALC882_FIXUP_GPIO3] = {
4493 .type = ALC_FIXUP_VERBS,
4494 .v.verbs = alc_gpio3_init_verbs,
4495 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004496 [ALC882_FIXUP_ASUS_W2JC] = {
4497 .type = ALC_FIXUP_VERBS,
4498 .v.verbs = alc_gpio1_init_verbs,
4499 .chained = true,
4500 .chain_id = ALC882_FIXUP_EAPD,
4501 },
4502 [ALC889_FIXUP_COEF] = {
4503 .type = ALC_FIXUP_FUNC,
4504 .v.func = alc889_fixup_coef,
4505 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004506 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4507 .type = ALC_FIXUP_PINS,
4508 .v.pins = (const struct alc_pincfg[]) {
4509 { 0x16, 0x99130111 }, /* CLFE speaker */
4510 { 0x17, 0x99130112 }, /* surround speaker */
4511 { }
4512 }
4513 },
4514 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4515 .type = ALC_FIXUP_PINS,
4516 .v.pins = (const struct alc_pincfg[]) {
4517 { 0x16, 0x99130111 }, /* CLFE speaker */
4518 { 0x1b, 0x99130112 }, /* surround speaker */
4519 { }
4520 },
4521 .chained = true,
4522 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4523 },
4524 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4525 /* additional init verbs for Acer Aspire 8930G */
4526 .type = ALC_FIXUP_VERBS,
4527 .v.verbs = (const struct hda_verb[]) {
4528 /* Enable all DACs */
4529 /* DAC DISABLE/MUTE 1? */
4530 /* setting bits 1-5 disables DAC nids 0x02-0x06
4531 * apparently. Init=0x38 */
4532 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4533 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4534 /* DAC DISABLE/MUTE 2? */
4535 /* some bit here disables the other DACs.
4536 * Init=0x4900 */
4537 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4538 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4539 /* DMIC fix
4540 * This laptop has a stereo digital microphone.
4541 * The mics are only 1cm apart which makes the stereo
4542 * useless. However, either the mic or the ALC889
4543 * makes the signal become a difference/sum signal
4544 * instead of standard stereo, which is annoying.
4545 * So instead we flip this bit which makes the
4546 * codec replicate the sum signal to both channels,
4547 * turning it into a normal mono mic.
4548 */
4549 /* DMIC_CONTROL? Init value = 0x0001 */
4550 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4551 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4552 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4553 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4554 { }
4555 }
4556 },
Takashi Iwai56710872011-11-14 17:42:11 +01004557 [ALC885_FIXUP_MACPRO_GPIO] = {
4558 .type = ALC_FIXUP_FUNC,
4559 .v.func = alc885_fixup_macpro_gpio,
4560 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004561};
4562
4563static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004564 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4565 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4566 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4567 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4568 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4569 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004570 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4571 ALC882_FIXUP_ACER_ASPIRE_4930G),
4572 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4573 ALC882_FIXUP_ACER_ASPIRE_4930G),
4574 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4575 ALC882_FIXUP_ACER_ASPIRE_8930G),
4576 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4577 ALC882_FIXUP_ACER_ASPIRE_8930G),
4578 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4579 ALC882_FIXUP_ACER_ASPIRE_4930G),
4580 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4581 ALC882_FIXUP_ACER_ASPIRE_4930G),
4582 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4583 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004584 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004585 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a32011-11-09 12:55:18 +01004586 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004587 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004588 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004589 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004590 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01004591
4592 /* All Apple entries are in codec SSIDs */
4593 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4594 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4595 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4596 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4597 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4598
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004599 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004600 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004601 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004602 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4603 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004604 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004605 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004606 {}
4607};
4608
4609/*
4610 * BIOS auto configuration
4611 */
4612/* almost identical with ALC880 parser... */
4613static int alc882_parse_auto_config(struct hda_codec *codec)
4614{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004615 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004616 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4617 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004618}
4619
Takashi Iwai1d045db2011-07-07 18:23:21 +02004620/*
4621 */
4622#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4623#include "alc882_quirks.c"
4624#endif
4625
4626static int patch_alc882(struct hda_codec *codec)
4627{
4628 struct alc_spec *spec;
4629 int err, board_config;
4630
4631 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4632 if (spec == NULL)
4633 return -ENOMEM;
4634
4635 codec->spec = spec;
4636
4637 spec->mixer_nid = 0x0b;
4638
4639 switch (codec->vendor_id) {
4640 case 0x10ec0882:
4641 case 0x10ec0885:
4642 break;
4643 default:
4644 /* ALC883 and variants */
4645 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4646 break;
4647 }
4648
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004649 err = alc_codec_rename_from_preset(codec);
4650 if (err < 0)
4651 goto error;
4652
Takashi Iwaib2539692011-11-14 17:32:17 +01004653 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4654 alc882_models, NULL);
4655 if (board_config < 0)
4656 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004657 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4658
4659 if (board_config < 0) {
4660 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4661 codec->chip_name);
4662 board_config = ALC_MODEL_AUTO;
4663 }
4664
4665 if (board_config == ALC_MODEL_AUTO) {
4666 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4667 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4668 }
4669
4670 alc_auto_parse_customize_define(codec);
4671
4672 if (board_config == ALC_MODEL_AUTO) {
4673 /* automatic parse from the BIOS config */
4674 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004675 if (err < 0)
4676 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004677 }
4678
David Henningssonfde48a12011-12-09 18:27:42 +08004679 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004680 setup_preset(codec, &alc882_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004681 spec->vmaster_nid = 0x0c;
4682 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004683
Takashi Iwai60a6a842011-07-27 14:01:24 +02004684 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004685 alc_auto_fill_adc_caps(codec);
4686 alc_rebuild_imux_for_auto_mic(codec);
4687 alc_remove_invalid_adc_nids(codec);
4688 }
4689
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004690 if (!spec->no_analog && !spec->cap_mixer)
4691 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004692
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004693 if (!spec->no_analog && has_cdefine_beep(codec)) {
4694 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004695 if (err < 0)
4696 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004697 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004698 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004699
4700 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4701
Takashi Iwai1d045db2011-07-07 18:23:21 +02004702 codec->patch_ops = alc_patch_ops;
4703 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004704 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004705 else
4706 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004707
Takashi Iwai1d045db2011-07-07 18:23:21 +02004708#ifdef CONFIG_SND_HDA_POWER_SAVE
4709 if (!spec->loopback.amplist)
4710 spec->loopback.amplist = alc882_loopbacks;
4711#endif
4712
4713 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004714
4715 error:
4716 alc_free(codec);
4717 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004718}
4719
4720
4721/*
4722 * ALC262 support
4723 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004724static int alc262_parse_auto_config(struct hda_codec *codec)
4725{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004726 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004727 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4728 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004729}
4730
4731/*
4732 * Pin config fixes
4733 */
4734enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004735 ALC262_FIXUP_FSC_H270,
4736 ALC262_FIXUP_HP_Z200,
4737 ALC262_FIXUP_TYAN,
Takashi Iwai12837c92011-11-07 12:45:24 +01004738 ALC262_FIXUP_TOSHIBA_RX1,
Takashi Iwaic4701502011-11-07 14:20:07 +01004739 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004740 ALC262_FIXUP_BENQ,
4741 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004742};
4743
4744static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004745 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004746 .type = ALC_FIXUP_PINS,
4747 .v.pins = (const struct alc_pincfg[]) {
4748 { 0x14, 0x99130110 }, /* speaker */
4749 { 0x15, 0x0221142f }, /* front HP */
4750 { 0x1b, 0x0121141f }, /* rear HP */
4751 { }
4752 }
4753 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004754 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004755 .type = ALC_FIXUP_PINS,
4756 .v.pins = (const struct alc_pincfg[]) {
4757 { 0x16, 0x99130120 }, /* internal speaker */
4758 { }
4759 }
4760 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004761 [ALC262_FIXUP_TYAN] = {
4762 .type = ALC_FIXUP_PINS,
4763 .v.pins = (const struct alc_pincfg[]) {
4764 { 0x14, 0x1993e1f0 }, /* int AUX */
4765 { }
4766 }
4767 },
Takashi Iwai12837c92011-11-07 12:45:24 +01004768 [ALC262_FIXUP_TOSHIBA_RX1] = {
4769 .type = ALC_FIXUP_PINS,
4770 .v.pins = (const struct alc_pincfg[]) {
4771 { 0x14, 0x90170110 }, /* speaker */
4772 { 0x15, 0x0421101f }, /* HP */
4773 { 0x1a, 0x40f000f0 }, /* N/A */
4774 { 0x1b, 0x40f000f0 }, /* N/A */
4775 { 0x1e, 0x40f000f0 }, /* N/A */
4776 }
4777 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004778 [ALC262_FIXUP_LENOVO_3000] = {
4779 .type = ALC_FIXUP_VERBS,
4780 .v.verbs = (const struct hda_verb[]) {
4781 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004782 {}
4783 },
4784 .chained = true,
4785 .chain_id = ALC262_FIXUP_BENQ,
4786 },
4787 [ALC262_FIXUP_BENQ] = {
4788 .type = ALC_FIXUP_VERBS,
4789 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004790 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4791 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4792 {}
4793 }
4794 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004795 [ALC262_FIXUP_BENQ_T31] = {
4796 .type = ALC_FIXUP_VERBS,
4797 .v.verbs = (const struct hda_verb[]) {
4798 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4799 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4800 {}
4801 }
4802 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004803};
4804
4805static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004806 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004807 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4808 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004809 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
Takashi Iwai12837c92011-11-07 12:45:24 +01004810 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4811 ALC262_FIXUP_TOSHIBA_RX1),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004812 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004813 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004814 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4815 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004816 {}
4817};
4818
4819
4820#ifdef CONFIG_SND_HDA_POWER_SAVE
4821#define alc262_loopbacks alc880_loopbacks
4822#endif
4823
Takashi Iwai1d045db2011-07-07 18:23:21 +02004824/*
4825 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004826static int patch_alc262(struct hda_codec *codec)
4827{
4828 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004829 int err;
4830
4831 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4832 if (spec == NULL)
4833 return -ENOMEM;
4834
4835 codec->spec = spec;
4836
4837 spec->mixer_nid = 0x0b;
4838
4839#if 0
4840 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4841 * under-run
4842 */
4843 {
4844 int tmp;
4845 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4846 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4847 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4848 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4849 }
4850#endif
4851 alc_auto_parse_customize_define(codec);
4852
4853 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4854
Takashi Iwai42399f72011-11-07 17:18:44 +01004855 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4856 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004857
Takashi Iwai42399f72011-11-07 17:18:44 +01004858 /* automatic parse from the BIOS config */
4859 err = alc262_parse_auto_config(codec);
4860 if (err < 0)
4861 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004862
Takashi Iwai60a6a842011-07-27 14:01:24 +02004863 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004864 alc_auto_fill_adc_caps(codec);
4865 alc_rebuild_imux_for_auto_mic(codec);
4866 alc_remove_invalid_adc_nids(codec);
4867 }
4868
4869 if (!spec->no_analog && !spec->cap_mixer)
4870 set_capture_mixer(codec);
4871
Takashi Iwai1d045db2011-07-07 18:23:21 +02004872 if (!spec->no_analog && has_cdefine_beep(codec)) {
4873 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004874 if (err < 0)
4875 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004876 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004877 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004878
4879 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4880
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004882 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004883 spec->shutup = alc_eapd_shutup;
4884
Takashi Iwai1d045db2011-07-07 18:23:21 +02004885#ifdef CONFIG_SND_HDA_POWER_SAVE
4886 if (!spec->loopback.amplist)
4887 spec->loopback.amplist = alc262_loopbacks;
4888#endif
4889
4890 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004891
4892 error:
4893 alc_free(codec);
4894 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004895}
4896
4897/*
4898 * ALC268
4899 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004900/* bind Beep switches of both NID 0x0f and 0x10 */
4901static const struct hda_bind_ctls alc268_bind_beep_sw = {
4902 .ops = &snd_hda_bind_sw,
4903 .values = {
4904 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4905 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4906 0
4907 },
4908};
4909
4910static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4911 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4912 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4913 { }
4914};
4915
4916/* set PCBEEP vol = 0, mute connections */
4917static const struct hda_verb alc268_beep_init_verbs[] = {
4918 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4919 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4920 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4921 { }
4922};
4923
4924/*
4925 * BIOS auto configuration
4926 */
4927static int alc268_parse_auto_config(struct hda_codec *codec)
4928{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004929 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004930 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004931 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4932 if (err > 0) {
4933 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4934 add_mixer(spec, alc268_beep_mixer);
4935 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004936 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004937 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004938 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004939}
4940
Takashi Iwai1d045db2011-07-07 18:23:21 +02004941/*
4942 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004943static int patch_alc268(struct hda_codec *codec)
4944{
4945 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004946 int i, has_beep, err;
4947
4948 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4949 if (spec == NULL)
4950 return -ENOMEM;
4951
4952 codec->spec = spec;
4953
4954 /* ALC268 has no aa-loopback mixer */
4955
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004956 /* automatic parse from the BIOS config */
4957 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004958 if (err < 0)
4959 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004960
Takashi Iwai1d045db2011-07-07 18:23:21 +02004961 has_beep = 0;
4962 for (i = 0; i < spec->num_mixers; i++) {
4963 if (spec->mixers[i] == alc268_beep_mixer) {
4964 has_beep = 1;
4965 break;
4966 }
4967 }
4968
4969 if (has_beep) {
4970 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004971 if (err < 0)
4972 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004973 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4974 /* override the amp caps for beep generator */
4975 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4976 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4977 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4978 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4979 (0 << AC_AMPCAP_MUTE_SHIFT));
4980 }
4981
Takashi Iwai60a6a842011-07-27 14:01:24 +02004982 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004983 alc_auto_fill_adc_caps(codec);
4984 alc_rebuild_imux_for_auto_mic(codec);
4985 alc_remove_invalid_adc_nids(codec);
4986 }
4987
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004988 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989 set_capture_mixer(codec);
4990
Takashi Iwai1d045db2011-07-07 18:23:21 +02004991 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004992 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993 spec->shutup = alc_eapd_shutup;
4994
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004996
4997 error:
4998 alc_free(codec);
4999 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000}
5001
5002/*
5003 * ALC269
5004 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005#ifdef CONFIG_SND_HDA_POWER_SAVE
5006#define alc269_loopbacks alc880_loopbacks
5007#endif
5008
5009static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5010 .substreams = 1,
5011 .channels_min = 2,
5012 .channels_max = 8,
5013 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5014 /* NID is set in alc_build_pcms */
5015 .ops = {
5016 .open = alc_playback_pcm_open,
5017 .prepare = alc_playback_pcm_prepare,
5018 .cleanup = alc_playback_pcm_cleanup
5019 },
5020};
5021
5022static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5023 .substreams = 1,
5024 .channels_min = 2,
5025 .channels_max = 2,
5026 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5027 /* NID is set in alc_build_pcms */
5028};
5029
5030#ifdef CONFIG_SND_HDA_POWER_SAVE
5031static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5032{
5033 switch (codec->subsystem_id) {
5034 case 0x103c1586:
5035 return 1;
5036 }
5037 return 0;
5038}
5039
5040static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5041{
5042 /* update mute-LED according to the speaker mute state */
5043 if (nid == 0x01 || nid == 0x14) {
5044 int pinval;
5045 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5046 HDA_AMP_MUTE)
5047 pinval = 0x24;
5048 else
5049 pinval = 0x20;
5050 /* mic2 vref pin is used for mute LED control */
5051 snd_hda_codec_update_cache(codec, 0x19, 0,
5052 AC_VERB_SET_PIN_WIDGET_CONTROL,
5053 pinval);
5054 }
5055 return alc_check_power_status(codec, nid);
5056}
5057#endif /* CONFIG_SND_HDA_POWER_SAVE */
5058
5059/* different alc269-variants */
5060enum {
5061 ALC269_TYPE_ALC269VA,
5062 ALC269_TYPE_ALC269VB,
5063 ALC269_TYPE_ALC269VC,
5064};
5065
5066/*
5067 * BIOS auto configuration
5068 */
5069static int alc269_parse_auto_config(struct hda_codec *codec)
5070{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005071 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005072 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5073 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5074 struct alc_spec *spec = codec->spec;
5075 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5076 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005077
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005078 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005079}
5080
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5082{
5083 int val = alc_read_coef_idx(codec, 0x04);
5084 if (power_up)
5085 val |= 1 << 11;
5086 else
5087 val &= ~(1 << 11);
5088 alc_write_coef_idx(codec, 0x04, val);
5089}
5090
5091static void alc269_shutup(struct hda_codec *codec)
5092{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005093 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005094 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005095 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005096 alc269_toggle_power_output(codec, 0);
5097 msleep(150);
5098 }
5099}
5100
Takashi Iwai2a439522011-07-26 09:52:50 +02005101#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005102static int alc269_resume(struct hda_codec *codec)
5103{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005104 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005105 alc269_toggle_power_output(codec, 0);
5106 msleep(150);
5107 }
5108
5109 codec->patch_ops.init(codec);
5110
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005111 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005112 alc269_toggle_power_output(codec, 1);
5113 msleep(200);
5114 }
5115
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005116 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005117 alc269_toggle_power_output(codec, 1);
5118
5119 snd_hda_codec_resume_amp(codec);
5120 snd_hda_codec_resume_cache(codec);
5121 hda_call_check_power_status(codec, 0x01);
5122 return 0;
5123}
Takashi Iwai2a439522011-07-26 09:52:50 +02005124#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005125
5126static void alc269_fixup_hweq(struct hda_codec *codec,
5127 const struct alc_fixup *fix, int action)
5128{
5129 int coef;
5130
5131 if (action != ALC_FIXUP_ACT_INIT)
5132 return;
5133 coef = alc_read_coef_idx(codec, 0x1e);
5134 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5135}
5136
5137static void alc271_fixup_dmic(struct hda_codec *codec,
5138 const struct alc_fixup *fix, int action)
5139{
5140 static const struct hda_verb verbs[] = {
5141 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5142 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5143 {}
5144 };
5145 unsigned int cfg;
5146
5147 if (strcmp(codec->chip_name, "ALC271X"))
5148 return;
5149 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5150 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5151 snd_hda_sequence_write(codec, verbs);
5152}
5153
Takashi Iwai017f2a12011-07-09 14:42:25 +02005154static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5155 const struct alc_fixup *fix, int action)
5156{
5157 struct alc_spec *spec = codec->spec;
5158
5159 if (action != ALC_FIXUP_ACT_PROBE)
5160 return;
5161
5162 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5163 * fix the sample rate of analog I/O to 44.1kHz
5164 */
5165 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5166 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5167}
5168
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005169static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5170 const struct alc_fixup *fix, int action)
5171{
5172 int coef;
5173
5174 if (action != ALC_FIXUP_ACT_INIT)
5175 return;
5176 /* The digital-mic unit sends PDM (differential signal) instead of
5177 * the standard PCM, thus you can't record a valid mono stream as is.
5178 * Below is a workaround specific to ALC269 to control the dmic
5179 * signal source as mono.
5180 */
5181 coef = alc_read_coef_idx(codec, 0x07);
5182 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5183}
5184
Takashi Iwai24519912011-08-16 15:08:49 +02005185static void alc269_quanta_automute(struct hda_codec *codec)
5186{
David Henningsson42cf0d02011-09-20 12:04:56 +02005187 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005188
5189 snd_hda_codec_write(codec, 0x20, 0,
5190 AC_VERB_SET_COEF_INDEX, 0x0c);
5191 snd_hda_codec_write(codec, 0x20, 0,
5192 AC_VERB_SET_PROC_COEF, 0x680);
5193
5194 snd_hda_codec_write(codec, 0x20, 0,
5195 AC_VERB_SET_COEF_INDEX, 0x0c);
5196 snd_hda_codec_write(codec, 0x20, 0,
5197 AC_VERB_SET_PROC_COEF, 0x480);
5198}
5199
5200static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5201 const struct alc_fixup *fix, int action)
5202{
5203 struct alc_spec *spec = codec->spec;
5204 if (action != ALC_FIXUP_ACT_PROBE)
5205 return;
5206 spec->automute_hook = alc269_quanta_automute;
5207}
5208
Takashi Iwai1d045db2011-07-07 18:23:21 +02005209enum {
5210 ALC269_FIXUP_SONY_VAIO,
5211 ALC275_FIXUP_SONY_VAIO_GPIO2,
5212 ALC269_FIXUP_DELL_M101Z,
5213 ALC269_FIXUP_SKU_IGNORE,
5214 ALC269_FIXUP_ASUS_G73JW,
5215 ALC269_FIXUP_LENOVO_EAPD,
5216 ALC275_FIXUP_SONY_HWEQ,
5217 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005218 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005219 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005220 ALC269_FIXUP_QUANTA_MUTE,
5221 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005222 ALC269_FIXUP_AMIC,
5223 ALC269_FIXUP_DMIC,
5224 ALC269VB_FIXUP_AMIC,
5225 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005226};
5227
5228static const struct alc_fixup alc269_fixups[] = {
5229 [ALC269_FIXUP_SONY_VAIO] = {
5230 .type = ALC_FIXUP_VERBS,
5231 .v.verbs = (const struct hda_verb[]) {
5232 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5233 {}
5234 }
5235 },
5236 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5237 .type = ALC_FIXUP_VERBS,
5238 .v.verbs = (const struct hda_verb[]) {
5239 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5240 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5241 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5242 { }
5243 },
5244 .chained = true,
5245 .chain_id = ALC269_FIXUP_SONY_VAIO
5246 },
5247 [ALC269_FIXUP_DELL_M101Z] = {
5248 .type = ALC_FIXUP_VERBS,
5249 .v.verbs = (const struct hda_verb[]) {
5250 /* Enables internal speaker */
5251 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5252 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5253 {}
5254 }
5255 },
5256 [ALC269_FIXUP_SKU_IGNORE] = {
5257 .type = ALC_FIXUP_SKU,
5258 .v.sku = ALC_FIXUP_SKU_IGNORE,
5259 },
5260 [ALC269_FIXUP_ASUS_G73JW] = {
5261 .type = ALC_FIXUP_PINS,
5262 .v.pins = (const struct alc_pincfg[]) {
5263 { 0x17, 0x99130111 }, /* subwoofer */
5264 { }
5265 }
5266 },
5267 [ALC269_FIXUP_LENOVO_EAPD] = {
5268 .type = ALC_FIXUP_VERBS,
5269 .v.verbs = (const struct hda_verb[]) {
5270 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5271 {}
5272 }
5273 },
5274 [ALC275_FIXUP_SONY_HWEQ] = {
5275 .type = ALC_FIXUP_FUNC,
5276 .v.func = alc269_fixup_hweq,
5277 .chained = true,
5278 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5279 },
5280 [ALC271_FIXUP_DMIC] = {
5281 .type = ALC_FIXUP_FUNC,
5282 .v.func = alc271_fixup_dmic,
5283 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005284 [ALC269_FIXUP_PCM_44K] = {
5285 .type = ALC_FIXUP_FUNC,
5286 .v.func = alc269_fixup_pcm_44k,
5287 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005288 [ALC269_FIXUP_STEREO_DMIC] = {
5289 .type = ALC_FIXUP_FUNC,
5290 .v.func = alc269_fixup_stereo_dmic,
5291 },
Takashi Iwai24519912011-08-16 15:08:49 +02005292 [ALC269_FIXUP_QUANTA_MUTE] = {
5293 .type = ALC_FIXUP_FUNC,
5294 .v.func = alc269_fixup_quanta_mute,
5295 },
5296 [ALC269_FIXUP_LIFEBOOK] = {
5297 .type = ALC_FIXUP_PINS,
5298 .v.pins = (const struct alc_pincfg[]) {
5299 { 0x1a, 0x2101103f }, /* dock line-out */
5300 { 0x1b, 0x23a11040 }, /* dock mic-in */
5301 { }
5302 },
5303 .chained = true,
5304 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5305 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005306 [ALC269_FIXUP_AMIC] = {
5307 .type = ALC_FIXUP_PINS,
5308 .v.pins = (const struct alc_pincfg[]) {
5309 { 0x14, 0x99130110 }, /* speaker */
5310 { 0x15, 0x0121401f }, /* HP out */
5311 { 0x18, 0x01a19c20 }, /* mic */
5312 { 0x19, 0x99a3092f }, /* int-mic */
5313 { }
5314 },
5315 },
5316 [ALC269_FIXUP_DMIC] = {
5317 .type = ALC_FIXUP_PINS,
5318 .v.pins = (const struct alc_pincfg[]) {
5319 { 0x12, 0x99a3092f }, /* int-mic */
5320 { 0x14, 0x99130110 }, /* speaker */
5321 { 0x15, 0x0121401f }, /* HP out */
5322 { 0x18, 0x01a19c20 }, /* mic */
5323 { }
5324 },
5325 },
5326 [ALC269VB_FIXUP_AMIC] = {
5327 .type = ALC_FIXUP_PINS,
5328 .v.pins = (const struct alc_pincfg[]) {
5329 { 0x14, 0x99130110 }, /* speaker */
5330 { 0x18, 0x01a19c20 }, /* mic */
5331 { 0x19, 0x99a3092f }, /* int-mic */
5332 { 0x21, 0x0121401f }, /* HP out */
5333 { }
5334 },
5335 },
David Henningsson2267ea92012-01-03 08:45:56 +01005336 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02005337 .type = ALC_FIXUP_PINS,
5338 .v.pins = (const struct alc_pincfg[]) {
5339 { 0x12, 0x99a3092f }, /* int-mic */
5340 { 0x14, 0x99130110 }, /* speaker */
5341 { 0x18, 0x01a19c20 }, /* mic */
5342 { 0x21, 0x0121401f }, /* HP out */
5343 { }
5344 },
5345 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005346};
5347
5348static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005349 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005350 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5351 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5352 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5353 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5354 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005355 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5356 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5357 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5358 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5359 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5360 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005361 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005362 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5363 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5364 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5365 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5366 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005367 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005368 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005369 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005370
5371#if 1
5372 /* Below is a quirk table taken from the old code.
5373 * Basically the device should work as is without the fixup table.
5374 * If BIOS doesn't give a proper info, enable the corresponding
5375 * fixup entry.
5376 */
5377 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5378 ALC269_FIXUP_AMIC),
5379 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5380 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
5381 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5382 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5383 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5384 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5385 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5386 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5387 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5388 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5389 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5390 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5391 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5392 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5393 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5394 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5395 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5396 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5397 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5398 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5399 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5400 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5401 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5402 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5403 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5404 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5405 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5406 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5407 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5408 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5409 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5410 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5411 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5412 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5413 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5414 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5415 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5416 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5417 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5418 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5419#endif
5420 {}
5421};
5422
5423static const struct alc_model_fixup alc269_fixup_models[] = {
5424 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5425 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005426 {}
5427};
5428
5429
5430static int alc269_fill_coef(struct hda_codec *codec)
5431{
5432 int val;
5433
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005434 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005435 alc_write_coef_idx(codec, 0xf, 0x960b);
5436 alc_write_coef_idx(codec, 0xe, 0x8817);
5437 }
5438
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005439 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005440 alc_write_coef_idx(codec, 0xf, 0x960b);
5441 alc_write_coef_idx(codec, 0xe, 0x8814);
5442 }
5443
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005444 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005445 val = alc_read_coef_idx(codec, 0x04);
5446 /* Power up output pin */
5447 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5448 }
5449
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005450 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451 val = alc_read_coef_idx(codec, 0xd);
5452 if ((val & 0x0c00) >> 10 != 0x1) {
5453 /* Capless ramp up clock control */
5454 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5455 }
5456 val = alc_read_coef_idx(codec, 0x17);
5457 if ((val & 0x01c0) >> 6 != 0x4) {
5458 /* Class D power on reset */
5459 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5460 }
5461 }
5462
5463 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5464 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5465
5466 val = alc_read_coef_idx(codec, 0x4); /* HP */
5467 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5468
5469 return 0;
5470}
5471
5472/*
5473 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005474static int patch_alc269(struct hda_codec *codec)
5475{
5476 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005477 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005478
5479 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5480 if (spec == NULL)
5481 return -ENOMEM;
5482
5483 codec->spec = spec;
5484
5485 spec->mixer_nid = 0x0b;
5486
5487 alc_auto_parse_customize_define(codec);
5488
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005489 err = alc_codec_rename_from_preset(codec);
5490 if (err < 0)
5491 goto error;
5492
Takashi Iwai1d045db2011-07-07 18:23:21 +02005493 if (codec->vendor_id == 0x10ec0269) {
5494 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005495 switch (alc_get_coef0(codec) & 0x00f0) {
5496 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005497 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005498 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005499 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005500 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005501 break;
5502 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005503 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5504 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005505 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005506 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005507 break;
5508 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005509 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005510 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005511 if (err < 0)
5512 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005513 alc269_fill_coef(codec);
5514 }
5515
Takashi Iwaia4297b52011-08-23 18:40:12 +02005516 alc_pick_fixup(codec, alc269_fixup_models,
5517 alc269_fixup_tbl, alc269_fixups);
5518 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005519
Takashi Iwaia4297b52011-08-23 18:40:12 +02005520 /* automatic parse from the BIOS config */
5521 err = alc269_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 Iwai60a6a842011-07-27 14:01:24 +02005525 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005526 alc_auto_fill_adc_caps(codec);
5527 alc_rebuild_imux_for_auto_mic(codec);
5528 alc_remove_invalid_adc_nids(codec);
5529 }
5530
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005531 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005532 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005533
5534 if (!spec->no_analog && has_cdefine_beep(codec)) {
5535 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005536 if (err < 0)
5537 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005538 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005539 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005540
5541 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5542
Takashi Iwai1d045db2011-07-07 18:23:21 +02005543 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005544#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005545 codec->patch_ops.resume = alc269_resume;
5546#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005547 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005548 spec->shutup = alc269_shutup;
5549
Takashi Iwai1d045db2011-07-07 18:23:21 +02005550#ifdef CONFIG_SND_HDA_POWER_SAVE
5551 if (!spec->loopback.amplist)
5552 spec->loopback.amplist = alc269_loopbacks;
5553 if (alc269_mic2_for_mute_led(codec))
5554 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5555#endif
5556
5557 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005558
5559 error:
5560 alc_free(codec);
5561 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005562}
5563
5564/*
5565 * ALC861
5566 */
5567
Takashi Iwai1d045db2011-07-07 18:23:21 +02005568static int alc861_parse_auto_config(struct hda_codec *codec)
5569{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005570 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005571 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5572 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005573}
5574
Takashi Iwai1d045db2011-07-07 18:23:21 +02005575#ifdef CONFIG_SND_HDA_POWER_SAVE
5576static const struct hda_amp_list alc861_loopbacks[] = {
5577 { 0x15, HDA_INPUT, 0 },
5578 { 0x15, HDA_INPUT, 1 },
5579 { 0x15, HDA_INPUT, 2 },
5580 { 0x15, HDA_INPUT, 3 },
5581 { } /* end */
5582};
5583#endif
5584
5585
5586/* Pin config fixes */
5587enum {
5588 PINFIX_FSC_AMILO_PI1505,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005589 PINFIX_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005590};
5591
5592static const struct alc_fixup alc861_fixups[] = {
5593 [PINFIX_FSC_AMILO_PI1505] = {
5594 .type = ALC_FIXUP_PINS,
5595 .v.pins = (const struct alc_pincfg[]) {
5596 { 0x0b, 0x0221101f }, /* HP */
5597 { 0x0f, 0x90170310 }, /* speaker */
5598 { }
5599 }
5600 },
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005601 [PINFIX_ASUS_A6RP] = {
5602 .type = ALC_FIXUP_VERBS,
5603 .v.verbs = (const struct hda_verb[]) {
5604 /* node 0x0f VREF seems controlling the master output */
5605 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5606 { }
5607 },
5608 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005609};
5610
5611static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005612 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", PINFIX_ASUS_A6RP),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005613 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5614 {}
5615};
5616
5617/*
5618 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005619static int patch_alc861(struct hda_codec *codec)
5620{
5621 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005622 int err;
5623
5624 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5625 if (spec == NULL)
5626 return -ENOMEM;
5627
5628 codec->spec = spec;
5629
5630 spec->mixer_nid = 0x15;
5631
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005632 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5633 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005634
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005635 /* automatic parse from the BIOS config */
5636 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005637 if (err < 0)
5638 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005639
Takashi Iwai60a6a842011-07-27 14:01:24 +02005640 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005641 alc_auto_fill_adc_caps(codec);
5642 alc_rebuild_imux_for_auto_mic(codec);
5643 alc_remove_invalid_adc_nids(codec);
5644 }
5645
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005646 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005647 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005648
5649 if (!spec->no_analog) {
5650 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005651 if (err < 0)
5652 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005653 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5654 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005655
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5657
5658 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005659 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005660#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005661 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005662 if (!spec->loopback.amplist)
5663 spec->loopback.amplist = alc861_loopbacks;
5664#endif
5665
5666 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005667
5668 error:
5669 alc_free(codec);
5670 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005671}
5672
5673/*
5674 * ALC861-VD support
5675 *
5676 * Based on ALC882
5677 *
5678 * In addition, an independent DAC
5679 */
5680#ifdef CONFIG_SND_HDA_POWER_SAVE
5681#define alc861vd_loopbacks alc880_loopbacks
5682#endif
5683
Takashi Iwai1d045db2011-07-07 18:23:21 +02005684static int alc861vd_parse_auto_config(struct hda_codec *codec)
5685{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005686 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005687 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5688 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005689}
5690
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005692 ALC660VD_FIX_ASUS_GPIO1,
5693 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005694};
5695
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005696/* exclude VREF80 */
5697static void alc861vd_fixup_dallas(struct hda_codec *codec,
5698 const struct alc_fixup *fix, int action)
5699{
5700 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5701 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5702 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5703 }
5704}
5705
Takashi Iwai1d045db2011-07-07 18:23:21 +02005706static const struct alc_fixup alc861vd_fixups[] = {
5707 [ALC660VD_FIX_ASUS_GPIO1] = {
5708 .type = ALC_FIXUP_VERBS,
5709 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005710 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005711 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5712 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5713 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5714 { }
5715 }
5716 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005717 [ALC861VD_FIX_DALLAS] = {
5718 .type = ALC_FIXUP_FUNC,
5719 .v.func = alc861vd_fixup_dallas,
5720 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721};
5722
5723static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005724 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005725 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005726 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727 {}
5728};
5729
5730static const struct hda_verb alc660vd_eapd_verbs[] = {
5731 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5732 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5733 { }
5734};
5735
5736/*
5737 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005738static int patch_alc861vd(struct hda_codec *codec)
5739{
5740 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005741 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005742
5743 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5744 if (spec == NULL)
5745 return -ENOMEM;
5746
5747 codec->spec = spec;
5748
5749 spec->mixer_nid = 0x0b;
5750
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005751 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5752 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005754 /* automatic parse from the BIOS config */
5755 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005756 if (err < 0)
5757 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005758
Takashi Iwai1d045db2011-07-07 18:23:21 +02005759 if (codec->vendor_id == 0x10ec0660) {
5760 /* always turn on EAPD */
5761 add_verb(spec, alc660vd_eapd_verbs);
5762 }
5763
Takashi Iwai60a6a842011-07-27 14:01:24 +02005764 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765 alc_auto_fill_adc_caps(codec);
5766 alc_rebuild_imux_for_auto_mic(codec);
5767 alc_remove_invalid_adc_nids(codec);
5768 }
5769
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005770 if (!spec->no_analog && !spec->cap_mixer)
5771 set_capture_mixer(codec);
5772
5773 if (!spec->no_analog) {
5774 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005775 if (err < 0)
5776 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005777 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5778 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005779
Takashi Iwai1d045db2011-07-07 18:23:21 +02005780 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5781
5782 codec->patch_ops = alc_patch_ops;
5783
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005784 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005785 spec->shutup = alc_eapd_shutup;
5786#ifdef CONFIG_SND_HDA_POWER_SAVE
5787 if (!spec->loopback.amplist)
5788 spec->loopback.amplist = alc861vd_loopbacks;
5789#endif
5790
5791 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005792
5793 error:
5794 alc_free(codec);
5795 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005796}
5797
5798/*
5799 * ALC662 support
5800 *
5801 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5802 * configuration. Each pin widget can choose any input DACs and a mixer.
5803 * Each ADC is connected from a mixer of all inputs. This makes possible
5804 * 6-channel independent captures.
5805 *
5806 * In addition, an independent DAC for the multi-playback (not used in this
5807 * driver yet).
5808 */
5809#ifdef CONFIG_SND_HDA_POWER_SAVE
5810#define alc662_loopbacks alc880_loopbacks
5811#endif
5812
5813/*
5814 * BIOS auto configuration
5815 */
5816
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005817static int alc662_parse_auto_config(struct hda_codec *codec)
5818{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005819 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005820 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5821 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5822 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005823
Kailang Yang6227cdc2010-02-25 08:36:52 +01005824 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5825 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005826 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005827 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005828 ssids = alc662_ssids;
5829 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005830}
5831
Todd Broch6be79482010-12-07 16:51:05 -08005832static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005833 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005834{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005835 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005836 return;
Todd Broch6be79482010-12-07 16:51:05 -08005837 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5838 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5839 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5840 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5841 (0 << AC_AMPCAP_MUTE_SHIFT)))
5842 printk(KERN_WARNING
5843 "hda_codec: failed to override amp caps for NID 0x2\n");
5844}
5845
David Henningsson6cb3b702010-09-09 08:51:44 +02005846enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005847 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005848 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005849 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005850 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005851 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005852 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005853 ALC662_FIXUP_ASUS_MODE1,
5854 ALC662_FIXUP_ASUS_MODE2,
5855 ALC662_FIXUP_ASUS_MODE3,
5856 ALC662_FIXUP_ASUS_MODE4,
5857 ALC662_FIXUP_ASUS_MODE5,
5858 ALC662_FIXUP_ASUS_MODE6,
5859 ALC662_FIXUP_ASUS_MODE7,
5860 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005861};
5862
5863static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005864 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005865 .type = ALC_FIXUP_PINS,
5866 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005867 { 0x15, 0x99130112 }, /* subwoofer */
5868 { }
5869 }
5870 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005871 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005872 .type = ALC_FIXUP_PINS,
5873 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005874 { 0x17, 0x99130112 }, /* subwoofer */
5875 { }
5876 }
5877 },
Todd Broch6be79482010-12-07 16:51:05 -08005878 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005879 .type = ALC_FIXUP_FUNC,
5880 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005881 },
5882 [ALC662_FIXUP_CZC_P10T] = {
5883 .type = ALC_FIXUP_VERBS,
5884 .v.verbs = (const struct hda_verb[]) {
5885 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5886 {}
5887 }
5888 },
David Henningsson94024cd2011-04-29 14:10:55 +02005889 [ALC662_FIXUP_SKU_IGNORE] = {
5890 .type = ALC_FIXUP_SKU,
5891 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005892 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005893 [ALC662_FIXUP_HP_RP5800] = {
5894 .type = ALC_FIXUP_PINS,
5895 .v.pins = (const struct alc_pincfg[]) {
5896 { 0x14, 0x0221201f }, /* HP out */
5897 { }
5898 },
5899 .chained = true,
5900 .chain_id = ALC662_FIXUP_SKU_IGNORE
5901 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005902 [ALC662_FIXUP_ASUS_MODE1] = {
5903 .type = ALC_FIXUP_PINS,
5904 .v.pins = (const struct alc_pincfg[]) {
5905 { 0x14, 0x99130110 }, /* speaker */
5906 { 0x18, 0x01a19c20 }, /* mic */
5907 { 0x19, 0x99a3092f }, /* int-mic */
5908 { 0x21, 0x0121401f }, /* HP out */
5909 { }
5910 },
5911 .chained = true,
5912 .chain_id = ALC662_FIXUP_SKU_IGNORE
5913 },
5914 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005915 .type = ALC_FIXUP_PINS,
5916 .v.pins = (const struct alc_pincfg[]) {
5917 { 0x14, 0x99130110 }, /* speaker */
5918 { 0x18, 0x01a19820 }, /* mic */
5919 { 0x19, 0x99a3092f }, /* int-mic */
5920 { 0x1b, 0x0121401f }, /* HP out */
5921 { }
5922 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005923 .chained = true,
5924 .chain_id = ALC662_FIXUP_SKU_IGNORE
5925 },
5926 [ALC662_FIXUP_ASUS_MODE3] = {
5927 .type = ALC_FIXUP_PINS,
5928 .v.pins = (const struct alc_pincfg[]) {
5929 { 0x14, 0x99130110 }, /* speaker */
5930 { 0x15, 0x0121441f }, /* HP */
5931 { 0x18, 0x01a19840 }, /* mic */
5932 { 0x19, 0x99a3094f }, /* int-mic */
5933 { 0x21, 0x01211420 }, /* HP2 */
5934 { }
5935 },
5936 .chained = true,
5937 .chain_id = ALC662_FIXUP_SKU_IGNORE
5938 },
5939 [ALC662_FIXUP_ASUS_MODE4] = {
5940 .type = ALC_FIXUP_PINS,
5941 .v.pins = (const struct alc_pincfg[]) {
5942 { 0x14, 0x99130110 }, /* speaker */
5943 { 0x16, 0x99130111 }, /* speaker */
5944 { 0x18, 0x01a19840 }, /* mic */
5945 { 0x19, 0x99a3094f }, /* int-mic */
5946 { 0x21, 0x0121441f }, /* HP */
5947 { }
5948 },
5949 .chained = true,
5950 .chain_id = ALC662_FIXUP_SKU_IGNORE
5951 },
5952 [ALC662_FIXUP_ASUS_MODE5] = {
5953 .type = ALC_FIXUP_PINS,
5954 .v.pins = (const struct alc_pincfg[]) {
5955 { 0x14, 0x99130110 }, /* speaker */
5956 { 0x15, 0x0121441f }, /* HP */
5957 { 0x16, 0x99130111 }, /* speaker */
5958 { 0x18, 0x01a19840 }, /* mic */
5959 { 0x19, 0x99a3094f }, /* int-mic */
5960 { }
5961 },
5962 .chained = true,
5963 .chain_id = ALC662_FIXUP_SKU_IGNORE
5964 },
5965 [ALC662_FIXUP_ASUS_MODE6] = {
5966 .type = ALC_FIXUP_PINS,
5967 .v.pins = (const struct alc_pincfg[]) {
5968 { 0x14, 0x99130110 }, /* speaker */
5969 { 0x15, 0x01211420 }, /* HP2 */
5970 { 0x18, 0x01a19840 }, /* mic */
5971 { 0x19, 0x99a3094f }, /* int-mic */
5972 { 0x1b, 0x0121441f }, /* HP */
5973 { }
5974 },
5975 .chained = true,
5976 .chain_id = ALC662_FIXUP_SKU_IGNORE
5977 },
5978 [ALC662_FIXUP_ASUS_MODE7] = {
5979 .type = ALC_FIXUP_PINS,
5980 .v.pins = (const struct alc_pincfg[]) {
5981 { 0x14, 0x99130110 }, /* speaker */
5982 { 0x17, 0x99130111 }, /* speaker */
5983 { 0x18, 0x01a19840 }, /* mic */
5984 { 0x19, 0x99a3094f }, /* int-mic */
5985 { 0x1b, 0x01214020 }, /* HP */
5986 { 0x21, 0x0121401f }, /* HP */
5987 { }
5988 },
5989 .chained = true,
5990 .chain_id = ALC662_FIXUP_SKU_IGNORE
5991 },
5992 [ALC662_FIXUP_ASUS_MODE8] = {
5993 .type = ALC_FIXUP_PINS,
5994 .v.pins = (const struct alc_pincfg[]) {
5995 { 0x14, 0x99130110 }, /* speaker */
5996 { 0x12, 0x99a30970 }, /* int-mic */
5997 { 0x15, 0x01214020 }, /* HP */
5998 { 0x17, 0x99130111 }, /* speaker */
5999 { 0x18, 0x01a19840 }, /* mic */
6000 { 0x21, 0x0121401f }, /* HP */
6001 { }
6002 },
6003 .chained = true,
6004 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006005 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006006};
6007
Takashi Iwaia9111322011-05-02 11:30:18 +02006008static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006009 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006010 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006011 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006012 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006013 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006014 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006015 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006016 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006017 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006018 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006019
6020#if 0
6021 /* Below is a quirk table taken from the old code.
6022 * Basically the device should work as is without the fixup table.
6023 * If BIOS doesn't give a proper info, enable the corresponding
6024 * fixup entry.
6025 */
6026 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6027 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6028 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6029 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6030 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6031 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6032 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6033 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6034 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6035 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6036 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6037 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6038 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6039 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6040 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6041 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6042 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6043 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6044 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6045 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6046 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6047 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6048 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6049 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6050 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6051 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6052 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6053 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6054 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6055 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6056 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6057 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6058 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6059 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6060 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6061 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6062 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6063 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6064 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6065 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6066 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6067 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6068 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6069 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6070 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6071 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6072 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6073 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6074 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6075 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6076#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006077 {}
6078};
6079
Todd Broch6be79482010-12-07 16:51:05 -08006080static const struct alc_model_fixup alc662_fixup_models[] = {
6081 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006082 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6083 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6084 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6085 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6086 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6087 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6088 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6089 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006090 {}
6091};
David Henningsson6cb3b702010-09-09 08:51:44 +02006092
6093
Takashi Iwai1d045db2011-07-07 18:23:21 +02006094/*
6095 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006096static int patch_alc662(struct hda_codec *codec)
6097{
6098 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006099 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006100
6101 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6102 if (!spec)
6103 return -ENOMEM;
6104
6105 codec->spec = spec;
6106
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006107 spec->mixer_nid = 0x0b;
6108
Takashi Iwai53c334a2011-08-23 18:27:14 +02006109 /* handle multiple HPs as is */
6110 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6111
Kailang Yangda00c242010-03-19 11:23:45 +01006112 alc_auto_parse_customize_define(codec);
6113
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006114 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6115
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006116 err = alc_codec_rename_from_preset(codec);
6117 if (err < 0)
6118 goto error;
6119
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006120 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006121 codec->bus->pci->subsystem_vendor == 0x1025 &&
6122 spec->cdefine.platform_type == 1) {
6123 if (alc_codec_rename(codec, "ALC272X") < 0)
6124 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006125 }
Kailang Yang274693f2009-12-03 10:07:50 +01006126
Takashi Iwaib9c51062011-08-24 18:08:07 +02006127 alc_pick_fixup(codec, alc662_fixup_models,
6128 alc662_fixup_tbl, alc662_fixups);
6129 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6130 /* automatic parse from the BIOS config */
6131 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006132 if (err < 0)
6133 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006134
Takashi Iwai60a6a842011-07-27 14:01:24 +02006135 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006136 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006137 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006138 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006139 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006140
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006141 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006142 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006143
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006144 if (!spec->no_analog && has_cdefine_beep(codec)) {
6145 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006146 if (err < 0)
6147 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006148 switch (codec->vendor_id) {
6149 case 0x10ec0662:
6150 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6151 break;
6152 case 0x10ec0272:
6153 case 0x10ec0663:
6154 case 0x10ec0665:
6155 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6156 break;
6157 case 0x10ec0273:
6158 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6159 break;
6160 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006161 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006162
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006163 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6164
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006165 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006166 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c7161532011-04-07 10:37:16 +02006167 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006168
Takashi Iwaicb53c622007-08-10 17:21:45 +02006169#ifdef CONFIG_SND_HDA_POWER_SAVE
6170 if (!spec->loopback.amplist)
6171 spec->loopback.amplist = alc662_loopbacks;
6172#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006173
6174 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006175
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006176 error:
6177 alc_free(codec);
6178 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006179}
6180
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006181/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006182 * ALC680 support
6183 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006184
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006185static int alc680_parse_auto_config(struct hda_codec *codec)
6186{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006187 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006188}
6189
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006190/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006191 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006192static int patch_alc680(struct hda_codec *codec)
6193{
6194 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006195 int err;
6196
6197 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6198 if (spec == NULL)
6199 return -ENOMEM;
6200
6201 codec->spec = spec;
6202
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006203 /* ALC680 has no aa-loopback mixer */
6204
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006205 /* automatic parse from the BIOS config */
6206 err = alc680_parse_auto_config(codec);
6207 if (err < 0) {
6208 alc_free(codec);
6209 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006210 }
6211
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006212 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006213 set_capture_mixer(codec);
6214
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006215 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006216 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006217
6218 return 0;
6219}
6220
6221/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006222 * patch entries
6223 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006224static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006225 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006226 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006227 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006228 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006229 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006230 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006231 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006232 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006233 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006234 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006235 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006236 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006237 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6238 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6239 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006240 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006241 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006242 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6243 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006244 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6245 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006246 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006247 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006248 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006249 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006250 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006251 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006252 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006253 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006254 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006255 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006256 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006257 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006258 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006259 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006260 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006261 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006262 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006263 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006264 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006265 {} /* terminator */
6266};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006267
6268MODULE_ALIAS("snd-hda-codec-id:10ec*");
6269
6270MODULE_LICENSE("GPL");
6271MODULE_DESCRIPTION("Realtek HD-audio codec");
6272
6273static struct hda_codec_preset_list realtek_list = {
6274 .preset = snd_hda_preset_realtek,
6275 .owner = THIS_MODULE,
6276};
6277
6278static int __init patch_realtek_init(void)
6279{
6280 return snd_hda_add_codec_preset(&realtek_list);
6281}
6282
6283static void __exit patch_realtek_exit(void)
6284{
6285 snd_hda_delete_codec_preset(&realtek_list);
6286}
6287
6288module_init(patch_realtek_init)
6289module_exit(patch_realtek_exit)