blob: 42b6a01e17db90e08829dbcb3bd0f115060ae10b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e42006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
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 Iwai49535502009-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 Iwai1c716152011-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 Iwai31150f22012-01-30 10:54:08 +0100180 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200181
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100182 /* other flags */
183 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200184 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100185 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200186 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200187 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100188 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200189
190 /* auto-mute control */
191 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200192 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200193
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200194 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200195 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100196
Takashi Iwai2134ea42008-01-10 16:53:55 +0100197 /* for virtual master */
198 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200199#ifdef CONFIG_SND_HDA_POWER_SAVE
200 struct hda_loopback_check loopback;
201#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200202
203 /* for PLL fix */
204 hda_nid_t pll_nid;
205 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200206 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100207
208 /* fix-up list */
209 int fixup_id;
210 const struct alc_fixup *fixup_list;
211 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200212
213 /* multi-io */
214 int multi_ios;
215 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200216
217 /* bind volumes */
218 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100219};
220
Takashi Iwai1d045db2011-07-07 18:23:21 +0200221#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Takashi Iwai44c02402011-07-08 15:14:19 +0200223static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
224 int dir, unsigned int bits)
225{
226 if (!nid)
227 return false;
228 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
229 if (query_amp_caps(codec, nid, dir) & bits)
230 return true;
231 return false;
232}
233
234#define nid_has_mute(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
236#define nid_has_volume(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*
240 * input MUX handling
241 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200242static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
246 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200247 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
248 if (mux_idx >= spec->num_mux_defs)
249 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100250 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
251 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200252 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200255static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct alc_spec *spec = codec->spec;
260 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
261
262 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
263 return 0;
264}
265
Takashi Iwai21268962011-07-07 15:01:13 +0200266static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Takashi Iwai21268962011-07-07 15:01:13 +0200268 struct alc_spec *spec = codec->spec;
269 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
270
271 if (spec->cur_adc && spec->cur_adc != new_adc) {
272 /* stream is running, let's swap the current ADC */
273 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
274 spec->cur_adc = new_adc;
275 snd_hda_codec_setup_stream(codec, new_adc,
276 spec->cur_adc_stream_tag, 0,
277 spec->cur_adc_format);
278 return true;
279 }
280 return false;
281}
282
Takashi Iwai61071592011-11-23 07:52:15 +0100283static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
284{
285 return spec->capsrc_nids ?
286 spec->capsrc_nids[idx] : spec->adc_nids[idx];
287}
288
Takashi Iwai24de1832011-11-07 17:13:39 +0100289static void call_update_outputs(struct hda_codec *codec);
290
Takashi Iwai21268962011-07-07 15:01:13 +0200291/* select the given imux item; either unmute exclusively or select the route */
292static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
293 unsigned int idx, bool force)
294{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100296 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100297 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100298 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200299 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Takashi Iwaicd896c32008-11-18 12:36:33 +0100301 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
302 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100303 if (!imux->num_items && mux_idx > 0)
304 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100305 if (!imux->num_items)
306 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100307
Takashi Iwai21268962011-07-07 15:01:13 +0200308 if (idx >= imux->num_items)
309 idx = imux->num_items - 1;
310 if (spec->cur_mux[adc_idx] == idx && !force)
311 return 0;
312 spec->cur_mux[adc_idx] = idx;
313
Takashi Iwai24de1832011-11-07 17:13:39 +0100314 /* for shared I/O, change the pin-control accordingly */
315 if (spec->shared_mic_hp) {
316 /* NOTE: this assumes that there are only two inputs, the
317 * first is the real internal mic and the second is HP jack.
318 */
319 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
320 AC_VERB_SET_PIN_WIDGET_CONTROL,
321 spec->cur_mux[adc_idx] ?
322 PIN_VREF80 : PIN_HP);
323 spec->automute_speaker = !spec->cur_mux[adc_idx];
324 call_update_outputs(codec);
325 }
326
Takashi Iwai21268962011-07-07 15:01:13 +0200327 if (spec->dyn_adc_switch) {
328 alc_dyn_adc_pcm_resetup(codec, idx);
329 adc_idx = spec->dyn_adc_idx[idx];
330 }
331
Takashi Iwai61071592011-11-23 07:52:15 +0100332 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200333
334 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100335 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
336 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200337 return 1;
338
Takashi Iwaia22d5432009-07-27 12:54:26 +0200339 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200340 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100341 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100342 int active = imux->items[idx].index;
343 for (i = 0; i < num_conns; i++) {
344 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
345 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100346 HDA_AMP_MUTE, v);
347 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100348 } else {
349 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200350 snd_hda_codec_write_cache(codec, nid, 0,
351 AC_VERB_SET_CONNECT_SEL,
352 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100353 }
Takashi Iwai21268962011-07-07 15:01:13 +0200354 return 1;
355}
356
357static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
358 struct snd_ctl_elem_value *ucontrol)
359{
360 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
361 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
362 return alc_mux_select(codec, adc_idx,
363 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100364}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100367 * set up the input pin config (depending on the given auto-pin type)
368 */
369static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
370 int auto_pin_type)
371{
372 unsigned int val = PIN_IN;
373
Takashi Iwai86e29592010-09-09 14:50:17 +0200374 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100375 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200376 unsigned int oldval;
377 oldval = snd_hda_codec_read(codec, nid, 0,
378 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100379 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100380 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200381 /* if the default pin setup is vref50, we give it priority */
382 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100383 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200384 else if (pincap & AC_PINCAP_VREF_50)
385 val = PIN_VREF50;
386 else if (pincap & AC_PINCAP_VREF_100)
387 val = PIN_VREF100;
388 else if (pincap & AC_PINCAP_VREF_GRD)
389 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100390 }
391 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
392}
393
394/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200395 * Append the given mixer and verb elements for the later use
396 * The mixer array is referred in build_controls(), and init_verbs are
397 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100398 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200399static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100400{
401 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
402 return;
403 spec->mixers[spec->num_mixers++] = mix;
404}
405
406static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
407{
408 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
409 return;
410 spec->init_verbs[spec->num_init_verbs++] = verb;
411}
412
413/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200414 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100415 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200416/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200417static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200418 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
419 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
420 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
421 { }
422};
423
Takashi Iwaia9111322011-05-02 11:30:18 +0200424static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200425 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
427 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
428 { }
429};
430
Takashi Iwaia9111322011-05-02 11:30:18 +0200431static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200432 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
433 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
434 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
435 { }
436};
437
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200438/*
439 * Fix hardware PLL issue
440 * On some codecs, the analog PLL gating control must be off while
441 * the default value is 1.
442 */
443static void alc_fix_pll(struct hda_codec *codec)
444{
445 struct alc_spec *spec = codec->spec;
446 unsigned int val;
447
448 if (!spec->pll_nid)
449 return;
450 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
451 spec->pll_coef_idx);
452 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
453 AC_VERB_GET_PROC_COEF, 0);
454 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
455 spec->pll_coef_idx);
456 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
457 val & ~(1 << spec->pll_coef_bit));
458}
459
460static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
461 unsigned int coef_idx, unsigned int coef_bit)
462{
463 struct alc_spec *spec = codec->spec;
464 spec->pll_nid = nid;
465 spec->pll_coef_idx = coef_idx;
466 spec->pll_coef_bit = coef_bit;
467 alc_fix_pll(codec);
468}
469
Takashi Iwai1d045db2011-07-07 18:23:21 +0200470/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200471 * Jack detections for HP auto-mute and mic-switch
472 */
473
474/* check each pin in the given array; returns true if any of them is plugged */
475static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200476{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200477 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200478
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200479 for (i = 0; i < num_pins; i++) {
480 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200481 if (!nid)
482 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200483 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200484 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200485 return present;
486}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200487
Takashi Iwai1d045db2011-07-07 18:23:21 +0200488/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200489static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200490 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200491{
492 struct alc_spec *spec = codec->spec;
493 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200494 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495 int i;
496
497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100499 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200500 if (!nid)
501 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200502 switch (spec->automute_mode) {
503 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100504 /* don't reset VREF value in case it's controlling
505 * the amp (see alc861_fixup_asus_amp_vref_0f())
506 */
507 if (spec->keep_vref_in_automute) {
508 val = snd_hda_codec_read(codec, nid, 0,
509 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
510 val &= ~PIN_HP;
511 } else
512 val = 0;
513 val |= pin_bits;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200514 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200515 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai31150f22012-01-30 10:54:08 +0100516 val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200517 break;
518 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200519 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200520 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200521 break;
522 case ALC_AUTOMUTE_MIXER:
523 nid = spec->automute_mixer_nid[i];
524 if (!nid)
525 break;
526 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200527 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200528 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200530 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200531 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200532 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200533}
534
David Henningsson42cf0d02011-09-20 12:04:56 +0200535/* Toggle outputs muting */
536static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537{
538 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200539 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200540
Takashi Iwaic0a20262011-06-10 15:28:15 +0200541 /* Control HP pins/amps depending on master_mute state;
542 * in general, HP pins/amps control should be enabled in all cases,
543 * but currently set only for master_mute, just to be safe
544 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100545 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
546 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200547 spec->autocfg.hp_pins, spec->master_mute, true);
548
David Henningsson42cf0d02011-09-20 12:04:56 +0200549 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200550 on = 0;
551 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200552 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200553 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200554 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556
557 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200558 /* if LO is a copy of either HP or Speaker, don't need to handle it */
559 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
560 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200562 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200563 on = 0;
564 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200565 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200567 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200568 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200569}
570
David Henningsson42cf0d02011-09-20 12:04:56 +0200571static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200572{
573 struct alc_spec *spec = codec->spec;
574 if (spec->automute_hook)
575 spec->automute_hook(codec);
576 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200577 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200578}
579
Takashi Iwai1d045db2011-07-07 18:23:21 +0200580/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200581static void alc_hp_automute(struct hda_codec *codec)
582{
583 struct alc_spec *spec = codec->spec;
584
David Henningsson42cf0d02011-09-20 12:04:56 +0200585 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200586 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
587 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200588 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200589 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200590 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591}
592
Takashi Iwai1d045db2011-07-07 18:23:21 +0200593/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200594static void alc_line_automute(struct hda_codec *codec)
595{
596 struct alc_spec *spec = codec->spec;
597
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200598 /* check LO jack only when it's different from HP */
599 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
600 return;
601
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602 spec->line_jack_present =
603 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
604 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200605 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200606 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200607 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200608}
609
Takashi Iwai8d087c72011-06-28 12:45:47 +0200610#define get_connection_index(codec, mux, nid) \
611 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200612
Takashi Iwai1d045db2011-07-07 18:23:21 +0200613/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200614static void alc_mic_automute(struct hda_codec *codec)
615{
616 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200617 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200618
Takashi Iwai21268962011-07-07 15:01:13 +0200619 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200620 return;
621 if (snd_BUG_ON(!spec->adc_nids))
622 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200623 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200624 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200625
Takashi Iwai21268962011-07-07 15:01:13 +0200626 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
627 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
628 else if (spec->dock_mic_idx >= 0 &&
629 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
630 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
631 else
632 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200633}
634
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100635/* handle the specified unsol action (ALC_XXX_EVENT) */
636static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200637{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100638 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200639 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200640 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200641 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200642 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200643 alc_line_automute(codec);
644 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200645 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200646 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200647 break;
648 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200649 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200650}
651
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100652/* unsolicited event for HP jack sensing */
653static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
654{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100655 if (codec->vendor_id == 0x10ec0880)
656 res >>= 28;
657 else
658 res >>= 26;
Takashi Iwaia7309792012-01-19 15:03:48 +0100659 res = snd_hda_jack_get_action(codec, res);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100660 alc_exec_unsol_event(codec, res);
661}
662
Takashi Iwai1d045db2011-07-07 18:23:21 +0200663/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200664static void alc_inithook(struct hda_codec *codec)
665{
Takashi Iwaid922b512011-04-28 12:18:53 +0200666 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200667 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200668 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200669}
670
Kailang Yangf9423e72008-05-27 12:32:25 +0200671/* additional initialization for ALC888 variants */
672static void alc888_coef_init(struct hda_codec *codec)
673{
674 unsigned int tmp;
675
676 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
677 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
678 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100679 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200680 /* alc888S-VC */
681 snd_hda_codec_read(codec, 0x20, 0,
682 AC_VERB_SET_PROC_COEF, 0x830);
683 else
684 /* alc888-VB */
685 snd_hda_codec_read(codec, 0x20, 0,
686 AC_VERB_SET_PROC_COEF, 0x3030);
687}
688
Takashi Iwai1d045db2011-07-07 18:23:21 +0200689/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200690static void alc889_coef_init(struct hda_codec *codec)
691{
692 unsigned int tmp;
693
694 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
695 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
696 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
698}
699
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100700/* turn on/off EAPD control (only if available) */
701static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
702{
703 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
704 return;
705 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
706 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
707 on ? 2 : 0);
708}
709
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200710/* turn on/off EAPD controls of the codec */
711static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
712{
713 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200714 static hda_nid_t pins[] = {
715 0x0f, 0x10, 0x14, 0x15, 0
716 };
717 hda_nid_t *p;
718 for (p = pins; *p; p++)
719 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200720}
721
Takashi Iwai1c716152011-04-07 10:37:16 +0200722/* generic shutup callback;
723 * just turning off EPAD and a little pause for avoiding pop-noise
724 */
725static void alc_eapd_shutup(struct hda_codec *codec)
726{
727 alc_auto_setup_eapd(codec, false);
728 msleep(200);
729}
730
Takashi Iwai1d045db2011-07-07 18:23:21 +0200731/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200732static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200733{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200734 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200735
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200736 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200737 switch (type) {
738 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200739 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
740 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200741 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200742 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
743 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200744 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200745 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
746 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200747 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200748 switch (codec->vendor_id) {
749 case 0x10ec0260:
750 snd_hda_codec_write(codec, 0x1a, 0,
751 AC_VERB_SET_COEF_INDEX, 7);
752 tmp = snd_hda_codec_read(codec, 0x1a, 0,
753 AC_VERB_GET_PROC_COEF, 0);
754 snd_hda_codec_write(codec, 0x1a, 0,
755 AC_VERB_SET_COEF_INDEX, 7);
756 snd_hda_codec_write(codec, 0x1a, 0,
757 AC_VERB_SET_PROC_COEF,
758 tmp | 0x2010);
759 break;
760 case 0x10ec0262:
761 case 0x10ec0880:
762 case 0x10ec0882:
763 case 0x10ec0883:
764 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100765 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100766 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200767 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200768 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200769 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200771 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100772#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200773 case 0x10ec0267:
774 case 0x10ec0268:
775 snd_hda_codec_write(codec, 0x20, 0,
776 AC_VERB_SET_COEF_INDEX, 7);
777 tmp = snd_hda_codec_read(codec, 0x20, 0,
778 AC_VERB_GET_PROC_COEF, 0);
779 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200780 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200781 snd_hda_codec_write(codec, 0x20, 0,
782 AC_VERB_SET_PROC_COEF,
783 tmp | 0x3000);
784 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100785#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200786 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200787 break;
788 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200789}
Kailang Yangea1fb292008-08-26 12:58:38 +0200790
Takashi Iwai1d045db2011-07-07 18:23:21 +0200791/*
792 * Auto-Mute mode mixer enum support
793 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200794static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_info *uinfo)
796{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct alc_spec *spec = codec->spec;
799 static const char * const texts2[] = {
800 "Disabled", "Enabled"
801 };
802 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200803 "Disabled", "Speaker Only", "Line-Out+Speaker"
804 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200805 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200806
807 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
808 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200809 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200810 uinfo->value.enumerated.items = 3;
811 texts = texts3;
812 } else {
813 uinfo->value.enumerated.items = 2;
814 texts = texts2;
815 }
816 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
817 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200818 strcpy(uinfo->value.enumerated.name,
819 texts[uinfo->value.enumerated.item]);
820 return 0;
821}
822
823static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
824 struct snd_ctl_elem_value *ucontrol)
825{
826 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
827 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200828 unsigned int val = 0;
829 if (spec->automute_speaker)
830 val++;
831 if (spec->automute_lo)
832 val++;
833
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200834 ucontrol->value.enumerated.item[0] = val;
835 return 0;
836}
837
838static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
840{
841 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
842 struct alc_spec *spec = codec->spec;
843
844 switch (ucontrol->value.enumerated.item[0]) {
845 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200846 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200847 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200848 spec->automute_speaker = 0;
849 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200850 break;
851 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200852 if (spec->automute_speaker_possible) {
853 if (!spec->automute_lo && spec->automute_speaker)
854 return 0;
855 spec->automute_speaker = 1;
856 spec->automute_lo = 0;
857 } else if (spec->automute_lo_possible) {
858 if (spec->automute_lo)
859 return 0;
860 spec->automute_lo = 1;
861 } else
862 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200863 break;
864 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200865 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200866 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200867 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200868 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200869 spec->automute_speaker = 1;
870 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200871 break;
872 default:
873 return -EINVAL;
874 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200875 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200876 return 1;
877}
878
Takashi Iwaia9111322011-05-02 11:30:18 +0200879static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
881 .name = "Auto-Mute Mode",
882 .info = alc_automute_mode_info,
883 .get = alc_automute_mode_get,
884 .put = alc_automute_mode_put,
885};
886
Takashi Iwai1d045db2011-07-07 18:23:21 +0200887static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
888{
889 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
890 return snd_array_new(&spec->kctls);
891}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200892
893static int alc_add_automute_mode_enum(struct hda_codec *codec)
894{
895 struct alc_spec *spec = codec->spec;
896 struct snd_kcontrol_new *knew;
897
898 knew = alc_kcontrol_new(spec);
899 if (!knew)
900 return -ENOMEM;
901 *knew = alc_automute_mode_enum;
902 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
903 if (!knew->name)
904 return -ENOMEM;
905 return 0;
906}
907
Takashi Iwai1d045db2011-07-07 18:23:21 +0200908/*
909 * Check the availability of HP/line-out auto-mute;
910 * Set up appropriately if really supported
911 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200912static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200913{
914 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200915 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200916 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200917 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200918
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200919 if (cfg->hp_pins[0])
920 present++;
921 if (cfg->line_out_pins[0])
922 present++;
923 if (cfg->speaker_pins[0])
924 present++;
925 if (present < 2) /* need two different output types */
926 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200927
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200928 if (!cfg->speaker_pins[0] &&
929 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200930 memcpy(cfg->speaker_pins, cfg->line_out_pins,
931 sizeof(cfg->speaker_pins));
932 cfg->speaker_outs = cfg->line_outs;
933 }
934
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200935 if (!cfg->hp_pins[0] &&
936 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200937 memcpy(cfg->hp_pins, cfg->line_out_pins,
938 sizeof(cfg->hp_pins));
939 cfg->hp_outs = cfg->line_outs;
940 }
941
David Henningsson42cf0d02011-09-20 12:04:56 +0200942 spec->automute_mode = ALC_AUTOMUTE_PIN;
943
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200944 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200945 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200946 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200947 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200948 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200949 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200950 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200951 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200952 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200953
David Henningsson42cf0d02011-09-20 12:04:56 +0200954 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
955 if (cfg->speaker_outs)
956 for (i = 0; i < cfg->line_outs; i++) {
957 hda_nid_t nid = cfg->line_out_pins[i];
958 if (!is_jack_detectable(codec, nid))
959 continue;
960 snd_printdd("realtek: Enable Line-Out "
961 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200962 snd_hda_jack_detect_enable(codec, nid,
963 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200964 spec->detect_lo = 1;
965 }
966 spec->automute_lo_possible = spec->detect_hp;
967 }
968
969 spec->automute_speaker_possible = cfg->speaker_outs &&
970 (spec->detect_hp || spec->detect_lo);
971
972 spec->automute_lo = spec->automute_lo_possible;
973 spec->automute_speaker = spec->automute_speaker_possible;
974
975 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200976 /* create a control for automute mode */
977 alc_add_automute_mode_enum(codec);
978 spec->unsol_event = alc_sku_unsol_event;
979 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200980}
981
Takashi Iwai1d045db2011-07-07 18:23:21 +0200982/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200983static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
984{
985 int i;
986 for (i = 0; i < nums; i++)
987 if (list[i] == nid)
988 return i;
989 return -1;
990}
991
Takashi Iwai1d045db2011-07-07 18:23:21 +0200992/* check whether dynamic ADC-switching is available */
993static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
994{
995 struct alc_spec *spec = codec->spec;
996 struct hda_input_mux *imux = &spec->private_imux[0];
997 int i, n, idx;
998 hda_nid_t cap, pin;
999
1000 if (imux != spec->input_mux) /* no dynamic imux? */
1001 return false;
1002
1003 for (n = 0; n < spec->num_adc_nids; n++) {
1004 cap = spec->private_capsrc_nids[n];
1005 for (i = 0; i < imux->num_items; i++) {
1006 pin = spec->imux_pins[i];
1007 if (!pin)
1008 return false;
1009 if (get_connection_index(codec, cap, pin) < 0)
1010 break;
1011 }
1012 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001013 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001014 }
1015
1016 for (i = 0; i < imux->num_items; i++) {
1017 pin = spec->imux_pins[i];
1018 for (n = 0; n < spec->num_adc_nids; n++) {
1019 cap = spec->private_capsrc_nids[n];
1020 idx = get_connection_index(codec, cap, pin);
1021 if (idx >= 0) {
1022 imux->items[i].index = idx;
1023 spec->dyn_adc_idx[i] = n;
1024 break;
1025 }
1026 }
1027 }
1028
1029 snd_printdd("realtek: enabling ADC switching\n");
1030 spec->dyn_adc_switch = 1;
1031 return true;
1032}
Takashi Iwai21268962011-07-07 15:01:13 +02001033
1034/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1035static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1036{
1037 struct alc_spec *spec = codec->spec;
1038 struct hda_input_mux *imux;
1039 static char * const texts[3] = {
1040 "Mic", "Internal Mic", "Dock Mic"
1041 };
1042 int i;
1043
1044 if (!spec->auto_mic)
1045 return false;
1046 imux = &spec->private_imux[0];
1047 if (spec->input_mux == imux)
1048 return true;
1049 spec->imux_pins[0] = spec->ext_mic_pin;
1050 spec->imux_pins[1] = spec->int_mic_pin;
1051 spec->imux_pins[2] = spec->dock_mic_pin;
1052 for (i = 0; i < 3; i++) {
1053 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001054 if (spec->imux_pins[i]) {
1055 hda_nid_t pin = spec->imux_pins[i];
1056 int c;
1057 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001058 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001059 int idx = get_connection_index(codec, cap, pin);
1060 if (idx >= 0) {
1061 imux->items[i].index = idx;
1062 break;
1063 }
1064 }
Takashi Iwai21268962011-07-07 15:01:13 +02001065 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001066 }
Takashi Iwai21268962011-07-07 15:01:13 +02001067 }
1068 spec->num_mux_defs = 1;
1069 spec->input_mux = imux;
1070 return true;
1071}
1072
1073/* check whether all auto-mic pins are valid; setup indices if OK */
1074static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1075{
1076 struct alc_spec *spec = codec->spec;
1077 const struct hda_input_mux *imux;
1078
1079 if (!spec->auto_mic)
1080 return false;
1081 if (spec->auto_mic_valid_imux)
1082 return true; /* already checked */
1083
1084 /* fill up imux indices */
1085 if (!alc_check_dyn_adc_switch(codec)) {
1086 spec->auto_mic = 0;
1087 return false;
1088 }
1089
1090 imux = spec->input_mux;
1091 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1092 spec->imux_pins, imux->num_items);
1093 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1094 spec->imux_pins, imux->num_items);
1095 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1098 spec->auto_mic = 0;
1099 return false; /* no corresponding imux */
1100 }
1101
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001102 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001103 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001104 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1105 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001106
1107 spec->auto_mic_valid_imux = 1;
1108 spec->auto_mic = 1;
1109 return true;
1110}
1111
Takashi Iwai1d045db2011-07-07 18:23:21 +02001112/*
1113 * Check the availability of auto-mic switch;
1114 * Set up if really supported
1115 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001116static void alc_init_auto_mic(struct hda_codec *codec)
1117{
1118 struct alc_spec *spec = codec->spec;
1119 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001120 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001121 int i;
1122
Takashi Iwai24de1832011-11-07 17:13:39 +01001123 if (spec->shared_mic_hp)
1124 return; /* no auto-mic for the shared I/O */
1125
Takashi Iwai21268962011-07-07 15:01:13 +02001126 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1127
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001128 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001129 for (i = 0; i < cfg->num_inputs; i++) {
1130 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001131 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001132 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001133 switch (snd_hda_get_input_pin_attr(defcfg)) {
1134 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001135 if (fixed)
1136 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001137 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1138 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001139 fixed = nid;
1140 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001141 case INPUT_PIN_ATTR_UNUSED:
1142 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001143 case INPUT_PIN_ATTR_DOCK:
1144 if (dock)
1145 return; /* already occupied */
1146 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1147 return; /* invalid type */
1148 dock = nid;
1149 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001150 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001151 if (ext)
1152 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001153 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1154 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001155 ext = nid;
1156 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001157 }
1158 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001159 if (!ext && dock) {
1160 ext = dock;
1161 dock = 0;
1162 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001163 if (!ext || !fixed)
1164 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001165 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001166 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001167 if (dock && !is_jack_detectable(codec, dock))
1168 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001169
1170 /* check imux indices */
1171 spec->ext_mic_pin = ext;
1172 spec->int_mic_pin = fixed;
1173 spec->dock_mic_pin = dock;
1174
1175 spec->auto_mic = 1;
1176 if (!alc_auto_mic_check_imux(codec))
1177 return;
1178
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001179 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1180 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001181 spec->unsol_event = alc_sku_unsol_event;
1182}
1183
Takashi Iwai1d045db2011-07-07 18:23:21 +02001184/* check the availabilities of auto-mute and auto-mic switches */
1185static void alc_auto_check_switches(struct hda_codec *codec)
1186{
David Henningsson42cf0d02011-09-20 12:04:56 +02001187 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001188 alc_init_auto_mic(codec);
1189}
1190
1191/*
1192 * Realtek SSID verification
1193 */
1194
David Henningsson90622912010-10-14 14:50:18 +02001195/* Could be any non-zero and even value. When used as fixup, tells
1196 * the driver to ignore any present sku defines.
1197 */
1198#define ALC_FIXUP_SKU_IGNORE (2)
1199
Kailang Yangda00c242010-03-19 11:23:45 +01001200static int alc_auto_parse_customize_define(struct hda_codec *codec)
1201{
1202 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001203 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001204 struct alc_spec *spec = codec->spec;
1205
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001206 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1207
David Henningsson90622912010-10-14 14:50:18 +02001208 if (spec->cdefine.fixup) {
1209 ass = spec->cdefine.sku_cfg;
1210 if (ass == ALC_FIXUP_SKU_IGNORE)
1211 return -1;
1212 goto do_sku;
1213 }
1214
Kailang Yangda00c242010-03-19 11:23:45 +01001215 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001216 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001217 goto do_sku;
1218
1219 nid = 0x1d;
1220 if (codec->vendor_id == 0x10ec0260)
1221 nid = 0x17;
1222 ass = snd_hda_codec_get_pincfg(codec, nid);
1223
1224 if (!(ass & 1)) {
1225 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1226 codec->chip_name, ass);
1227 return -1;
1228 }
1229
1230 /* check sum */
1231 tmp = 0;
1232 for (i = 1; i < 16; i++) {
1233 if ((ass >> i) & 1)
1234 tmp++;
1235 }
1236 if (((ass >> 16) & 0xf) != tmp)
1237 return -1;
1238
1239 spec->cdefine.port_connectivity = ass >> 30;
1240 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1241 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1242 spec->cdefine.customization = ass >> 8;
1243do_sku:
1244 spec->cdefine.sku_cfg = ass;
1245 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1246 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1247 spec->cdefine.swap = (ass & 0x2) >> 1;
1248 spec->cdefine.override = ass & 0x1;
1249
1250 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1251 nid, spec->cdefine.sku_cfg);
1252 snd_printd("SKU: port_connectivity=0x%x\n",
1253 spec->cdefine.port_connectivity);
1254 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1255 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1256 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1257 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1258 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1259 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1260 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1261
1262 return 0;
1263}
1264
Takashi Iwai1d045db2011-07-07 18:23:21 +02001265/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001266static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1267{
Takashi Iwai21268962011-07-07 15:01:13 +02001268 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001269}
1270
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001271/* check subsystem ID and set up device-specific initialization;
1272 * return 1 if initialized, 0 if invalid SSID
1273 */
1274/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1275 * 31 ~ 16 : Manufacture ID
1276 * 15 ~ 8 : SKU ID
1277 * 7 ~ 0 : Assembly ID
1278 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1279 */
1280static int alc_subsystem_id(struct hda_codec *codec,
1281 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001282 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001283{
1284 unsigned int ass, tmp, i;
1285 unsigned nid;
1286 struct alc_spec *spec = codec->spec;
1287
David Henningsson90622912010-10-14 14:50:18 +02001288 if (spec->cdefine.fixup) {
1289 ass = spec->cdefine.sku_cfg;
1290 if (ass == ALC_FIXUP_SKU_IGNORE)
1291 return 0;
1292 goto do_sku;
1293 }
1294
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001295 ass = codec->subsystem_id & 0xffff;
1296 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1297 goto do_sku;
1298
1299 /* invalid SSID, check the special NID pin defcfg instead */
1300 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001301 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001302 * 29~21 : reserve
1303 * 20 : PCBEEP input
1304 * 19~16 : Check sum (15:1)
1305 * 15~1 : Custom
1306 * 0 : override
1307 */
1308 nid = 0x1d;
1309 if (codec->vendor_id == 0x10ec0260)
1310 nid = 0x17;
1311 ass = snd_hda_codec_get_pincfg(codec, nid);
1312 snd_printd("realtek: No valid SSID, "
1313 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001314 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001315 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001316 return 0;
1317 if ((ass >> 30) != 1) /* no physical connection */
1318 return 0;
1319
1320 /* check sum */
1321 tmp = 0;
1322 for (i = 1; i < 16; i++) {
1323 if ((ass >> i) & 1)
1324 tmp++;
1325 }
1326 if (((ass >> 16) & 0xf) != tmp)
1327 return 0;
1328do_sku:
1329 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1330 ass & 0xffff, codec->vendor_id);
1331 /*
1332 * 0 : override
1333 * 1 : Swap Jack
1334 * 2 : 0 --> Desktop, 1 --> Laptop
1335 * 3~5 : External Amplifier control
1336 * 7~6 : Reserved
1337 */
1338 tmp = (ass & 0x38) >> 3; /* external Amp control */
1339 switch (tmp) {
1340 case 1:
1341 spec->init_amp = ALC_INIT_GPIO1;
1342 break;
1343 case 3:
1344 spec->init_amp = ALC_INIT_GPIO2;
1345 break;
1346 case 7:
1347 spec->init_amp = ALC_INIT_GPIO3;
1348 break;
1349 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001350 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001351 spec->init_amp = ALC_INIT_DEFAULT;
1352 break;
1353 }
1354
1355 /* is laptop or Desktop and enable the function "Mute internal speaker
1356 * when the external headphone out jack is plugged"
1357 */
1358 if (!(ass & 0x8000))
1359 return 1;
1360 /*
1361 * 10~8 : Jack location
1362 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1363 * 14~13: Resvered
1364 * 15 : 1 --> enable the function "Mute internal speaker
1365 * when the external headphone out jack is plugged"
1366 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001367 if (!spec->autocfg.hp_pins[0] &&
1368 !(spec->autocfg.line_out_pins[0] &&
1369 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001370 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001371 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1372 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001373 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001374 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001375 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001376 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001377 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001378 else if (tmp == 3)
1379 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001380 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001381 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001382 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1383 spec->autocfg.line_outs))
1384 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001385 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001386 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001387 return 1;
1388}
Kailang Yangea1fb292008-08-26 12:58:38 +02001389
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001390/* Check the validity of ALC subsystem-id
1391 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1392static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001393{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001394 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001395 struct alc_spec *spec = codec->spec;
1396 snd_printd("realtek: "
1397 "Enable default setup for auto mode as fallback\n");
1398 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001399 }
Takashi Iwai21268962011-07-07 15:01:13 +02001400}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001401
Takashi Iwai41e41f12005-06-08 14:48:49 +02001402/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001403 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001404 */
1405
1406struct alc_pincfg {
1407 hda_nid_t nid;
1408 u32 val;
1409};
1410
Todd Broche1eb5f12010-12-06 11:19:51 -08001411struct alc_model_fixup {
1412 const int id;
1413 const char *name;
1414};
1415
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001416struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001417 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001418 bool chained;
1419 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001420 union {
1421 unsigned int sku;
1422 const struct alc_pincfg *pins;
1423 const struct hda_verb *verbs;
1424 void (*func)(struct hda_codec *codec,
1425 const struct alc_fixup *fix,
1426 int action);
1427 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001428};
1429
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001430enum {
1431 ALC_FIXUP_INVALID,
1432 ALC_FIXUP_SKU,
1433 ALC_FIXUP_PINS,
1434 ALC_FIXUP_VERBS,
1435 ALC_FIXUP_FUNC,
1436};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001437
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001438enum {
1439 ALC_FIXUP_ACT_PRE_PROBE,
1440 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001441 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001442};
1443
1444static void alc_apply_fixup(struct hda_codec *codec, int action)
1445{
1446 struct alc_spec *spec = codec->spec;
1447 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001448#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001449 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001450#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001451 int depth = 0;
1452
1453 if (!spec->fixup_list)
1454 return;
1455
1456 while (id >= 0) {
1457 const struct alc_fixup *fix = spec->fixup_list + id;
1458 const struct alc_pincfg *cfg;
1459
1460 switch (fix->type) {
1461 case ALC_FIXUP_SKU:
1462 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001463 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001464 snd_printdd(KERN_INFO "hda_codec: %s: "
1465 "Apply sku override for %s\n",
1466 codec->chip_name, modelname);
1467 spec->cdefine.sku_cfg = fix->v.sku;
1468 spec->cdefine.fixup = 1;
1469 break;
1470 case ALC_FIXUP_PINS:
1471 cfg = fix->v.pins;
1472 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1473 break;
1474 snd_printdd(KERN_INFO "hda_codec: %s: "
1475 "Apply pincfg for %s\n",
1476 codec->chip_name, modelname);
1477 for (; cfg->nid; cfg++)
1478 snd_hda_codec_set_pincfg(codec, cfg->nid,
1479 cfg->val);
1480 break;
1481 case ALC_FIXUP_VERBS:
1482 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1483 break;
1484 snd_printdd(KERN_INFO "hda_codec: %s: "
1485 "Apply fix-verbs for %s\n",
1486 codec->chip_name, modelname);
1487 add_verb(codec->spec, fix->v.verbs);
1488 break;
1489 case ALC_FIXUP_FUNC:
1490 if (!fix->v.func)
1491 break;
1492 snd_printdd(KERN_INFO "hda_codec: %s: "
1493 "Apply fix-func for %s\n",
1494 codec->chip_name, modelname);
1495 fix->v.func(codec, fix, action);
1496 break;
1497 default:
1498 snd_printk(KERN_ERR "hda_codec: %s: "
1499 "Invalid fixup type %d\n",
1500 codec->chip_name, fix->type);
1501 break;
1502 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001503 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001504 break;
1505 if (++depth > 10)
1506 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001507 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001508 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001509}
1510
Todd Broche1eb5f12010-12-06 11:19:51 -08001511static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001512 const struct alc_model_fixup *models,
1513 const struct snd_pci_quirk *quirk,
1514 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001515{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001516 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001517 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001518 int id = -1;
1519 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001520
Todd Broche1eb5f12010-12-06 11:19:51 -08001521 if (codec->modelname && models) {
1522 while (models->name) {
1523 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001524 id = models->id;
1525 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001526 break;
1527 }
1528 models++;
1529 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001530 }
1531 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001532 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1533 if (q) {
1534 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001535#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001536 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001537#endif
1538 }
1539 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001540 if (id < 0) {
1541 for (q = quirk; q->subvendor; q++) {
1542 unsigned int vendorid =
1543 q->subdevice | (q->subvendor << 16);
1544 if (vendorid == codec->subsystem_id) {
1545 id = q->value;
1546#ifdef CONFIG_SND_DEBUG_VERBOSE
1547 name = q->name;
1548#endif
1549 break;
1550 }
1551 }
1552 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001553
1554 spec->fixup_id = id;
1555 if (id >= 0) {
1556 spec->fixup_list = fixlist;
1557 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001558 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001559}
1560
Takashi Iwai1d045db2011-07-07 18:23:21 +02001561/*
1562 * COEF access helper functions
1563 */
Kailang Yang274693f2009-12-03 10:07:50 +01001564static int alc_read_coef_idx(struct hda_codec *codec,
1565 unsigned int coef_idx)
1566{
1567 unsigned int val;
1568 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1569 coef_idx);
1570 val = snd_hda_codec_read(codec, 0x20, 0,
1571 AC_VERB_GET_PROC_COEF, 0);
1572 return val;
1573}
1574
Kailang Yang977ddd62010-09-15 10:02:29 +02001575static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1576 unsigned int coef_val)
1577{
1578 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1579 coef_idx);
1580 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1581 coef_val);
1582}
1583
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001584/* a special bypass for COEF 0; read the cached value at the second time */
1585static unsigned int alc_get_coef0(struct hda_codec *codec)
1586{
1587 struct alc_spec *spec = codec->spec;
1588 if (!spec->coef0)
1589 spec->coef0 = alc_read_coef_idx(codec, 0);
1590 return spec->coef0;
1591}
1592
Takashi Iwai1d045db2011-07-07 18:23:21 +02001593/*
1594 * Digital I/O handling
1595 */
1596
Takashi Iwai757899a2010-07-30 10:48:14 +02001597/* set right pin controls for digital I/O */
1598static void alc_auto_init_digital(struct hda_codec *codec)
1599{
1600 struct alc_spec *spec = codec->spec;
1601 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001602 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001603
1604 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1605 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001606 if (!pin)
1607 continue;
1608 snd_hda_codec_write(codec, pin, 0,
1609 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1610 if (!i)
1611 dac = spec->multiout.dig_out_nid;
1612 else
1613 dac = spec->slave_dig_outs[i - 1];
1614 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1615 continue;
1616 snd_hda_codec_write(codec, dac, 0,
1617 AC_VERB_SET_AMP_GAIN_MUTE,
1618 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001619 }
1620 pin = spec->autocfg.dig_in_pin;
1621 if (pin)
1622 snd_hda_codec_write(codec, pin, 0,
1623 AC_VERB_SET_PIN_WIDGET_CONTROL,
1624 PIN_IN);
1625}
1626
1627/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1628static void alc_auto_parse_digital(struct hda_codec *codec)
1629{
1630 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001631 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001632 hda_nid_t dig_nid;
1633
1634 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001635 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001636 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001637 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001638 err = snd_hda_get_connections(codec,
1639 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001640 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001641 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001642 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001643 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001644 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001645 spec->multiout.dig_out_nid = dig_nid;
1646 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1647 } else {
1648 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001649 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001650 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001651 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001652 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001653 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001654 }
1655
1656 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001657 dig_nid = codec->start_nid;
1658 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1659 unsigned int wcaps = get_wcaps(codec, dig_nid);
1660 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1661 continue;
1662 if (!(wcaps & AC_WCAP_DIGITAL))
1663 continue;
1664 if (!(wcaps & AC_WCAP_CONN_LIST))
1665 continue;
1666 err = get_connection_index(codec, dig_nid,
1667 spec->autocfg.dig_in_pin);
1668 if (err >= 0) {
1669 spec->dig_in_nid = dig_nid;
1670 break;
1671 }
1672 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001673 }
1674}
1675
Takashi Iwaif95474e2007-07-10 00:47:43 +02001676/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001677 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001678 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001679static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1680 struct snd_ctl_elem_info *uinfo)
1681{
1682 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1683 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001684 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001685 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001686
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001687 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001688 if (spec->vol_in_capsrc)
1689 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1690 else
1691 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1692 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001693 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001694 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001695 return err;
1696}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001698static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1699 unsigned int size, unsigned int __user *tlv)
1700{
1701 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1702 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001703 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001704 int err;
1705
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001706 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001707 if (spec->vol_in_capsrc)
1708 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1709 else
1710 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1711 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001712 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001713 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001714 return err;
1715}
1716
1717typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1718 struct snd_ctl_elem_value *ucontrol);
1719
1720static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1721 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001722 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001723{
1724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1725 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001726 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001727
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001728 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001729 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001730 for (i = 0; i < spec->num_adc_nids; i++) {
1731 kcontrol->private_value =
1732 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1733 3, 0, HDA_INPUT);
1734 err = func(kcontrol, ucontrol);
1735 if (err < 0)
1736 goto error;
1737 }
1738 } else {
1739 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001740 if (spec->vol_in_capsrc)
1741 kcontrol->private_value =
1742 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1743 3, 0, HDA_OUTPUT);
1744 else
1745 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001746 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1747 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001748 err = func(kcontrol, ucontrol);
1749 }
1750 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001751 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001752 return err;
1753}
1754
1755static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol)
1757{
1758 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001759 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001760}
1761
1762static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol)
1764{
1765 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001766 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001767}
1768
1769/* capture mixer elements */
1770#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1771
1772static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1773 struct snd_ctl_elem_value *ucontrol)
1774{
1775 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001776 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001777}
1778
1779static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1780 struct snd_ctl_elem_value *ucontrol)
1781{
1782 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001783 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001784}
1785
Takashi Iwaia23b6882009-03-23 15:21:36 +01001786#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001787 { \
1788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1789 .name = "Capture Switch", \
1790 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1791 .count = num, \
1792 .info = alc_cap_sw_info, \
1793 .get = alc_cap_sw_get, \
1794 .put = alc_cap_sw_put, \
1795 }, \
1796 { \
1797 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1798 .name = "Capture Volume", \
1799 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1800 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1801 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1802 .count = num, \
1803 .info = alc_cap_vol_info, \
1804 .get = alc_cap_vol_get, \
1805 .put = alc_cap_vol_put, \
1806 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001807 }
1808
1809#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001810 { \
1811 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1812 /* .name = "Capture Source", */ \
1813 .name = "Input Source", \
1814 .count = num, \
1815 .info = alc_mux_enum_info, \
1816 .get = alc_mux_enum_get, \
1817 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001818 }
1819
1820#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001821static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001822 _DEFINE_CAPMIX(num), \
1823 _DEFINE_CAPSRC(num), \
1824 { } /* end */ \
1825}
1826
1827#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001828static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001829 _DEFINE_CAPMIX(num), \
1830 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001831}
1832
1833/* up to three ADCs */
1834DEFINE_CAPMIX(1);
1835DEFINE_CAPMIX(2);
1836DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001837DEFINE_CAPMIX_NOSRC(1);
1838DEFINE_CAPMIX_NOSRC(2);
1839DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001840
1841/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001842 * virtual master controls
1843 */
1844
1845/*
1846 * slave controls for virtual master
1847 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001848static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001849 "Front Playback Volume",
1850 "Surround Playback Volume",
1851 "Center Playback Volume",
1852 "LFE Playback Volume",
1853 "Side Playback Volume",
1854 "Headphone Playback Volume",
1855 "Speaker Playback Volume",
1856 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001857 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001858 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001859 NULL,
1860};
1861
Takashi Iwaiea734962011-01-17 11:29:34 +01001862static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001863 "Front Playback Switch",
1864 "Surround Playback Switch",
1865 "Center Playback Switch",
1866 "LFE Playback Switch",
1867 "Side Playback Switch",
1868 "Headphone Playback Switch",
1869 "Speaker Playback Switch",
1870 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001871 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001872 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001873 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001874 NULL,
1875};
1876
1877/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001878 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001880
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001881#define NID_MAPPING (-1)
1882
1883#define SUBDEV_SPEAKER_ (0 << 6)
1884#define SUBDEV_HP_ (1 << 6)
1885#define SUBDEV_LINE_ (2 << 6)
1886#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1887#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1888#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1889
Takashi Iwai603c4012008-07-30 15:01:44 +02001890static void alc_free_kctls(struct hda_codec *codec);
1891
Takashi Iwai67d634c2009-11-16 15:35:59 +01001892#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001893/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001894static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001895 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001896 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001897 { } /* end */
1898};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001899#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001900
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001901static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902{
1903 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001904 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001905 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001906 int i, j, err;
1907 unsigned int u;
1908 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
1910 for (i = 0; i < spec->num_mixers; i++) {
1911 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1912 if (err < 0)
1913 return err;
1914 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001915 if (spec->cap_mixer) {
1916 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1917 if (err < 0)
1918 return err;
1919 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001921 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001922 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001923 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 if (err < 0)
1925 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001926 if (!spec->no_analog) {
1927 err = snd_hda_create_spdif_share_sw(codec,
1928 &spec->multiout);
1929 if (err < 0)
1930 return err;
1931 spec->multiout.share_spdif = 1;
1932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 }
1934 if (spec->dig_in_nid) {
1935 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1936 if (err < 0)
1937 return err;
1938 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001939
Takashi Iwai67d634c2009-11-16 15:35:59 +01001940#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001941 /* create beep controls if needed */
1942 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001943 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001944 for (knew = alc_beep_mixer; knew->name; knew++) {
1945 struct snd_kcontrol *kctl;
1946 kctl = snd_ctl_new1(knew, codec);
1947 if (!kctl)
1948 return -ENOMEM;
1949 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001950 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001951 if (err < 0)
1952 return err;
1953 }
1954 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001955#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001956
Takashi Iwai2134ea42008-01-10 16:53:55 +01001957 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001958 if (!spec->no_analog &&
1959 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001960 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001961 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001962 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001963 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001964 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001965 if (err < 0)
1966 return err;
1967 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001968 if (!spec->no_analog &&
1969 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001970 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1971 NULL, alc_slave_sws);
1972 if (err < 0)
1973 return err;
1974 }
1975
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001976 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001977 if (spec->capsrc_nids || spec->adc_nids) {
1978 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1979 if (!kctl)
1980 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1981 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001982 err = snd_hda_add_nid(codec, kctl, i,
1983 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001984 if (err < 0)
1985 return err;
1986 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001987 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001988 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001989 const char *kname = kctl ? kctl->id.name : NULL;
1990 for (knew = spec->cap_mixer; knew->name; knew++) {
1991 if (kname && strcmp(knew->name, kname) == 0)
1992 continue;
1993 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1994 for (i = 0; kctl && i < kctl->count; i++) {
1995 err = snd_hda_add_nid(codec, kctl, i,
1996 spec->adc_nids[i]);
1997 if (err < 0)
1998 return err;
1999 }
2000 }
2001 }
2002
2003 /* other nid->control mapping */
2004 for (i = 0; i < spec->num_mixers; i++) {
2005 for (knew = spec->mixers[i]; knew->name; knew++) {
2006 if (knew->iface != NID_MAPPING)
2007 continue;
2008 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2009 if (kctl == NULL)
2010 continue;
2011 u = knew->subdevice;
2012 for (j = 0; j < 4; j++, u >>= 8) {
2013 nid = u & 0x3f;
2014 if (nid == 0)
2015 continue;
2016 switch (u & 0xc0) {
2017 case SUBDEV_SPEAKER_:
2018 nid = spec->autocfg.speaker_pins[nid];
2019 break;
2020 case SUBDEV_LINE_:
2021 nid = spec->autocfg.line_out_pins[nid];
2022 break;
2023 case SUBDEV_HP_:
2024 nid = spec->autocfg.hp_pins[nid];
2025 break;
2026 default:
2027 continue;
2028 }
2029 err = snd_hda_add_nid(codec, kctl, 0, nid);
2030 if (err < 0)
2031 return err;
2032 }
2033 u = knew->private_value;
2034 for (j = 0; j < 4; j++, u >>= 8) {
2035 nid = u & 0xff;
2036 if (nid == 0)
2037 continue;
2038 err = snd_hda_add_nid(codec, kctl, 0, nid);
2039 if (err < 0)
2040 return err;
2041 }
2042 }
2043 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002044
2045 alc_free_kctls(codec); /* no longer needed */
2046
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002047 return 0;
2048}
2049
2050static int alc_build_controls(struct hda_codec *codec)
2051{
2052 struct alc_spec *spec = codec->spec;
2053 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002054 if (err < 0)
2055 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002056 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057}
2058
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002059
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002061 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002062 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002063
Takashi Iwai584c0c42011-03-10 12:51:11 +01002064static void alc_init_special_input_src(struct hda_codec *codec);
2065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066static int alc_init(struct hda_codec *codec)
2067{
2068 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002069 unsigned int i;
2070
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002071 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002072 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002073
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002074 for (i = 0; i < spec->num_init_verbs; i++)
2075 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002076 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002077
2078 if (spec->init_hook)
2079 spec->init_hook(codec);
2080
Takashi Iwai58701122011-01-13 15:41:45 +01002081 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2082
Takashi Iwai01a61e12011-10-28 00:03:22 +02002083 snd_hda_jack_report_sync(codec);
2084
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002085 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 return 0;
2087}
2088
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002089static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2090{
2091 struct alc_spec *spec = codec->spec;
2092
2093 if (spec->unsol_event)
2094 spec->unsol_event(codec, res);
2095}
2096
Takashi Iwaicb53c622007-08-10 17:21:45 +02002097#ifdef CONFIG_SND_HDA_POWER_SAVE
2098static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2099{
2100 struct alc_spec *spec = codec->spec;
2101 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2102}
2103#endif
2104
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105/*
2106 * Analog playback callbacks
2107 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002108static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002110 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111{
2112 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002113 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2114 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115}
2116
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002117static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 struct hda_codec *codec,
2119 unsigned int stream_tag,
2120 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002121 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
2123 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002124 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2125 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126}
2127
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002128static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002130 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131{
2132 struct alc_spec *spec = codec->spec;
2133 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2134}
2135
2136/*
2137 * Digital out
2138 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002139static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002141 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142{
2143 struct alc_spec *spec = codec->spec;
2144 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2145}
2146
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002147static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002148 struct hda_codec *codec,
2149 unsigned int stream_tag,
2150 unsigned int format,
2151 struct snd_pcm_substream *substream)
2152{
2153 struct alc_spec *spec = codec->spec;
2154 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2155 stream_tag, format, substream);
2156}
2157
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002158static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002159 struct hda_codec *codec,
2160 struct snd_pcm_substream *substream)
2161{
2162 struct alc_spec *spec = codec->spec;
2163 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2164}
2165
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002166static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002168 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
2170 struct alc_spec *spec = codec->spec;
2171 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2172}
2173
2174/*
2175 * Analog capture
2176 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002177static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 struct hda_codec *codec,
2179 unsigned int stream_tag,
2180 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002181 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182{
2183 struct alc_spec *spec = codec->spec;
2184
Takashi Iwai63300792008-01-24 15:31:36 +01002185 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 stream_tag, 0, format);
2187 return 0;
2188}
2189
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002190static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002192 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193{
2194 struct alc_spec *spec = codec->spec;
2195
Takashi Iwai888afa12008-03-18 09:57:50 +01002196 snd_hda_codec_cleanup_stream(codec,
2197 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 return 0;
2199}
2200
Takashi Iwai840b64c2010-07-13 22:49:01 +02002201/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002202static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002203 struct hda_codec *codec,
2204 unsigned int stream_tag,
2205 unsigned int format,
2206 struct snd_pcm_substream *substream)
2207{
2208 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002209 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002210 spec->cur_adc_stream_tag = stream_tag;
2211 spec->cur_adc_format = format;
2212 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2213 return 0;
2214}
2215
Takashi Iwai21268962011-07-07 15:01:13 +02002216static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002217 struct hda_codec *codec,
2218 struct snd_pcm_substream *substream)
2219{
2220 struct alc_spec *spec = codec->spec;
2221 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2222 spec->cur_adc = 0;
2223 return 0;
2224}
2225
Takashi Iwai21268962011-07-07 15:01:13 +02002226static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002227 .substreams = 1,
2228 .channels_min = 2,
2229 .channels_max = 2,
2230 .nid = 0, /* fill later */
2231 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002232 .prepare = dyn_adc_capture_pcm_prepare,
2233 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002234 },
2235};
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_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 .substreams = 1,
2241 .channels_min = 2,
2242 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002243 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002245 .open = alc_playback_pcm_open,
2246 .prepare = alc_playback_pcm_prepare,
2247 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 },
2249};
2250
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002251static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002252 .substreams = 1,
2253 .channels_min = 2,
2254 .channels_max = 2,
2255 /* NID is set in alc_build_pcms */
2256};
2257
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002258static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002259 .substreams = 1,
2260 .channels_min = 2,
2261 .channels_max = 2,
2262 /* NID is set in alc_build_pcms */
2263};
2264
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002265static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002266 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 .channels_min = 2,
2268 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002269 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002271 .prepare = alc_alt_capture_pcm_prepare,
2272 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 },
2274};
2275
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002276static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 .substreams = 1,
2278 .channels_min = 2,
2279 .channels_max = 2,
2280 /* NID is set in alc_build_pcms */
2281 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002282 .open = alc_dig_playback_pcm_open,
2283 .close = alc_dig_playback_pcm_close,
2284 .prepare = alc_dig_playback_pcm_prepare,
2285 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 },
2287};
2288
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002289static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 .substreams = 1,
2291 .channels_min = 2,
2292 .channels_max = 2,
2293 /* NID is set in alc_build_pcms */
2294};
2295
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002296/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002297static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002298 .substreams = 0,
2299 .channels_min = 0,
2300 .channels_max = 0,
2301};
2302
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303static int alc_build_pcms(struct hda_codec *codec)
2304{
2305 struct alc_spec *spec = codec->spec;
2306 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002307 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002308 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 int i;
2310
2311 codec->num_pcms = 1;
2312 codec->pcm_info = info;
2313
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002314 if (spec->no_analog)
2315 goto skip_analog;
2316
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002317 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2318 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002320
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002321 if (spec->multiout.dac_nids > 0) {
2322 p = spec->stream_analog_playback;
2323 if (!p)
2324 p = &alc_pcm_analog_playback;
2325 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002326 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2327 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002328 if (spec->adc_nids) {
2329 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002330 if (!p) {
2331 if (spec->dyn_adc_switch)
2332 p = &dyn_adc_pcm_analog_capture;
2333 else
2334 p = &alc_pcm_analog_capture;
2335 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002336 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002337 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2338 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339
Takashi Iwai4a471b72005-12-07 13:56:29 +01002340 if (spec->channel_mode) {
2341 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2342 for (i = 0; i < spec->num_channel_mode; i++) {
2343 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 }
2347 }
2348
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002349 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002350 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002352 snprintf(spec->stream_name_digital,
2353 sizeof(spec->stream_name_digital),
2354 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002355 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002356 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002357 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002359 if (spec->dig_out_type)
2360 info->pcm_type = spec->dig_out_type;
2361 else
2362 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002363 if (spec->multiout.dig_out_nid) {
2364 p = spec->stream_digital_playback;
2365 if (!p)
2366 p = &alc_pcm_digital_playback;
2367 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2369 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002370 if (spec->dig_in_nid) {
2371 p = spec->stream_digital_capture;
2372 if (!p)
2373 p = &alc_pcm_digital_capture;
2374 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2376 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002377 /* FIXME: do we need this for all Realtek codec models? */
2378 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 }
2380
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002381 if (spec->no_analog)
2382 return 0;
2383
Takashi Iwaie08a0072006-09-07 17:52:14 +02002384 /* If the use of more than one ADC is requested for the current
2385 * model, configure a second analog capture-only PCM.
2386 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002387 have_multi_adcs = (spec->num_adc_nids > 1) &&
2388 !spec->dyn_adc_switch && !spec->auto_mic &&
2389 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002390 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002391 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002392 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002393 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002394 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002395 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002396 p = spec->stream_analog_alt_playback;
2397 if (!p)
2398 p = &alc_pcm_analog_alt_playback;
2399 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002400 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2401 spec->alt_dac_nid;
2402 } else {
2403 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2404 alc_pcm_null_stream;
2405 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2406 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002407 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002408 p = spec->stream_analog_alt_capture;
2409 if (!p)
2410 p = &alc_pcm_analog_alt_capture;
2411 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002412 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2413 spec->adc_nids[1];
2414 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2415 spec->num_adc_nids - 1;
2416 } else {
2417 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2418 alc_pcm_null_stream;
2419 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002420 }
2421 }
2422
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 return 0;
2424}
2425
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002426static inline void alc_shutup(struct hda_codec *codec)
2427{
Takashi Iwai1c716152011-04-07 10:37:16 +02002428 struct alc_spec *spec = codec->spec;
2429
2430 if (spec && spec->shutup)
2431 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002432 snd_hda_shutup_pins(codec);
2433}
2434
Takashi Iwai603c4012008-07-30 15:01:44 +02002435static void alc_free_kctls(struct hda_codec *codec)
2436{
2437 struct alc_spec *spec = codec->spec;
2438
2439 if (spec->kctls.list) {
2440 struct snd_kcontrol_new *kctl = spec->kctls.list;
2441 int i;
2442 for (i = 0; i < spec->kctls.used; i++)
2443 kfree(kctl[i].name);
2444 }
2445 snd_array_free(&spec->kctls);
2446}
2447
Takashi Iwai23c09b02011-08-19 09:05:35 +02002448static void alc_free_bind_ctls(struct hda_codec *codec)
2449{
2450 struct alc_spec *spec = codec->spec;
2451 if (spec->bind_ctls.list) {
2452 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2453 int i;
2454 for (i = 0; i < spec->bind_ctls.used; i++)
2455 kfree(ctl[i]);
2456 }
2457 snd_array_free(&spec->bind_ctls);
2458}
2459
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460static void alc_free(struct hda_codec *codec)
2461{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002462 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002463
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002464 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002465 return;
2466
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002467 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002468 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002469 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002470 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002471 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472}
2473
Hector Martinf5de24b2009-12-20 22:51:31 +01002474#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002475static void alc_power_eapd(struct hda_codec *codec)
2476{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002477 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002478}
2479
Hector Martinf5de24b2009-12-20 22:51:31 +01002480static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2481{
2482 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002483 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002484 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002485 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002486 return 0;
2487}
2488#endif
2489
Takashi Iwai2a439522011-07-26 09:52:50 +02002490#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002491static int alc_resume(struct hda_codec *codec)
2492{
Takashi Iwai1c716152011-04-07 10:37:16 +02002493 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002494 codec->patch_ops.init(codec);
2495 snd_hda_codec_resume_amp(codec);
2496 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002497 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002498 return 0;
2499}
Takashi Iwaie044c392008-10-27 16:56:24 +01002500#endif
2501
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502/*
2503 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002504static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 .build_controls = alc_build_controls,
2506 .build_pcms = alc_build_pcms,
2507 .init = alc_init,
2508 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002509 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002510#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002511 .resume = alc_resume,
2512#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002513#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002514 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002515 .check_power_status = alc_check_power_status,
2516#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002517 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518};
2519
Kailang Yangc027ddc2010-03-19 11:33:06 +01002520/* replace the codec chip_name with the given string */
2521static int alc_codec_rename(struct hda_codec *codec, const char *name)
2522{
2523 kfree(codec->chip_name);
2524 codec->chip_name = kstrdup(name, GFP_KERNEL);
2525 if (!codec->chip_name) {
2526 alc_free(codec);
2527 return -ENOMEM;
2528 }
2529 return 0;
2530}
2531
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002532/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002533 * Rename codecs appropriately from COEF value
2534 */
2535struct alc_codec_rename_table {
2536 unsigned int vendor_id;
2537 unsigned short coef_mask;
2538 unsigned short coef_bits;
2539 const char *name;
2540};
2541
2542static struct alc_codec_rename_table rename_tbl[] = {
2543 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2544 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2545 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2546 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2547 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2548 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2549 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2550 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2551 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2552 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2553 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2554 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2555 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2556 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2557 { } /* terminator */
2558};
2559
2560static int alc_codec_rename_from_preset(struct hda_codec *codec)
2561{
2562 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002563
2564 for (p = rename_tbl; p->vendor_id; p++) {
2565 if (p->vendor_id != codec->vendor_id)
2566 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002567 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002568 return alc_codec_rename(codec, p->name);
2569 }
2570 return 0;
2571}
2572
2573/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002574 * Automatic parse of I/O pins from the BIOS configuration
2575 */
2576
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002577enum {
2578 ALC_CTL_WIDGET_VOL,
2579 ALC_CTL_WIDGET_MUTE,
2580 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002581 ALC_CTL_BIND_VOL,
2582 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002583};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002584static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002585 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2586 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002587 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002588 HDA_BIND_VOL(NULL, 0),
2589 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002590};
2591
2592/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002593static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002594 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002595{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002596 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002597
Takashi Iwaice764ab2011-04-27 16:35:23 +02002598 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002599 if (!knew)
2600 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002601 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002602 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002603 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002604 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002605 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002606 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002607 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002608 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002609 return 0;
2610}
2611
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002612static int add_control_with_pfx(struct alc_spec *spec, int type,
2613 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002614 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002615{
2616 char name[32];
2617 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002618 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002619}
2620
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002621#define add_pb_vol_ctrl(spec, type, pfx, val) \
2622 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2623#define add_pb_sw_ctrl(spec, type, pfx, val) \
2624 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2625#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2626 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2627#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2628 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002629
Takashi Iwai23c09b02011-08-19 09:05:35 +02002630static const char * const channel_name[4] = {
2631 "Front", "Surround", "CLFE", "Side"
2632};
2633
Takashi Iwai6843ca12011-06-24 11:03:58 +02002634static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2635 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002636{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002637 struct auto_pin_cfg *cfg = &spec->autocfg;
2638
Takashi Iwai6843ca12011-06-24 11:03:58 +02002639 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002640 if (cfg->line_outs == 1 && !spec->multi_ios &&
2641 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002642 return "Master";
2643
2644 switch (cfg->line_out_type) {
2645 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002646 if (cfg->line_outs == 1)
2647 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002648 if (cfg->line_outs == 2)
2649 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002650 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002651 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002652 /* for multi-io case, only the primary out */
2653 if (ch && spec->multi_ios)
2654 break;
2655 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002656 return "Headphone";
2657 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002658 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002659 return "PCM";
2660 break;
2661 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002662 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2663 return "PCM";
2664
2665 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002666}
2667
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002668/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002669static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002670 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002671 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002672{
Kailang Yangdf694da2005-12-05 19:42:22 +01002673 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002674
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002675 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002676 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2677 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002678 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002679 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002680 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2681 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002682 return err;
2683 return 0;
2684}
2685
Takashi Iwai05f5f472009-08-25 13:10:18 +02002686static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002687{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002688 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2689 return (pincap & AC_PINCAP_IN) != 0;
2690}
2691
Takashi Iwai1d045db2011-07-07 18:23:21 +02002692/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002693static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002694{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002695 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002696 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002697 hda_nid_t *adc_nids = spec->private_adc_nids;
2698 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2699 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002700 int i, nums = 0;
2701
Takashi Iwai24de1832011-11-07 17:13:39 +01002702 if (spec->shared_mic_hp)
2703 max_nums = 1; /* no multi streams with the shared HP/mic */
2704
Takashi Iwaib7821702011-07-06 15:12:46 +02002705 nid = codec->start_nid;
2706 for (i = 0; i < codec->num_nodes; i++, nid++) {
2707 hda_nid_t src;
2708 const hda_nid_t *list;
2709 unsigned int caps = get_wcaps(codec, nid);
2710 int type = get_wcaps_type(caps);
2711
2712 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2713 continue;
2714 adc_nids[nums] = nid;
2715 cap_nids[nums] = nid;
2716 src = nid;
2717 for (;;) {
2718 int n;
2719 type = get_wcaps_type(get_wcaps(codec, src));
2720 if (type == AC_WID_PIN)
2721 break;
2722 if (type == AC_WID_AUD_SEL) {
2723 cap_nids[nums] = src;
2724 break;
2725 }
2726 n = snd_hda_get_conn_list(codec, src, &list);
2727 if (n > 1) {
2728 cap_nids[nums] = src;
2729 break;
2730 } else if (n != 1)
2731 break;
2732 src = *list;
2733 }
2734 if (++nums >= max_nums)
2735 break;
2736 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002737 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002738 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002739 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002740 return nums;
2741}
2742
Takashi Iwai05f5f472009-08-25 13:10:18 +02002743/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002744static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002745{
2746 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002747 const struct auto_pin_cfg *cfg = &spec->autocfg;
2748 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002749 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002750 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002751 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002752 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002753
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002754 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002755 if (num_adcs < 0)
2756 return 0;
2757
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002758 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002759 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002760 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002761
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002762 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002763 if (!alc_is_input_pin(codec, pin))
2764 continue;
2765
David Henningsson5322bf22011-01-05 11:03:56 +01002766 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002767 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2768 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002769 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002770 type_idx++;
2771 else
2772 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002773 prev_label = label;
2774
Takashi Iwai05f5f472009-08-25 13:10:18 +02002775 if (mixer) {
2776 idx = get_connection_index(codec, mixer, pin);
2777 if (idx >= 0) {
2778 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002779 label, type_idx,
2780 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002781 if (err < 0)
2782 return err;
2783 }
2784 }
2785
Takashi Iwaib7821702011-07-06 15:12:46 +02002786 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002787 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002788 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002789 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002790 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002791 snd_hda_add_imux_item(imux, label, idx, NULL);
2792 break;
2793 }
2794 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002795 }
Takashi Iwai21268962011-07-07 15:01:13 +02002796
2797 spec->num_mux_defs = 1;
2798 spec->input_mux = imux;
2799
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002800 return 0;
2801}
2802
Takashi Iwai24de1832011-11-07 17:13:39 +01002803/* create a shared input with the headphone out */
2804static int alc_auto_create_shared_input(struct hda_codec *codec)
2805{
2806 struct alc_spec *spec = codec->spec;
2807 struct auto_pin_cfg *cfg = &spec->autocfg;
2808 unsigned int defcfg;
2809 hda_nid_t nid;
2810
2811 /* only one internal input pin? */
2812 if (cfg->num_inputs != 1)
2813 return 0;
2814 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2815 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2816 return 0;
2817
2818 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2819 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2820 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2821 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2822 else
2823 return 0; /* both not available */
2824
2825 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2826 return 0; /* no input */
2827
2828 cfg->inputs[1].pin = nid;
2829 cfg->inputs[1].type = AUTO_PIN_MIC;
2830 cfg->num_inputs = 2;
2831 spec->shared_mic_hp = 1;
2832 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2833 return 0;
2834}
2835
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002836static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2837 unsigned int pin_type)
2838{
2839 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2840 pin_type);
2841 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002842 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2843 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002844 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002845}
2846
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002847static int get_pin_type(int line_out_type)
2848{
2849 if (line_out_type == AUTO_PIN_HP_OUT)
2850 return PIN_HP;
2851 else
2852 return PIN_OUT;
2853}
2854
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002855static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002856{
2857 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002858 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002859 int i;
2860
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002861 for (i = 0; i < cfg->num_inputs; i++) {
2862 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002863 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002864 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002865 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002866 snd_hda_codec_write(codec, nid, 0,
2867 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002868 AMP_OUT_MUTE);
2869 }
2870 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002871
2872 /* mute all loopback inputs */
2873 if (spec->mixer_nid) {
2874 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2875 for (i = 0; i < nums; i++)
2876 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2877 AC_VERB_SET_AMP_GAIN_MUTE,
2878 AMP_IN_MUTE(i));
2879 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002880}
2881
Takashi Iwai7085ec12009-10-02 09:03:58 +02002882/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002883static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002884{
Takashi Iwai604401a2011-04-27 15:14:23 +02002885 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002886 int i, num;
2887
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002888 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2889 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002890 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2891 for (i = 0; i < num; i++) {
2892 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2893 return list[i];
2894 }
2895 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002896}
2897
Takashi Iwai604401a2011-04-27 15:14:23 +02002898/* go down to the selector widget before the mixer */
2899static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2900{
2901 hda_nid_t srcs[5];
2902 int num = snd_hda_get_connections(codec, pin, srcs,
2903 ARRAY_SIZE(srcs));
2904 if (num != 1 ||
2905 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2906 return pin;
2907 return srcs[0];
2908}
2909
Takashi Iwai7085ec12009-10-02 09:03:58 +02002910/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002911static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002912 hda_nid_t dac)
2913{
David Henningssoncc1c4522010-11-24 14:17:47 +01002914 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002915 int i, num;
2916
Takashi Iwai604401a2011-04-27 15:14:23 +02002917 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002918 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2919 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002920 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002921 return mix[i];
2922 }
2923 return 0;
2924}
2925
Takashi Iwaice764ab2011-04-27 16:35:23 +02002926/* select the connection from pin to DAC if needed */
2927static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2928 hda_nid_t dac)
2929{
2930 hda_nid_t mix[5];
2931 int i, num;
2932
2933 pin = alc_go_down_to_selector(codec, pin);
2934 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2935 if (num < 2)
2936 return 0;
2937 for (i = 0; i < num; i++) {
2938 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2939 snd_hda_codec_update_cache(codec, pin, 0,
2940 AC_VERB_SET_CONNECT_SEL, i);
2941 return 0;
2942 }
2943 }
2944 return 0;
2945}
2946
Takashi Iwai7085ec12009-10-02 09:03:58 +02002947/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002948static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002949{
2950 struct alc_spec *spec = codec->spec;
2951 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002952 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002953
Takashi Iwai604401a2011-04-27 15:14:23 +02002954 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002955 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002956 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002957 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002958 if (!nid)
2959 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002960 if (found_in_nid_list(nid, spec->multiout.dac_nids,
Takashi Iwai0a34b422011-12-07 17:20:30 +01002961 ARRAY_SIZE(spec->private_dac_nids)))
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002962 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002963 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2964 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2965 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002966 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2967 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2968 continue;
2969 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002970 }
2971 return 0;
2972}
2973
Takashi Iwai07b18f62011-11-10 15:42:54 +01002974/* check whether the DAC is reachable from the pin */
2975static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2976 hda_nid_t pin, hda_nid_t dac)
2977{
2978 hda_nid_t srcs[5];
2979 int i, num;
2980
2981 pin = alc_go_down_to_selector(codec, pin);
2982 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2983 for (i = 0; i < num; i++) {
2984 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2985 if (nid == dac)
2986 return true;
2987 }
2988 return false;
2989}
2990
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002991static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2992{
2993 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2994 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2995 return alc_auto_look_for_dac(codec, pin);
2996 return 0;
2997}
2998
Takashi Iwai0a34b422011-12-07 17:20:30 +01002999/* return 0 if no possible DAC is found, 1 if one or more found */
Takashi Iwaic2674682011-08-24 17:57:44 +02003000static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3001 const hda_nid_t *pins, hda_nid_t *dacs)
3002{
3003 int i;
3004
3005 if (num_outs && !dacs[0]) {
3006 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3007 if (!dacs[0])
3008 return 0;
3009 }
3010
3011 for (i = 1; i < num_outs; i++)
3012 dacs[i] = get_dac_if_single(codec, pins[i]);
3013 for (i = 1; i < num_outs; i++) {
3014 if (!dacs[i])
3015 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3016 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003017 return 1;
Takashi Iwaic2674682011-08-24 17:57:44 +02003018}
3019
3020static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003021 unsigned int location, int offset);
David Henningssonfde48a12011-12-09 18:27:42 +08003022static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3023 hda_nid_t pin, hda_nid_t dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003024
Takashi Iwai7085ec12009-10-02 09:03:58 +02003025/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003026static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003027{
3028 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003029 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003030 unsigned int location, defcfg;
3031 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003032 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003033 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003034
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003035 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003036 /* set num_dacs once to full for alc_auto_look_for_dac() */
3037 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003038 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003039 spec->multiout.extra_out_nid[0] = 0;
3040 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3041 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003042 spec->multi_ios = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003043
3044 /* fill hard-wired DACs first */
3045 if (!redone) {
3046 for (i = 0; i < cfg->line_outs; i++)
3047 spec->private_dac_nids[i] =
3048 get_dac_if_single(codec, cfg->line_out_pins[i]);
3049 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003050 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003051 get_dac_if_single(codec, cfg->hp_pins[0]);
3052 if (cfg->speaker_outs)
3053 spec->multiout.extra_out_nid[0] =
3054 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003055 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003056
3057 for (i = 0; i < cfg->line_outs; i++) {
3058 hda_nid_t pin = cfg->line_out_pins[i];
3059 if (spec->private_dac_nids[i])
3060 continue;
3061 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3062 if (!spec->private_dac_nids[i] && !redone) {
3063 /* if we can't find primary DACs, re-probe without
3064 * checking the hard-wired DACs
3065 */
3066 redone = true;
3067 goto again;
3068 }
3069 }
3070
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003071 /* re-count num_dacs and squash invalid entries */
3072 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003073 for (i = 0; i < cfg->line_outs; i++) {
3074 if (spec->private_dac_nids[i])
3075 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003076 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003077 memmove(spec->private_dac_nids + i,
3078 spec->private_dac_nids + i + 1,
3079 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003080 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3081 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003082 }
3083
Takashi Iwaic2674682011-08-24 17:57:44 +02003084 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3085 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003086 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3087 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003088
Takashi Iwai07b18f62011-11-10 15:42:54 +01003089 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003090 if (num_pins > 0) {
3091 spec->multi_ios = num_pins;
3092 spec->ext_channel_count = 2;
3093 spec->multiout.num_dacs = num_pins + 1;
3094 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003095 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003096
Takashi Iwai716eef02011-10-21 15:07:42 +02003097 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3098 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003099 spec->multiout.hp_out_nid);
Takashi Iwai0a34b422011-12-07 17:20:30 +01003100 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3101 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3102 cfg->speaker_pins,
3103 spec->multiout.extra_out_nid);
3104 /* if no speaker volume is assigned, try again as the primary
3105 * output
3106 */
3107 if (!err && cfg->speaker_outs > 0 &&
3108 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3109 cfg->hp_outs = cfg->line_outs;
3110 memcpy(cfg->hp_pins, cfg->line_out_pins,
3111 sizeof(cfg->hp_pins));
3112 cfg->line_outs = cfg->speaker_outs;
3113 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3114 sizeof(cfg->speaker_pins));
3115 cfg->speaker_outs = 0;
3116 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3117 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3118 redone = false;
3119 goto again;
3120 }
3121 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003122
Takashi Iwai07b18f62011-11-10 15:42:54 +01003123 if (!spec->multi_ios &&
3124 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3125 cfg->hp_outs) {
3126 /* try multi-ios with HP + inputs */
3127 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3128 location = get_defcfg_location(defcfg);
3129
3130 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3131 if (num_pins > 0) {
3132 spec->multi_ios = num_pins;
3133 spec->ext_channel_count = 2;
3134 spec->multiout.num_dacs = num_pins + 1;
3135 }
3136 }
3137
David Henningssonfde48a12011-12-09 18:27:42 +08003138 if (cfg->line_out_pins[0])
3139 spec->vmaster_nid =
3140 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3141 spec->multiout.dac_nids[0]);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003142 return 0;
3143}
3144
Takashi Iwai527e4d72011-10-27 16:33:27 +02003145static inline unsigned int get_ctl_pos(unsigned int data)
3146{
3147 hda_nid_t nid = get_amp_nid_(data);
3148 unsigned int dir = get_amp_direction_(data);
3149 return (nid << 1) | dir;
3150}
3151
3152#define is_ctl_used(bits, data) \
3153 test_bit(get_ctl_pos(data), bits)
3154#define mark_ctl_usage(bits, data) \
3155 set_bit(get_ctl_pos(data), bits)
3156
Takashi Iwai343a04b2011-07-06 14:28:39 +02003157static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003158 const char *pfx, int cidx,
3159 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003160{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003161 struct alc_spec *spec = codec->spec;
3162 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003163 if (!nid)
3164 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003165 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3166 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3167 return 0;
3168 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003169 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003170 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003171}
3172
Takashi Iwaie29d3772011-11-14 17:13:23 +01003173static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3174 const char *pfx, int cidx,
3175 hda_nid_t nid)
3176{
3177 int chs = 1;
3178 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3179 chs = 3;
3180 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3181}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003182
3183/* create a mute-switch for the given mixer widget;
3184 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3185 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003186static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003187 const char *pfx, int cidx,
3188 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003189{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003190 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003191 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003192 int type;
3193 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003194 if (!nid)
3195 return 0;
3196 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3197 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3198 type = ALC_CTL_WIDGET_MUTE;
3199 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3200 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003201 type = ALC_CTL_WIDGET_MUTE;
3202 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3203 } else {
3204 type = ALC_CTL_BIND_MUTE;
3205 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3206 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003207 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3208 return 0;
3209 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003210 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003211}
3212
Takashi Iwaie29d3772011-11-14 17:13:23 +01003213static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3214 int cidx, hda_nid_t nid)
3215{
3216 int chs = 1;
3217 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3218 chs = 3;
3219 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3220}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003221
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003222static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3223 hda_nid_t pin, hda_nid_t dac)
3224{
3225 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3226 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3227 return pin;
3228 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3229 return mix;
3230 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3231 return dac;
3232 return 0;
3233}
3234
3235static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3236 hda_nid_t pin, hda_nid_t dac)
3237{
3238 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3239 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3240 return dac;
3241 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3242 return mix;
3243 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3244 return pin;
3245 return 0;
3246}
3247
Takashi Iwai7085ec12009-10-02 09:03:58 +02003248/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003249static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003250 const struct auto_pin_cfg *cfg)
3251{
3252 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003253 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003254
Takashi Iwaice764ab2011-04-27 16:35:23 +02003255 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003256 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003257 noutputs += spec->multi_ios;
3258
3259 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003260 const char *name;
3261 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003262 hda_nid_t dac, pin;
3263 hda_nid_t sw, vol;
3264
3265 dac = spec->multiout.dac_nids[i];
3266 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003267 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003268 if (i >= cfg->line_outs)
3269 pin = spec->multi_io[i - 1].pin;
3270 else
3271 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003272
3273 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3274 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003275 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003276 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003277 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003278 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003279 if (err < 0)
3280 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003281 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003282 if (err < 0)
3283 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003284 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003285 if (err < 0)
3286 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003287 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003288 if (err < 0)
3289 return err;
3290 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003291 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003292 if (err < 0)
3293 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003294 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003295 if (err < 0)
3296 return err;
3297 }
3298 }
3299 return 0;
3300}
3301
Takashi Iwai343a04b2011-07-06 14:28:39 +02003302static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003303 hda_nid_t dac, const char *pfx,
3304 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003305{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003306 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003307 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003308 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003309
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003310 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003311 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003312 /* the corresponding DAC is already occupied */
3313 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3314 return 0; /* no way */
3315 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003316 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3317 if (is_ctl_used(spec->sw_ctls, val))
3318 return 0; /* already created */
3319 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003320 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003321 }
3322
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003323 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3324 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003325 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003326 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003327 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003328 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003329 if (err < 0)
3330 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003331 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003332}
3333
Takashi Iwai23c09b02011-08-19 09:05:35 +02003334static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3335 unsigned int nums,
3336 struct hda_ctl_ops *ops)
3337{
3338 struct alc_spec *spec = codec->spec;
3339 struct hda_bind_ctls **ctlp, *ctl;
3340 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3341 ctlp = snd_array_new(&spec->bind_ctls);
3342 if (!ctlp)
3343 return NULL;
3344 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3345 *ctlp = ctl;
3346 if (ctl)
3347 ctl->ops = ops;
3348 return ctl;
3349}
3350
3351/* add playback controls for speaker and HP outputs */
3352static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3353 const hda_nid_t *pins,
3354 const hda_nid_t *dacs,
3355 const char *pfx)
3356{
3357 struct alc_spec *spec = codec->spec;
3358 struct hda_bind_ctls *ctl;
3359 char name[32];
3360 int i, n, err;
3361
3362 if (!num_pins || !pins[0])
3363 return 0;
3364
Takashi Iwai527e4d72011-10-27 16:33:27 +02003365 if (num_pins == 1) {
3366 hda_nid_t dac = *dacs;
3367 if (!dac)
3368 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003369 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003370 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003371
3372 if (dacs[num_pins - 1]) {
3373 /* OK, we have a multi-output system with individual volumes */
3374 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003375 if (num_pins >= 3) {
3376 snprintf(name, sizeof(name), "%s %s",
3377 pfx, channel_name[i]);
3378 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3379 name, 0);
3380 } else {
3381 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3382 pfx, i);
3383 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003384 if (err < 0)
3385 return err;
3386 }
3387 return 0;
3388 }
3389
3390 /* Let's create a bind-controls */
3391 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3392 if (!ctl)
3393 return -ENOMEM;
3394 n = 0;
3395 for (i = 0; i < num_pins; i++) {
3396 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3397 ctl->values[n++] =
3398 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3399 }
3400 if (n) {
3401 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3402 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3403 if (err < 0)
3404 return err;
3405 }
3406
3407 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3408 if (!ctl)
3409 return -ENOMEM;
3410 n = 0;
3411 for (i = 0; i < num_pins; i++) {
3412 hda_nid_t vol;
3413 if (!pins[i] || !dacs[i])
3414 continue;
3415 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3416 if (vol)
3417 ctl->values[n++] =
3418 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3419 }
3420 if (n) {
3421 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3422 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3423 if (err < 0)
3424 return err;
3425 }
3426 return 0;
3427}
3428
Takashi Iwai343a04b2011-07-06 14:28:39 +02003429static int alc_auto_create_hp_out(struct hda_codec *codec)
3430{
3431 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003432 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3433 spec->autocfg.hp_pins,
3434 spec->multiout.hp_out_nid,
3435 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003436}
3437
3438static int alc_auto_create_speaker_out(struct hda_codec *codec)
3439{
3440 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003441 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3442 spec->autocfg.speaker_pins,
3443 spec->multiout.extra_out_nid,
3444 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003445}
3446
Takashi Iwai343a04b2011-07-06 14:28:39 +02003447static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003448 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003449 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003450{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003451 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003452 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003453 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003454
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003455 alc_set_pin_output(codec, pin, pin_type);
3456 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003457 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003458 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003459 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003460 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003461 mix = srcs[i];
3462 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003463 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003464 if (!mix)
3465 return;
3466
3467 /* need the manual connection? */
3468 if (num > 1)
3469 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3470 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003471 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3472 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003473 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003474 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003475 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003476 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003477 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003478 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3479 if (nid)
3480 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3481 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003482
3483 /* unmute DAC if it's not assigned to a mixer */
3484 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3485 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3486 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3487 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003488}
3489
Takashi Iwai343a04b2011-07-06 14:28:39 +02003490static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003491{
3492 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003493 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003494 int i;
3495
3496 for (i = 0; i <= HDA_SIDE; i++) {
3497 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3498 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003499 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003500 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003501 }
3502}
3503
Takashi Iwai343a04b2011-07-06 14:28:39 +02003504static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003505{
3506 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003507 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003508 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003509
David Henningsson636030e2011-10-12 19:26:03 +02003510 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003511 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3512 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003513 pin = spec->autocfg.hp_pins[i];
3514 if (!pin)
3515 break;
3516 dac = spec->multiout.hp_out_nid[i];
3517 if (!dac) {
3518 if (i > 0 && spec->multiout.hp_out_nid[0])
3519 dac = spec->multiout.hp_out_nid[0];
3520 else
3521 dac = spec->multiout.dac_nids[0];
3522 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003523 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3524 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003525 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003526 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3527 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003528 pin = spec->autocfg.speaker_pins[i];
3529 if (!pin)
3530 break;
3531 dac = spec->multiout.extra_out_nid[i];
3532 if (!dac) {
3533 if (i > 0 && spec->multiout.extra_out_nid[0])
3534 dac = spec->multiout.extra_out_nid[0];
3535 else
3536 dac = spec->multiout.dac_nids[0];
3537 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003538 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3539 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003540}
3541
Takashi Iwaice764ab2011-04-27 16:35:23 +02003542/*
3543 * multi-io helper
3544 */
3545static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003546 unsigned int location,
3547 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003548{
3549 struct alc_spec *spec = codec->spec;
3550 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003551 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003552 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003553
Takashi Iwai07b18f62011-11-10 15:42:54 +01003554 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003555 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3556 for (i = 0; i < cfg->num_inputs; i++) {
3557 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003558 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003559 unsigned int defcfg, caps;
3560 if (cfg->inputs[i].type != type)
3561 continue;
3562 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3563 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3564 continue;
3565 if (location && get_defcfg_location(defcfg) != location)
3566 continue;
3567 caps = snd_hda_query_pin_caps(codec, nid);
3568 if (!(caps & AC_PINCAP_OUT))
3569 continue;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003570 if (offset && offset + num_pins < dacs) {
3571 dac = spec->private_dac_nids[offset + num_pins];
3572 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3573 dac = 0;
3574 }
3575 if (!dac)
3576 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003577 if (!dac)
3578 continue;
3579 spec->multi_io[num_pins].pin = nid;
3580 spec->multi_io[num_pins].dac = dac;
3581 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003582 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003583 }
3584 }
Takashi Iwai07b18f62011-11-10 15:42:54 +01003585 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003586 if (num_pins < 2) {
3587 /* clear up again */
Takashi Iwai07b18f62011-11-10 15:42:54 +01003588 memset(spec->private_dac_nids + dacs, 0,
3589 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003590 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003591 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003592 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003593 return num_pins;
3594}
3595
3596static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3597 struct snd_ctl_elem_info *uinfo)
3598{
3599 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3600 struct alc_spec *spec = codec->spec;
3601
3602 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3603 uinfo->count = 1;
3604 uinfo->value.enumerated.items = spec->multi_ios + 1;
3605 if (uinfo->value.enumerated.item > spec->multi_ios)
3606 uinfo->value.enumerated.item = spec->multi_ios;
3607 sprintf(uinfo->value.enumerated.name, "%dch",
3608 (uinfo->value.enumerated.item + 1) * 2);
3609 return 0;
3610}
3611
3612static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3613 struct snd_ctl_elem_value *ucontrol)
3614{
3615 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3616 struct alc_spec *spec = codec->spec;
3617 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3618 return 0;
3619}
3620
3621static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3622{
3623 struct alc_spec *spec = codec->spec;
3624 hda_nid_t nid = spec->multi_io[idx].pin;
3625
3626 if (!spec->multi_io[idx].ctl_in)
3627 spec->multi_io[idx].ctl_in =
3628 snd_hda_codec_read(codec, nid, 0,
3629 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3630 if (output) {
3631 snd_hda_codec_update_cache(codec, nid, 0,
3632 AC_VERB_SET_PIN_WIDGET_CONTROL,
3633 PIN_OUT);
3634 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3635 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3636 HDA_AMP_MUTE, 0);
3637 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3638 } else {
3639 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3640 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3641 HDA_AMP_MUTE, HDA_AMP_MUTE);
3642 snd_hda_codec_update_cache(codec, nid, 0,
3643 AC_VERB_SET_PIN_WIDGET_CONTROL,
3644 spec->multi_io[idx].ctl_in);
3645 }
3646 return 0;
3647}
3648
3649static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3650 struct snd_ctl_elem_value *ucontrol)
3651{
3652 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3653 struct alc_spec *spec = codec->spec;
3654 int i, ch;
3655
3656 ch = ucontrol->value.enumerated.item[0];
3657 if (ch < 0 || ch > spec->multi_ios)
3658 return -EINVAL;
3659 if (ch == (spec->ext_channel_count - 1) / 2)
3660 return 0;
3661 spec->ext_channel_count = (ch + 1) * 2;
3662 for (i = 0; i < spec->multi_ios; i++)
3663 alc_set_multi_io(codec, i, i < ch);
3664 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003665 if (spec->need_dac_fix && !spec->const_channel_count)
3666 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003667 return 1;
3668}
3669
Takashi Iwaia9111322011-05-02 11:30:18 +02003670static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003671 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3672 .name = "Channel Mode",
3673 .info = alc_auto_ch_mode_info,
3674 .get = alc_auto_ch_mode_get,
3675 .put = alc_auto_ch_mode_put,
3676};
3677
Takashi Iwai23c09b02011-08-19 09:05:35 +02003678static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003679{
3680 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003681
Takashi Iwaic2674682011-08-24 17:57:44 +02003682 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003683 struct snd_kcontrol_new *knew;
3684
3685 knew = alc_kcontrol_new(spec);
3686 if (!knew)
3687 return -ENOMEM;
3688 *knew = alc_auto_channel_mode_enum;
3689 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3690 if (!knew->name)
3691 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003692 }
3693 return 0;
3694}
3695
Takashi Iwai1d045db2011-07-07 18:23:21 +02003696/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3697 * active input pins
3698 */
3699static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3700{
3701 struct alc_spec *spec = codec->spec;
3702 const struct hda_input_mux *imux;
3703 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3704 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3705 int i, n, nums;
3706
3707 imux = spec->input_mux;
3708 if (!imux)
3709 return;
3710 if (spec->dyn_adc_switch)
3711 return;
3712
3713 nums = 0;
3714 for (n = 0; n < spec->num_adc_nids; n++) {
3715 hda_nid_t cap = spec->private_capsrc_nids[n];
3716 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3717 for (i = 0; i < imux->num_items; i++) {
3718 hda_nid_t pin = spec->imux_pins[i];
3719 if (pin) {
3720 if (get_connection_index(codec, cap, pin) < 0)
3721 break;
3722 } else if (num_conns <= imux->items[i].index)
3723 break;
3724 }
3725 if (i >= imux->num_items) {
3726 adc_nids[nums] = spec->private_adc_nids[n];
3727 capsrc_nids[nums++] = cap;
3728 }
3729 }
3730 if (!nums) {
3731 /* check whether ADC-switch is possible */
3732 if (!alc_check_dyn_adc_switch(codec)) {
3733 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3734 " using fallback 0x%x\n",
3735 codec->chip_name, spec->private_adc_nids[0]);
3736 spec->num_adc_nids = 1;
3737 spec->auto_mic = 0;
3738 return;
3739 }
3740 } else if (nums != spec->num_adc_nids) {
3741 memcpy(spec->private_adc_nids, adc_nids,
3742 nums * sizeof(hda_nid_t));
3743 memcpy(spec->private_capsrc_nids, capsrc_nids,
3744 nums * sizeof(hda_nid_t));
3745 spec->num_adc_nids = nums;
3746 }
3747
3748 if (spec->auto_mic)
3749 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3750 else if (spec->input_mux->num_items == 1)
3751 spec->num_adc_nids = 1; /* reduce to a single ADC */
3752}
3753
3754/*
3755 * initialize ADC paths
3756 */
3757static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3758{
3759 struct alc_spec *spec = codec->spec;
3760 hda_nid_t nid;
3761
3762 nid = spec->adc_nids[adc_idx];
3763 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003764 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003765 snd_hda_codec_write(codec, nid, 0,
3766 AC_VERB_SET_AMP_GAIN_MUTE,
3767 AMP_IN_MUTE(0));
3768 return;
3769 }
3770 if (!spec->capsrc_nids)
3771 return;
3772 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003773 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003774 snd_hda_codec_write(codec, nid, 0,
3775 AC_VERB_SET_AMP_GAIN_MUTE,
3776 AMP_OUT_MUTE);
3777}
3778
3779static void alc_auto_init_input_src(struct hda_codec *codec)
3780{
3781 struct alc_spec *spec = codec->spec;
3782 int c, nums;
3783
3784 for (c = 0; c < spec->num_adc_nids; c++)
3785 alc_auto_init_adc(codec, c);
3786 if (spec->dyn_adc_switch)
3787 nums = 1;
3788 else
3789 nums = spec->num_adc_nids;
3790 for (c = 0; c < nums; c++)
3791 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3792}
3793
3794/* add mic boosts if needed */
3795static int alc_auto_add_mic_boost(struct hda_codec *codec)
3796{
3797 struct alc_spec *spec = codec->spec;
3798 struct auto_pin_cfg *cfg = &spec->autocfg;
3799 int i, err;
3800 int type_idx = 0;
3801 hda_nid_t nid;
3802 const char *prev_label = NULL;
3803
3804 for (i = 0; i < cfg->num_inputs; i++) {
3805 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3806 break;
3807 nid = cfg->inputs[i].pin;
3808 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3809 const char *label;
3810 char boost_label[32];
3811
3812 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003813 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3814 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003815 if (prev_label && !strcmp(label, prev_label))
3816 type_idx++;
3817 else
3818 type_idx = 0;
3819 prev_label = label;
3820
3821 snprintf(boost_label, sizeof(boost_label),
3822 "%s Boost Volume", label);
3823 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3824 boost_label, type_idx,
3825 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3826 if (err < 0)
3827 return err;
3828 }
3829 }
3830 return 0;
3831}
3832
3833/* select or unmute the given capsrc route */
3834static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3835 int idx)
3836{
3837 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3838 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3839 HDA_AMP_MUTE, 0);
3840 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3841 snd_hda_codec_write_cache(codec, cap, 0,
3842 AC_VERB_SET_CONNECT_SEL, idx);
3843 }
3844}
3845
3846/* set the default connection to that pin */
3847static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3848{
3849 struct alc_spec *spec = codec->spec;
3850 int i;
3851
3852 if (!pin)
3853 return 0;
3854 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01003855 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003856 int idx;
3857
3858 idx = get_connection_index(codec, cap, pin);
3859 if (idx < 0)
3860 continue;
3861 select_or_unmute_capsrc(codec, cap, idx);
3862 return i; /* return the found index */
3863 }
3864 return -1; /* not found */
3865}
3866
3867/* initialize some special cases for input sources */
3868static void alc_init_special_input_src(struct hda_codec *codec)
3869{
3870 struct alc_spec *spec = codec->spec;
3871 int i;
3872
3873 for (i = 0; i < spec->autocfg.num_inputs; i++)
3874 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3875}
3876
3877/* assign appropriate capture mixers */
3878static void set_capture_mixer(struct hda_codec *codec)
3879{
3880 struct alc_spec *spec = codec->spec;
3881 static const struct snd_kcontrol_new *caps[2][3] = {
3882 { alc_capture_mixer_nosrc1,
3883 alc_capture_mixer_nosrc2,
3884 alc_capture_mixer_nosrc3 },
3885 { alc_capture_mixer1,
3886 alc_capture_mixer2,
3887 alc_capture_mixer3 },
3888 };
3889
3890 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003891 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003892 if (!spec->capsrc_nids)
3893 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003894 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003895 return; /* no volume in capsrc, too */
3896 spec->vol_in_capsrc = 1;
3897 }
3898
3899 if (spec->num_adc_nids > 0) {
3900 int mux = 0;
3901 int num_adcs = 0;
3902
3903 if (spec->input_mux && spec->input_mux->num_items > 1)
3904 mux = 1;
3905 if (spec->auto_mic) {
3906 num_adcs = 1;
3907 mux = 0;
3908 } else if (spec->dyn_adc_switch)
3909 num_adcs = 1;
3910 if (!num_adcs) {
3911 if (spec->num_adc_nids > 3)
3912 spec->num_adc_nids = 3;
3913 else if (!spec->num_adc_nids)
3914 return;
3915 num_adcs = spec->num_adc_nids;
3916 }
3917 spec->cap_mixer = caps[mux][num_adcs - 1];
3918 }
3919}
3920
3921/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003922 * standard auto-parser initializations
3923 */
3924static void alc_auto_init_std(struct hda_codec *codec)
3925{
3926 struct alc_spec *spec = codec->spec;
3927 alc_auto_init_multi_out(codec);
3928 alc_auto_init_extra_out(codec);
3929 alc_auto_init_analog_input(codec);
3930 alc_auto_init_input_src(codec);
3931 alc_auto_init_digital(codec);
3932 if (spec->unsol_event)
3933 alc_inithook(codec);
3934}
3935
3936/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003937 * Digital-beep handlers
3938 */
3939#ifdef CONFIG_SND_HDA_INPUT_BEEP
3940#define set_beep_amp(spec, nid, idx, dir) \
3941 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3942
3943static const struct snd_pci_quirk beep_white_list[] = {
3944 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3945 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3946 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3947 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3948 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3949 {}
3950};
3951
3952static inline int has_cdefine_beep(struct hda_codec *codec)
3953{
3954 struct alc_spec *spec = codec->spec;
3955 const struct snd_pci_quirk *q;
3956 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3957 if (q)
3958 return q->value;
3959 return spec->cdefine.enable_pcbeep;
3960}
3961#else
3962#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3963#define has_cdefine_beep(codec) 0
3964#endif
3965
3966/* parse the BIOS configuration and set up the alc_spec */
3967/* return 1 if successful, 0 if the proper config is not found,
3968 * or a negative error code
3969 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003970static int alc_parse_auto_config(struct hda_codec *codec,
3971 const hda_nid_t *ignore_nids,
3972 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003973{
3974 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003975 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003976 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003977
Takashi Iwai53c334a2011-08-23 18:27:14 +02003978 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3979 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003980 if (err < 0)
3981 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003982 if (!cfg->line_outs) {
3983 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003984 spec->multiout.max_channels = 2;
3985 spec->no_analog = 1;
3986 goto dig_only;
3987 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003988 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003989 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003990
Takashi Iwai06503672011-10-06 08:27:19 +02003991 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3992 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003993 /* use HP as primary out */
3994 cfg->speaker_outs = cfg->line_outs;
3995 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3996 sizeof(cfg->speaker_pins));
3997 cfg->line_outs = cfg->hp_outs;
3998 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3999 cfg->hp_outs = 0;
4000 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4001 cfg->line_out_type = AUTO_PIN_HP_OUT;
4002 }
4003
Takashi Iwai1d045db2011-07-07 18:23:21 +02004004 err = alc_auto_fill_dac_nids(codec);
4005 if (err < 0)
4006 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004007 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004008 if (err < 0)
4009 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004010 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004011 if (err < 0)
4012 return err;
4013 err = alc_auto_create_hp_out(codec);
4014 if (err < 0)
4015 return err;
4016 err = alc_auto_create_speaker_out(codec);
4017 if (err < 0)
4018 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004019 err = alc_auto_create_shared_input(codec);
4020 if (err < 0)
4021 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004022 err = alc_auto_create_input_ctls(codec);
4023 if (err < 0)
4024 return err;
4025
4026 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4027
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004028 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004029 alc_auto_parse_digital(codec);
4030
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004031 if (!spec->no_analog)
4032 alc_remove_invalid_adc_nids(codec);
4033
4034 if (ssid_nids)
4035 alc_ssid_check(codec, ssid_nids);
4036
4037 if (!spec->no_analog) {
4038 alc_auto_check_switches(codec);
4039 err = alc_auto_add_mic_boost(codec);
4040 if (err < 0)
4041 return err;
4042 }
4043
Takashi Iwai1d045db2011-07-07 18:23:21 +02004044 if (spec->kctls.list)
4045 add_mixer(spec, spec->kctls.list);
4046
Takashi Iwai1d045db2011-07-07 18:23:21 +02004047 return 1;
4048}
4049
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004050static int alc880_parse_auto_config(struct hda_codec *codec)
4051{
4052 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4053 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4054 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4055}
4056
Takashi Iwai1d045db2011-07-07 18:23:21 +02004057#ifdef CONFIG_SND_HDA_POWER_SAVE
4058static const struct hda_amp_list alc880_loopbacks[] = {
4059 { 0x0b, HDA_INPUT, 0 },
4060 { 0x0b, HDA_INPUT, 1 },
4061 { 0x0b, HDA_INPUT, 2 },
4062 { 0x0b, HDA_INPUT, 3 },
4063 { 0x0b, HDA_INPUT, 4 },
4064 { } /* end */
4065};
4066#endif
4067
4068/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004069 * ALC880 fix-ups
4070 */
4071enum {
4072 ALC880_FIXUP_GPIO2,
4073 ALC880_FIXUP_MEDION_RIM,
4074};
4075
4076static const struct alc_fixup alc880_fixups[] = {
4077 [ALC880_FIXUP_GPIO2] = {
4078 .type = ALC_FIXUP_VERBS,
4079 .v.verbs = alc_gpio2_init_verbs,
4080 },
4081 [ALC880_FIXUP_MEDION_RIM] = {
4082 .type = ALC_FIXUP_VERBS,
4083 .v.verbs = (const struct hda_verb[]) {
4084 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4085 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4086 { }
4087 },
4088 .chained = true,
4089 .chain_id = ALC880_FIXUP_GPIO2,
4090 },
4091};
4092
4093static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4094 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4095 {}
4096};
4097
4098
4099/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004100 * board setups
4101 */
4102#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4103#define alc_board_config \
4104 snd_hda_check_board_config
4105#define alc_board_codec_sid_config \
4106 snd_hda_check_board_codec_sid_config
4107#include "alc_quirks.c"
4108#else
4109#define alc_board_config(codec, nums, models, tbl) -1
4110#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4111#define setup_preset(codec, x) /* NOP */
4112#endif
4113
4114/*
4115 * OK, here we have finally the patch for ALC880
4116 */
4117#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4118#include "alc880_quirks.c"
4119#endif
4120
4121static int patch_alc880(struct hda_codec *codec)
4122{
4123 struct alc_spec *spec;
4124 int board_config;
4125 int err;
4126
4127 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4128 if (spec == NULL)
4129 return -ENOMEM;
4130
4131 codec->spec = spec;
4132
4133 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004134 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004135
4136 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4137 alc880_models, alc880_cfg_tbl);
4138 if (board_config < 0) {
4139 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4140 codec->chip_name);
4141 board_config = ALC_MODEL_AUTO;
4142 }
4143
4144 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004145 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4146 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4147 }
4148
4149 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004150 /* automatic parse from the BIOS config */
4151 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004152 if (err < 0)
4153 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004154#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4155 else if (!err) {
4156 printk(KERN_INFO
4157 "hda_codec: Cannot set up configuration "
4158 "from BIOS. Using 3-stack mode...\n");
4159 board_config = ALC880_3ST;
4160 }
4161#endif
4162 }
4163
David Henningssonfde48a12011-12-09 18:27:42 +08004164 if (board_config != ALC_MODEL_AUTO) {
4165 spec->vmaster_nid = 0x0c;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004166 setup_preset(codec, &alc880_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004167 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004168
Takashi Iwai60a6a842011-07-27 14:01:24 +02004169 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004170 alc_auto_fill_adc_caps(codec);
4171 alc_rebuild_imux_for_auto_mic(codec);
4172 alc_remove_invalid_adc_nids(codec);
4173 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004174
4175 if (!spec->no_analog && !spec->cap_mixer)
4176 set_capture_mixer(codec);
4177
4178 if (!spec->no_analog) {
4179 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004180 if (err < 0)
4181 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004182 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4183 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004184
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004185 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4186
Takashi Iwai1d045db2011-07-07 18:23:21 +02004187 codec->patch_ops = alc_patch_ops;
4188 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004189 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004190 else
4191 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004192#ifdef CONFIG_SND_HDA_POWER_SAVE
4193 if (!spec->loopback.amplist)
4194 spec->loopback.amplist = alc880_loopbacks;
4195#endif
4196
4197 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004198
4199 error:
4200 alc_free(codec);
4201 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004202}
4203
4204
4205/*
4206 * ALC260 support
4207 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004208static int alc260_parse_auto_config(struct hda_codec *codec)
4209{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004210 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004211 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4212 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004213}
4214
Takashi Iwai1d045db2011-07-07 18:23:21 +02004215#ifdef CONFIG_SND_HDA_POWER_SAVE
4216static const struct hda_amp_list alc260_loopbacks[] = {
4217 { 0x07, HDA_INPUT, 0 },
4218 { 0x07, HDA_INPUT, 1 },
4219 { 0x07, HDA_INPUT, 2 },
4220 { 0x07, HDA_INPUT, 3 },
4221 { 0x07, HDA_INPUT, 4 },
4222 { } /* end */
4223};
4224#endif
4225
4226/*
4227 * Pin config fixes
4228 */
4229enum {
4230 PINFIX_HP_DC5750,
4231};
4232
4233static const struct alc_fixup alc260_fixups[] = {
4234 [PINFIX_HP_DC5750] = {
4235 .type = ALC_FIXUP_PINS,
4236 .v.pins = (const struct alc_pincfg[]) {
4237 { 0x11, 0x90130110 }, /* speaker */
4238 { }
4239 }
4240 },
4241};
4242
4243static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4244 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4245 {}
4246};
4247
4248/*
4249 */
4250#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4251#include "alc260_quirks.c"
4252#endif
4253
4254static int patch_alc260(struct hda_codec *codec)
4255{
4256 struct alc_spec *spec;
4257 int err, board_config;
4258
4259 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4260 if (spec == NULL)
4261 return -ENOMEM;
4262
4263 codec->spec = spec;
4264
4265 spec->mixer_nid = 0x07;
4266
4267 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4268 alc260_models, alc260_cfg_tbl);
4269 if (board_config < 0) {
4270 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4271 codec->chip_name);
4272 board_config = ALC_MODEL_AUTO;
4273 }
4274
4275 if (board_config == ALC_MODEL_AUTO) {
4276 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4277 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4278 }
4279
4280 if (board_config == ALC_MODEL_AUTO) {
4281 /* automatic parse from the BIOS config */
4282 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004283 if (err < 0)
4284 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004285#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4286 else if (!err) {
4287 printk(KERN_INFO
4288 "hda_codec: Cannot set up configuration "
4289 "from BIOS. Using base mode...\n");
4290 board_config = ALC260_BASIC;
4291 }
4292#endif
4293 }
4294
David Henningssonfde48a12011-12-09 18:27:42 +08004295 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004296 setup_preset(codec, &alc260_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004297 spec->vmaster_nid = 0x08;
4298 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004299
Takashi Iwai60a6a842011-07-27 14:01:24 +02004300 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004301 alc_auto_fill_adc_caps(codec);
4302 alc_rebuild_imux_for_auto_mic(codec);
4303 alc_remove_invalid_adc_nids(codec);
4304 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004305
4306 if (!spec->no_analog && !spec->cap_mixer)
4307 set_capture_mixer(codec);
4308
4309 if (!spec->no_analog) {
4310 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004311 if (err < 0)
4312 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004313 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4314 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004315
4316 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4317
Takashi Iwai1d045db2011-07-07 18:23:21 +02004318 codec->patch_ops = alc_patch_ops;
4319 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004320 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004321 else
4322 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004323 spec->shutup = alc_eapd_shutup;
4324#ifdef CONFIG_SND_HDA_POWER_SAVE
4325 if (!spec->loopback.amplist)
4326 spec->loopback.amplist = alc260_loopbacks;
4327#endif
4328
4329 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004330
4331 error:
4332 alc_free(codec);
4333 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004334}
4335
4336
4337/*
4338 * ALC882/883/885/888/889 support
4339 *
4340 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4341 * configuration. Each pin widget can choose any input DACs and a mixer.
4342 * Each ADC is connected from a mixer of all inputs. This makes possible
4343 * 6-channel independent captures.
4344 *
4345 * In addition, an independent DAC for the multi-playback (not used in this
4346 * driver yet).
4347 */
4348#ifdef CONFIG_SND_HDA_POWER_SAVE
4349#define alc882_loopbacks alc880_loopbacks
4350#endif
4351
4352/*
4353 * Pin config fixes
4354 */
4355enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004356 ALC882_FIXUP_ABIT_AW9D_MAX,
4357 ALC882_FIXUP_LENOVO_Y530,
4358 ALC882_FIXUP_PB_M5210,
4359 ALC882_FIXUP_ACER_ASPIRE_7736,
4360 ALC882_FIXUP_ASUS_W90V,
4361 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004362 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004363 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004364 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004365 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004366 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004367 ALC889_FIXUP_COEF,
4368 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004369 ALC882_FIXUP_ACER_ASPIRE_4930G,
4370 ALC882_FIXUP_ACER_ASPIRE_8930G,
4371 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004372 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004373};
4374
Takashi Iwai68ef0562011-11-09 18:24:44 +01004375static void alc889_fixup_coef(struct hda_codec *codec,
4376 const struct alc_fixup *fix, int action)
4377{
4378 if (action != ALC_FIXUP_ACT_INIT)
4379 return;
4380 alc889_coef_init(codec);
4381}
4382
Takashi Iwai56710872011-11-14 17:42:11 +01004383/* toggle speaker-output according to the hp-jack state */
4384static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4385{
4386 unsigned int gpiostate, gpiomask, gpiodir;
4387
4388 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4389 AC_VERB_GET_GPIO_DATA, 0);
4390
4391 if (!muted)
4392 gpiostate |= (1 << pin);
4393 else
4394 gpiostate &= ~(1 << pin);
4395
4396 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4397 AC_VERB_GET_GPIO_MASK, 0);
4398 gpiomask |= (1 << pin);
4399
4400 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4401 AC_VERB_GET_GPIO_DIRECTION, 0);
4402 gpiodir |= (1 << pin);
4403
4404
4405 snd_hda_codec_write(codec, codec->afg, 0,
4406 AC_VERB_SET_GPIO_MASK, gpiomask);
4407 snd_hda_codec_write(codec, codec->afg, 0,
4408 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4409
4410 msleep(1);
4411
4412 snd_hda_codec_write(codec, codec->afg, 0,
4413 AC_VERB_SET_GPIO_DATA, gpiostate);
4414}
4415
4416/* set up GPIO at initialization */
4417static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4418 const struct alc_fixup *fix, int action)
4419{
4420 if (action != ALC_FIXUP_ACT_INIT)
4421 return;
4422 alc882_gpio_mute(codec, 0, 0);
4423 alc882_gpio_mute(codec, 1, 0);
4424}
4425
Takashi Iwai1d045db2011-07-07 18:23:21 +02004426static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004427 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004428 .type = ALC_FIXUP_PINS,
4429 .v.pins = (const struct alc_pincfg[]) {
4430 { 0x15, 0x01080104 }, /* side */
4431 { 0x16, 0x01011012 }, /* rear */
4432 { 0x17, 0x01016011 }, /* clfe */
4433 { }
4434 }
4435 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004436 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004437 .type = ALC_FIXUP_PINS,
4438 .v.pins = (const struct alc_pincfg[]) {
4439 { 0x15, 0x99130112 }, /* rear int speakers */
4440 { 0x16, 0x99130111 }, /* subwoofer */
4441 { }
4442 }
4443 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004444 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004445 .type = ALC_FIXUP_VERBS,
4446 .v.verbs = (const struct hda_verb[]) {
4447 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4448 {}
4449 }
4450 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004451 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004452 .type = ALC_FIXUP_SKU,
4453 .v.sku = ALC_FIXUP_SKU_IGNORE,
4454 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004455 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004456 .type = ALC_FIXUP_PINS,
4457 .v.pins = (const struct alc_pincfg[]) {
4458 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4459 { }
4460 }
4461 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004462 [ALC889_FIXUP_VAIO_TT] = {
4463 .type = ALC_FIXUP_PINS,
4464 .v.pins = (const struct alc_pincfg[]) {
4465 { 0x17, 0x90170111 }, /* hidden surround speaker */
4466 { }
4467 }
4468 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004469 [ALC888_FIXUP_EEE1601] = {
4470 .type = ALC_FIXUP_VERBS,
4471 .v.verbs = (const struct hda_verb[]) {
4472 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4473 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4474 { }
4475 }
Takashi Iwai177943a2011-11-09 12:55:18 +01004476 },
4477 [ALC882_FIXUP_EAPD] = {
4478 .type = ALC_FIXUP_VERBS,
4479 .v.verbs = (const struct hda_verb[]) {
4480 /* change to EAPD mode */
4481 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4482 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4483 { }
4484 }
4485 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004486 [ALC883_FIXUP_EAPD] = {
4487 .type = ALC_FIXUP_VERBS,
4488 .v.verbs = (const struct hda_verb[]) {
4489 /* change to EAPD mode */
4490 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4491 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4492 { }
4493 }
4494 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004495 [ALC883_FIXUP_ACER_EAPD] = {
4496 .type = ALC_FIXUP_VERBS,
4497 .v.verbs = (const struct hda_verb[]) {
4498 /* eanable EAPD on Acer laptops */
4499 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4500 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4501 { }
4502 }
4503 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004504 [ALC882_FIXUP_GPIO3] = {
4505 .type = ALC_FIXUP_VERBS,
4506 .v.verbs = alc_gpio3_init_verbs,
4507 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004508 [ALC882_FIXUP_ASUS_W2JC] = {
4509 .type = ALC_FIXUP_VERBS,
4510 .v.verbs = alc_gpio1_init_verbs,
4511 .chained = true,
4512 .chain_id = ALC882_FIXUP_EAPD,
4513 },
4514 [ALC889_FIXUP_COEF] = {
4515 .type = ALC_FIXUP_FUNC,
4516 .v.func = alc889_fixup_coef,
4517 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004518 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4519 .type = ALC_FIXUP_PINS,
4520 .v.pins = (const struct alc_pincfg[]) {
4521 { 0x16, 0x99130111 }, /* CLFE speaker */
4522 { 0x17, 0x99130112 }, /* surround speaker */
4523 { }
4524 }
4525 },
4526 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4527 .type = ALC_FIXUP_PINS,
4528 .v.pins = (const struct alc_pincfg[]) {
4529 { 0x16, 0x99130111 }, /* CLFE speaker */
4530 { 0x1b, 0x99130112 }, /* surround speaker */
4531 { }
4532 },
4533 .chained = true,
4534 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4535 },
4536 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4537 /* additional init verbs for Acer Aspire 8930G */
4538 .type = ALC_FIXUP_VERBS,
4539 .v.verbs = (const struct hda_verb[]) {
4540 /* Enable all DACs */
4541 /* DAC DISABLE/MUTE 1? */
4542 /* setting bits 1-5 disables DAC nids 0x02-0x06
4543 * apparently. Init=0x38 */
4544 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4545 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4546 /* DAC DISABLE/MUTE 2? */
4547 /* some bit here disables the other DACs.
4548 * Init=0x4900 */
4549 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4550 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4551 /* DMIC fix
4552 * This laptop has a stereo digital microphone.
4553 * The mics are only 1cm apart which makes the stereo
4554 * useless. However, either the mic or the ALC889
4555 * makes the signal become a difference/sum signal
4556 * instead of standard stereo, which is annoying.
4557 * So instead we flip this bit which makes the
4558 * codec replicate the sum signal to both channels,
4559 * turning it into a normal mono mic.
4560 */
4561 /* DMIC_CONTROL? Init value = 0x0001 */
4562 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4563 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4564 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4565 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4566 { }
4567 }
4568 },
Takashi Iwai56710872011-11-14 17:42:11 +01004569 [ALC885_FIXUP_MACPRO_GPIO] = {
4570 .type = ALC_FIXUP_FUNC,
4571 .v.func = alc885_fixup_macpro_gpio,
4572 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004573};
4574
4575static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004576 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4577 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4578 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4579 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4580 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4581 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004582 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4583 ALC882_FIXUP_ACER_ASPIRE_4930G),
4584 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4585 ALC882_FIXUP_ACER_ASPIRE_4930G),
4586 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4587 ALC882_FIXUP_ACER_ASPIRE_8930G),
4588 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4589 ALC882_FIXUP_ACER_ASPIRE_8930G),
4590 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4591 ALC882_FIXUP_ACER_ASPIRE_4930G),
4592 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4593 ALC882_FIXUP_ACER_ASPIRE_4930G),
4594 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4595 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004596 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004597 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01004598 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004599 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004600 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004601 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004602 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01004603
4604 /* All Apple entries are in codec SSIDs */
4605 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4606 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4607 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4608 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4609 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4610
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004611 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004612 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004613 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004614 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4615 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004616 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004617 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004618 {}
4619};
4620
4621/*
4622 * BIOS auto configuration
4623 */
4624/* almost identical with ALC880 parser... */
4625static int alc882_parse_auto_config(struct hda_codec *codec)
4626{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004627 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004628 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4629 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004630}
4631
Takashi Iwai1d045db2011-07-07 18:23:21 +02004632/*
4633 */
4634#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4635#include "alc882_quirks.c"
4636#endif
4637
4638static int patch_alc882(struct hda_codec *codec)
4639{
4640 struct alc_spec *spec;
4641 int err, board_config;
4642
4643 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4644 if (spec == NULL)
4645 return -ENOMEM;
4646
4647 codec->spec = spec;
4648
4649 spec->mixer_nid = 0x0b;
4650
4651 switch (codec->vendor_id) {
4652 case 0x10ec0882:
4653 case 0x10ec0885:
4654 break;
4655 default:
4656 /* ALC883 and variants */
4657 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4658 break;
4659 }
4660
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004661 err = alc_codec_rename_from_preset(codec);
4662 if (err < 0)
4663 goto error;
4664
Takashi Iwaib2539692011-11-14 17:32:17 +01004665 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4666 alc882_models, NULL);
4667 if (board_config < 0)
4668 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004669 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4670
4671 if (board_config < 0) {
4672 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4673 codec->chip_name);
4674 board_config = ALC_MODEL_AUTO;
4675 }
4676
4677 if (board_config == ALC_MODEL_AUTO) {
4678 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4679 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4680 }
4681
4682 alc_auto_parse_customize_define(codec);
4683
4684 if (board_config == ALC_MODEL_AUTO) {
4685 /* automatic parse from the BIOS config */
4686 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004687 if (err < 0)
4688 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004689 }
4690
David Henningssonfde48a12011-12-09 18:27:42 +08004691 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004692 setup_preset(codec, &alc882_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004693 spec->vmaster_nid = 0x0c;
4694 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004695
Takashi Iwai60a6a842011-07-27 14:01:24 +02004696 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004697 alc_auto_fill_adc_caps(codec);
4698 alc_rebuild_imux_for_auto_mic(codec);
4699 alc_remove_invalid_adc_nids(codec);
4700 }
4701
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004702 if (!spec->no_analog && !spec->cap_mixer)
4703 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004704
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004705 if (!spec->no_analog && has_cdefine_beep(codec)) {
4706 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004707 if (err < 0)
4708 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004709 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004710 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004711
4712 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4713
Takashi Iwai1d045db2011-07-07 18:23:21 +02004714 codec->patch_ops = alc_patch_ops;
4715 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004716 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004717 else
4718 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004719
Takashi Iwai1d045db2011-07-07 18:23:21 +02004720#ifdef CONFIG_SND_HDA_POWER_SAVE
4721 if (!spec->loopback.amplist)
4722 spec->loopback.amplist = alc882_loopbacks;
4723#endif
4724
4725 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004726
4727 error:
4728 alc_free(codec);
4729 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004730}
4731
4732
4733/*
4734 * ALC262 support
4735 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004736static int alc262_parse_auto_config(struct hda_codec *codec)
4737{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004738 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004739 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4740 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004741}
4742
4743/*
4744 * Pin config fixes
4745 */
4746enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004747 ALC262_FIXUP_FSC_H270,
4748 ALC262_FIXUP_HP_Z200,
4749 ALC262_FIXUP_TYAN,
Takashi Iwai12837c92011-11-07 12:45:24 +01004750 ALC262_FIXUP_TOSHIBA_RX1,
Takashi Iwaic4701502011-11-07 14:20:07 +01004751 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004752 ALC262_FIXUP_BENQ,
4753 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004754};
4755
4756static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004757 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004758 .type = ALC_FIXUP_PINS,
4759 .v.pins = (const struct alc_pincfg[]) {
4760 { 0x14, 0x99130110 }, /* speaker */
4761 { 0x15, 0x0221142f }, /* front HP */
4762 { 0x1b, 0x0121141f }, /* rear HP */
4763 { }
4764 }
4765 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004766 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004767 .type = ALC_FIXUP_PINS,
4768 .v.pins = (const struct alc_pincfg[]) {
4769 { 0x16, 0x99130120 }, /* internal speaker */
4770 { }
4771 }
4772 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004773 [ALC262_FIXUP_TYAN] = {
4774 .type = ALC_FIXUP_PINS,
4775 .v.pins = (const struct alc_pincfg[]) {
4776 { 0x14, 0x1993e1f0 }, /* int AUX */
4777 { }
4778 }
4779 },
Takashi Iwai12837c92011-11-07 12:45:24 +01004780 [ALC262_FIXUP_TOSHIBA_RX1] = {
4781 .type = ALC_FIXUP_PINS,
4782 .v.pins = (const struct alc_pincfg[]) {
4783 { 0x14, 0x90170110 }, /* speaker */
4784 { 0x15, 0x0421101f }, /* HP */
4785 { 0x1a, 0x40f000f0 }, /* N/A */
4786 { 0x1b, 0x40f000f0 }, /* N/A */
4787 { 0x1e, 0x40f000f0 }, /* N/A */
4788 }
4789 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004790 [ALC262_FIXUP_LENOVO_3000] = {
4791 .type = ALC_FIXUP_VERBS,
4792 .v.verbs = (const struct hda_verb[]) {
4793 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004794 {}
4795 },
4796 .chained = true,
4797 .chain_id = ALC262_FIXUP_BENQ,
4798 },
4799 [ALC262_FIXUP_BENQ] = {
4800 .type = ALC_FIXUP_VERBS,
4801 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004802 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4803 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4804 {}
4805 }
4806 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004807 [ALC262_FIXUP_BENQ_T31] = {
4808 .type = ALC_FIXUP_VERBS,
4809 .v.verbs = (const struct hda_verb[]) {
4810 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4811 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4812 {}
4813 }
4814 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004815};
4816
4817static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004818 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004819 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4820 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004821 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
Takashi Iwai12837c92011-11-07 12:45:24 +01004822 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4823 ALC262_FIXUP_TOSHIBA_RX1),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004824 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004825 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004826 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4827 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004828 {}
4829};
4830
4831
4832#ifdef CONFIG_SND_HDA_POWER_SAVE
4833#define alc262_loopbacks alc880_loopbacks
4834#endif
4835
Takashi Iwai1d045db2011-07-07 18:23:21 +02004836/*
4837 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004838static int patch_alc262(struct hda_codec *codec)
4839{
4840 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004841 int err;
4842
4843 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4844 if (spec == NULL)
4845 return -ENOMEM;
4846
4847 codec->spec = spec;
4848
4849 spec->mixer_nid = 0x0b;
4850
4851#if 0
4852 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4853 * under-run
4854 */
4855 {
4856 int tmp;
4857 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4858 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4859 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4860 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4861 }
4862#endif
4863 alc_auto_parse_customize_define(codec);
4864
4865 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4866
Takashi Iwai42399f72011-11-07 17:18:44 +01004867 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4868 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004869
Takashi Iwai42399f72011-11-07 17:18:44 +01004870 /* automatic parse from the BIOS config */
4871 err = alc262_parse_auto_config(codec);
4872 if (err < 0)
4873 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004874
Takashi Iwai60a6a842011-07-27 14:01:24 +02004875 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004876 alc_auto_fill_adc_caps(codec);
4877 alc_rebuild_imux_for_auto_mic(codec);
4878 alc_remove_invalid_adc_nids(codec);
4879 }
4880
4881 if (!spec->no_analog && !spec->cap_mixer)
4882 set_capture_mixer(codec);
4883
Takashi Iwai1d045db2011-07-07 18:23:21 +02004884 if (!spec->no_analog && has_cdefine_beep(codec)) {
4885 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004886 if (err < 0)
4887 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004888 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004889 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004890
4891 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4892
Takashi Iwai1d045db2011-07-07 18:23:21 +02004893 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004894 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004895 spec->shutup = alc_eapd_shutup;
4896
Takashi Iwai1d045db2011-07-07 18:23:21 +02004897#ifdef CONFIG_SND_HDA_POWER_SAVE
4898 if (!spec->loopback.amplist)
4899 spec->loopback.amplist = alc262_loopbacks;
4900#endif
4901
4902 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004903
4904 error:
4905 alc_free(codec);
4906 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004907}
4908
4909/*
4910 * ALC268
4911 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004912/* bind Beep switches of both NID 0x0f and 0x10 */
4913static const struct hda_bind_ctls alc268_bind_beep_sw = {
4914 .ops = &snd_hda_bind_sw,
4915 .values = {
4916 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4917 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4918 0
4919 },
4920};
4921
4922static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4923 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4924 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4925 { }
4926};
4927
4928/* set PCBEEP vol = 0, mute connections */
4929static const struct hda_verb alc268_beep_init_verbs[] = {
4930 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4931 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4932 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4933 { }
4934};
4935
4936/*
4937 * BIOS auto configuration
4938 */
4939static int alc268_parse_auto_config(struct hda_codec *codec)
4940{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004941 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004942 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004943 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4944 if (err > 0) {
4945 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4946 add_mixer(spec, alc268_beep_mixer);
4947 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004948 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004949 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004950 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004951}
4952
Takashi Iwai1d045db2011-07-07 18:23:21 +02004953/*
4954 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004955static int patch_alc268(struct hda_codec *codec)
4956{
4957 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004958 int i, has_beep, err;
4959
4960 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4961 if (spec == NULL)
4962 return -ENOMEM;
4963
4964 codec->spec = spec;
4965
4966 /* ALC268 has no aa-loopback mixer */
4967
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004968 /* automatic parse from the BIOS config */
4969 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004970 if (err < 0)
4971 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004972
Takashi Iwai1d045db2011-07-07 18:23:21 +02004973 has_beep = 0;
4974 for (i = 0; i < spec->num_mixers; i++) {
4975 if (spec->mixers[i] == alc268_beep_mixer) {
4976 has_beep = 1;
4977 break;
4978 }
4979 }
4980
4981 if (has_beep) {
4982 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004983 if (err < 0)
4984 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004985 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4986 /* override the amp caps for beep generator */
4987 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4988 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4989 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4990 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4991 (0 << AC_AMPCAP_MUTE_SHIFT));
4992 }
4993
Takashi Iwai60a6a842011-07-27 14:01:24 +02004994 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995 alc_auto_fill_adc_caps(codec);
4996 alc_rebuild_imux_for_auto_mic(codec);
4997 alc_remove_invalid_adc_nids(codec);
4998 }
4999
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005000 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005001 set_capture_mixer(codec);
5002
Takashi Iwai1d045db2011-07-07 18:23:21 +02005003 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005004 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005 spec->shutup = alc_eapd_shutup;
5006
Takashi Iwai1d045db2011-07-07 18:23:21 +02005007 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005008
5009 error:
5010 alc_free(codec);
5011 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005012}
5013
5014/*
5015 * ALC269
5016 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005017#ifdef CONFIG_SND_HDA_POWER_SAVE
5018#define alc269_loopbacks alc880_loopbacks
5019#endif
5020
5021static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5022 .substreams = 1,
5023 .channels_min = 2,
5024 .channels_max = 8,
5025 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5026 /* NID is set in alc_build_pcms */
5027 .ops = {
5028 .open = alc_playback_pcm_open,
5029 .prepare = alc_playback_pcm_prepare,
5030 .cleanup = alc_playback_pcm_cleanup
5031 },
5032};
5033
5034static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5035 .substreams = 1,
5036 .channels_min = 2,
5037 .channels_max = 2,
5038 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5039 /* NID is set in alc_build_pcms */
5040};
5041
5042#ifdef CONFIG_SND_HDA_POWER_SAVE
5043static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5044{
5045 switch (codec->subsystem_id) {
5046 case 0x103c1586:
5047 return 1;
5048 }
5049 return 0;
5050}
5051
5052static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5053{
5054 /* update mute-LED according to the speaker mute state */
5055 if (nid == 0x01 || nid == 0x14) {
5056 int pinval;
5057 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5058 HDA_AMP_MUTE)
5059 pinval = 0x24;
5060 else
5061 pinval = 0x20;
5062 /* mic2 vref pin is used for mute LED control */
5063 snd_hda_codec_update_cache(codec, 0x19, 0,
5064 AC_VERB_SET_PIN_WIDGET_CONTROL,
5065 pinval);
5066 }
5067 return alc_check_power_status(codec, nid);
5068}
5069#endif /* CONFIG_SND_HDA_POWER_SAVE */
5070
5071/* different alc269-variants */
5072enum {
5073 ALC269_TYPE_ALC269VA,
5074 ALC269_TYPE_ALC269VB,
5075 ALC269_TYPE_ALC269VC,
5076};
5077
5078/*
5079 * BIOS auto configuration
5080 */
5081static int alc269_parse_auto_config(struct hda_codec *codec)
5082{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005083 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005084 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5085 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5086 struct alc_spec *spec = codec->spec;
5087 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5088 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005089
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005090 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005091}
5092
Takashi Iwai1d045db2011-07-07 18:23:21 +02005093static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5094{
5095 int val = alc_read_coef_idx(codec, 0x04);
5096 if (power_up)
5097 val |= 1 << 11;
5098 else
5099 val &= ~(1 << 11);
5100 alc_write_coef_idx(codec, 0x04, val);
5101}
5102
5103static void alc269_shutup(struct hda_codec *codec)
5104{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005105 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005106 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005107 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005108 alc269_toggle_power_output(codec, 0);
5109 msleep(150);
5110 }
5111}
5112
Takashi Iwai2a439522011-07-26 09:52:50 +02005113#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005114static int alc269_resume(struct hda_codec *codec)
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, 0);
5118 msleep(150);
5119 }
5120
5121 codec->patch_ops.init(codec);
5122
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005123 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005124 alc269_toggle_power_output(codec, 1);
5125 msleep(200);
5126 }
5127
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005128 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005129 alc269_toggle_power_output(codec, 1);
5130
5131 snd_hda_codec_resume_amp(codec);
5132 snd_hda_codec_resume_cache(codec);
5133 hda_call_check_power_status(codec, 0x01);
5134 return 0;
5135}
Takashi Iwai2a439522011-07-26 09:52:50 +02005136#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005137
5138static void alc269_fixup_hweq(struct hda_codec *codec,
5139 const struct alc_fixup *fix, int action)
5140{
5141 int coef;
5142
5143 if (action != ALC_FIXUP_ACT_INIT)
5144 return;
5145 coef = alc_read_coef_idx(codec, 0x1e);
5146 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5147}
5148
5149static void alc271_fixup_dmic(struct hda_codec *codec,
5150 const struct alc_fixup *fix, int action)
5151{
5152 static const struct hda_verb verbs[] = {
5153 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5154 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5155 {}
5156 };
5157 unsigned int cfg;
5158
5159 if (strcmp(codec->chip_name, "ALC271X"))
5160 return;
5161 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5162 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5163 snd_hda_sequence_write(codec, verbs);
5164}
5165
Takashi Iwai017f2a12011-07-09 14:42:25 +02005166static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5167 const struct alc_fixup *fix, int action)
5168{
5169 struct alc_spec *spec = codec->spec;
5170
5171 if (action != ALC_FIXUP_ACT_PROBE)
5172 return;
5173
5174 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5175 * fix the sample rate of analog I/O to 44.1kHz
5176 */
5177 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5178 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5179}
5180
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005181static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5182 const struct alc_fixup *fix, int action)
5183{
5184 int coef;
5185
5186 if (action != ALC_FIXUP_ACT_INIT)
5187 return;
5188 /* The digital-mic unit sends PDM (differential signal) instead of
5189 * the standard PCM, thus you can't record a valid mono stream as is.
5190 * Below is a workaround specific to ALC269 to control the dmic
5191 * signal source as mono.
5192 */
5193 coef = alc_read_coef_idx(codec, 0x07);
5194 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5195}
5196
Takashi Iwai24519912011-08-16 15:08:49 +02005197static void alc269_quanta_automute(struct hda_codec *codec)
5198{
David Henningsson42cf0d02011-09-20 12:04:56 +02005199 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005200
5201 snd_hda_codec_write(codec, 0x20, 0,
5202 AC_VERB_SET_COEF_INDEX, 0x0c);
5203 snd_hda_codec_write(codec, 0x20, 0,
5204 AC_VERB_SET_PROC_COEF, 0x680);
5205
5206 snd_hda_codec_write(codec, 0x20, 0,
5207 AC_VERB_SET_COEF_INDEX, 0x0c);
5208 snd_hda_codec_write(codec, 0x20, 0,
5209 AC_VERB_SET_PROC_COEF, 0x480);
5210}
5211
5212static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5213 const struct alc_fixup *fix, int action)
5214{
5215 struct alc_spec *spec = codec->spec;
5216 if (action != ALC_FIXUP_ACT_PROBE)
5217 return;
5218 spec->automute_hook = alc269_quanta_automute;
5219}
5220
Takashi Iwai1d045db2011-07-07 18:23:21 +02005221enum {
5222 ALC269_FIXUP_SONY_VAIO,
5223 ALC275_FIXUP_SONY_VAIO_GPIO2,
5224 ALC269_FIXUP_DELL_M101Z,
5225 ALC269_FIXUP_SKU_IGNORE,
5226 ALC269_FIXUP_ASUS_G73JW,
5227 ALC269_FIXUP_LENOVO_EAPD,
5228 ALC275_FIXUP_SONY_HWEQ,
5229 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005230 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005231 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005232 ALC269_FIXUP_QUANTA_MUTE,
5233 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005234 ALC269_FIXUP_AMIC,
5235 ALC269_FIXUP_DMIC,
5236 ALC269VB_FIXUP_AMIC,
5237 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005238};
5239
5240static const struct alc_fixup alc269_fixups[] = {
5241 [ALC269_FIXUP_SONY_VAIO] = {
5242 .type = ALC_FIXUP_VERBS,
5243 .v.verbs = (const struct hda_verb[]) {
5244 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5245 {}
5246 }
5247 },
5248 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5249 .type = ALC_FIXUP_VERBS,
5250 .v.verbs = (const struct hda_verb[]) {
5251 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5252 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5253 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5254 { }
5255 },
5256 .chained = true,
5257 .chain_id = ALC269_FIXUP_SONY_VAIO
5258 },
5259 [ALC269_FIXUP_DELL_M101Z] = {
5260 .type = ALC_FIXUP_VERBS,
5261 .v.verbs = (const struct hda_verb[]) {
5262 /* Enables internal speaker */
5263 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5264 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5265 {}
5266 }
5267 },
5268 [ALC269_FIXUP_SKU_IGNORE] = {
5269 .type = ALC_FIXUP_SKU,
5270 .v.sku = ALC_FIXUP_SKU_IGNORE,
5271 },
5272 [ALC269_FIXUP_ASUS_G73JW] = {
5273 .type = ALC_FIXUP_PINS,
5274 .v.pins = (const struct alc_pincfg[]) {
5275 { 0x17, 0x99130111 }, /* subwoofer */
5276 { }
5277 }
5278 },
5279 [ALC269_FIXUP_LENOVO_EAPD] = {
5280 .type = ALC_FIXUP_VERBS,
5281 .v.verbs = (const struct hda_verb[]) {
5282 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5283 {}
5284 }
5285 },
5286 [ALC275_FIXUP_SONY_HWEQ] = {
5287 .type = ALC_FIXUP_FUNC,
5288 .v.func = alc269_fixup_hweq,
5289 .chained = true,
5290 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5291 },
5292 [ALC271_FIXUP_DMIC] = {
5293 .type = ALC_FIXUP_FUNC,
5294 .v.func = alc271_fixup_dmic,
5295 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005296 [ALC269_FIXUP_PCM_44K] = {
5297 .type = ALC_FIXUP_FUNC,
5298 .v.func = alc269_fixup_pcm_44k,
5299 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005300 [ALC269_FIXUP_STEREO_DMIC] = {
5301 .type = ALC_FIXUP_FUNC,
5302 .v.func = alc269_fixup_stereo_dmic,
5303 },
Takashi Iwai24519912011-08-16 15:08:49 +02005304 [ALC269_FIXUP_QUANTA_MUTE] = {
5305 .type = ALC_FIXUP_FUNC,
5306 .v.func = alc269_fixup_quanta_mute,
5307 },
5308 [ALC269_FIXUP_LIFEBOOK] = {
5309 .type = ALC_FIXUP_PINS,
5310 .v.pins = (const struct alc_pincfg[]) {
5311 { 0x1a, 0x2101103f }, /* dock line-out */
5312 { 0x1b, 0x23a11040 }, /* dock mic-in */
5313 { }
5314 },
5315 .chained = true,
5316 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5317 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005318 [ALC269_FIXUP_AMIC] = {
5319 .type = ALC_FIXUP_PINS,
5320 .v.pins = (const struct alc_pincfg[]) {
5321 { 0x14, 0x99130110 }, /* speaker */
5322 { 0x15, 0x0121401f }, /* HP out */
5323 { 0x18, 0x01a19c20 }, /* mic */
5324 { 0x19, 0x99a3092f }, /* int-mic */
5325 { }
5326 },
5327 },
5328 [ALC269_FIXUP_DMIC] = {
5329 .type = ALC_FIXUP_PINS,
5330 .v.pins = (const struct alc_pincfg[]) {
5331 { 0x12, 0x99a3092f }, /* int-mic */
5332 { 0x14, 0x99130110 }, /* speaker */
5333 { 0x15, 0x0121401f }, /* HP out */
5334 { 0x18, 0x01a19c20 }, /* mic */
5335 { }
5336 },
5337 },
5338 [ALC269VB_FIXUP_AMIC] = {
5339 .type = ALC_FIXUP_PINS,
5340 .v.pins = (const struct alc_pincfg[]) {
5341 { 0x14, 0x99130110 }, /* speaker */
5342 { 0x18, 0x01a19c20 }, /* mic */
5343 { 0x19, 0x99a3092f }, /* int-mic */
5344 { 0x21, 0x0121401f }, /* HP out */
5345 { }
5346 },
5347 },
David Henningsson2267ea92012-01-03 08:45:56 +01005348 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02005349 .type = ALC_FIXUP_PINS,
5350 .v.pins = (const struct alc_pincfg[]) {
5351 { 0x12, 0x99a3092f }, /* int-mic */
5352 { 0x14, 0x99130110 }, /* speaker */
5353 { 0x18, 0x01a19c20 }, /* mic */
5354 { 0x21, 0x0121401f }, /* HP out */
5355 { }
5356 },
5357 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005358};
5359
5360static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005361 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005362 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5363 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5364 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5365 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5366 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005367 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5368 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5369 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5370 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5371 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5372 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005373 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005374 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5375 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5376 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5377 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5378 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005379 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005380 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005381 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005382
5383#if 1
5384 /* Below is a quirk table taken from the old code.
5385 * Basically the device should work as is without the fixup table.
5386 * If BIOS doesn't give a proper info, enable the corresponding
5387 * fixup entry.
5388 */
5389 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5390 ALC269_FIXUP_AMIC),
5391 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005392 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5393 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5394 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5395 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5396 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5397 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5398 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5399 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5400 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5401 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5402 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5403 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5404 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5405 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5406 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5407 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5408 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5409 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5410 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5411 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5412 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5413 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5414 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5415 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5416 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5417 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5418 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5419 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5420 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5421 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5422 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5423 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5424 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5425 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5426 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5427 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5428 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5429 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5430#endif
5431 {}
5432};
5433
5434static const struct alc_model_fixup alc269_fixup_models[] = {
5435 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5436 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005437 {}
5438};
5439
5440
5441static int alc269_fill_coef(struct hda_codec *codec)
5442{
5443 int val;
5444
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005445 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005446 alc_write_coef_idx(codec, 0xf, 0x960b);
5447 alc_write_coef_idx(codec, 0xe, 0x8817);
5448 }
5449
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005450 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451 alc_write_coef_idx(codec, 0xf, 0x960b);
5452 alc_write_coef_idx(codec, 0xe, 0x8814);
5453 }
5454
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005455 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005456 val = alc_read_coef_idx(codec, 0x04);
5457 /* Power up output pin */
5458 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5459 }
5460
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005461 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005462 val = alc_read_coef_idx(codec, 0xd);
5463 if ((val & 0x0c00) >> 10 != 0x1) {
5464 /* Capless ramp up clock control */
5465 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5466 }
5467 val = alc_read_coef_idx(codec, 0x17);
5468 if ((val & 0x01c0) >> 6 != 0x4) {
5469 /* Class D power on reset */
5470 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5471 }
5472 }
5473
5474 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5475 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5476
5477 val = alc_read_coef_idx(codec, 0x4); /* HP */
5478 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5479
5480 return 0;
5481}
5482
5483/*
5484 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005485static int patch_alc269(struct hda_codec *codec)
5486{
5487 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005488 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489
5490 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5491 if (spec == NULL)
5492 return -ENOMEM;
5493
5494 codec->spec = spec;
5495
5496 spec->mixer_nid = 0x0b;
5497
5498 alc_auto_parse_customize_define(codec);
5499
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005500 err = alc_codec_rename_from_preset(codec);
5501 if (err < 0)
5502 goto error;
5503
Takashi Iwai1d045db2011-07-07 18:23:21 +02005504 if (codec->vendor_id == 0x10ec0269) {
5505 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005506 switch (alc_get_coef0(codec) & 0x00f0) {
5507 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005509 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005510 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005511 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005512 break;
5513 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005514 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5515 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005516 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005517 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005518 break;
5519 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005520 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005521 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005522 if (err < 0)
5523 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005524 alc269_fill_coef(codec);
5525 }
5526
Takashi Iwaia4297b52011-08-23 18:40:12 +02005527 alc_pick_fixup(codec, alc269_fixup_models,
5528 alc269_fixup_tbl, alc269_fixups);
5529 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005530
Takashi Iwaia4297b52011-08-23 18:40:12 +02005531 /* automatic parse from the BIOS config */
5532 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005533 if (err < 0)
5534 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005535
Takashi Iwai60a6a842011-07-27 14:01:24 +02005536 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005537 alc_auto_fill_adc_caps(codec);
5538 alc_rebuild_imux_for_auto_mic(codec);
5539 alc_remove_invalid_adc_nids(codec);
5540 }
5541
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005542 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005543 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005544
5545 if (!spec->no_analog && has_cdefine_beep(codec)) {
5546 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005547 if (err < 0)
5548 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005549 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005550 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005551
5552 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5553
Takashi Iwai1d045db2011-07-07 18:23:21 +02005554 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005555#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005556 codec->patch_ops.resume = alc269_resume;
5557#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005558 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005559 spec->shutup = alc269_shutup;
5560
Takashi Iwai1d045db2011-07-07 18:23:21 +02005561#ifdef CONFIG_SND_HDA_POWER_SAVE
5562 if (!spec->loopback.amplist)
5563 spec->loopback.amplist = alc269_loopbacks;
5564 if (alc269_mic2_for_mute_led(codec))
5565 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5566#endif
5567
5568 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005569
5570 error:
5571 alc_free(codec);
5572 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005573}
5574
5575/*
5576 * ALC861
5577 */
5578
Takashi Iwai1d045db2011-07-07 18:23:21 +02005579static int alc861_parse_auto_config(struct hda_codec *codec)
5580{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005581 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005582 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5583 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005584}
5585
Takashi Iwai1d045db2011-07-07 18:23:21 +02005586#ifdef CONFIG_SND_HDA_POWER_SAVE
5587static const struct hda_amp_list alc861_loopbacks[] = {
5588 { 0x15, HDA_INPUT, 0 },
5589 { 0x15, HDA_INPUT, 1 },
5590 { 0x15, HDA_INPUT, 2 },
5591 { 0x15, HDA_INPUT, 3 },
5592 { } /* end */
5593};
5594#endif
5595
5596
5597/* Pin config fixes */
5598enum {
5599 PINFIX_FSC_AMILO_PI1505,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005600 PINFIX_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005601};
5602
Takashi Iwai31150f22012-01-30 10:54:08 +01005603/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5604static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5605 const struct alc_fixup *fix, int action)
5606{
5607 struct alc_spec *spec = codec->spec;
5608 unsigned int val;
5609
5610 if (action != ALC_FIXUP_ACT_INIT)
5611 return;
5612 val = snd_hda_codec_read(codec, 0x0f, 0,
5613 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5614 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5615 val |= AC_PINCTL_IN_EN;
5616 val |= AC_PINCTL_VREF_50;
5617 snd_hda_codec_write(codec, 0x0f, 0,
5618 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5619 spec->keep_vref_in_automute = 1;
5620}
5621
Takashi Iwai1d045db2011-07-07 18:23:21 +02005622static const struct alc_fixup alc861_fixups[] = {
5623 [PINFIX_FSC_AMILO_PI1505] = {
5624 .type = ALC_FIXUP_PINS,
5625 .v.pins = (const struct alc_pincfg[]) {
5626 { 0x0b, 0x0221101f }, /* HP */
5627 { 0x0f, 0x90170310 }, /* speaker */
5628 { }
5629 }
5630 },
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005631 [PINFIX_ASUS_A6RP] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01005632 .type = ALC_FIXUP_FUNC,
5633 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005634 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005635};
5636
5637static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01005638 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", PINFIX_ASUS_A6RP),
Takashi Iwaib3a81522012-01-26 15:56:16 +01005639 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", PINFIX_ASUS_A6RP),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005640 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5641 {}
5642};
5643
5644/*
5645 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005646static int patch_alc861(struct hda_codec *codec)
5647{
5648 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649 int err;
5650
5651 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5652 if (spec == NULL)
5653 return -ENOMEM;
5654
5655 codec->spec = spec;
5656
5657 spec->mixer_nid = 0x15;
5658
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005659 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5660 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005662 /* automatic parse from the BIOS config */
5663 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005664 if (err < 0)
5665 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005666
Takashi Iwai60a6a842011-07-27 14:01:24 +02005667 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005668 alc_auto_fill_adc_caps(codec);
5669 alc_rebuild_imux_for_auto_mic(codec);
5670 alc_remove_invalid_adc_nids(codec);
5671 }
5672
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005673 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005674 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005675
5676 if (!spec->no_analog) {
5677 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005678 if (err < 0)
5679 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005680 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5681 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005682
Takashi Iwai1d045db2011-07-07 18:23:21 +02005683 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5684
5685 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005686 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005687#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005688 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005689 if (!spec->loopback.amplist)
5690 spec->loopback.amplist = alc861_loopbacks;
5691#endif
5692
5693 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005694
5695 error:
5696 alc_free(codec);
5697 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005698}
5699
5700/*
5701 * ALC861-VD support
5702 *
5703 * Based on ALC882
5704 *
5705 * In addition, an independent DAC
5706 */
5707#ifdef CONFIG_SND_HDA_POWER_SAVE
5708#define alc861vd_loopbacks alc880_loopbacks
5709#endif
5710
Takashi Iwai1d045db2011-07-07 18:23:21 +02005711static int alc861vd_parse_auto_config(struct hda_codec *codec)
5712{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005713 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005714 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5715 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005716}
5717
Takashi Iwai1d045db2011-07-07 18:23:21 +02005718enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005719 ALC660VD_FIX_ASUS_GPIO1,
5720 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721};
5722
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005723/* exclude VREF80 */
5724static void alc861vd_fixup_dallas(struct hda_codec *codec,
5725 const struct alc_fixup *fix, int action)
5726{
5727 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5728 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5729 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5730 }
5731}
5732
Takashi Iwai1d045db2011-07-07 18:23:21 +02005733static const struct alc_fixup alc861vd_fixups[] = {
5734 [ALC660VD_FIX_ASUS_GPIO1] = {
5735 .type = ALC_FIXUP_VERBS,
5736 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005737 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005738 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5739 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5740 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5741 { }
5742 }
5743 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005744 [ALC861VD_FIX_DALLAS] = {
5745 .type = ALC_FIXUP_FUNC,
5746 .v.func = alc861vd_fixup_dallas,
5747 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748};
5749
5750static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005751 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005752 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005753 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754 {}
5755};
5756
5757static const struct hda_verb alc660vd_eapd_verbs[] = {
5758 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5759 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5760 { }
5761};
5762
5763/*
5764 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765static int patch_alc861vd(struct hda_codec *codec)
5766{
5767 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005768 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005769
5770 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5771 if (spec == NULL)
5772 return -ENOMEM;
5773
5774 codec->spec = spec;
5775
5776 spec->mixer_nid = 0x0b;
5777
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005778 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5779 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005780
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005781 /* automatic parse from the BIOS config */
5782 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005783 if (err < 0)
5784 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005785
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786 if (codec->vendor_id == 0x10ec0660) {
5787 /* always turn on EAPD */
5788 add_verb(spec, alc660vd_eapd_verbs);
5789 }
5790
Takashi Iwai60a6a842011-07-27 14:01:24 +02005791 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005792 alc_auto_fill_adc_caps(codec);
5793 alc_rebuild_imux_for_auto_mic(codec);
5794 alc_remove_invalid_adc_nids(codec);
5795 }
5796
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005797 if (!spec->no_analog && !spec->cap_mixer)
5798 set_capture_mixer(codec);
5799
5800 if (!spec->no_analog) {
5801 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005802 if (err < 0)
5803 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005804 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5805 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005806
Takashi Iwai1d045db2011-07-07 18:23:21 +02005807 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5808
5809 codec->patch_ops = alc_patch_ops;
5810
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005811 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005812 spec->shutup = alc_eapd_shutup;
5813#ifdef CONFIG_SND_HDA_POWER_SAVE
5814 if (!spec->loopback.amplist)
5815 spec->loopback.amplist = alc861vd_loopbacks;
5816#endif
5817
5818 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005819
5820 error:
5821 alc_free(codec);
5822 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005823}
5824
5825/*
5826 * ALC662 support
5827 *
5828 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5829 * configuration. Each pin widget can choose any input DACs and a mixer.
5830 * Each ADC is connected from a mixer of all inputs. This makes possible
5831 * 6-channel independent captures.
5832 *
5833 * In addition, an independent DAC for the multi-playback (not used in this
5834 * driver yet).
5835 */
5836#ifdef CONFIG_SND_HDA_POWER_SAVE
5837#define alc662_loopbacks alc880_loopbacks
5838#endif
5839
5840/*
5841 * BIOS auto configuration
5842 */
5843
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005844static int alc662_parse_auto_config(struct hda_codec *codec)
5845{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005846 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005847 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5848 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5849 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005850
Kailang Yang6227cdc2010-02-25 08:36:52 +01005851 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5852 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005853 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005854 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005855 ssids = alc662_ssids;
5856 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005857}
5858
Todd Broch6be79482010-12-07 16:51:05 -08005859static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005860 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005861{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005862 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005863 return;
Todd Broch6be79482010-12-07 16:51:05 -08005864 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5865 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5866 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5867 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5868 (0 << AC_AMPCAP_MUTE_SHIFT)))
5869 printk(KERN_WARNING
5870 "hda_codec: failed to override amp caps for NID 0x2\n");
5871}
5872
David Henningsson6cb3b702010-09-09 08:51:44 +02005873enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005874 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005875 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005876 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005877 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005878 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005879 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005880 ALC662_FIXUP_ASUS_MODE1,
5881 ALC662_FIXUP_ASUS_MODE2,
5882 ALC662_FIXUP_ASUS_MODE3,
5883 ALC662_FIXUP_ASUS_MODE4,
5884 ALC662_FIXUP_ASUS_MODE5,
5885 ALC662_FIXUP_ASUS_MODE6,
5886 ALC662_FIXUP_ASUS_MODE7,
5887 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005888};
5889
5890static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005891 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005892 .type = ALC_FIXUP_PINS,
5893 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005894 { 0x15, 0x99130112 }, /* subwoofer */
5895 { }
5896 }
5897 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005898 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005899 .type = ALC_FIXUP_PINS,
5900 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005901 { 0x17, 0x99130112 }, /* subwoofer */
5902 { }
5903 }
5904 },
Todd Broch6be79482010-12-07 16:51:05 -08005905 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005906 .type = ALC_FIXUP_FUNC,
5907 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005908 },
5909 [ALC662_FIXUP_CZC_P10T] = {
5910 .type = ALC_FIXUP_VERBS,
5911 .v.verbs = (const struct hda_verb[]) {
5912 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5913 {}
5914 }
5915 },
David Henningsson94024cd2011-04-29 14:10:55 +02005916 [ALC662_FIXUP_SKU_IGNORE] = {
5917 .type = ALC_FIXUP_SKU,
5918 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005919 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005920 [ALC662_FIXUP_HP_RP5800] = {
5921 .type = ALC_FIXUP_PINS,
5922 .v.pins = (const struct alc_pincfg[]) {
5923 { 0x14, 0x0221201f }, /* HP out */
5924 { }
5925 },
5926 .chained = true,
5927 .chain_id = ALC662_FIXUP_SKU_IGNORE
5928 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005929 [ALC662_FIXUP_ASUS_MODE1] = {
5930 .type = ALC_FIXUP_PINS,
5931 .v.pins = (const struct alc_pincfg[]) {
5932 { 0x14, 0x99130110 }, /* speaker */
5933 { 0x18, 0x01a19c20 }, /* mic */
5934 { 0x19, 0x99a3092f }, /* int-mic */
5935 { 0x21, 0x0121401f }, /* HP out */
5936 { }
5937 },
5938 .chained = true,
5939 .chain_id = ALC662_FIXUP_SKU_IGNORE
5940 },
5941 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005942 .type = ALC_FIXUP_PINS,
5943 .v.pins = (const struct alc_pincfg[]) {
5944 { 0x14, 0x99130110 }, /* speaker */
5945 { 0x18, 0x01a19820 }, /* mic */
5946 { 0x19, 0x99a3092f }, /* int-mic */
5947 { 0x1b, 0x0121401f }, /* HP out */
5948 { }
5949 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005950 .chained = true,
5951 .chain_id = ALC662_FIXUP_SKU_IGNORE
5952 },
5953 [ALC662_FIXUP_ASUS_MODE3] = {
5954 .type = ALC_FIXUP_PINS,
5955 .v.pins = (const struct alc_pincfg[]) {
5956 { 0x14, 0x99130110 }, /* speaker */
5957 { 0x15, 0x0121441f }, /* HP */
5958 { 0x18, 0x01a19840 }, /* mic */
5959 { 0x19, 0x99a3094f }, /* int-mic */
5960 { 0x21, 0x01211420 }, /* HP2 */
5961 { }
5962 },
5963 .chained = true,
5964 .chain_id = ALC662_FIXUP_SKU_IGNORE
5965 },
5966 [ALC662_FIXUP_ASUS_MODE4] = {
5967 .type = ALC_FIXUP_PINS,
5968 .v.pins = (const struct alc_pincfg[]) {
5969 { 0x14, 0x99130110 }, /* speaker */
5970 { 0x16, 0x99130111 }, /* speaker */
5971 { 0x18, 0x01a19840 }, /* mic */
5972 { 0x19, 0x99a3094f }, /* int-mic */
5973 { 0x21, 0x0121441f }, /* HP */
5974 { }
5975 },
5976 .chained = true,
5977 .chain_id = ALC662_FIXUP_SKU_IGNORE
5978 },
5979 [ALC662_FIXUP_ASUS_MODE5] = {
5980 .type = ALC_FIXUP_PINS,
5981 .v.pins = (const struct alc_pincfg[]) {
5982 { 0x14, 0x99130110 }, /* speaker */
5983 { 0x15, 0x0121441f }, /* HP */
5984 { 0x16, 0x99130111 }, /* speaker */
5985 { 0x18, 0x01a19840 }, /* mic */
5986 { 0x19, 0x99a3094f }, /* int-mic */
5987 { }
5988 },
5989 .chained = true,
5990 .chain_id = ALC662_FIXUP_SKU_IGNORE
5991 },
5992 [ALC662_FIXUP_ASUS_MODE6] = {
5993 .type = ALC_FIXUP_PINS,
5994 .v.pins = (const struct alc_pincfg[]) {
5995 { 0x14, 0x99130110 }, /* speaker */
5996 { 0x15, 0x01211420 }, /* HP2 */
5997 { 0x18, 0x01a19840 }, /* mic */
5998 { 0x19, 0x99a3094f }, /* int-mic */
5999 { 0x1b, 0x0121441f }, /* HP */
6000 { }
6001 },
6002 .chained = true,
6003 .chain_id = ALC662_FIXUP_SKU_IGNORE
6004 },
6005 [ALC662_FIXUP_ASUS_MODE7] = {
6006 .type = ALC_FIXUP_PINS,
6007 .v.pins = (const struct alc_pincfg[]) {
6008 { 0x14, 0x99130110 }, /* speaker */
6009 { 0x17, 0x99130111 }, /* speaker */
6010 { 0x18, 0x01a19840 }, /* mic */
6011 { 0x19, 0x99a3094f }, /* int-mic */
6012 { 0x1b, 0x01214020 }, /* HP */
6013 { 0x21, 0x0121401f }, /* HP */
6014 { }
6015 },
6016 .chained = true,
6017 .chain_id = ALC662_FIXUP_SKU_IGNORE
6018 },
6019 [ALC662_FIXUP_ASUS_MODE8] = {
6020 .type = ALC_FIXUP_PINS,
6021 .v.pins = (const struct alc_pincfg[]) {
6022 { 0x14, 0x99130110 }, /* speaker */
6023 { 0x12, 0x99a30970 }, /* int-mic */
6024 { 0x15, 0x01214020 }, /* HP */
6025 { 0x17, 0x99130111 }, /* speaker */
6026 { 0x18, 0x01a19840 }, /* mic */
6027 { 0x21, 0x0121401f }, /* HP */
6028 { }
6029 },
6030 .chained = true,
6031 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006032 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006033};
6034
Takashi Iwaia9111322011-05-02 11:30:18 +02006035static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006036 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006037 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006038 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006039 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006040 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006041 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006042 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006043 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006044 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006045 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006046
6047#if 0
6048 /* Below is a quirk table taken from the old code.
6049 * Basically the device should work as is without the fixup table.
6050 * If BIOS doesn't give a proper info, enable the corresponding
6051 * fixup entry.
6052 */
6053 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6054 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6055 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6056 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6057 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6058 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6059 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6060 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6061 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6062 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6063 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6064 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6065 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6066 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6067 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6068 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6069 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6070 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6071 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6072 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6073 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6074 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6075 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6076 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6077 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6078 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6079 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6080 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6081 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6082 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6083 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6084 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6085 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6086 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6087 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6088 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6089 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6090 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6091 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6092 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6093 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6094 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6095 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6096 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6097 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6098 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6099 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6100 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6101 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6102 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6103#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006104 {}
6105};
6106
Todd Broch6be79482010-12-07 16:51:05 -08006107static const struct alc_model_fixup alc662_fixup_models[] = {
6108 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006109 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6110 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6111 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6112 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6113 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6114 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6115 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6116 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006117 {}
6118};
David Henningsson6cb3b702010-09-09 08:51:44 +02006119
6120
Takashi Iwai1d045db2011-07-07 18:23:21 +02006121/*
6122 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006123static int patch_alc662(struct hda_codec *codec)
6124{
6125 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006126 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006127
6128 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6129 if (!spec)
6130 return -ENOMEM;
6131
6132 codec->spec = spec;
6133
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006134 spec->mixer_nid = 0x0b;
6135
Takashi Iwai53c334a2011-08-23 18:27:14 +02006136 /* handle multiple HPs as is */
6137 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6138
Kailang Yangda00c242010-03-19 11:23:45 +01006139 alc_auto_parse_customize_define(codec);
6140
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006141 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6142
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006143 err = alc_codec_rename_from_preset(codec);
6144 if (err < 0)
6145 goto error;
6146
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006147 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006148 codec->bus->pci->subsystem_vendor == 0x1025 &&
6149 spec->cdefine.platform_type == 1) {
6150 if (alc_codec_rename(codec, "ALC272X") < 0)
6151 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006152 }
Kailang Yang274693f2009-12-03 10:07:50 +01006153
Takashi Iwaib9c51062011-08-24 18:08:07 +02006154 alc_pick_fixup(codec, alc662_fixup_models,
6155 alc662_fixup_tbl, alc662_fixups);
6156 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6157 /* automatic parse from the BIOS config */
6158 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006159 if (err < 0)
6160 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006161
Takashi Iwai60a6a842011-07-27 14:01:24 +02006162 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006163 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006164 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006165 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006166 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006167
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006168 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006169 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006170
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006171 if (!spec->no_analog && has_cdefine_beep(codec)) {
6172 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006173 if (err < 0)
6174 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006175 switch (codec->vendor_id) {
6176 case 0x10ec0662:
6177 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6178 break;
6179 case 0x10ec0272:
6180 case 0x10ec0663:
6181 case 0x10ec0665:
6182 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6183 break;
6184 case 0x10ec0273:
6185 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6186 break;
6187 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006188 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006189
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006190 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6191
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006192 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006193 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006194 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006195
Takashi Iwaicb53c622007-08-10 17:21:45 +02006196#ifdef CONFIG_SND_HDA_POWER_SAVE
6197 if (!spec->loopback.amplist)
6198 spec->loopback.amplist = alc662_loopbacks;
6199#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006200
6201 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006202
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006203 error:
6204 alc_free(codec);
6205 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006206}
6207
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006208/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006209 * ALC680 support
6210 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006211
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006212static int alc680_parse_auto_config(struct hda_codec *codec)
6213{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006214 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006215}
6216
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006217/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006218 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006219static int patch_alc680(struct hda_codec *codec)
6220{
6221 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006222 int err;
6223
6224 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6225 if (spec == NULL)
6226 return -ENOMEM;
6227
6228 codec->spec = spec;
6229
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006230 /* ALC680 has no aa-loopback mixer */
6231
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006232 /* automatic parse from the BIOS config */
6233 err = alc680_parse_auto_config(codec);
6234 if (err < 0) {
6235 alc_free(codec);
6236 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006237 }
6238
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006239 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006240 set_capture_mixer(codec);
6241
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006242 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006243 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006244
6245 return 0;
6246}
6247
6248/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249 * patch entries
6250 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006251static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006252 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006254 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006255 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006256 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006257 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006258 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006259 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006260 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006261 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006262 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006263 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006264 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6265 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6266 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006267 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02006268 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006269 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6270 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006271 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6272 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006273 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006274 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006275 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006276 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006277 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006278 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006279 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006280 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006281 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006282 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006283 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006284 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006285 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006286 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02006287 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006288 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006289 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006290 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006291 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006292 {} /* terminator */
6293};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006294
6295MODULE_ALIAS("snd-hda-codec-id:10ec*");
6296
6297MODULE_LICENSE("GPL");
6298MODULE_DESCRIPTION("Realtek HD-audio codec");
6299
6300static struct hda_codec_preset_list realtek_list = {
6301 .preset = snd_hda_preset_realtek,
6302 .owner = THIS_MODULE,
6303};
6304
6305static int __init patch_realtek_init(void)
6306{
6307 return snd_hda_add_codec_preset(&realtek_list);
6308}
6309
6310static void __exit patch_realtek_exit(void)
6311{
6312 snd_hda_delete_codec_preset(&realtek_list);
6313}
6314
6315module_init(patch_realtek_init)
6316module_exit(patch_realtek_exit)