blob: 2326bf379525e177d9d4d1e31e6cc42e2432d5dc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e482006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083struct alc_spec {
84 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020085 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010088 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Takashi Iwai2d9c6482009-10-13 08:06:55 +020090 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020091 * don't forget NULL
92 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020093 */
94 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Takashi Iwaiaa563af2009-07-31 10:05:11 +020096 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020097 const struct hda_pcm_stream *stream_analog_playback;
98 const struct hda_pcm_stream *stream_analog_capture;
99 const struct hda_pcm_stream *stream_analog_alt_playback;
100 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200102 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200103 const struct hda_pcm_stream *stream_digital_playback;
104 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200107 struct hda_multi_out multiout; /* playback set-up
108 * max_channels, dacs must be set
109 * dig_out_nid and hp_nid are optional
110 */
Takashi Iwai63300792008-01-24 15:31:36 +0100111 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100112 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100113 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* capture */
116 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200117 const hda_nid_t *adc_nids;
118 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200119 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200120 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwai527e4d72011-10-27 16:33:27 +0200121 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
122 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Takashi Iwai840b64c2010-07-13 22:49:01 +0200124 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200125 hda_nid_t cur_adc;
126 unsigned int cur_adc_stream_tag;
127 unsigned int cur_adc_format;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200130 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 const struct hda_input_mux *input_mux;
132 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200133 hda_nid_t ext_mic_pin;
134 hda_nid_t dock_mic_pin;
135 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100138 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200140 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200141 int const_channel_count;
142 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100145 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200146
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200147 /* dynamic controls, init_verbs and input_mux */
148 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100149 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200150 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200151 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200152 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200153 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200155 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
156 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
157 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100158
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100159 /* hooks */
160 void (*init_hook)(struct hda_codec *codec);
161 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100162#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500163 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#endif
Takashi Iwai1c7161532011-04-07 10:37:16 +0200165 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200166 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100167
Takashi Iwai834be882006-03-01 14:16:17 +0100168 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200169 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200170 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200171 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200172 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200173 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200174 unsigned int automute_speaker:1; /* automute speaker outputs */
175 unsigned int automute_lo:1; /* automute LO outputs */
176 unsigned int detect_hp:1; /* Headphone detection enabled */
177 unsigned int detect_lo:1; /* Line-out detection enabled */
178 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
179 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200180
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100181 /* other flags */
182 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200183 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100184 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200185 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200186 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100187 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai3a938972011-10-28 01:16:55 +0200188 unsigned int use_jack_tbl:1; /* 1 for model=auto */
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 Iwaia9fd4f32009-05-08 15:57:59 +0200499 if (!nid)
500 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200501 switch (spec->automute_mode) {
502 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200503 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200504 AC_VERB_SET_PIN_WIDGET_CONTROL,
505 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200506 break;
507 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200508 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200509 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200510 break;
511 case ALC_AUTOMUTE_MIXER:
512 nid = spec->automute_mixer_nid[i];
513 if (!nid)
514 break;
515 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200516 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200517 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200518 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200519 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200520 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200521 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200522}
523
David Henningsson42cf0d02011-09-20 12:04:56 +0200524/* Toggle outputs muting */
525static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526{
527 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200528 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529
Takashi Iwaic0a20262011-06-10 15:28:15 +0200530 /* Control HP pins/amps depending on master_mute state;
531 * in general, HP pins/amps control should be enabled in all cases,
532 * but currently set only for master_mute, just to be safe
533 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100534 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
535 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200536 spec->autocfg.hp_pins, spec->master_mute, true);
537
David Henningsson42cf0d02011-09-20 12:04:56 +0200538 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200539 on = 0;
540 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200541 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200542 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200544 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200545
546 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200547 /* if LO is a copy of either HP or Speaker, don't need to handle it */
548 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
549 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200550 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200551 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200552 on = 0;
553 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200554 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200557 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558}
559
David Henningsson42cf0d02011-09-20 12:04:56 +0200560static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200561{
562 struct alc_spec *spec = codec->spec;
563 if (spec->automute_hook)
564 spec->automute_hook(codec);
565 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200566 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200567}
568
Takashi Iwai1d045db2011-07-07 18:23:21 +0200569/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200570static void alc_hp_automute(struct hda_codec *codec)
571{
572 struct alc_spec *spec = codec->spec;
573
David Henningsson42cf0d02011-09-20 12:04:56 +0200574 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200575 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
576 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200577 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200578 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200579 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200580}
581
Takashi Iwai1d045db2011-07-07 18:23:21 +0200582/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583static void alc_line_automute(struct hda_codec *codec)
584{
585 struct alc_spec *spec = codec->spec;
586
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200587 /* check LO jack only when it's different from HP */
588 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
589 return;
590
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591 spec->line_jack_present =
592 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
593 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200594 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200595 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200596 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200597}
598
Takashi Iwai8d087c72011-06-28 12:45:47 +0200599#define get_connection_index(codec, mux, nid) \
600 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200601
Takashi Iwai1d045db2011-07-07 18:23:21 +0200602/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200603static void alc_mic_automute(struct hda_codec *codec)
604{
605 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200606 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200607
Takashi Iwai21268962011-07-07 15:01:13 +0200608 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200609 return;
610 if (snd_BUG_ON(!spec->adc_nids))
611 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200612 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200613 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200614
Takashi Iwai21268962011-07-07 15:01:13 +0200615 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
616 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
617 else if (spec->dock_mic_idx >= 0 &&
618 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
619 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
620 else
621 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200622}
623
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100624/* handle the specified unsol action (ALC_XXX_EVENT) */
625static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200626{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100627 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200628 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200629 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200630 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200631 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200632 alc_line_automute(codec);
633 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200634 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200635 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200636 break;
637 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200638 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200639}
640
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100641/* unsolicited event for HP jack sensing */
642static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
643{
644 struct alc_spec *spec = codec->spec;
645 if (codec->vendor_id == 0x10ec0880)
646 res >>= 28;
647 else
648 res >>= 26;
649 if (spec->use_jack_tbl)
650 res = snd_hda_jack_get_action(codec, res);
651 alc_exec_unsol_event(codec, res);
652}
653
Takashi Iwai1d045db2011-07-07 18:23:21 +0200654/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200655static void alc_inithook(struct hda_codec *codec)
656{
Takashi Iwaid922b512011-04-28 12:18:53 +0200657 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200658 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200659 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200660}
661
Kailang Yangf9423e72008-05-27 12:32:25 +0200662/* additional initialization for ALC888 variants */
663static void alc888_coef_init(struct hda_codec *codec)
664{
665 unsigned int tmp;
666
667 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
668 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
669 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100670 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200671 /* alc888S-VC */
672 snd_hda_codec_read(codec, 0x20, 0,
673 AC_VERB_SET_PROC_COEF, 0x830);
674 else
675 /* alc888-VB */
676 snd_hda_codec_read(codec, 0x20, 0,
677 AC_VERB_SET_PROC_COEF, 0x3030);
678}
679
Takashi Iwai1d045db2011-07-07 18:23:21 +0200680/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200681static void alc889_coef_init(struct hda_codec *codec)
682{
683 unsigned int tmp;
684
685 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
686 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
687 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
688 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
689}
690
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100691/* turn on/off EAPD control (only if available) */
692static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
693{
694 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
695 return;
696 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
697 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
698 on ? 2 : 0);
699}
700
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200701/* turn on/off EAPD controls of the codec */
702static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
703{
704 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200705 static hda_nid_t pins[] = {
706 0x0f, 0x10, 0x14, 0x15, 0
707 };
708 hda_nid_t *p;
709 for (p = pins; *p; p++)
710 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200711}
712
Takashi Iwai1c7161532011-04-07 10:37:16 +0200713/* generic shutup callback;
714 * just turning off EPAD and a little pause for avoiding pop-noise
715 */
716static void alc_eapd_shutup(struct hda_codec *codec)
717{
718 alc_auto_setup_eapd(codec, false);
719 msleep(200);
720}
721
Takashi Iwai1d045db2011-07-07 18:23:21 +0200722/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200723static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200724{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200725 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200726
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200727 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200728 switch (type) {
729 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200730 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
731 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200732 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200733 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
734 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200735 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200736 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
737 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200738 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200739 switch (codec->vendor_id) {
740 case 0x10ec0260:
741 snd_hda_codec_write(codec, 0x1a, 0,
742 AC_VERB_SET_COEF_INDEX, 7);
743 tmp = snd_hda_codec_read(codec, 0x1a, 0,
744 AC_VERB_GET_PROC_COEF, 0);
745 snd_hda_codec_write(codec, 0x1a, 0,
746 AC_VERB_SET_COEF_INDEX, 7);
747 snd_hda_codec_write(codec, 0x1a, 0,
748 AC_VERB_SET_PROC_COEF,
749 tmp | 0x2010);
750 break;
751 case 0x10ec0262:
752 case 0x10ec0880:
753 case 0x10ec0882:
754 case 0x10ec0883:
755 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100756 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100757 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200758 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200759 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200760 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200761 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200762 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100763#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200764 case 0x10ec0267:
765 case 0x10ec0268:
766 snd_hda_codec_write(codec, 0x20, 0,
767 AC_VERB_SET_COEF_INDEX, 7);
768 tmp = snd_hda_codec_read(codec, 0x20, 0,
769 AC_VERB_GET_PROC_COEF, 0);
770 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200771 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200772 snd_hda_codec_write(codec, 0x20, 0,
773 AC_VERB_SET_PROC_COEF,
774 tmp | 0x3000);
775 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100776#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200777 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200778 break;
779 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200780}
Kailang Yangea1fb292008-08-26 12:58:38 +0200781
Takashi Iwai1d045db2011-07-07 18:23:21 +0200782/*
783 * Auto-Mute mode mixer enum support
784 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200785static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
786 struct snd_ctl_elem_info *uinfo)
787{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200788 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
789 struct alc_spec *spec = codec->spec;
790 static const char * const texts2[] = {
791 "Disabled", "Enabled"
792 };
793 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200794 "Disabled", "Speaker Only", "Line-Out+Speaker"
795 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200796 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200797
798 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
799 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200800 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200801 uinfo->value.enumerated.items = 3;
802 texts = texts3;
803 } else {
804 uinfo->value.enumerated.items = 2;
805 texts = texts2;
806 }
807 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
808 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200809 strcpy(uinfo->value.enumerated.name,
810 texts[uinfo->value.enumerated.item]);
811 return 0;
812}
813
814static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
815 struct snd_ctl_elem_value *ucontrol)
816{
817 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
818 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200819 unsigned int val = 0;
820 if (spec->automute_speaker)
821 val++;
822 if (spec->automute_lo)
823 val++;
824
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200825 ucontrol->value.enumerated.item[0] = val;
826 return 0;
827}
828
829static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
830 struct snd_ctl_elem_value *ucontrol)
831{
832 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
833 struct alc_spec *spec = codec->spec;
834
835 switch (ucontrol->value.enumerated.item[0]) {
836 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200837 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200838 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200839 spec->automute_speaker = 0;
840 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200841 break;
842 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200843 if (spec->automute_speaker_possible) {
844 if (!spec->automute_lo && spec->automute_speaker)
845 return 0;
846 spec->automute_speaker = 1;
847 spec->automute_lo = 0;
848 } else if (spec->automute_lo_possible) {
849 if (spec->automute_lo)
850 return 0;
851 spec->automute_lo = 1;
852 } else
853 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200854 break;
855 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200856 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200857 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200858 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200859 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200860 spec->automute_speaker = 1;
861 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200862 break;
863 default:
864 return -EINVAL;
865 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200866 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200867 return 1;
868}
869
Takashi Iwaia9111322011-05-02 11:30:18 +0200870static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200871 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
872 .name = "Auto-Mute Mode",
873 .info = alc_automute_mode_info,
874 .get = alc_automute_mode_get,
875 .put = alc_automute_mode_put,
876};
877
Takashi Iwai1d045db2011-07-07 18:23:21 +0200878static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
879{
880 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
881 return snd_array_new(&spec->kctls);
882}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200883
884static int alc_add_automute_mode_enum(struct hda_codec *codec)
885{
886 struct alc_spec *spec = codec->spec;
887 struct snd_kcontrol_new *knew;
888
889 knew = alc_kcontrol_new(spec);
890 if (!knew)
891 return -ENOMEM;
892 *knew = alc_automute_mode_enum;
893 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
894 if (!knew->name)
895 return -ENOMEM;
896 return 0;
897}
898
Takashi Iwai1d045db2011-07-07 18:23:21 +0200899/*
900 * Check the availability of HP/line-out auto-mute;
901 * Set up appropriately if really supported
902 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200903static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200904{
905 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200906 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200907 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200908 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200909
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200910 if (cfg->hp_pins[0])
911 present++;
912 if (cfg->line_out_pins[0])
913 present++;
914 if (cfg->speaker_pins[0])
915 present++;
916 if (present < 2) /* need two different output types */
917 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200918
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200919 if (!cfg->speaker_pins[0] &&
920 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200921 memcpy(cfg->speaker_pins, cfg->line_out_pins,
922 sizeof(cfg->speaker_pins));
923 cfg->speaker_outs = cfg->line_outs;
924 }
925
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200926 if (!cfg->hp_pins[0] &&
927 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200928 memcpy(cfg->hp_pins, cfg->line_out_pins,
929 sizeof(cfg->hp_pins));
930 cfg->hp_outs = cfg->line_outs;
931 }
932
David Henningsson42cf0d02011-09-20 12:04:56 +0200933 spec->automute_mode = ALC_AUTOMUTE_PIN;
934
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200935 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200936 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200937 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200938 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200939 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200940 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200941 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200942 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200943 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200944
David Henningsson42cf0d02011-09-20 12:04:56 +0200945 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
946 if (cfg->speaker_outs)
947 for (i = 0; i < cfg->line_outs; i++) {
948 hda_nid_t nid = cfg->line_out_pins[i];
949 if (!is_jack_detectable(codec, nid))
950 continue;
951 snd_printdd("realtek: Enable Line-Out "
952 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200953 snd_hda_jack_detect_enable(codec, nid,
954 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200955 spec->detect_lo = 1;
956 }
957 spec->automute_lo_possible = spec->detect_hp;
958 }
959
960 spec->automute_speaker_possible = cfg->speaker_outs &&
961 (spec->detect_hp || spec->detect_lo);
962
963 spec->automute_lo = spec->automute_lo_possible;
964 spec->automute_speaker = spec->automute_speaker_possible;
965
966 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200967 /* create a control for automute mode */
968 alc_add_automute_mode_enum(codec);
969 spec->unsol_event = alc_sku_unsol_event;
970 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200971}
972
Takashi Iwai1d045db2011-07-07 18:23:21 +0200973/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200974static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
975{
976 int i;
977 for (i = 0; i < nums; i++)
978 if (list[i] == nid)
979 return i;
980 return -1;
981}
982
Takashi Iwai1d045db2011-07-07 18:23:21 +0200983/* check whether dynamic ADC-switching is available */
984static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
985{
986 struct alc_spec *spec = codec->spec;
987 struct hda_input_mux *imux = &spec->private_imux[0];
988 int i, n, idx;
989 hda_nid_t cap, pin;
990
991 if (imux != spec->input_mux) /* no dynamic imux? */
992 return false;
993
994 for (n = 0; n < spec->num_adc_nids; n++) {
995 cap = spec->private_capsrc_nids[n];
996 for (i = 0; i < imux->num_items; i++) {
997 pin = spec->imux_pins[i];
998 if (!pin)
999 return false;
1000 if (get_connection_index(codec, cap, pin) < 0)
1001 break;
1002 }
1003 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001004 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001005 }
1006
1007 for (i = 0; i < imux->num_items; i++) {
1008 pin = spec->imux_pins[i];
1009 for (n = 0; n < spec->num_adc_nids; n++) {
1010 cap = spec->private_capsrc_nids[n];
1011 idx = get_connection_index(codec, cap, pin);
1012 if (idx >= 0) {
1013 imux->items[i].index = idx;
1014 spec->dyn_adc_idx[i] = n;
1015 break;
1016 }
1017 }
1018 }
1019
1020 snd_printdd("realtek: enabling ADC switching\n");
1021 spec->dyn_adc_switch = 1;
1022 return true;
1023}
Takashi Iwai21268962011-07-07 15:01:13 +02001024
1025/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1026static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1027{
1028 struct alc_spec *spec = codec->spec;
1029 struct hda_input_mux *imux;
1030 static char * const texts[3] = {
1031 "Mic", "Internal Mic", "Dock Mic"
1032 };
1033 int i;
1034
1035 if (!spec->auto_mic)
1036 return false;
1037 imux = &spec->private_imux[0];
1038 if (spec->input_mux == imux)
1039 return true;
1040 spec->imux_pins[0] = spec->ext_mic_pin;
1041 spec->imux_pins[1] = spec->int_mic_pin;
1042 spec->imux_pins[2] = spec->dock_mic_pin;
1043 for (i = 0; i < 3; i++) {
1044 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001045 if (spec->imux_pins[i]) {
1046 hda_nid_t pin = spec->imux_pins[i];
1047 int c;
1048 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001049 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001050 int idx = get_connection_index(codec, cap, pin);
1051 if (idx >= 0) {
1052 imux->items[i].index = idx;
1053 break;
1054 }
1055 }
Takashi Iwai21268962011-07-07 15:01:13 +02001056 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001057 }
Takashi Iwai21268962011-07-07 15:01:13 +02001058 }
1059 spec->num_mux_defs = 1;
1060 spec->input_mux = imux;
1061 return true;
1062}
1063
1064/* check whether all auto-mic pins are valid; setup indices if OK */
1065static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1066{
1067 struct alc_spec *spec = codec->spec;
1068 const struct hda_input_mux *imux;
1069
1070 if (!spec->auto_mic)
1071 return false;
1072 if (spec->auto_mic_valid_imux)
1073 return true; /* already checked */
1074
1075 /* fill up imux indices */
1076 if (!alc_check_dyn_adc_switch(codec)) {
1077 spec->auto_mic = 0;
1078 return false;
1079 }
1080
1081 imux = spec->input_mux;
1082 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1083 spec->imux_pins, imux->num_items);
1084 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1085 spec->imux_pins, imux->num_items);
1086 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1087 spec->imux_pins, imux->num_items);
1088 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1089 spec->auto_mic = 0;
1090 return false; /* no corresponding imux */
1091 }
1092
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001093 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001094 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001095 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1096 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001097
1098 spec->auto_mic_valid_imux = 1;
1099 spec->auto_mic = 1;
1100 return true;
1101}
1102
Takashi Iwai1d045db2011-07-07 18:23:21 +02001103/*
1104 * Check the availability of auto-mic switch;
1105 * Set up if really supported
1106 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001107static void alc_init_auto_mic(struct hda_codec *codec)
1108{
1109 struct alc_spec *spec = codec->spec;
1110 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001111 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001112 int i;
1113
Takashi Iwai24de1832011-11-07 17:13:39 +01001114 if (spec->shared_mic_hp)
1115 return; /* no auto-mic for the shared I/O */
1116
Takashi Iwai21268962011-07-07 15:01:13 +02001117 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1118
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001119 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001120 for (i = 0; i < cfg->num_inputs; i++) {
1121 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001122 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001123 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001124 switch (snd_hda_get_input_pin_attr(defcfg)) {
1125 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001126 if (fixed)
1127 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001128 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1129 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001130 fixed = nid;
1131 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001132 case INPUT_PIN_ATTR_UNUSED:
1133 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001134 case INPUT_PIN_ATTR_DOCK:
1135 if (dock)
1136 return; /* already occupied */
1137 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1138 return; /* invalid type */
1139 dock = nid;
1140 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001141 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001142 if (ext)
1143 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001144 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1145 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001146 ext = nid;
1147 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001148 }
1149 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001150 if (!ext && dock) {
1151 ext = dock;
1152 dock = 0;
1153 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001154 if (!ext || !fixed)
1155 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001156 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001157 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001158 if (dock && !is_jack_detectable(codec, dock))
1159 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001160
1161 /* check imux indices */
1162 spec->ext_mic_pin = ext;
1163 spec->int_mic_pin = fixed;
1164 spec->dock_mic_pin = dock;
1165
1166 spec->auto_mic = 1;
1167 if (!alc_auto_mic_check_imux(codec))
1168 return;
1169
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001170 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1171 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001172 spec->unsol_event = alc_sku_unsol_event;
1173}
1174
Takashi Iwai1d045db2011-07-07 18:23:21 +02001175/* check the availabilities of auto-mute and auto-mic switches */
1176static void alc_auto_check_switches(struct hda_codec *codec)
1177{
David Henningsson42cf0d02011-09-20 12:04:56 +02001178 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001179 alc_init_auto_mic(codec);
1180}
1181
1182/*
1183 * Realtek SSID verification
1184 */
1185
David Henningsson90622912010-10-14 14:50:18 +02001186/* Could be any non-zero and even value. When used as fixup, tells
1187 * the driver to ignore any present sku defines.
1188 */
1189#define ALC_FIXUP_SKU_IGNORE (2)
1190
Kailang Yangda00c242010-03-19 11:23:45 +01001191static int alc_auto_parse_customize_define(struct hda_codec *codec)
1192{
1193 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001194 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001195 struct alc_spec *spec = codec->spec;
1196
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001197 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1198
David Henningsson90622912010-10-14 14:50:18 +02001199 if (spec->cdefine.fixup) {
1200 ass = spec->cdefine.sku_cfg;
1201 if (ass == ALC_FIXUP_SKU_IGNORE)
1202 return -1;
1203 goto do_sku;
1204 }
1205
Kailang Yangda00c242010-03-19 11:23:45 +01001206 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001207 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001208 goto do_sku;
1209
1210 nid = 0x1d;
1211 if (codec->vendor_id == 0x10ec0260)
1212 nid = 0x17;
1213 ass = snd_hda_codec_get_pincfg(codec, nid);
1214
1215 if (!(ass & 1)) {
1216 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1217 codec->chip_name, ass);
1218 return -1;
1219 }
1220
1221 /* check sum */
1222 tmp = 0;
1223 for (i = 1; i < 16; i++) {
1224 if ((ass >> i) & 1)
1225 tmp++;
1226 }
1227 if (((ass >> 16) & 0xf) != tmp)
1228 return -1;
1229
1230 spec->cdefine.port_connectivity = ass >> 30;
1231 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1232 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1233 spec->cdefine.customization = ass >> 8;
1234do_sku:
1235 spec->cdefine.sku_cfg = ass;
1236 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1237 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1238 spec->cdefine.swap = (ass & 0x2) >> 1;
1239 spec->cdefine.override = ass & 0x1;
1240
1241 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1242 nid, spec->cdefine.sku_cfg);
1243 snd_printd("SKU: port_connectivity=0x%x\n",
1244 spec->cdefine.port_connectivity);
1245 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1246 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1247 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1248 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1249 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1250 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1251 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1252
1253 return 0;
1254}
1255
Takashi Iwai1d045db2011-07-07 18:23:21 +02001256/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001257static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1258{
Takashi Iwai21268962011-07-07 15:01:13 +02001259 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001260}
1261
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001262/* check subsystem ID and set up device-specific initialization;
1263 * return 1 if initialized, 0 if invalid SSID
1264 */
1265/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1266 * 31 ~ 16 : Manufacture ID
1267 * 15 ~ 8 : SKU ID
1268 * 7 ~ 0 : Assembly ID
1269 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1270 */
1271static int alc_subsystem_id(struct hda_codec *codec,
1272 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001273 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001274{
1275 unsigned int ass, tmp, i;
1276 unsigned nid;
1277 struct alc_spec *spec = codec->spec;
1278
David Henningsson90622912010-10-14 14:50:18 +02001279 if (spec->cdefine.fixup) {
1280 ass = spec->cdefine.sku_cfg;
1281 if (ass == ALC_FIXUP_SKU_IGNORE)
1282 return 0;
1283 goto do_sku;
1284 }
1285
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001286 ass = codec->subsystem_id & 0xffff;
1287 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1288 goto do_sku;
1289
1290 /* invalid SSID, check the special NID pin defcfg instead */
1291 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001292 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001293 * 29~21 : reserve
1294 * 20 : PCBEEP input
1295 * 19~16 : Check sum (15:1)
1296 * 15~1 : Custom
1297 * 0 : override
1298 */
1299 nid = 0x1d;
1300 if (codec->vendor_id == 0x10ec0260)
1301 nid = 0x17;
1302 ass = snd_hda_codec_get_pincfg(codec, nid);
1303 snd_printd("realtek: No valid SSID, "
1304 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001305 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001306 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001307 return 0;
1308 if ((ass >> 30) != 1) /* no physical connection */
1309 return 0;
1310
1311 /* check sum */
1312 tmp = 0;
1313 for (i = 1; i < 16; i++) {
1314 if ((ass >> i) & 1)
1315 tmp++;
1316 }
1317 if (((ass >> 16) & 0xf) != tmp)
1318 return 0;
1319do_sku:
1320 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1321 ass & 0xffff, codec->vendor_id);
1322 /*
1323 * 0 : override
1324 * 1 : Swap Jack
1325 * 2 : 0 --> Desktop, 1 --> Laptop
1326 * 3~5 : External Amplifier control
1327 * 7~6 : Reserved
1328 */
1329 tmp = (ass & 0x38) >> 3; /* external Amp control */
1330 switch (tmp) {
1331 case 1:
1332 spec->init_amp = ALC_INIT_GPIO1;
1333 break;
1334 case 3:
1335 spec->init_amp = ALC_INIT_GPIO2;
1336 break;
1337 case 7:
1338 spec->init_amp = ALC_INIT_GPIO3;
1339 break;
1340 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001341 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001342 spec->init_amp = ALC_INIT_DEFAULT;
1343 break;
1344 }
1345
1346 /* is laptop or Desktop and enable the function "Mute internal speaker
1347 * when the external headphone out jack is plugged"
1348 */
1349 if (!(ass & 0x8000))
1350 return 1;
1351 /*
1352 * 10~8 : Jack location
1353 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1354 * 14~13: Resvered
1355 * 15 : 1 --> enable the function "Mute internal speaker
1356 * when the external headphone out jack is plugged"
1357 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001358 if (!spec->autocfg.hp_pins[0] &&
1359 !(spec->autocfg.line_out_pins[0] &&
1360 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001361 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001362 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1363 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001364 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001365 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001366 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001367 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001368 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001369 else if (tmp == 3)
1370 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001371 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001372 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001373 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1374 spec->autocfg.line_outs))
1375 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001376 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001377 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001378 return 1;
1379}
Kailang Yangea1fb292008-08-26 12:58:38 +02001380
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001381/* Check the validity of ALC subsystem-id
1382 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1383static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001384{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001385 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001386 struct alc_spec *spec = codec->spec;
1387 snd_printd("realtek: "
1388 "Enable default setup for auto mode as fallback\n");
1389 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001390 }
Takashi Iwai21268962011-07-07 15:01:13 +02001391}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001392
Takashi Iwai41e41f12005-06-08 14:48:49 +02001393/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001394 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001395 */
1396
1397struct alc_pincfg {
1398 hda_nid_t nid;
1399 u32 val;
1400};
1401
Todd Broche1eb5f12010-12-06 11:19:51 -08001402struct alc_model_fixup {
1403 const int id;
1404 const char *name;
1405};
1406
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001407struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001408 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001409 bool chained;
1410 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001411 union {
1412 unsigned int sku;
1413 const struct alc_pincfg *pins;
1414 const struct hda_verb *verbs;
1415 void (*func)(struct hda_codec *codec,
1416 const struct alc_fixup *fix,
1417 int action);
1418 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001419};
1420
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001421enum {
1422 ALC_FIXUP_INVALID,
1423 ALC_FIXUP_SKU,
1424 ALC_FIXUP_PINS,
1425 ALC_FIXUP_VERBS,
1426 ALC_FIXUP_FUNC,
1427};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001428
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001429enum {
1430 ALC_FIXUP_ACT_PRE_PROBE,
1431 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001432 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001433};
1434
1435static void alc_apply_fixup(struct hda_codec *codec, int action)
1436{
1437 struct alc_spec *spec = codec->spec;
1438 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001439#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001440 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001441#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001442 int depth = 0;
1443
1444 if (!spec->fixup_list)
1445 return;
1446
1447 while (id >= 0) {
1448 const struct alc_fixup *fix = spec->fixup_list + id;
1449 const struct alc_pincfg *cfg;
1450
1451 switch (fix->type) {
1452 case ALC_FIXUP_SKU:
1453 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001454 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001455 snd_printdd(KERN_INFO "hda_codec: %s: "
1456 "Apply sku override for %s\n",
1457 codec->chip_name, modelname);
1458 spec->cdefine.sku_cfg = fix->v.sku;
1459 spec->cdefine.fixup = 1;
1460 break;
1461 case ALC_FIXUP_PINS:
1462 cfg = fix->v.pins;
1463 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1464 break;
1465 snd_printdd(KERN_INFO "hda_codec: %s: "
1466 "Apply pincfg for %s\n",
1467 codec->chip_name, modelname);
1468 for (; cfg->nid; cfg++)
1469 snd_hda_codec_set_pincfg(codec, cfg->nid,
1470 cfg->val);
1471 break;
1472 case ALC_FIXUP_VERBS:
1473 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1474 break;
1475 snd_printdd(KERN_INFO "hda_codec: %s: "
1476 "Apply fix-verbs for %s\n",
1477 codec->chip_name, modelname);
1478 add_verb(codec->spec, fix->v.verbs);
1479 break;
1480 case ALC_FIXUP_FUNC:
1481 if (!fix->v.func)
1482 break;
1483 snd_printdd(KERN_INFO "hda_codec: %s: "
1484 "Apply fix-func for %s\n",
1485 codec->chip_name, modelname);
1486 fix->v.func(codec, fix, action);
1487 break;
1488 default:
1489 snd_printk(KERN_ERR "hda_codec: %s: "
1490 "Invalid fixup type %d\n",
1491 codec->chip_name, fix->type);
1492 break;
1493 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001494 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001495 break;
1496 if (++depth > 10)
1497 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001498 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001499 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001500}
1501
Todd Broche1eb5f12010-12-06 11:19:51 -08001502static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001503 const struct alc_model_fixup *models,
1504 const struct snd_pci_quirk *quirk,
1505 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001506{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001507 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001508 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001509 int id = -1;
1510 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001511
Todd Broche1eb5f12010-12-06 11:19:51 -08001512 if (codec->modelname && models) {
1513 while (models->name) {
1514 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001515 id = models->id;
1516 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001517 break;
1518 }
1519 models++;
1520 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001521 }
1522 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001523 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1524 if (q) {
1525 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001526#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001527 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001528#endif
1529 }
1530 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001531 if (id < 0) {
1532 for (q = quirk; q->subvendor; q++) {
1533 unsigned int vendorid =
1534 q->subdevice | (q->subvendor << 16);
1535 if (vendorid == codec->subsystem_id) {
1536 id = q->value;
1537#ifdef CONFIG_SND_DEBUG_VERBOSE
1538 name = q->name;
1539#endif
1540 break;
1541 }
1542 }
1543 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001544
1545 spec->fixup_id = id;
1546 if (id >= 0) {
1547 spec->fixup_list = fixlist;
1548 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001549 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001550}
1551
Takashi Iwai1d045db2011-07-07 18:23:21 +02001552/*
1553 * COEF access helper functions
1554 */
Kailang Yang274693f2009-12-03 10:07:50 +01001555static int alc_read_coef_idx(struct hda_codec *codec,
1556 unsigned int coef_idx)
1557{
1558 unsigned int val;
1559 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1560 coef_idx);
1561 val = snd_hda_codec_read(codec, 0x20, 0,
1562 AC_VERB_GET_PROC_COEF, 0);
1563 return val;
1564}
1565
Kailang Yang977ddd62010-09-15 10:02:29 +02001566static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1567 unsigned int coef_val)
1568{
1569 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1570 coef_idx);
1571 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1572 coef_val);
1573}
1574
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001575/* a special bypass for COEF 0; read the cached value at the second time */
1576static unsigned int alc_get_coef0(struct hda_codec *codec)
1577{
1578 struct alc_spec *spec = codec->spec;
1579 if (!spec->coef0)
1580 spec->coef0 = alc_read_coef_idx(codec, 0);
1581 return spec->coef0;
1582}
1583
Takashi Iwai1d045db2011-07-07 18:23:21 +02001584/*
1585 * Digital I/O handling
1586 */
1587
Takashi Iwai757899a2010-07-30 10:48:14 +02001588/* set right pin controls for digital I/O */
1589static void alc_auto_init_digital(struct hda_codec *codec)
1590{
1591 struct alc_spec *spec = codec->spec;
1592 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001593 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001594
1595 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1596 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001597 if (!pin)
1598 continue;
1599 snd_hda_codec_write(codec, pin, 0,
1600 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1601 if (!i)
1602 dac = spec->multiout.dig_out_nid;
1603 else
1604 dac = spec->slave_dig_outs[i - 1];
1605 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1606 continue;
1607 snd_hda_codec_write(codec, dac, 0,
1608 AC_VERB_SET_AMP_GAIN_MUTE,
1609 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001610 }
1611 pin = spec->autocfg.dig_in_pin;
1612 if (pin)
1613 snd_hda_codec_write(codec, pin, 0,
1614 AC_VERB_SET_PIN_WIDGET_CONTROL,
1615 PIN_IN);
1616}
1617
1618/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1619static void alc_auto_parse_digital(struct hda_codec *codec)
1620{
1621 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001622 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001623 hda_nid_t dig_nid;
1624
1625 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001626 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001627 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001628 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001629 err = snd_hda_get_connections(codec,
1630 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001631 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001632 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001633 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001634 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001635 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001636 spec->multiout.dig_out_nid = dig_nid;
1637 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1638 } else {
1639 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001640 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001641 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001642 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001643 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001644 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001645 }
1646
1647 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001648 dig_nid = codec->start_nid;
1649 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1650 unsigned int wcaps = get_wcaps(codec, dig_nid);
1651 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1652 continue;
1653 if (!(wcaps & AC_WCAP_DIGITAL))
1654 continue;
1655 if (!(wcaps & AC_WCAP_CONN_LIST))
1656 continue;
1657 err = get_connection_index(codec, dig_nid,
1658 spec->autocfg.dig_in_pin);
1659 if (err >= 0) {
1660 spec->dig_in_nid = dig_nid;
1661 break;
1662 }
1663 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001664 }
1665}
1666
Takashi Iwaif95474e2007-07-10 00:47:43 +02001667/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001668 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001669 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001670static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1671 struct snd_ctl_elem_info *uinfo)
1672{
1673 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1674 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001675 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001676 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001677
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001678 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001679 if (spec->vol_in_capsrc)
1680 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1681 else
1682 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1683 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001684 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001685 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001686 return err;
1687}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001689static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1690 unsigned int size, unsigned int __user *tlv)
1691{
1692 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1693 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001694 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001695 int err;
1696
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001697 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001698 if (spec->vol_in_capsrc)
1699 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1700 else
1701 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1702 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001703 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001704 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001705 return err;
1706}
1707
1708typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1709 struct snd_ctl_elem_value *ucontrol);
1710
1711static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1712 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001713 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001714{
1715 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1716 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001717 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001718
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001719 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001720 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001721 for (i = 0; i < spec->num_adc_nids; i++) {
1722 kcontrol->private_value =
1723 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1724 3, 0, HDA_INPUT);
1725 err = func(kcontrol, ucontrol);
1726 if (err < 0)
1727 goto error;
1728 }
1729 } else {
1730 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001731 if (spec->vol_in_capsrc)
1732 kcontrol->private_value =
1733 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1734 3, 0, HDA_OUTPUT);
1735 else
1736 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001737 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1738 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001739 err = func(kcontrol, ucontrol);
1740 }
1741 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001742 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001743 return err;
1744}
1745
1746static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1747 struct snd_ctl_elem_value *ucontrol)
1748{
1749 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001750 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001751}
1752
1753static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1754 struct snd_ctl_elem_value *ucontrol)
1755{
1756 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001757 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001758}
1759
1760/* capture mixer elements */
1761#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1762
1763static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1764 struct snd_ctl_elem_value *ucontrol)
1765{
1766 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001767 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001768}
1769
1770static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1771 struct snd_ctl_elem_value *ucontrol)
1772{
1773 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001774 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001775}
1776
Takashi Iwaia23b6882009-03-23 15:21:36 +01001777#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001778 { \
1779 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1780 .name = "Capture Switch", \
1781 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1782 .count = num, \
1783 .info = alc_cap_sw_info, \
1784 .get = alc_cap_sw_get, \
1785 .put = alc_cap_sw_put, \
1786 }, \
1787 { \
1788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1789 .name = "Capture Volume", \
1790 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1791 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1792 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1793 .count = num, \
1794 .info = alc_cap_vol_info, \
1795 .get = alc_cap_vol_get, \
1796 .put = alc_cap_vol_put, \
1797 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001798 }
1799
1800#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001801 { \
1802 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1803 /* .name = "Capture Source", */ \
1804 .name = "Input Source", \
1805 .count = num, \
1806 .info = alc_mux_enum_info, \
1807 .get = alc_mux_enum_get, \
1808 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001809 }
1810
1811#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001812static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001813 _DEFINE_CAPMIX(num), \
1814 _DEFINE_CAPSRC(num), \
1815 { } /* end */ \
1816}
1817
1818#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001819static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001820 _DEFINE_CAPMIX(num), \
1821 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001822}
1823
1824/* up to three ADCs */
1825DEFINE_CAPMIX(1);
1826DEFINE_CAPMIX(2);
1827DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001828DEFINE_CAPMIX_NOSRC(1);
1829DEFINE_CAPMIX_NOSRC(2);
1830DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001831
1832/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001833 * virtual master controls
1834 */
1835
1836/*
1837 * slave controls for virtual master
1838 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001839static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001840 "Front Playback Volume",
1841 "Surround Playback Volume",
1842 "Center Playback Volume",
1843 "LFE Playback Volume",
1844 "Side Playback Volume",
1845 "Headphone Playback Volume",
1846 "Speaker Playback Volume",
1847 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001848 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001849 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001850 NULL,
1851};
1852
Takashi Iwaiea734962011-01-17 11:29:34 +01001853static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001854 "Front Playback Switch",
1855 "Surround Playback Switch",
1856 "Center Playback Switch",
1857 "LFE Playback Switch",
1858 "Side Playback Switch",
1859 "Headphone Playback Switch",
1860 "Speaker Playback Switch",
1861 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001862 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001863 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001864 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001865 NULL,
1866};
1867
1868/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001869 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001871
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001872#define NID_MAPPING (-1)
1873
1874#define SUBDEV_SPEAKER_ (0 << 6)
1875#define SUBDEV_HP_ (1 << 6)
1876#define SUBDEV_LINE_ (2 << 6)
1877#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1878#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1879#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1880
Takashi Iwai603c4012008-07-30 15:01:44 +02001881static void alc_free_kctls(struct hda_codec *codec);
1882
Takashi Iwai67d634c2009-11-16 15:35:59 +01001883#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001884/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001885static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001886 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001887 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001888 { } /* end */
1889};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001890#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001891
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001892static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893{
1894 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001895 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001896 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001897 int i, j, err;
1898 unsigned int u;
1899 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
1901 for (i = 0; i < spec->num_mixers; i++) {
1902 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1903 if (err < 0)
1904 return err;
1905 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001906 if (spec->cap_mixer) {
1907 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1908 if (err < 0)
1909 return err;
1910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001912 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001913 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001914 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 if (err < 0)
1916 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001917 if (!spec->no_analog) {
1918 err = snd_hda_create_spdif_share_sw(codec,
1919 &spec->multiout);
1920 if (err < 0)
1921 return err;
1922 spec->multiout.share_spdif = 1;
1923 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 }
1925 if (spec->dig_in_nid) {
1926 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1927 if (err < 0)
1928 return err;
1929 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001930
Takashi Iwai67d634c2009-11-16 15:35:59 +01001931#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001932 /* create beep controls if needed */
1933 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001934 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001935 for (knew = alc_beep_mixer; knew->name; knew++) {
1936 struct snd_kcontrol *kctl;
1937 kctl = snd_ctl_new1(knew, codec);
1938 if (!kctl)
1939 return -ENOMEM;
1940 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001941 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001942 if (err < 0)
1943 return err;
1944 }
1945 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001946#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001947
Takashi Iwai2134ea42008-01-10 16:53:55 +01001948 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001949 if (!spec->no_analog &&
1950 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001951 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001952 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001953 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001954 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001955 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001956 if (err < 0)
1957 return err;
1958 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001959 if (!spec->no_analog &&
1960 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001961 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1962 NULL, alc_slave_sws);
1963 if (err < 0)
1964 return err;
1965 }
1966
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001967 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001968 if (spec->capsrc_nids || spec->adc_nids) {
1969 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1970 if (!kctl)
1971 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1972 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001973 err = snd_hda_add_nid(codec, kctl, i,
1974 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001975 if (err < 0)
1976 return err;
1977 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001978 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001979 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001980 const char *kname = kctl ? kctl->id.name : NULL;
1981 for (knew = spec->cap_mixer; knew->name; knew++) {
1982 if (kname && strcmp(knew->name, kname) == 0)
1983 continue;
1984 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1985 for (i = 0; kctl && i < kctl->count; i++) {
1986 err = snd_hda_add_nid(codec, kctl, i,
1987 spec->adc_nids[i]);
1988 if (err < 0)
1989 return err;
1990 }
1991 }
1992 }
1993
1994 /* other nid->control mapping */
1995 for (i = 0; i < spec->num_mixers; i++) {
1996 for (knew = spec->mixers[i]; knew->name; knew++) {
1997 if (knew->iface != NID_MAPPING)
1998 continue;
1999 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2000 if (kctl == NULL)
2001 continue;
2002 u = knew->subdevice;
2003 for (j = 0; j < 4; j++, u >>= 8) {
2004 nid = u & 0x3f;
2005 if (nid == 0)
2006 continue;
2007 switch (u & 0xc0) {
2008 case SUBDEV_SPEAKER_:
2009 nid = spec->autocfg.speaker_pins[nid];
2010 break;
2011 case SUBDEV_LINE_:
2012 nid = spec->autocfg.line_out_pins[nid];
2013 break;
2014 case SUBDEV_HP_:
2015 nid = spec->autocfg.hp_pins[nid];
2016 break;
2017 default:
2018 continue;
2019 }
2020 err = snd_hda_add_nid(codec, kctl, 0, nid);
2021 if (err < 0)
2022 return err;
2023 }
2024 u = knew->private_value;
2025 for (j = 0; j < 4; j++, u >>= 8) {
2026 nid = u & 0xff;
2027 if (nid == 0)
2028 continue;
2029 err = snd_hda_add_nid(codec, kctl, 0, nid);
2030 if (err < 0)
2031 return err;
2032 }
2033 }
2034 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002035
2036 alc_free_kctls(codec); /* no longer needed */
2037
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002038 return 0;
2039}
2040
2041static int alc_build_controls(struct hda_codec *codec)
2042{
2043 struct alc_spec *spec = codec->spec;
2044 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002045 if (err < 0)
2046 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002047 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048}
2049
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002050
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002052 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002053 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002054
Takashi Iwai584c0c42011-03-10 12:51:11 +01002055static void alc_init_special_input_src(struct hda_codec *codec);
2056
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057static int alc_init(struct hda_codec *codec)
2058{
2059 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002060 unsigned int i;
2061
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002062 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002063 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002064
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002065 for (i = 0; i < spec->num_init_verbs; i++)
2066 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002067 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002068
2069 if (spec->init_hook)
2070 spec->init_hook(codec);
2071
Takashi Iwai58701122011-01-13 15:41:45 +01002072 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2073
Takashi Iwai01a61e12011-10-28 00:03:22 +02002074 snd_hda_jack_report_sync(codec);
2075
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002076 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 return 0;
2078}
2079
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002080static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2081{
2082 struct alc_spec *spec = codec->spec;
2083
2084 if (spec->unsol_event)
2085 spec->unsol_event(codec, res);
2086}
2087
Takashi Iwaicb53c622007-08-10 17:21:45 +02002088#ifdef CONFIG_SND_HDA_POWER_SAVE
2089static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2090{
2091 struct alc_spec *spec = codec->spec;
2092 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2093}
2094#endif
2095
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096/*
2097 * Analog playback callbacks
2098 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002099static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002101 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
2103 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002104 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2105 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002108static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct hda_codec *codec,
2110 unsigned int stream_tag,
2111 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002112 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
2114 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002115 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2116 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117}
2118
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002119static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002121 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
2123 struct alc_spec *spec = codec->spec;
2124 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2125}
2126
2127/*
2128 * Digital out
2129 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002130static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002132 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133{
2134 struct alc_spec *spec = codec->spec;
2135 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2136}
2137
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002138static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002139 struct hda_codec *codec,
2140 unsigned int stream_tag,
2141 unsigned int format,
2142 struct snd_pcm_substream *substream)
2143{
2144 struct alc_spec *spec = codec->spec;
2145 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2146 stream_tag, format, substream);
2147}
2148
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002149static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002150 struct hda_codec *codec,
2151 struct snd_pcm_substream *substream)
2152{
2153 struct alc_spec *spec = codec->spec;
2154 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2155}
2156
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002157static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002159 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160{
2161 struct alc_spec *spec = codec->spec;
2162 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2163}
2164
2165/*
2166 * Analog capture
2167 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002168static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 struct hda_codec *codec,
2170 unsigned int stream_tag,
2171 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002172 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173{
2174 struct alc_spec *spec = codec->spec;
2175
Takashi Iwai63300792008-01-24 15:31:36 +01002176 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 stream_tag, 0, format);
2178 return 0;
2179}
2180
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002181static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002183 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184{
2185 struct alc_spec *spec = codec->spec;
2186
Takashi Iwai888afa12008-03-18 09:57:50 +01002187 snd_hda_codec_cleanup_stream(codec,
2188 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 return 0;
2190}
2191
Takashi Iwai840b64c2010-07-13 22:49:01 +02002192/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002193static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002194 struct hda_codec *codec,
2195 unsigned int stream_tag,
2196 unsigned int format,
2197 struct snd_pcm_substream *substream)
2198{
2199 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002200 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002201 spec->cur_adc_stream_tag = stream_tag;
2202 spec->cur_adc_format = format;
2203 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2204 return 0;
2205}
2206
Takashi Iwai21268962011-07-07 15:01:13 +02002207static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002208 struct hda_codec *codec,
2209 struct snd_pcm_substream *substream)
2210{
2211 struct alc_spec *spec = codec->spec;
2212 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2213 spec->cur_adc = 0;
2214 return 0;
2215}
2216
Takashi Iwai21268962011-07-07 15:01:13 +02002217static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002218 .substreams = 1,
2219 .channels_min = 2,
2220 .channels_max = 2,
2221 .nid = 0, /* fill later */
2222 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002223 .prepare = dyn_adc_capture_pcm_prepare,
2224 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002225 },
2226};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002227
2228/*
2229 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002230static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 .substreams = 1,
2232 .channels_min = 2,
2233 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002234 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002236 .open = alc_playback_pcm_open,
2237 .prepare = alc_playback_pcm_prepare,
2238 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 },
2240};
2241
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002242static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002243 .substreams = 1,
2244 .channels_min = 2,
2245 .channels_max = 2,
2246 /* NID is set in alc_build_pcms */
2247};
2248
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002249static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002250 .substreams = 1,
2251 .channels_min = 2,
2252 .channels_max = 2,
2253 /* NID is set in alc_build_pcms */
2254};
2255
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002256static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002257 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 .channels_min = 2,
2259 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002260 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002262 .prepare = alc_alt_capture_pcm_prepare,
2263 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 },
2265};
2266
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002267static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 .substreams = 1,
2269 .channels_min = 2,
2270 .channels_max = 2,
2271 /* NID is set in alc_build_pcms */
2272 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002273 .open = alc_dig_playback_pcm_open,
2274 .close = alc_dig_playback_pcm_close,
2275 .prepare = alc_dig_playback_pcm_prepare,
2276 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 },
2278};
2279
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002280static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 .substreams = 1,
2282 .channels_min = 2,
2283 .channels_max = 2,
2284 /* NID is set in alc_build_pcms */
2285};
2286
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002287/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002288static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002289 .substreams = 0,
2290 .channels_min = 0,
2291 .channels_max = 0,
2292};
2293
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294static int alc_build_pcms(struct hda_codec *codec)
2295{
2296 struct alc_spec *spec = codec->spec;
2297 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002298 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002299 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 int i;
2301
2302 codec->num_pcms = 1;
2303 codec->pcm_info = info;
2304
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002305 if (spec->no_analog)
2306 goto skip_analog;
2307
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002308 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2309 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002311
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002312 if (spec->multiout.dac_nids > 0) {
2313 p = spec->stream_analog_playback;
2314 if (!p)
2315 p = &alc_pcm_analog_playback;
2316 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002317 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2318 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002319 if (spec->adc_nids) {
2320 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002321 if (!p) {
2322 if (spec->dyn_adc_switch)
2323 p = &dyn_adc_pcm_analog_capture;
2324 else
2325 p = &alc_pcm_analog_capture;
2326 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002327 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002328 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2329 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330
Takashi Iwai4a471b72005-12-07 13:56:29 +01002331 if (spec->channel_mode) {
2332 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2333 for (i = 0; i < spec->num_channel_mode; i++) {
2334 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2335 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 }
2338 }
2339
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002340 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002341 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002343 snprintf(spec->stream_name_digital,
2344 sizeof(spec->stream_name_digital),
2345 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002346 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002347 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002348 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002350 if (spec->dig_out_type)
2351 info->pcm_type = spec->dig_out_type;
2352 else
2353 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002354 if (spec->multiout.dig_out_nid) {
2355 p = spec->stream_digital_playback;
2356 if (!p)
2357 p = &alc_pcm_digital_playback;
2358 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2360 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002361 if (spec->dig_in_nid) {
2362 p = spec->stream_digital_capture;
2363 if (!p)
2364 p = &alc_pcm_digital_capture;
2365 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2367 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002368 /* FIXME: do we need this for all Realtek codec models? */
2369 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 }
2371
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002372 if (spec->no_analog)
2373 return 0;
2374
Takashi Iwaie08a0072006-09-07 17:52:14 +02002375 /* If the use of more than one ADC is requested for the current
2376 * model, configure a second analog capture-only PCM.
2377 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002378 have_multi_adcs = (spec->num_adc_nids > 1) &&
2379 !spec->dyn_adc_switch && !spec->auto_mic &&
2380 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002381 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002382 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002383 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002384 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002385 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002386 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002387 p = spec->stream_analog_alt_playback;
2388 if (!p)
2389 p = &alc_pcm_analog_alt_playback;
2390 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002391 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2392 spec->alt_dac_nid;
2393 } else {
2394 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2395 alc_pcm_null_stream;
2396 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2397 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002398 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002399 p = spec->stream_analog_alt_capture;
2400 if (!p)
2401 p = &alc_pcm_analog_alt_capture;
2402 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002403 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2404 spec->adc_nids[1];
2405 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2406 spec->num_adc_nids - 1;
2407 } else {
2408 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2409 alc_pcm_null_stream;
2410 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002411 }
2412 }
2413
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 return 0;
2415}
2416
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002417static inline void alc_shutup(struct hda_codec *codec)
2418{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002419 struct alc_spec *spec = codec->spec;
2420
2421 if (spec && spec->shutup)
2422 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002423 snd_hda_shutup_pins(codec);
2424}
2425
Takashi Iwai603c4012008-07-30 15:01:44 +02002426static void alc_free_kctls(struct hda_codec *codec)
2427{
2428 struct alc_spec *spec = codec->spec;
2429
2430 if (spec->kctls.list) {
2431 struct snd_kcontrol_new *kctl = spec->kctls.list;
2432 int i;
2433 for (i = 0; i < spec->kctls.used; i++)
2434 kfree(kctl[i].name);
2435 }
2436 snd_array_free(&spec->kctls);
2437}
2438
Takashi Iwai23c09b02011-08-19 09:05:35 +02002439static void alc_free_bind_ctls(struct hda_codec *codec)
2440{
2441 struct alc_spec *spec = codec->spec;
2442 if (spec->bind_ctls.list) {
2443 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2444 int i;
2445 for (i = 0; i < spec->bind_ctls.used; i++)
2446 kfree(ctl[i]);
2447 }
2448 snd_array_free(&spec->bind_ctls);
2449}
2450
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451static void alc_free(struct hda_codec *codec)
2452{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002453 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002454
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002455 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002456 return;
2457
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002458 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002459 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002460 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002461 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002462 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463}
2464
Hector Martinf5de24b2009-12-20 22:51:31 +01002465#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002466static void alc_power_eapd(struct hda_codec *codec)
2467{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002468 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002469}
2470
Hector Martinf5de24b2009-12-20 22:51:31 +01002471static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2472{
2473 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002474 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002475 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002476 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002477 return 0;
2478}
2479#endif
2480
Takashi Iwai2a439522011-07-26 09:52:50 +02002481#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002482static int alc_resume(struct hda_codec *codec)
2483{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002484 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002485 codec->patch_ops.init(codec);
2486 snd_hda_codec_resume_amp(codec);
2487 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002488 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002489 return 0;
2490}
Takashi Iwaie044c392008-10-27 16:56:24 +01002491#endif
2492
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493/*
2494 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002495static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 .build_controls = alc_build_controls,
2497 .build_pcms = alc_build_pcms,
2498 .init = alc_init,
2499 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002500 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002501#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002502 .resume = alc_resume,
2503#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002504#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002505 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002506 .check_power_status = alc_check_power_status,
2507#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002508 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509};
2510
Kailang Yangc027ddc2010-03-19 11:33:06 +01002511/* replace the codec chip_name with the given string */
2512static int alc_codec_rename(struct hda_codec *codec, const char *name)
2513{
2514 kfree(codec->chip_name);
2515 codec->chip_name = kstrdup(name, GFP_KERNEL);
2516 if (!codec->chip_name) {
2517 alc_free(codec);
2518 return -ENOMEM;
2519 }
2520 return 0;
2521}
2522
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002523/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002524 * Rename codecs appropriately from COEF value
2525 */
2526struct alc_codec_rename_table {
2527 unsigned int vendor_id;
2528 unsigned short coef_mask;
2529 unsigned short coef_bits;
2530 const char *name;
2531};
2532
2533static struct alc_codec_rename_table rename_tbl[] = {
2534 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2535 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2536 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2537 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2538 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2539 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2540 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2541 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2542 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2543 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2544 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2545 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2546 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2547 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2548 { } /* terminator */
2549};
2550
2551static int alc_codec_rename_from_preset(struct hda_codec *codec)
2552{
2553 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002554
2555 for (p = rename_tbl; p->vendor_id; p++) {
2556 if (p->vendor_id != codec->vendor_id)
2557 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002558 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002559 return alc_codec_rename(codec, p->name);
2560 }
2561 return 0;
2562}
2563
2564/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002565 * Automatic parse of I/O pins from the BIOS configuration
2566 */
2567
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002568enum {
2569 ALC_CTL_WIDGET_VOL,
2570 ALC_CTL_WIDGET_MUTE,
2571 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002572 ALC_CTL_BIND_VOL,
2573 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002574};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002575static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002576 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2577 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002578 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002579 HDA_BIND_VOL(NULL, 0),
2580 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002581};
2582
2583/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002584static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002585 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002586{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002587 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002588
Takashi Iwaice764ab2011-04-27 16:35:23 +02002589 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002590 if (!knew)
2591 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002592 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002593 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002594 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002595 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002596 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002597 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002598 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002599 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002600 return 0;
2601}
2602
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002603static int add_control_with_pfx(struct alc_spec *spec, int type,
2604 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002605 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002606{
2607 char name[32];
2608 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002609 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002610}
2611
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002612#define add_pb_vol_ctrl(spec, type, pfx, val) \
2613 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2614#define add_pb_sw_ctrl(spec, type, pfx, val) \
2615 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2616#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2617 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2618#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2619 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002620
Takashi Iwai23c09b02011-08-19 09:05:35 +02002621static const char * const channel_name[4] = {
2622 "Front", "Surround", "CLFE", "Side"
2623};
2624
Takashi Iwai6843ca12011-06-24 11:03:58 +02002625static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2626 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002627{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002628 struct auto_pin_cfg *cfg = &spec->autocfg;
2629
Takashi Iwai6843ca12011-06-24 11:03:58 +02002630 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002631 if (cfg->line_outs == 1 && !spec->multi_ios &&
2632 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002633 return "Master";
2634
2635 switch (cfg->line_out_type) {
2636 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002637 if (cfg->line_outs == 1)
2638 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002639 if (cfg->line_outs == 2)
2640 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002641 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002642 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002643 /* for multi-io case, only the primary out */
2644 if (ch && spec->multi_ios)
2645 break;
2646 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002647 return "Headphone";
2648 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002649 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002650 return "PCM";
2651 break;
2652 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002653 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2654 return "PCM";
2655
2656 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002657}
2658
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002659/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002660static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002661 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002662 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002663{
Kailang Yangdf694da2005-12-05 19:42:22 +01002664 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002665
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002666 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002667 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2668 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002669 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002670 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002671 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2672 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002673 return err;
2674 return 0;
2675}
2676
Takashi Iwai05f5f472009-08-25 13:10:18 +02002677static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002678{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002679 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2680 return (pincap & AC_PINCAP_IN) != 0;
2681}
2682
Takashi Iwai1d045db2011-07-07 18:23:21 +02002683/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002684static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002685{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002686 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002687 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002688 hda_nid_t *adc_nids = spec->private_adc_nids;
2689 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2690 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002691 int i, nums = 0;
2692
Takashi Iwai24de1832011-11-07 17:13:39 +01002693 if (spec->shared_mic_hp)
2694 max_nums = 1; /* no multi streams with the shared HP/mic */
2695
Takashi Iwaib7821702011-07-06 15:12:46 +02002696 nid = codec->start_nid;
2697 for (i = 0; i < codec->num_nodes; i++, nid++) {
2698 hda_nid_t src;
2699 const hda_nid_t *list;
2700 unsigned int caps = get_wcaps(codec, nid);
2701 int type = get_wcaps_type(caps);
2702
2703 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2704 continue;
2705 adc_nids[nums] = nid;
2706 cap_nids[nums] = nid;
2707 src = nid;
2708 for (;;) {
2709 int n;
2710 type = get_wcaps_type(get_wcaps(codec, src));
2711 if (type == AC_WID_PIN)
2712 break;
2713 if (type == AC_WID_AUD_SEL) {
2714 cap_nids[nums] = src;
2715 break;
2716 }
2717 n = snd_hda_get_conn_list(codec, src, &list);
2718 if (n > 1) {
2719 cap_nids[nums] = src;
2720 break;
2721 } else if (n != 1)
2722 break;
2723 src = *list;
2724 }
2725 if (++nums >= max_nums)
2726 break;
2727 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002728 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002729 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002730 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002731 return nums;
2732}
2733
Takashi Iwai05f5f472009-08-25 13:10:18 +02002734/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002735static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002736{
2737 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002738 const struct auto_pin_cfg *cfg = &spec->autocfg;
2739 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002740 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002741 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002742 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002743 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002744
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002745 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002746 if (num_adcs < 0)
2747 return 0;
2748
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002749 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002750 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002751 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002752
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002753 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002754 if (!alc_is_input_pin(codec, pin))
2755 continue;
2756
David Henningsson5322bf22011-01-05 11:03:56 +01002757 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002758 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2759 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002760 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002761 type_idx++;
2762 else
2763 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002764 prev_label = label;
2765
Takashi Iwai05f5f472009-08-25 13:10:18 +02002766 if (mixer) {
2767 idx = get_connection_index(codec, mixer, pin);
2768 if (idx >= 0) {
2769 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002770 label, type_idx,
2771 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002772 if (err < 0)
2773 return err;
2774 }
2775 }
2776
Takashi Iwaib7821702011-07-06 15:12:46 +02002777 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002778 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002779 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002780 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002781 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002782 snd_hda_add_imux_item(imux, label, idx, NULL);
2783 break;
2784 }
2785 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002786 }
Takashi Iwai21268962011-07-07 15:01:13 +02002787
2788 spec->num_mux_defs = 1;
2789 spec->input_mux = imux;
2790
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002791 return 0;
2792}
2793
Takashi Iwai24de1832011-11-07 17:13:39 +01002794/* create a shared input with the headphone out */
2795static int alc_auto_create_shared_input(struct hda_codec *codec)
2796{
2797 struct alc_spec *spec = codec->spec;
2798 struct auto_pin_cfg *cfg = &spec->autocfg;
2799 unsigned int defcfg;
2800 hda_nid_t nid;
2801
2802 /* only one internal input pin? */
2803 if (cfg->num_inputs != 1)
2804 return 0;
2805 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2806 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2807 return 0;
2808
2809 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2810 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2811 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2812 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2813 else
2814 return 0; /* both not available */
2815
2816 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2817 return 0; /* no input */
2818
2819 cfg->inputs[1].pin = nid;
2820 cfg->inputs[1].type = AUTO_PIN_MIC;
2821 cfg->num_inputs = 2;
2822 spec->shared_mic_hp = 1;
2823 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2824 return 0;
2825}
2826
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002827static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2828 unsigned int pin_type)
2829{
2830 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2831 pin_type);
2832 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002833 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2834 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002835 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002836}
2837
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002838static int get_pin_type(int line_out_type)
2839{
2840 if (line_out_type == AUTO_PIN_HP_OUT)
2841 return PIN_HP;
2842 else
2843 return PIN_OUT;
2844}
2845
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002846static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002847{
2848 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002849 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002850 int i;
2851
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002852 for (i = 0; i < cfg->num_inputs; i++) {
2853 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002854 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002855 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002856 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002857 snd_hda_codec_write(codec, nid, 0,
2858 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002859 AMP_OUT_MUTE);
2860 }
2861 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002862
2863 /* mute all loopback inputs */
2864 if (spec->mixer_nid) {
2865 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2866 for (i = 0; i < nums; i++)
2867 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2868 AC_VERB_SET_AMP_GAIN_MUTE,
2869 AMP_IN_MUTE(i));
2870 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002871}
2872
Takashi Iwai7085ec12009-10-02 09:03:58 +02002873/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002874static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002875{
Takashi Iwai604401a2011-04-27 15:14:23 +02002876 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002877 int i, num;
2878
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002879 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2880 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002881 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2882 for (i = 0; i < num; i++) {
2883 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2884 return list[i];
2885 }
2886 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002887}
2888
Takashi Iwai604401a2011-04-27 15:14:23 +02002889/* go down to the selector widget before the mixer */
2890static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2891{
2892 hda_nid_t srcs[5];
2893 int num = snd_hda_get_connections(codec, pin, srcs,
2894 ARRAY_SIZE(srcs));
2895 if (num != 1 ||
2896 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2897 return pin;
2898 return srcs[0];
2899}
2900
Takashi Iwai7085ec12009-10-02 09:03:58 +02002901/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002902static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002903 hda_nid_t dac)
2904{
David Henningssoncc1c4522010-11-24 14:17:47 +01002905 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002906 int i, num;
2907
Takashi Iwai604401a2011-04-27 15:14:23 +02002908 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002909 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2910 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002911 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002912 return mix[i];
2913 }
2914 return 0;
2915}
2916
Takashi Iwaice764ab2011-04-27 16:35:23 +02002917/* select the connection from pin to DAC if needed */
2918static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2919 hda_nid_t dac)
2920{
2921 hda_nid_t mix[5];
2922 int i, num;
2923
2924 pin = alc_go_down_to_selector(codec, pin);
2925 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2926 if (num < 2)
2927 return 0;
2928 for (i = 0; i < num; i++) {
2929 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2930 snd_hda_codec_update_cache(codec, pin, 0,
2931 AC_VERB_SET_CONNECT_SEL, i);
2932 return 0;
2933 }
2934 }
2935 return 0;
2936}
2937
Takashi Iwai7085ec12009-10-02 09:03:58 +02002938/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002939static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002940{
2941 struct alc_spec *spec = codec->spec;
2942 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002943 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002944
Takashi Iwai604401a2011-04-27 15:14:23 +02002945 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002946 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002947 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002948 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002949 if (!nid)
2950 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002951 if (found_in_nid_list(nid, spec->multiout.dac_nids,
Takashi Iwai0a34b422011-12-07 17:20:30 +01002952 ARRAY_SIZE(spec->private_dac_nids)))
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002953 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002954 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2955 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2956 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002957 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2958 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2959 continue;
2960 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002961 }
2962 return 0;
2963}
2964
Takashi Iwai07b18f62011-11-10 15:42:54 +01002965/* check whether the DAC is reachable from the pin */
2966static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2967 hda_nid_t pin, hda_nid_t dac)
2968{
2969 hda_nid_t srcs[5];
2970 int i, num;
2971
2972 pin = alc_go_down_to_selector(codec, pin);
2973 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2974 for (i = 0; i < num; i++) {
2975 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2976 if (nid == dac)
2977 return true;
2978 }
2979 return false;
2980}
2981
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002982static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2983{
2984 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2985 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2986 return alc_auto_look_for_dac(codec, pin);
2987 return 0;
2988}
2989
Takashi Iwai0a34b422011-12-07 17:20:30 +01002990/* return 0 if no possible DAC is found, 1 if one or more found */
Takashi Iwaic2674682011-08-24 17:57:44 +02002991static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2992 const hda_nid_t *pins, hda_nid_t *dacs)
2993{
2994 int i;
2995
2996 if (num_outs && !dacs[0]) {
2997 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2998 if (!dacs[0])
2999 return 0;
3000 }
3001
3002 for (i = 1; i < num_outs; i++)
3003 dacs[i] = get_dac_if_single(codec, pins[i]);
3004 for (i = 1; i < num_outs; i++) {
3005 if (!dacs[i])
3006 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3007 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003008 return 1;
Takashi Iwaic2674682011-08-24 17:57:44 +02003009}
3010
3011static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003012 unsigned int location, int offset);
David Henningssonfde48a12011-12-09 18:27:42 +08003013static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3014 hda_nid_t pin, hda_nid_t dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003015
Takashi Iwai7085ec12009-10-02 09:03:58 +02003016/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003017static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003018{
3019 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003020 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003021 unsigned int location, defcfg;
3022 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003023 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003024 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003025
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003026 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003027 /* set num_dacs once to full for alc_auto_look_for_dac() */
3028 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003029 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003030 spec->multiout.extra_out_nid[0] = 0;
3031 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3032 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003033 spec->multi_ios = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003034
3035 /* fill hard-wired DACs first */
3036 if (!redone) {
3037 for (i = 0; i < cfg->line_outs; i++)
3038 spec->private_dac_nids[i] =
3039 get_dac_if_single(codec, cfg->line_out_pins[i]);
3040 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003041 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003042 get_dac_if_single(codec, cfg->hp_pins[0]);
3043 if (cfg->speaker_outs)
3044 spec->multiout.extra_out_nid[0] =
3045 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003046 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003047
3048 for (i = 0; i < cfg->line_outs; i++) {
3049 hda_nid_t pin = cfg->line_out_pins[i];
3050 if (spec->private_dac_nids[i])
3051 continue;
3052 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3053 if (!spec->private_dac_nids[i] && !redone) {
3054 /* if we can't find primary DACs, re-probe without
3055 * checking the hard-wired DACs
3056 */
3057 redone = true;
3058 goto again;
3059 }
3060 }
3061
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003062 /* re-count num_dacs and squash invalid entries */
3063 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003064 for (i = 0; i < cfg->line_outs; i++) {
3065 if (spec->private_dac_nids[i])
3066 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003067 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003068 memmove(spec->private_dac_nids + i,
3069 spec->private_dac_nids + i + 1,
3070 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003071 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3072 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003073 }
3074
Takashi Iwaic2674682011-08-24 17:57:44 +02003075 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3076 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003077 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3078 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003079
Takashi Iwai07b18f62011-11-10 15:42:54 +01003080 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003081 if (num_pins > 0) {
3082 spec->multi_ios = num_pins;
3083 spec->ext_channel_count = 2;
3084 spec->multiout.num_dacs = num_pins + 1;
3085 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003086 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003087
Takashi Iwai716eef02011-10-21 15:07:42 +02003088 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3089 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003090 spec->multiout.hp_out_nid);
Takashi Iwai0a34b422011-12-07 17:20:30 +01003091 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3092 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3093 cfg->speaker_pins,
3094 spec->multiout.extra_out_nid);
3095 /* if no speaker volume is assigned, try again as the primary
3096 * output
3097 */
3098 if (!err && cfg->speaker_outs > 0 &&
3099 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3100 cfg->hp_outs = cfg->line_outs;
3101 memcpy(cfg->hp_pins, cfg->line_out_pins,
3102 sizeof(cfg->hp_pins));
3103 cfg->line_outs = cfg->speaker_outs;
3104 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3105 sizeof(cfg->speaker_pins));
3106 cfg->speaker_outs = 0;
3107 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3108 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3109 redone = false;
3110 goto again;
3111 }
3112 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003113
Takashi Iwai07b18f62011-11-10 15:42:54 +01003114 if (!spec->multi_ios &&
3115 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3116 cfg->hp_outs) {
3117 /* try multi-ios with HP + inputs */
3118 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3119 location = get_defcfg_location(defcfg);
3120
3121 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3122 if (num_pins > 0) {
3123 spec->multi_ios = num_pins;
3124 spec->ext_channel_count = 2;
3125 spec->multiout.num_dacs = num_pins + 1;
3126 }
3127 }
3128
David Henningssonfde48a12011-12-09 18:27:42 +08003129 if (cfg->line_out_pins[0])
3130 spec->vmaster_nid =
3131 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3132 spec->multiout.dac_nids[0]);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003133 return 0;
3134}
3135
Takashi Iwai527e4d72011-10-27 16:33:27 +02003136static inline unsigned int get_ctl_pos(unsigned int data)
3137{
3138 hda_nid_t nid = get_amp_nid_(data);
3139 unsigned int dir = get_amp_direction_(data);
3140 return (nid << 1) | dir;
3141}
3142
3143#define is_ctl_used(bits, data) \
3144 test_bit(get_ctl_pos(data), bits)
3145#define mark_ctl_usage(bits, data) \
3146 set_bit(get_ctl_pos(data), bits)
3147
Takashi Iwai343a04b2011-07-06 14:28:39 +02003148static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003149 const char *pfx, int cidx,
3150 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003151{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003152 struct alc_spec *spec = codec->spec;
3153 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003154 if (!nid)
3155 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003156 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3157 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3158 return 0;
3159 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003160 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003161 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003162}
3163
Takashi Iwaie29d3772011-11-14 17:13:23 +01003164static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3165 const char *pfx, int cidx,
3166 hda_nid_t nid)
3167{
3168 int chs = 1;
3169 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3170 chs = 3;
3171 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3172}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003173
3174/* create a mute-switch for the given mixer widget;
3175 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3176 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003177static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003178 const char *pfx, int cidx,
3179 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003180{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003181 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003182 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003183 int type;
3184 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003185 if (!nid)
3186 return 0;
3187 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3188 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3189 type = ALC_CTL_WIDGET_MUTE;
3190 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3191 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003192 type = ALC_CTL_WIDGET_MUTE;
3193 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3194 } else {
3195 type = ALC_CTL_BIND_MUTE;
3196 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3197 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003198 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3199 return 0;
3200 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003201 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003202}
3203
Takashi Iwaie29d3772011-11-14 17:13:23 +01003204static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3205 int cidx, hda_nid_t nid)
3206{
3207 int chs = 1;
3208 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3209 chs = 3;
3210 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3211}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003212
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003213static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3214 hda_nid_t pin, hda_nid_t dac)
3215{
3216 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3217 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3218 return pin;
3219 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3220 return mix;
3221 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3222 return dac;
3223 return 0;
3224}
3225
3226static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3227 hda_nid_t pin, hda_nid_t dac)
3228{
3229 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3230 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3231 return dac;
3232 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3233 return mix;
3234 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3235 return pin;
3236 return 0;
3237}
3238
Takashi Iwai7085ec12009-10-02 09:03:58 +02003239/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003240static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003241 const struct auto_pin_cfg *cfg)
3242{
3243 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003244 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003245
Takashi Iwaice764ab2011-04-27 16:35:23 +02003246 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003247 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003248 noutputs += spec->multi_ios;
3249
3250 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003251 const char *name;
3252 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003253 hda_nid_t dac, pin;
3254 hda_nid_t sw, vol;
3255
3256 dac = spec->multiout.dac_nids[i];
3257 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003258 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003259 if (i >= cfg->line_outs)
3260 pin = spec->multi_io[i - 1].pin;
3261 else
3262 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003263
3264 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3265 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003266 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003267 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003268 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003269 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003270 if (err < 0)
3271 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003272 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003273 if (err < 0)
3274 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003275 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003276 if (err < 0)
3277 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003278 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003279 if (err < 0)
3280 return err;
3281 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003282 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003283 if (err < 0)
3284 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003285 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003286 if (err < 0)
3287 return err;
3288 }
3289 }
3290 return 0;
3291}
3292
Takashi Iwai343a04b2011-07-06 14:28:39 +02003293static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003294 hda_nid_t dac, const char *pfx,
3295 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003296{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003297 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003298 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003299 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003300
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003301 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003302 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003303 /* the corresponding DAC is already occupied */
3304 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3305 return 0; /* no way */
3306 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003307 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3308 if (is_ctl_used(spec->sw_ctls, val))
3309 return 0; /* already created */
3310 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003311 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003312 }
3313
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003314 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3315 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003316 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003317 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003318 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003319 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003320 if (err < 0)
3321 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003322 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003323}
3324
Takashi Iwai23c09b02011-08-19 09:05:35 +02003325static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3326 unsigned int nums,
3327 struct hda_ctl_ops *ops)
3328{
3329 struct alc_spec *spec = codec->spec;
3330 struct hda_bind_ctls **ctlp, *ctl;
3331 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3332 ctlp = snd_array_new(&spec->bind_ctls);
3333 if (!ctlp)
3334 return NULL;
3335 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3336 *ctlp = ctl;
3337 if (ctl)
3338 ctl->ops = ops;
3339 return ctl;
3340}
3341
3342/* add playback controls for speaker and HP outputs */
3343static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3344 const hda_nid_t *pins,
3345 const hda_nid_t *dacs,
3346 const char *pfx)
3347{
3348 struct alc_spec *spec = codec->spec;
3349 struct hda_bind_ctls *ctl;
3350 char name[32];
3351 int i, n, err;
3352
3353 if (!num_pins || !pins[0])
3354 return 0;
3355
Takashi Iwai527e4d72011-10-27 16:33:27 +02003356 if (num_pins == 1) {
3357 hda_nid_t dac = *dacs;
3358 if (!dac)
3359 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003360 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003361 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003362
3363 if (dacs[num_pins - 1]) {
3364 /* OK, we have a multi-output system with individual volumes */
3365 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003366 if (num_pins >= 3) {
3367 snprintf(name, sizeof(name), "%s %s",
3368 pfx, channel_name[i]);
3369 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3370 name, 0);
3371 } else {
3372 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3373 pfx, i);
3374 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003375 if (err < 0)
3376 return err;
3377 }
3378 return 0;
3379 }
3380
3381 /* Let's create a bind-controls */
3382 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3383 if (!ctl)
3384 return -ENOMEM;
3385 n = 0;
3386 for (i = 0; i < num_pins; i++) {
3387 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3388 ctl->values[n++] =
3389 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3390 }
3391 if (n) {
3392 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3393 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3394 if (err < 0)
3395 return err;
3396 }
3397
3398 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3399 if (!ctl)
3400 return -ENOMEM;
3401 n = 0;
3402 for (i = 0; i < num_pins; i++) {
3403 hda_nid_t vol;
3404 if (!pins[i] || !dacs[i])
3405 continue;
3406 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3407 if (vol)
3408 ctl->values[n++] =
3409 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3410 }
3411 if (n) {
3412 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3413 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3414 if (err < 0)
3415 return err;
3416 }
3417 return 0;
3418}
3419
Takashi Iwai343a04b2011-07-06 14:28:39 +02003420static int alc_auto_create_hp_out(struct hda_codec *codec)
3421{
3422 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003423 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3424 spec->autocfg.hp_pins,
3425 spec->multiout.hp_out_nid,
3426 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003427}
3428
3429static int alc_auto_create_speaker_out(struct hda_codec *codec)
3430{
3431 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003432 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3433 spec->autocfg.speaker_pins,
3434 spec->multiout.extra_out_nid,
3435 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003436}
3437
Takashi Iwai343a04b2011-07-06 14:28:39 +02003438static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003439 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003440 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003441{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003442 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003443 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003444 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003445
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003446 alc_set_pin_output(codec, pin, pin_type);
3447 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003448 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003449 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003450 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003451 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003452 mix = srcs[i];
3453 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003454 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003455 if (!mix)
3456 return;
3457
3458 /* need the manual connection? */
3459 if (num > 1)
3460 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3461 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003462 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3463 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003464 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003465 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003466 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003467 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003468 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003469 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3470 if (nid)
3471 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3472 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003473
3474 /* unmute DAC if it's not assigned to a mixer */
3475 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3476 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3477 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3478 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003479}
3480
Takashi Iwai343a04b2011-07-06 14:28:39 +02003481static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003482{
3483 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003484 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003485 int i;
3486
3487 for (i = 0; i <= HDA_SIDE; i++) {
3488 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3489 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003490 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003491 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003492 }
3493}
3494
Takashi Iwai343a04b2011-07-06 14:28:39 +02003495static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003496{
3497 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003498 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003499 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003500
David Henningsson636030e2011-10-12 19:26:03 +02003501 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003502 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3503 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003504 pin = spec->autocfg.hp_pins[i];
3505 if (!pin)
3506 break;
3507 dac = spec->multiout.hp_out_nid[i];
3508 if (!dac) {
3509 if (i > 0 && spec->multiout.hp_out_nid[0])
3510 dac = spec->multiout.hp_out_nid[0];
3511 else
3512 dac = spec->multiout.dac_nids[0];
3513 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003514 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3515 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003516 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003517 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3518 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003519 pin = spec->autocfg.speaker_pins[i];
3520 if (!pin)
3521 break;
3522 dac = spec->multiout.extra_out_nid[i];
3523 if (!dac) {
3524 if (i > 0 && spec->multiout.extra_out_nid[0])
3525 dac = spec->multiout.extra_out_nid[0];
3526 else
3527 dac = spec->multiout.dac_nids[0];
3528 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003529 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3530 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003531}
3532
Takashi Iwaice764ab2011-04-27 16:35:23 +02003533/*
3534 * multi-io helper
3535 */
3536static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003537 unsigned int location,
3538 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003539{
3540 struct alc_spec *spec = codec->spec;
3541 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003542 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003543 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003544
Takashi Iwai07b18f62011-11-10 15:42:54 +01003545 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003546 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3547 for (i = 0; i < cfg->num_inputs; i++) {
3548 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003549 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003550 unsigned int defcfg, caps;
3551 if (cfg->inputs[i].type != type)
3552 continue;
3553 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3554 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3555 continue;
3556 if (location && get_defcfg_location(defcfg) != location)
3557 continue;
3558 caps = snd_hda_query_pin_caps(codec, nid);
3559 if (!(caps & AC_PINCAP_OUT))
3560 continue;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003561 if (offset && offset + num_pins < dacs) {
3562 dac = spec->private_dac_nids[offset + num_pins];
3563 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3564 dac = 0;
3565 }
3566 if (!dac)
3567 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003568 if (!dac)
3569 continue;
3570 spec->multi_io[num_pins].pin = nid;
3571 spec->multi_io[num_pins].dac = dac;
3572 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003573 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003574 }
3575 }
Takashi Iwai07b18f62011-11-10 15:42:54 +01003576 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003577 if (num_pins < 2) {
3578 /* clear up again */
Takashi Iwai07b18f62011-11-10 15:42:54 +01003579 memset(spec->private_dac_nids + dacs, 0,
3580 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003581 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003582 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003583 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003584 return num_pins;
3585}
3586
3587static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3588 struct snd_ctl_elem_info *uinfo)
3589{
3590 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3591 struct alc_spec *spec = codec->spec;
3592
3593 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3594 uinfo->count = 1;
3595 uinfo->value.enumerated.items = spec->multi_ios + 1;
3596 if (uinfo->value.enumerated.item > spec->multi_ios)
3597 uinfo->value.enumerated.item = spec->multi_ios;
3598 sprintf(uinfo->value.enumerated.name, "%dch",
3599 (uinfo->value.enumerated.item + 1) * 2);
3600 return 0;
3601}
3602
3603static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3604 struct snd_ctl_elem_value *ucontrol)
3605{
3606 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3607 struct alc_spec *spec = codec->spec;
3608 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3609 return 0;
3610}
3611
3612static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3613{
3614 struct alc_spec *spec = codec->spec;
3615 hda_nid_t nid = spec->multi_io[idx].pin;
3616
3617 if (!spec->multi_io[idx].ctl_in)
3618 spec->multi_io[idx].ctl_in =
3619 snd_hda_codec_read(codec, nid, 0,
3620 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3621 if (output) {
3622 snd_hda_codec_update_cache(codec, nid, 0,
3623 AC_VERB_SET_PIN_WIDGET_CONTROL,
3624 PIN_OUT);
3625 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3626 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3627 HDA_AMP_MUTE, 0);
3628 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3629 } else {
3630 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3631 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3632 HDA_AMP_MUTE, HDA_AMP_MUTE);
3633 snd_hda_codec_update_cache(codec, nid, 0,
3634 AC_VERB_SET_PIN_WIDGET_CONTROL,
3635 spec->multi_io[idx].ctl_in);
3636 }
3637 return 0;
3638}
3639
3640static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3641 struct snd_ctl_elem_value *ucontrol)
3642{
3643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3644 struct alc_spec *spec = codec->spec;
3645 int i, ch;
3646
3647 ch = ucontrol->value.enumerated.item[0];
3648 if (ch < 0 || ch > spec->multi_ios)
3649 return -EINVAL;
3650 if (ch == (spec->ext_channel_count - 1) / 2)
3651 return 0;
3652 spec->ext_channel_count = (ch + 1) * 2;
3653 for (i = 0; i < spec->multi_ios; i++)
3654 alc_set_multi_io(codec, i, i < ch);
3655 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003656 if (spec->need_dac_fix && !spec->const_channel_count)
3657 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003658 return 1;
3659}
3660
Takashi Iwaia9111322011-05-02 11:30:18 +02003661static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003662 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3663 .name = "Channel Mode",
3664 .info = alc_auto_ch_mode_info,
3665 .get = alc_auto_ch_mode_get,
3666 .put = alc_auto_ch_mode_put,
3667};
3668
Takashi Iwai23c09b02011-08-19 09:05:35 +02003669static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003670{
3671 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003672
Takashi Iwaic2674682011-08-24 17:57:44 +02003673 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003674 struct snd_kcontrol_new *knew;
3675
3676 knew = alc_kcontrol_new(spec);
3677 if (!knew)
3678 return -ENOMEM;
3679 *knew = alc_auto_channel_mode_enum;
3680 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3681 if (!knew->name)
3682 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003683 }
3684 return 0;
3685}
3686
Takashi Iwai1d045db2011-07-07 18:23:21 +02003687/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3688 * active input pins
3689 */
3690static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3691{
3692 struct alc_spec *spec = codec->spec;
3693 const struct hda_input_mux *imux;
3694 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3695 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3696 int i, n, nums;
3697
3698 imux = spec->input_mux;
3699 if (!imux)
3700 return;
3701 if (spec->dyn_adc_switch)
3702 return;
3703
3704 nums = 0;
3705 for (n = 0; n < spec->num_adc_nids; n++) {
3706 hda_nid_t cap = spec->private_capsrc_nids[n];
3707 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3708 for (i = 0; i < imux->num_items; i++) {
3709 hda_nid_t pin = spec->imux_pins[i];
3710 if (pin) {
3711 if (get_connection_index(codec, cap, pin) < 0)
3712 break;
3713 } else if (num_conns <= imux->items[i].index)
3714 break;
3715 }
3716 if (i >= imux->num_items) {
3717 adc_nids[nums] = spec->private_adc_nids[n];
3718 capsrc_nids[nums++] = cap;
3719 }
3720 }
3721 if (!nums) {
3722 /* check whether ADC-switch is possible */
3723 if (!alc_check_dyn_adc_switch(codec)) {
3724 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3725 " using fallback 0x%x\n",
3726 codec->chip_name, spec->private_adc_nids[0]);
3727 spec->num_adc_nids = 1;
3728 spec->auto_mic = 0;
3729 return;
3730 }
3731 } else if (nums != spec->num_adc_nids) {
3732 memcpy(spec->private_adc_nids, adc_nids,
3733 nums * sizeof(hda_nid_t));
3734 memcpy(spec->private_capsrc_nids, capsrc_nids,
3735 nums * sizeof(hda_nid_t));
3736 spec->num_adc_nids = nums;
3737 }
3738
3739 if (spec->auto_mic)
3740 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3741 else if (spec->input_mux->num_items == 1)
3742 spec->num_adc_nids = 1; /* reduce to a single ADC */
3743}
3744
3745/*
3746 * initialize ADC paths
3747 */
3748static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3749{
3750 struct alc_spec *spec = codec->spec;
3751 hda_nid_t nid;
3752
3753 nid = spec->adc_nids[adc_idx];
3754 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003755 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003756 snd_hda_codec_write(codec, nid, 0,
3757 AC_VERB_SET_AMP_GAIN_MUTE,
3758 AMP_IN_MUTE(0));
3759 return;
3760 }
3761 if (!spec->capsrc_nids)
3762 return;
3763 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003764 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003765 snd_hda_codec_write(codec, nid, 0,
3766 AC_VERB_SET_AMP_GAIN_MUTE,
3767 AMP_OUT_MUTE);
3768}
3769
3770static void alc_auto_init_input_src(struct hda_codec *codec)
3771{
3772 struct alc_spec *spec = codec->spec;
3773 int c, nums;
3774
3775 for (c = 0; c < spec->num_adc_nids; c++)
3776 alc_auto_init_adc(codec, c);
3777 if (spec->dyn_adc_switch)
3778 nums = 1;
3779 else
3780 nums = spec->num_adc_nids;
3781 for (c = 0; c < nums; c++)
3782 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3783}
3784
3785/* add mic boosts if needed */
3786static int alc_auto_add_mic_boost(struct hda_codec *codec)
3787{
3788 struct alc_spec *spec = codec->spec;
3789 struct auto_pin_cfg *cfg = &spec->autocfg;
3790 int i, err;
3791 int type_idx = 0;
3792 hda_nid_t nid;
3793 const char *prev_label = NULL;
3794
3795 for (i = 0; i < cfg->num_inputs; i++) {
3796 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3797 break;
3798 nid = cfg->inputs[i].pin;
3799 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3800 const char *label;
3801 char boost_label[32];
3802
3803 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003804 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3805 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003806 if (prev_label && !strcmp(label, prev_label))
3807 type_idx++;
3808 else
3809 type_idx = 0;
3810 prev_label = label;
3811
3812 snprintf(boost_label, sizeof(boost_label),
3813 "%s Boost Volume", label);
3814 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3815 boost_label, type_idx,
3816 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3817 if (err < 0)
3818 return err;
3819 }
3820 }
3821 return 0;
3822}
3823
3824/* select or unmute the given capsrc route */
3825static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3826 int idx)
3827{
3828 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3829 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3830 HDA_AMP_MUTE, 0);
3831 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3832 snd_hda_codec_write_cache(codec, cap, 0,
3833 AC_VERB_SET_CONNECT_SEL, idx);
3834 }
3835}
3836
3837/* set the default connection to that pin */
3838static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3839{
3840 struct alc_spec *spec = codec->spec;
3841 int i;
3842
3843 if (!pin)
3844 return 0;
3845 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01003846 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003847 int idx;
3848
3849 idx = get_connection_index(codec, cap, pin);
3850 if (idx < 0)
3851 continue;
3852 select_or_unmute_capsrc(codec, cap, idx);
3853 return i; /* return the found index */
3854 }
3855 return -1; /* not found */
3856}
3857
3858/* initialize some special cases for input sources */
3859static void alc_init_special_input_src(struct hda_codec *codec)
3860{
3861 struct alc_spec *spec = codec->spec;
3862 int i;
3863
3864 for (i = 0; i < spec->autocfg.num_inputs; i++)
3865 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3866}
3867
3868/* assign appropriate capture mixers */
3869static void set_capture_mixer(struct hda_codec *codec)
3870{
3871 struct alc_spec *spec = codec->spec;
3872 static const struct snd_kcontrol_new *caps[2][3] = {
3873 { alc_capture_mixer_nosrc1,
3874 alc_capture_mixer_nosrc2,
3875 alc_capture_mixer_nosrc3 },
3876 { alc_capture_mixer1,
3877 alc_capture_mixer2,
3878 alc_capture_mixer3 },
3879 };
3880
3881 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003882 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003883 if (!spec->capsrc_nids)
3884 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003885 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003886 return; /* no volume in capsrc, too */
3887 spec->vol_in_capsrc = 1;
3888 }
3889
3890 if (spec->num_adc_nids > 0) {
3891 int mux = 0;
3892 int num_adcs = 0;
3893
3894 if (spec->input_mux && spec->input_mux->num_items > 1)
3895 mux = 1;
3896 if (spec->auto_mic) {
3897 num_adcs = 1;
3898 mux = 0;
3899 } else if (spec->dyn_adc_switch)
3900 num_adcs = 1;
3901 if (!num_adcs) {
3902 if (spec->num_adc_nids > 3)
3903 spec->num_adc_nids = 3;
3904 else if (!spec->num_adc_nids)
3905 return;
3906 num_adcs = spec->num_adc_nids;
3907 }
3908 spec->cap_mixer = caps[mux][num_adcs - 1];
3909 }
3910}
3911
3912/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003913 * standard auto-parser initializations
3914 */
3915static void alc_auto_init_std(struct hda_codec *codec)
3916{
3917 struct alc_spec *spec = codec->spec;
Takashi Iwai3a938972011-10-28 01:16:55 +02003918 spec->use_jack_tbl = 1;
Takashi Iwaie4770622011-07-08 11:11:35 +02003919 alc_auto_init_multi_out(codec);
3920 alc_auto_init_extra_out(codec);
3921 alc_auto_init_analog_input(codec);
3922 alc_auto_init_input_src(codec);
3923 alc_auto_init_digital(codec);
3924 if (spec->unsol_event)
3925 alc_inithook(codec);
3926}
3927
3928/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003929 * Digital-beep handlers
3930 */
3931#ifdef CONFIG_SND_HDA_INPUT_BEEP
3932#define set_beep_amp(spec, nid, idx, dir) \
3933 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3934
3935static const struct snd_pci_quirk beep_white_list[] = {
3936 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3937 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3938 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3939 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3940 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3941 {}
3942};
3943
3944static inline int has_cdefine_beep(struct hda_codec *codec)
3945{
3946 struct alc_spec *spec = codec->spec;
3947 const struct snd_pci_quirk *q;
3948 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3949 if (q)
3950 return q->value;
3951 return spec->cdefine.enable_pcbeep;
3952}
3953#else
3954#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3955#define has_cdefine_beep(codec) 0
3956#endif
3957
3958/* parse the BIOS configuration and set up the alc_spec */
3959/* return 1 if successful, 0 if the proper config is not found,
3960 * or a negative error code
3961 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003962static int alc_parse_auto_config(struct hda_codec *codec,
3963 const hda_nid_t *ignore_nids,
3964 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003965{
3966 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003967 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003968 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003969
Takashi Iwai53c334a2011-08-23 18:27:14 +02003970 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3971 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003972 if (err < 0)
3973 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003974 if (!cfg->line_outs) {
3975 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003976 spec->multiout.max_channels = 2;
3977 spec->no_analog = 1;
3978 goto dig_only;
3979 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003980 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003981 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003982
Takashi Iwai06503672011-10-06 08:27:19 +02003983 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3984 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003985 /* use HP as primary out */
3986 cfg->speaker_outs = cfg->line_outs;
3987 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3988 sizeof(cfg->speaker_pins));
3989 cfg->line_outs = cfg->hp_outs;
3990 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3991 cfg->hp_outs = 0;
3992 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3993 cfg->line_out_type = AUTO_PIN_HP_OUT;
3994 }
3995
Takashi Iwai1d045db2011-07-07 18:23:21 +02003996 err = alc_auto_fill_dac_nids(codec);
3997 if (err < 0)
3998 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003999 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004000 if (err < 0)
4001 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004002 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004003 if (err < 0)
4004 return err;
4005 err = alc_auto_create_hp_out(codec);
4006 if (err < 0)
4007 return err;
4008 err = alc_auto_create_speaker_out(codec);
4009 if (err < 0)
4010 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004011 err = alc_auto_create_shared_input(codec);
4012 if (err < 0)
4013 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004014 err = alc_auto_create_input_ctls(codec);
4015 if (err < 0)
4016 return err;
4017
4018 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4019
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004020 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004021 alc_auto_parse_digital(codec);
4022
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004023 if (!spec->no_analog)
4024 alc_remove_invalid_adc_nids(codec);
4025
4026 if (ssid_nids)
4027 alc_ssid_check(codec, ssid_nids);
4028
4029 if (!spec->no_analog) {
4030 alc_auto_check_switches(codec);
4031 err = alc_auto_add_mic_boost(codec);
4032 if (err < 0)
4033 return err;
4034 }
4035
Takashi Iwai1d045db2011-07-07 18:23:21 +02004036 if (spec->kctls.list)
4037 add_mixer(spec, spec->kctls.list);
4038
Takashi Iwai1d045db2011-07-07 18:23:21 +02004039 return 1;
4040}
4041
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004042static int alc880_parse_auto_config(struct hda_codec *codec)
4043{
4044 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4045 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4046 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4047}
4048
Takashi Iwai1d045db2011-07-07 18:23:21 +02004049#ifdef CONFIG_SND_HDA_POWER_SAVE
4050static const struct hda_amp_list alc880_loopbacks[] = {
4051 { 0x0b, HDA_INPUT, 0 },
4052 { 0x0b, HDA_INPUT, 1 },
4053 { 0x0b, HDA_INPUT, 2 },
4054 { 0x0b, HDA_INPUT, 3 },
4055 { 0x0b, HDA_INPUT, 4 },
4056 { } /* end */
4057};
4058#endif
4059
4060/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004061 * ALC880 fix-ups
4062 */
4063enum {
4064 ALC880_FIXUP_GPIO2,
4065 ALC880_FIXUP_MEDION_RIM,
4066};
4067
4068static const struct alc_fixup alc880_fixups[] = {
4069 [ALC880_FIXUP_GPIO2] = {
4070 .type = ALC_FIXUP_VERBS,
4071 .v.verbs = alc_gpio2_init_verbs,
4072 },
4073 [ALC880_FIXUP_MEDION_RIM] = {
4074 .type = ALC_FIXUP_VERBS,
4075 .v.verbs = (const struct hda_verb[]) {
4076 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4077 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4078 { }
4079 },
4080 .chained = true,
4081 .chain_id = ALC880_FIXUP_GPIO2,
4082 },
4083};
4084
4085static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4086 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4087 {}
4088};
4089
4090
4091/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004092 * board setups
4093 */
4094#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4095#define alc_board_config \
4096 snd_hda_check_board_config
4097#define alc_board_codec_sid_config \
4098 snd_hda_check_board_codec_sid_config
4099#include "alc_quirks.c"
4100#else
4101#define alc_board_config(codec, nums, models, tbl) -1
4102#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4103#define setup_preset(codec, x) /* NOP */
4104#endif
4105
4106/*
4107 * OK, here we have finally the patch for ALC880
4108 */
4109#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4110#include "alc880_quirks.c"
4111#endif
4112
4113static int patch_alc880(struct hda_codec *codec)
4114{
4115 struct alc_spec *spec;
4116 int board_config;
4117 int err;
4118
4119 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4120 if (spec == NULL)
4121 return -ENOMEM;
4122
4123 codec->spec = spec;
4124
4125 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004126 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004127
4128 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4129 alc880_models, alc880_cfg_tbl);
4130 if (board_config < 0) {
4131 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4132 codec->chip_name);
4133 board_config = ALC_MODEL_AUTO;
4134 }
4135
4136 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004137 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4138 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4139 }
4140
4141 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004142 /* automatic parse from the BIOS config */
4143 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004144 if (err < 0)
4145 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004146#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4147 else if (!err) {
4148 printk(KERN_INFO
4149 "hda_codec: Cannot set up configuration "
4150 "from BIOS. Using 3-stack mode...\n");
4151 board_config = ALC880_3ST;
4152 }
4153#endif
4154 }
4155
David Henningssonfde48a12011-12-09 18:27:42 +08004156 if (board_config != ALC_MODEL_AUTO) {
4157 spec->vmaster_nid = 0x0c;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004158 setup_preset(codec, &alc880_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004159 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004160
Takashi Iwai60a6a842011-07-27 14:01:24 +02004161 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004162 alc_auto_fill_adc_caps(codec);
4163 alc_rebuild_imux_for_auto_mic(codec);
4164 alc_remove_invalid_adc_nids(codec);
4165 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004166
4167 if (!spec->no_analog && !spec->cap_mixer)
4168 set_capture_mixer(codec);
4169
4170 if (!spec->no_analog) {
4171 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004172 if (err < 0)
4173 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004174 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4175 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004176
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004177 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4178
Takashi Iwai1d045db2011-07-07 18:23:21 +02004179 codec->patch_ops = alc_patch_ops;
4180 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004181 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004182 else
4183 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004184#ifdef CONFIG_SND_HDA_POWER_SAVE
4185 if (!spec->loopback.amplist)
4186 spec->loopback.amplist = alc880_loopbacks;
4187#endif
4188
4189 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004190
4191 error:
4192 alc_free(codec);
4193 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004194}
4195
4196
4197/*
4198 * ALC260 support
4199 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004200static int alc260_parse_auto_config(struct hda_codec *codec)
4201{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004202 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004203 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4204 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004205}
4206
Takashi Iwai1d045db2011-07-07 18:23:21 +02004207#ifdef CONFIG_SND_HDA_POWER_SAVE
4208static const struct hda_amp_list alc260_loopbacks[] = {
4209 { 0x07, HDA_INPUT, 0 },
4210 { 0x07, HDA_INPUT, 1 },
4211 { 0x07, HDA_INPUT, 2 },
4212 { 0x07, HDA_INPUT, 3 },
4213 { 0x07, HDA_INPUT, 4 },
4214 { } /* end */
4215};
4216#endif
4217
4218/*
4219 * Pin config fixes
4220 */
4221enum {
4222 PINFIX_HP_DC5750,
4223};
4224
4225static const struct alc_fixup alc260_fixups[] = {
4226 [PINFIX_HP_DC5750] = {
4227 .type = ALC_FIXUP_PINS,
4228 .v.pins = (const struct alc_pincfg[]) {
4229 { 0x11, 0x90130110 }, /* speaker */
4230 { }
4231 }
4232 },
4233};
4234
4235static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4236 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4237 {}
4238};
4239
4240/*
4241 */
4242#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4243#include "alc260_quirks.c"
4244#endif
4245
4246static int patch_alc260(struct hda_codec *codec)
4247{
4248 struct alc_spec *spec;
4249 int err, board_config;
4250
4251 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4252 if (spec == NULL)
4253 return -ENOMEM;
4254
4255 codec->spec = spec;
4256
4257 spec->mixer_nid = 0x07;
4258
4259 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4260 alc260_models, alc260_cfg_tbl);
4261 if (board_config < 0) {
4262 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4263 codec->chip_name);
4264 board_config = ALC_MODEL_AUTO;
4265 }
4266
4267 if (board_config == ALC_MODEL_AUTO) {
4268 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4269 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4270 }
4271
4272 if (board_config == ALC_MODEL_AUTO) {
4273 /* automatic parse from the BIOS config */
4274 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004275 if (err < 0)
4276 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004277#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4278 else if (!err) {
4279 printk(KERN_INFO
4280 "hda_codec: Cannot set up configuration "
4281 "from BIOS. Using base mode...\n");
4282 board_config = ALC260_BASIC;
4283 }
4284#endif
4285 }
4286
David Henningssonfde48a12011-12-09 18:27:42 +08004287 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004288 setup_preset(codec, &alc260_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004289 spec->vmaster_nid = 0x08;
4290 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004291
Takashi Iwai60a6a842011-07-27 14:01:24 +02004292 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004293 alc_auto_fill_adc_caps(codec);
4294 alc_rebuild_imux_for_auto_mic(codec);
4295 alc_remove_invalid_adc_nids(codec);
4296 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004297
4298 if (!spec->no_analog && !spec->cap_mixer)
4299 set_capture_mixer(codec);
4300
4301 if (!spec->no_analog) {
4302 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004303 if (err < 0)
4304 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004305 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4306 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004307
4308 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4309
Takashi Iwai1d045db2011-07-07 18:23:21 +02004310 codec->patch_ops = alc_patch_ops;
4311 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004312 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004313 else
4314 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004315 spec->shutup = alc_eapd_shutup;
4316#ifdef CONFIG_SND_HDA_POWER_SAVE
4317 if (!spec->loopback.amplist)
4318 spec->loopback.amplist = alc260_loopbacks;
4319#endif
4320
4321 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004322
4323 error:
4324 alc_free(codec);
4325 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004326}
4327
4328
4329/*
4330 * ALC882/883/885/888/889 support
4331 *
4332 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4333 * configuration. Each pin widget can choose any input DACs and a mixer.
4334 * Each ADC is connected from a mixer of all inputs. This makes possible
4335 * 6-channel independent captures.
4336 *
4337 * In addition, an independent DAC for the multi-playback (not used in this
4338 * driver yet).
4339 */
4340#ifdef CONFIG_SND_HDA_POWER_SAVE
4341#define alc882_loopbacks alc880_loopbacks
4342#endif
4343
4344/*
4345 * Pin config fixes
4346 */
4347enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004348 ALC882_FIXUP_ABIT_AW9D_MAX,
4349 ALC882_FIXUP_LENOVO_Y530,
4350 ALC882_FIXUP_PB_M5210,
4351 ALC882_FIXUP_ACER_ASPIRE_7736,
4352 ALC882_FIXUP_ASUS_W90V,
4353 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004354 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a32011-11-09 12:55:18 +01004355 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004356 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004357 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004358 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004359 ALC889_FIXUP_COEF,
4360 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004361 ALC882_FIXUP_ACER_ASPIRE_4930G,
4362 ALC882_FIXUP_ACER_ASPIRE_8930G,
4363 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004364 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004365};
4366
Takashi Iwai68ef0562011-11-09 18:24:44 +01004367static void alc889_fixup_coef(struct hda_codec *codec,
4368 const struct alc_fixup *fix, int action)
4369{
4370 if (action != ALC_FIXUP_ACT_INIT)
4371 return;
4372 alc889_coef_init(codec);
4373}
4374
Takashi Iwai56710872011-11-14 17:42:11 +01004375/* toggle speaker-output according to the hp-jack state */
4376static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4377{
4378 unsigned int gpiostate, gpiomask, gpiodir;
4379
4380 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4381 AC_VERB_GET_GPIO_DATA, 0);
4382
4383 if (!muted)
4384 gpiostate |= (1 << pin);
4385 else
4386 gpiostate &= ~(1 << pin);
4387
4388 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4389 AC_VERB_GET_GPIO_MASK, 0);
4390 gpiomask |= (1 << pin);
4391
4392 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4393 AC_VERB_GET_GPIO_DIRECTION, 0);
4394 gpiodir |= (1 << pin);
4395
4396
4397 snd_hda_codec_write(codec, codec->afg, 0,
4398 AC_VERB_SET_GPIO_MASK, gpiomask);
4399 snd_hda_codec_write(codec, codec->afg, 0,
4400 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4401
4402 msleep(1);
4403
4404 snd_hda_codec_write(codec, codec->afg, 0,
4405 AC_VERB_SET_GPIO_DATA, gpiostate);
4406}
4407
4408/* set up GPIO at initialization */
4409static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4410 const struct alc_fixup *fix, int action)
4411{
4412 if (action != ALC_FIXUP_ACT_INIT)
4413 return;
4414 alc882_gpio_mute(codec, 0, 0);
4415 alc882_gpio_mute(codec, 1, 0);
4416}
4417
Takashi Iwai1d045db2011-07-07 18:23:21 +02004418static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004419 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004420 .type = ALC_FIXUP_PINS,
4421 .v.pins = (const struct alc_pincfg[]) {
4422 { 0x15, 0x01080104 }, /* side */
4423 { 0x16, 0x01011012 }, /* rear */
4424 { 0x17, 0x01016011 }, /* clfe */
4425 { }
4426 }
4427 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004428 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004429 .type = ALC_FIXUP_PINS,
4430 .v.pins = (const struct alc_pincfg[]) {
4431 { 0x15, 0x99130112 }, /* rear int speakers */
4432 { 0x16, 0x99130111 }, /* subwoofer */
4433 { }
4434 }
4435 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004436 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004437 .type = ALC_FIXUP_VERBS,
4438 .v.verbs = (const struct hda_verb[]) {
4439 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4440 {}
4441 }
4442 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004443 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004444 .type = ALC_FIXUP_SKU,
4445 .v.sku = ALC_FIXUP_SKU_IGNORE,
4446 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004447 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004448 .type = ALC_FIXUP_PINS,
4449 .v.pins = (const struct alc_pincfg[]) {
4450 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4451 { }
4452 }
4453 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004454 [ALC889_FIXUP_VAIO_TT] = {
4455 .type = ALC_FIXUP_PINS,
4456 .v.pins = (const struct alc_pincfg[]) {
4457 { 0x17, 0x90170111 }, /* hidden surround speaker */
4458 { }
4459 }
4460 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004461 [ALC888_FIXUP_EEE1601] = {
4462 .type = ALC_FIXUP_VERBS,
4463 .v.verbs = (const struct hda_verb[]) {
4464 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4465 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4466 { }
4467 }
Takashi Iwai177943a32011-11-09 12:55:18 +01004468 },
4469 [ALC882_FIXUP_EAPD] = {
4470 .type = ALC_FIXUP_VERBS,
4471 .v.verbs = (const struct hda_verb[]) {
4472 /* change to EAPD mode */
4473 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4474 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4475 { }
4476 }
4477 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004478 [ALC883_FIXUP_EAPD] = {
4479 .type = ALC_FIXUP_VERBS,
4480 .v.verbs = (const struct hda_verb[]) {
4481 /* change to EAPD mode */
4482 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4483 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4484 { }
4485 }
4486 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004487 [ALC883_FIXUP_ACER_EAPD] = {
4488 .type = ALC_FIXUP_VERBS,
4489 .v.verbs = (const struct hda_verb[]) {
4490 /* eanable EAPD on Acer laptops */
4491 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4492 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4493 { }
4494 }
4495 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004496 [ALC882_FIXUP_GPIO3] = {
4497 .type = ALC_FIXUP_VERBS,
4498 .v.verbs = alc_gpio3_init_verbs,
4499 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004500 [ALC882_FIXUP_ASUS_W2JC] = {
4501 .type = ALC_FIXUP_VERBS,
4502 .v.verbs = alc_gpio1_init_verbs,
4503 .chained = true,
4504 .chain_id = ALC882_FIXUP_EAPD,
4505 },
4506 [ALC889_FIXUP_COEF] = {
4507 .type = ALC_FIXUP_FUNC,
4508 .v.func = alc889_fixup_coef,
4509 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004510 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4511 .type = ALC_FIXUP_PINS,
4512 .v.pins = (const struct alc_pincfg[]) {
4513 { 0x16, 0x99130111 }, /* CLFE speaker */
4514 { 0x17, 0x99130112 }, /* surround speaker */
4515 { }
4516 }
4517 },
4518 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4519 .type = ALC_FIXUP_PINS,
4520 .v.pins = (const struct alc_pincfg[]) {
4521 { 0x16, 0x99130111 }, /* CLFE speaker */
4522 { 0x1b, 0x99130112 }, /* surround speaker */
4523 { }
4524 },
4525 .chained = true,
4526 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4527 },
4528 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4529 /* additional init verbs for Acer Aspire 8930G */
4530 .type = ALC_FIXUP_VERBS,
4531 .v.verbs = (const struct hda_verb[]) {
4532 /* Enable all DACs */
4533 /* DAC DISABLE/MUTE 1? */
4534 /* setting bits 1-5 disables DAC nids 0x02-0x06
4535 * apparently. Init=0x38 */
4536 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4537 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4538 /* DAC DISABLE/MUTE 2? */
4539 /* some bit here disables the other DACs.
4540 * Init=0x4900 */
4541 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4542 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4543 /* DMIC fix
4544 * This laptop has a stereo digital microphone.
4545 * The mics are only 1cm apart which makes the stereo
4546 * useless. However, either the mic or the ALC889
4547 * makes the signal become a difference/sum signal
4548 * instead of standard stereo, which is annoying.
4549 * So instead we flip this bit which makes the
4550 * codec replicate the sum signal to both channels,
4551 * turning it into a normal mono mic.
4552 */
4553 /* DMIC_CONTROL? Init value = 0x0001 */
4554 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4555 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4556 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4557 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4558 { }
4559 }
4560 },
Takashi Iwai56710872011-11-14 17:42:11 +01004561 [ALC885_FIXUP_MACPRO_GPIO] = {
4562 .type = ALC_FIXUP_FUNC,
4563 .v.func = alc885_fixup_macpro_gpio,
4564 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004565};
4566
4567static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004568 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4569 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4570 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4571 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4572 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4573 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004574 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4575 ALC882_FIXUP_ACER_ASPIRE_4930G),
4576 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4577 ALC882_FIXUP_ACER_ASPIRE_4930G),
4578 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4579 ALC882_FIXUP_ACER_ASPIRE_8930G),
4580 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4581 ALC882_FIXUP_ACER_ASPIRE_8930G),
4582 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4583 ALC882_FIXUP_ACER_ASPIRE_4930G),
4584 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4585 ALC882_FIXUP_ACER_ASPIRE_4930G),
4586 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4587 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004588 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004589 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a32011-11-09 12:55:18 +01004590 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004591 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004592 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004593 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004594 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01004595
4596 /* All Apple entries are in codec SSIDs */
4597 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4598 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4599 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4600 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4601 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4602
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004603 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004604 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004605 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004606 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4607 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004608 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004609 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004610 {}
4611};
4612
4613/*
4614 * BIOS auto configuration
4615 */
4616/* almost identical with ALC880 parser... */
4617static int alc882_parse_auto_config(struct hda_codec *codec)
4618{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004619 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004620 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4621 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004622}
4623
Takashi Iwai1d045db2011-07-07 18:23:21 +02004624/*
4625 */
4626#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4627#include "alc882_quirks.c"
4628#endif
4629
4630static int patch_alc882(struct hda_codec *codec)
4631{
4632 struct alc_spec *spec;
4633 int err, board_config;
4634
4635 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4636 if (spec == NULL)
4637 return -ENOMEM;
4638
4639 codec->spec = spec;
4640
4641 spec->mixer_nid = 0x0b;
4642
4643 switch (codec->vendor_id) {
4644 case 0x10ec0882:
4645 case 0x10ec0885:
4646 break;
4647 default:
4648 /* ALC883 and variants */
4649 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4650 break;
4651 }
4652
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004653 err = alc_codec_rename_from_preset(codec);
4654 if (err < 0)
4655 goto error;
4656
Takashi Iwaib2539692011-11-14 17:32:17 +01004657 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4658 alc882_models, NULL);
4659 if (board_config < 0)
4660 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004661 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4662
4663 if (board_config < 0) {
4664 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4665 codec->chip_name);
4666 board_config = ALC_MODEL_AUTO;
4667 }
4668
4669 if (board_config == ALC_MODEL_AUTO) {
4670 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4671 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4672 }
4673
4674 alc_auto_parse_customize_define(codec);
4675
4676 if (board_config == ALC_MODEL_AUTO) {
4677 /* automatic parse from the BIOS config */
4678 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004679 if (err < 0)
4680 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004681 }
4682
David Henningssonfde48a12011-12-09 18:27:42 +08004683 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004684 setup_preset(codec, &alc882_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004685 spec->vmaster_nid = 0x0c;
4686 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004687
Takashi Iwai60a6a842011-07-27 14:01:24 +02004688 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004689 alc_auto_fill_adc_caps(codec);
4690 alc_rebuild_imux_for_auto_mic(codec);
4691 alc_remove_invalid_adc_nids(codec);
4692 }
4693
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004694 if (!spec->no_analog && !spec->cap_mixer)
4695 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004696
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004697 if (!spec->no_analog && has_cdefine_beep(codec)) {
4698 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004699 if (err < 0)
4700 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004701 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004702 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004703
4704 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4705
Takashi Iwai1d045db2011-07-07 18:23:21 +02004706 codec->patch_ops = alc_patch_ops;
4707 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004708 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004709 else
4710 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004711
Takashi Iwai1d045db2011-07-07 18:23:21 +02004712#ifdef CONFIG_SND_HDA_POWER_SAVE
4713 if (!spec->loopback.amplist)
4714 spec->loopback.amplist = alc882_loopbacks;
4715#endif
4716
4717 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004718
4719 error:
4720 alc_free(codec);
4721 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004722}
4723
4724
4725/*
4726 * ALC262 support
4727 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004728static int alc262_parse_auto_config(struct hda_codec *codec)
4729{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004730 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004731 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4732 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004733}
4734
4735/*
4736 * Pin config fixes
4737 */
4738enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004739 ALC262_FIXUP_FSC_H270,
4740 ALC262_FIXUP_HP_Z200,
4741 ALC262_FIXUP_TYAN,
Takashi Iwai12837c92011-11-07 12:45:24 +01004742 ALC262_FIXUP_TOSHIBA_RX1,
Takashi Iwaic4701502011-11-07 14:20:07 +01004743 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004744 ALC262_FIXUP_BENQ,
4745 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004746};
4747
4748static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004749 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004750 .type = ALC_FIXUP_PINS,
4751 .v.pins = (const struct alc_pincfg[]) {
4752 { 0x14, 0x99130110 }, /* speaker */
4753 { 0x15, 0x0221142f }, /* front HP */
4754 { 0x1b, 0x0121141f }, /* rear HP */
4755 { }
4756 }
4757 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004758 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004759 .type = ALC_FIXUP_PINS,
4760 .v.pins = (const struct alc_pincfg[]) {
4761 { 0x16, 0x99130120 }, /* internal speaker */
4762 { }
4763 }
4764 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004765 [ALC262_FIXUP_TYAN] = {
4766 .type = ALC_FIXUP_PINS,
4767 .v.pins = (const struct alc_pincfg[]) {
4768 { 0x14, 0x1993e1f0 }, /* int AUX */
4769 { }
4770 }
4771 },
Takashi Iwai12837c92011-11-07 12:45:24 +01004772 [ALC262_FIXUP_TOSHIBA_RX1] = {
4773 .type = ALC_FIXUP_PINS,
4774 .v.pins = (const struct alc_pincfg[]) {
4775 { 0x14, 0x90170110 }, /* speaker */
4776 { 0x15, 0x0421101f }, /* HP */
4777 { 0x1a, 0x40f000f0 }, /* N/A */
4778 { 0x1b, 0x40f000f0 }, /* N/A */
4779 { 0x1e, 0x40f000f0 }, /* N/A */
4780 }
4781 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004782 [ALC262_FIXUP_LENOVO_3000] = {
4783 .type = ALC_FIXUP_VERBS,
4784 .v.verbs = (const struct hda_verb[]) {
4785 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004786 {}
4787 },
4788 .chained = true,
4789 .chain_id = ALC262_FIXUP_BENQ,
4790 },
4791 [ALC262_FIXUP_BENQ] = {
4792 .type = ALC_FIXUP_VERBS,
4793 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004794 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4795 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4796 {}
4797 }
4798 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004799 [ALC262_FIXUP_BENQ_T31] = {
4800 .type = ALC_FIXUP_VERBS,
4801 .v.verbs = (const struct hda_verb[]) {
4802 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4803 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4804 {}
4805 }
4806 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004807};
4808
4809static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004810 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004811 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4812 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004813 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
Takashi Iwai12837c92011-11-07 12:45:24 +01004814 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4815 ALC262_FIXUP_TOSHIBA_RX1),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004816 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004817 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004818 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4819 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004820 {}
4821};
4822
4823
4824#ifdef CONFIG_SND_HDA_POWER_SAVE
4825#define alc262_loopbacks alc880_loopbacks
4826#endif
4827
Takashi Iwai1d045db2011-07-07 18:23:21 +02004828/*
4829 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004830static int patch_alc262(struct hda_codec *codec)
4831{
4832 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004833 int err;
4834
4835 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4836 if (spec == NULL)
4837 return -ENOMEM;
4838
4839 codec->spec = spec;
4840
4841 spec->mixer_nid = 0x0b;
4842
4843#if 0
4844 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4845 * under-run
4846 */
4847 {
4848 int tmp;
4849 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4850 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4851 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4852 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4853 }
4854#endif
4855 alc_auto_parse_customize_define(codec);
4856
4857 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4858
Takashi Iwai42399f72011-11-07 17:18:44 +01004859 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4860 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004861
Takashi Iwai42399f72011-11-07 17:18:44 +01004862 /* automatic parse from the BIOS config */
4863 err = alc262_parse_auto_config(codec);
4864 if (err < 0)
4865 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004866
Takashi Iwai60a6a842011-07-27 14:01:24 +02004867 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004868 alc_auto_fill_adc_caps(codec);
4869 alc_rebuild_imux_for_auto_mic(codec);
4870 alc_remove_invalid_adc_nids(codec);
4871 }
4872
4873 if (!spec->no_analog && !spec->cap_mixer)
4874 set_capture_mixer(codec);
4875
Takashi Iwai1d045db2011-07-07 18:23:21 +02004876 if (!spec->no_analog && has_cdefine_beep(codec)) {
4877 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004878 if (err < 0)
4879 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004880 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004881 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004882
4883 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4884
Takashi Iwai1d045db2011-07-07 18:23:21 +02004885 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004886 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004887 spec->shutup = alc_eapd_shutup;
4888
Takashi Iwai1d045db2011-07-07 18:23:21 +02004889#ifdef CONFIG_SND_HDA_POWER_SAVE
4890 if (!spec->loopback.amplist)
4891 spec->loopback.amplist = alc262_loopbacks;
4892#endif
4893
4894 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004895
4896 error:
4897 alc_free(codec);
4898 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004899}
4900
4901/*
4902 * ALC268
4903 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004904/* bind Beep switches of both NID 0x0f and 0x10 */
4905static const struct hda_bind_ctls alc268_bind_beep_sw = {
4906 .ops = &snd_hda_bind_sw,
4907 .values = {
4908 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4909 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4910 0
4911 },
4912};
4913
4914static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4915 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4916 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4917 { }
4918};
4919
4920/* set PCBEEP vol = 0, mute connections */
4921static const struct hda_verb alc268_beep_init_verbs[] = {
4922 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4923 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4924 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4925 { }
4926};
4927
4928/*
4929 * BIOS auto configuration
4930 */
4931static int alc268_parse_auto_config(struct hda_codec *codec)
4932{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004933 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004934 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004935 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4936 if (err > 0) {
4937 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4938 add_mixer(spec, alc268_beep_mixer);
4939 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004940 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004941 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004942 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004943}
4944
Takashi Iwai1d045db2011-07-07 18:23:21 +02004945/*
4946 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004947static int patch_alc268(struct hda_codec *codec)
4948{
4949 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004950 int i, has_beep, err;
4951
4952 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4953 if (spec == NULL)
4954 return -ENOMEM;
4955
4956 codec->spec = spec;
4957
4958 /* ALC268 has no aa-loopback mixer */
4959
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004960 /* automatic parse from the BIOS config */
4961 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004962 if (err < 0)
4963 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004964
Takashi Iwai1d045db2011-07-07 18:23:21 +02004965 has_beep = 0;
4966 for (i = 0; i < spec->num_mixers; i++) {
4967 if (spec->mixers[i] == alc268_beep_mixer) {
4968 has_beep = 1;
4969 break;
4970 }
4971 }
4972
4973 if (has_beep) {
4974 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004975 if (err < 0)
4976 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004977 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4978 /* override the amp caps for beep generator */
4979 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4980 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4981 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4982 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4983 (0 << AC_AMPCAP_MUTE_SHIFT));
4984 }
4985
Takashi Iwai60a6a842011-07-27 14:01:24 +02004986 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004987 alc_auto_fill_adc_caps(codec);
4988 alc_rebuild_imux_for_auto_mic(codec);
4989 alc_remove_invalid_adc_nids(codec);
4990 }
4991
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004992 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993 set_capture_mixer(codec);
4994
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004996 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004997 spec->shutup = alc_eapd_shutup;
4998
Takashi Iwai1d045db2011-07-07 18:23:21 +02004999 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005000
5001 error:
5002 alc_free(codec);
5003 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005004}
5005
5006/*
5007 * ALC269
5008 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005009#ifdef CONFIG_SND_HDA_POWER_SAVE
5010#define alc269_loopbacks alc880_loopbacks
5011#endif
5012
5013static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5014 .substreams = 1,
5015 .channels_min = 2,
5016 .channels_max = 8,
5017 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5018 /* NID is set in alc_build_pcms */
5019 .ops = {
5020 .open = alc_playback_pcm_open,
5021 .prepare = alc_playback_pcm_prepare,
5022 .cleanup = alc_playback_pcm_cleanup
5023 },
5024};
5025
5026static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5027 .substreams = 1,
5028 .channels_min = 2,
5029 .channels_max = 2,
5030 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5031 /* NID is set in alc_build_pcms */
5032};
5033
5034#ifdef CONFIG_SND_HDA_POWER_SAVE
5035static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5036{
5037 switch (codec->subsystem_id) {
5038 case 0x103c1586:
5039 return 1;
5040 }
5041 return 0;
5042}
5043
5044static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5045{
5046 /* update mute-LED according to the speaker mute state */
5047 if (nid == 0x01 || nid == 0x14) {
5048 int pinval;
5049 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5050 HDA_AMP_MUTE)
5051 pinval = 0x24;
5052 else
5053 pinval = 0x20;
5054 /* mic2 vref pin is used for mute LED control */
5055 snd_hda_codec_update_cache(codec, 0x19, 0,
5056 AC_VERB_SET_PIN_WIDGET_CONTROL,
5057 pinval);
5058 }
5059 return alc_check_power_status(codec, nid);
5060}
5061#endif /* CONFIG_SND_HDA_POWER_SAVE */
5062
5063/* different alc269-variants */
5064enum {
5065 ALC269_TYPE_ALC269VA,
5066 ALC269_TYPE_ALC269VB,
5067 ALC269_TYPE_ALC269VC,
5068};
5069
5070/*
5071 * BIOS auto configuration
5072 */
5073static int alc269_parse_auto_config(struct hda_codec *codec)
5074{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005075 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005076 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5077 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5078 struct alc_spec *spec = codec->spec;
5079 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5080 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005082 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005083}
5084
Takashi Iwai1d045db2011-07-07 18:23:21 +02005085static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5086{
5087 int val = alc_read_coef_idx(codec, 0x04);
5088 if (power_up)
5089 val |= 1 << 11;
5090 else
5091 val &= ~(1 << 11);
5092 alc_write_coef_idx(codec, 0x04, val);
5093}
5094
5095static void alc269_shutup(struct hda_codec *codec)
5096{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005097 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005098 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005099 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005100 alc269_toggle_power_output(codec, 0);
5101 msleep(150);
5102 }
5103}
5104
Takashi Iwai2a439522011-07-26 09:52:50 +02005105#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005106static int alc269_resume(struct hda_codec *codec)
5107{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005108 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005109 alc269_toggle_power_output(codec, 0);
5110 msleep(150);
5111 }
5112
5113 codec->patch_ops.init(codec);
5114
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005115 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005116 alc269_toggle_power_output(codec, 1);
5117 msleep(200);
5118 }
5119
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005120 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005121 alc269_toggle_power_output(codec, 1);
5122
5123 snd_hda_codec_resume_amp(codec);
5124 snd_hda_codec_resume_cache(codec);
5125 hda_call_check_power_status(codec, 0x01);
5126 return 0;
5127}
Takashi Iwai2a439522011-07-26 09:52:50 +02005128#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005129
5130static void alc269_fixup_hweq(struct hda_codec *codec,
5131 const struct alc_fixup *fix, int action)
5132{
5133 int coef;
5134
5135 if (action != ALC_FIXUP_ACT_INIT)
5136 return;
5137 coef = alc_read_coef_idx(codec, 0x1e);
5138 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5139}
5140
5141static void alc271_fixup_dmic(struct hda_codec *codec,
5142 const struct alc_fixup *fix, int action)
5143{
5144 static const struct hda_verb verbs[] = {
5145 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5146 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5147 {}
5148 };
5149 unsigned int cfg;
5150
5151 if (strcmp(codec->chip_name, "ALC271X"))
5152 return;
5153 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5154 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5155 snd_hda_sequence_write(codec, verbs);
5156}
5157
Takashi Iwai017f2a12011-07-09 14:42:25 +02005158static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5159 const struct alc_fixup *fix, int action)
5160{
5161 struct alc_spec *spec = codec->spec;
5162
5163 if (action != ALC_FIXUP_ACT_PROBE)
5164 return;
5165
5166 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5167 * fix the sample rate of analog I/O to 44.1kHz
5168 */
5169 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5170 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5171}
5172
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005173static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5174 const struct alc_fixup *fix, int action)
5175{
5176 int coef;
5177
5178 if (action != ALC_FIXUP_ACT_INIT)
5179 return;
5180 /* The digital-mic unit sends PDM (differential signal) instead of
5181 * the standard PCM, thus you can't record a valid mono stream as is.
5182 * Below is a workaround specific to ALC269 to control the dmic
5183 * signal source as mono.
5184 */
5185 coef = alc_read_coef_idx(codec, 0x07);
5186 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5187}
5188
Takashi Iwai24519912011-08-16 15:08:49 +02005189static void alc269_quanta_automute(struct hda_codec *codec)
5190{
David Henningsson42cf0d02011-09-20 12:04:56 +02005191 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005192
5193 snd_hda_codec_write(codec, 0x20, 0,
5194 AC_VERB_SET_COEF_INDEX, 0x0c);
5195 snd_hda_codec_write(codec, 0x20, 0,
5196 AC_VERB_SET_PROC_COEF, 0x680);
5197
5198 snd_hda_codec_write(codec, 0x20, 0,
5199 AC_VERB_SET_COEF_INDEX, 0x0c);
5200 snd_hda_codec_write(codec, 0x20, 0,
5201 AC_VERB_SET_PROC_COEF, 0x480);
5202}
5203
5204static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5205 const struct alc_fixup *fix, int action)
5206{
5207 struct alc_spec *spec = codec->spec;
5208 if (action != ALC_FIXUP_ACT_PROBE)
5209 return;
5210 spec->automute_hook = alc269_quanta_automute;
5211}
5212
Takashi Iwai1d045db2011-07-07 18:23:21 +02005213enum {
5214 ALC269_FIXUP_SONY_VAIO,
5215 ALC275_FIXUP_SONY_VAIO_GPIO2,
5216 ALC269_FIXUP_DELL_M101Z,
5217 ALC269_FIXUP_SKU_IGNORE,
5218 ALC269_FIXUP_ASUS_G73JW,
5219 ALC269_FIXUP_LENOVO_EAPD,
5220 ALC275_FIXUP_SONY_HWEQ,
5221 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005222 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005223 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005224 ALC269_FIXUP_QUANTA_MUTE,
5225 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005226 ALC269_FIXUP_AMIC,
5227 ALC269_FIXUP_DMIC,
5228 ALC269VB_FIXUP_AMIC,
5229 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005230};
5231
5232static const struct alc_fixup alc269_fixups[] = {
5233 [ALC269_FIXUP_SONY_VAIO] = {
5234 .type = ALC_FIXUP_VERBS,
5235 .v.verbs = (const struct hda_verb[]) {
5236 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5237 {}
5238 }
5239 },
5240 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5241 .type = ALC_FIXUP_VERBS,
5242 .v.verbs = (const struct hda_verb[]) {
5243 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5244 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5245 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5246 { }
5247 },
5248 .chained = true,
5249 .chain_id = ALC269_FIXUP_SONY_VAIO
5250 },
5251 [ALC269_FIXUP_DELL_M101Z] = {
5252 .type = ALC_FIXUP_VERBS,
5253 .v.verbs = (const struct hda_verb[]) {
5254 /* Enables internal speaker */
5255 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5256 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5257 {}
5258 }
5259 },
5260 [ALC269_FIXUP_SKU_IGNORE] = {
5261 .type = ALC_FIXUP_SKU,
5262 .v.sku = ALC_FIXUP_SKU_IGNORE,
5263 },
5264 [ALC269_FIXUP_ASUS_G73JW] = {
5265 .type = ALC_FIXUP_PINS,
5266 .v.pins = (const struct alc_pincfg[]) {
5267 { 0x17, 0x99130111 }, /* subwoofer */
5268 { }
5269 }
5270 },
5271 [ALC269_FIXUP_LENOVO_EAPD] = {
5272 .type = ALC_FIXUP_VERBS,
5273 .v.verbs = (const struct hda_verb[]) {
5274 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5275 {}
5276 }
5277 },
5278 [ALC275_FIXUP_SONY_HWEQ] = {
5279 .type = ALC_FIXUP_FUNC,
5280 .v.func = alc269_fixup_hweq,
5281 .chained = true,
5282 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5283 },
5284 [ALC271_FIXUP_DMIC] = {
5285 .type = ALC_FIXUP_FUNC,
5286 .v.func = alc271_fixup_dmic,
5287 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005288 [ALC269_FIXUP_PCM_44K] = {
5289 .type = ALC_FIXUP_FUNC,
5290 .v.func = alc269_fixup_pcm_44k,
5291 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005292 [ALC269_FIXUP_STEREO_DMIC] = {
5293 .type = ALC_FIXUP_FUNC,
5294 .v.func = alc269_fixup_stereo_dmic,
5295 },
Takashi Iwai24519912011-08-16 15:08:49 +02005296 [ALC269_FIXUP_QUANTA_MUTE] = {
5297 .type = ALC_FIXUP_FUNC,
5298 .v.func = alc269_fixup_quanta_mute,
5299 },
5300 [ALC269_FIXUP_LIFEBOOK] = {
5301 .type = ALC_FIXUP_PINS,
5302 .v.pins = (const struct alc_pincfg[]) {
5303 { 0x1a, 0x2101103f }, /* dock line-out */
5304 { 0x1b, 0x23a11040 }, /* dock mic-in */
5305 { }
5306 },
5307 .chained = true,
5308 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5309 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005310 [ALC269_FIXUP_AMIC] = {
5311 .type = ALC_FIXUP_PINS,
5312 .v.pins = (const struct alc_pincfg[]) {
5313 { 0x14, 0x99130110 }, /* speaker */
5314 { 0x15, 0x0121401f }, /* HP out */
5315 { 0x18, 0x01a19c20 }, /* mic */
5316 { 0x19, 0x99a3092f }, /* int-mic */
5317 { }
5318 },
5319 },
5320 [ALC269_FIXUP_DMIC] = {
5321 .type = ALC_FIXUP_PINS,
5322 .v.pins = (const struct alc_pincfg[]) {
5323 { 0x12, 0x99a3092f }, /* int-mic */
5324 { 0x14, 0x99130110 }, /* speaker */
5325 { 0x15, 0x0121401f }, /* HP out */
5326 { 0x18, 0x01a19c20 }, /* mic */
5327 { }
5328 },
5329 },
5330 [ALC269VB_FIXUP_AMIC] = {
5331 .type = ALC_FIXUP_PINS,
5332 .v.pins = (const struct alc_pincfg[]) {
5333 { 0x14, 0x99130110 }, /* speaker */
5334 { 0x18, 0x01a19c20 }, /* mic */
5335 { 0x19, 0x99a3092f }, /* int-mic */
5336 { 0x21, 0x0121401f }, /* HP out */
5337 { }
5338 },
5339 },
David Henningsson2267ea92012-01-03 08:45:56 +01005340 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02005341 .type = ALC_FIXUP_PINS,
5342 .v.pins = (const struct alc_pincfg[]) {
5343 { 0x12, 0x99a3092f }, /* int-mic */
5344 { 0x14, 0x99130110 }, /* speaker */
5345 { 0x18, 0x01a19c20 }, /* mic */
5346 { 0x21, 0x0121401f }, /* HP out */
5347 { }
5348 },
5349 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005350};
5351
5352static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005353 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005354 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5355 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5356 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5357 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5358 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005359 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5360 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5361 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5362 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5363 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5364 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005365 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005366 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5367 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5368 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5369 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5370 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005371 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005372 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005373 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005374
5375#if 1
5376 /* Below is a quirk table taken from the old code.
5377 * Basically the device should work as is without the fixup table.
5378 * If BIOS doesn't give a proper info, enable the corresponding
5379 * fixup entry.
5380 */
5381 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5382 ALC269_FIXUP_AMIC),
5383 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5384 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
5385 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5386 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5387 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5388 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5389 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5390 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5391 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5392 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5393 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5394 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5395 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5396 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5397 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5398 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5399 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5400 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5401 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5402 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5403 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5404 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5405 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5406 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5407 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5408 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5409 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5410 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5411 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5412 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5413 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5414 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5415 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5416 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5417 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5418 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5419 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5420 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5421 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5422 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5423#endif
5424 {}
5425};
5426
5427static const struct alc_model_fixup alc269_fixup_models[] = {
5428 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5429 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005430 {}
5431};
5432
5433
5434static int alc269_fill_coef(struct hda_codec *codec)
5435{
5436 int val;
5437
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005438 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005439 alc_write_coef_idx(codec, 0xf, 0x960b);
5440 alc_write_coef_idx(codec, 0xe, 0x8817);
5441 }
5442
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005443 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005444 alc_write_coef_idx(codec, 0xf, 0x960b);
5445 alc_write_coef_idx(codec, 0xe, 0x8814);
5446 }
5447
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005448 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005449 val = alc_read_coef_idx(codec, 0x04);
5450 /* Power up output pin */
5451 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5452 }
5453
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005454 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005455 val = alc_read_coef_idx(codec, 0xd);
5456 if ((val & 0x0c00) >> 10 != 0x1) {
5457 /* Capless ramp up clock control */
5458 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5459 }
5460 val = alc_read_coef_idx(codec, 0x17);
5461 if ((val & 0x01c0) >> 6 != 0x4) {
5462 /* Class D power on reset */
5463 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5464 }
5465 }
5466
5467 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5468 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5469
5470 val = alc_read_coef_idx(codec, 0x4); /* HP */
5471 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5472
5473 return 0;
5474}
5475
5476/*
5477 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005478static int patch_alc269(struct hda_codec *codec)
5479{
5480 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005481 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005482
5483 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5484 if (spec == NULL)
5485 return -ENOMEM;
5486
5487 codec->spec = spec;
5488
5489 spec->mixer_nid = 0x0b;
5490
5491 alc_auto_parse_customize_define(codec);
5492
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005493 err = alc_codec_rename_from_preset(codec);
5494 if (err < 0)
5495 goto error;
5496
Takashi Iwai1d045db2011-07-07 18:23:21 +02005497 if (codec->vendor_id == 0x10ec0269) {
5498 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005499 switch (alc_get_coef0(codec) & 0x00f0) {
5500 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005501 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005502 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005503 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005504 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005505 break;
5506 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005507 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5508 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005509 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005510 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005511 break;
5512 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005513 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005514 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005515 if (err < 0)
5516 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005517 alc269_fill_coef(codec);
5518 }
5519
Takashi Iwaia4297b52011-08-23 18:40:12 +02005520 alc_pick_fixup(codec, alc269_fixup_models,
5521 alc269_fixup_tbl, alc269_fixups);
5522 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005523
Takashi Iwaia4297b52011-08-23 18:40:12 +02005524 /* automatic parse from the BIOS config */
5525 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005526 if (err < 0)
5527 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005528
Takashi Iwai60a6a842011-07-27 14:01:24 +02005529 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005530 alc_auto_fill_adc_caps(codec);
5531 alc_rebuild_imux_for_auto_mic(codec);
5532 alc_remove_invalid_adc_nids(codec);
5533 }
5534
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005535 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005536 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005537
5538 if (!spec->no_analog && has_cdefine_beep(codec)) {
5539 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005540 if (err < 0)
5541 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005542 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005543 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005544
5545 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5546
Takashi Iwai1d045db2011-07-07 18:23:21 +02005547 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005548#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005549 codec->patch_ops.resume = alc269_resume;
5550#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005551 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005552 spec->shutup = alc269_shutup;
5553
Takashi Iwai1d045db2011-07-07 18:23:21 +02005554#ifdef CONFIG_SND_HDA_POWER_SAVE
5555 if (!spec->loopback.amplist)
5556 spec->loopback.amplist = alc269_loopbacks;
5557 if (alc269_mic2_for_mute_led(codec))
5558 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5559#endif
5560
5561 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005562
5563 error:
5564 alc_free(codec);
5565 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005566}
5567
5568/*
5569 * ALC861
5570 */
5571
Takashi Iwai1d045db2011-07-07 18:23:21 +02005572static int alc861_parse_auto_config(struct hda_codec *codec)
5573{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005574 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005575 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5576 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005577}
5578
Takashi Iwai1d045db2011-07-07 18:23:21 +02005579#ifdef CONFIG_SND_HDA_POWER_SAVE
5580static const struct hda_amp_list alc861_loopbacks[] = {
5581 { 0x15, HDA_INPUT, 0 },
5582 { 0x15, HDA_INPUT, 1 },
5583 { 0x15, HDA_INPUT, 2 },
5584 { 0x15, HDA_INPUT, 3 },
5585 { } /* end */
5586};
5587#endif
5588
5589
5590/* Pin config fixes */
5591enum {
5592 PINFIX_FSC_AMILO_PI1505,
5593};
5594
5595static const struct alc_fixup alc861_fixups[] = {
5596 [PINFIX_FSC_AMILO_PI1505] = {
5597 .type = ALC_FIXUP_PINS,
5598 .v.pins = (const struct alc_pincfg[]) {
5599 { 0x0b, 0x0221101f }, /* HP */
5600 { 0x0f, 0x90170310 }, /* speaker */
5601 { }
5602 }
5603 },
5604};
5605
5606static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5607 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5608 {}
5609};
5610
5611/*
5612 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005613static int patch_alc861(struct hda_codec *codec)
5614{
5615 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005616 int err;
5617
5618 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5619 if (spec == NULL)
5620 return -ENOMEM;
5621
5622 codec->spec = spec;
5623
5624 spec->mixer_nid = 0x15;
5625
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005626 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5627 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005628
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005629 /* automatic parse from the BIOS config */
5630 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005631 if (err < 0)
5632 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005633
Takashi Iwai60a6a842011-07-27 14:01:24 +02005634 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005635 alc_auto_fill_adc_caps(codec);
5636 alc_rebuild_imux_for_auto_mic(codec);
5637 alc_remove_invalid_adc_nids(codec);
5638 }
5639
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005640 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005641 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005642
5643 if (!spec->no_analog) {
5644 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005645 if (err < 0)
5646 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005647 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5648 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005649
Takashi Iwai1d045db2011-07-07 18:23:21 +02005650 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5651
5652 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005653 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005654#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005655 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656 if (!spec->loopback.amplist)
5657 spec->loopback.amplist = alc861_loopbacks;
5658#endif
5659
5660 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005661
5662 error:
5663 alc_free(codec);
5664 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005665}
5666
5667/*
5668 * ALC861-VD support
5669 *
5670 * Based on ALC882
5671 *
5672 * In addition, an independent DAC
5673 */
5674#ifdef CONFIG_SND_HDA_POWER_SAVE
5675#define alc861vd_loopbacks alc880_loopbacks
5676#endif
5677
Takashi Iwai1d045db2011-07-07 18:23:21 +02005678static int alc861vd_parse_auto_config(struct hda_codec *codec)
5679{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005680 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005681 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5682 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005683}
5684
Takashi Iwai1d045db2011-07-07 18:23:21 +02005685enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005686 ALC660VD_FIX_ASUS_GPIO1,
5687 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005688};
5689
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005690/* exclude VREF80 */
5691static void alc861vd_fixup_dallas(struct hda_codec *codec,
5692 const struct alc_fixup *fix, int action)
5693{
5694 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5695 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5696 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5697 }
5698}
5699
Takashi Iwai1d045db2011-07-07 18:23:21 +02005700static const struct alc_fixup alc861vd_fixups[] = {
5701 [ALC660VD_FIX_ASUS_GPIO1] = {
5702 .type = ALC_FIXUP_VERBS,
5703 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005704 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005705 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5706 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5707 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5708 { }
5709 }
5710 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005711 [ALC861VD_FIX_DALLAS] = {
5712 .type = ALC_FIXUP_FUNC,
5713 .v.func = alc861vd_fixup_dallas,
5714 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005715};
5716
5717static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005718 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005719 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005720 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005721 {}
5722};
5723
5724static const struct hda_verb alc660vd_eapd_verbs[] = {
5725 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5726 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5727 { }
5728};
5729
5730/*
5731 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005732static int patch_alc861vd(struct hda_codec *codec)
5733{
5734 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005735 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005736
5737 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5738 if (spec == NULL)
5739 return -ENOMEM;
5740
5741 codec->spec = spec;
5742
5743 spec->mixer_nid = 0x0b;
5744
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005745 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5746 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005747
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005748 /* automatic parse from the BIOS config */
5749 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005750 if (err < 0)
5751 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005752
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753 if (codec->vendor_id == 0x10ec0660) {
5754 /* always turn on EAPD */
5755 add_verb(spec, alc660vd_eapd_verbs);
5756 }
5757
Takashi Iwai60a6a842011-07-27 14:01:24 +02005758 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005759 alc_auto_fill_adc_caps(codec);
5760 alc_rebuild_imux_for_auto_mic(codec);
5761 alc_remove_invalid_adc_nids(codec);
5762 }
5763
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005764 if (!spec->no_analog && !spec->cap_mixer)
5765 set_capture_mixer(codec);
5766
5767 if (!spec->no_analog) {
5768 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005769 if (err < 0)
5770 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005771 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5772 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005773
Takashi Iwai1d045db2011-07-07 18:23:21 +02005774 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5775
5776 codec->patch_ops = alc_patch_ops;
5777
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005778 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005779 spec->shutup = alc_eapd_shutup;
5780#ifdef CONFIG_SND_HDA_POWER_SAVE
5781 if (!spec->loopback.amplist)
5782 spec->loopback.amplist = alc861vd_loopbacks;
5783#endif
5784
5785 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005786
5787 error:
5788 alc_free(codec);
5789 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005790}
5791
5792/*
5793 * ALC662 support
5794 *
5795 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5796 * configuration. Each pin widget can choose any input DACs and a mixer.
5797 * Each ADC is connected from a mixer of all inputs. This makes possible
5798 * 6-channel independent captures.
5799 *
5800 * In addition, an independent DAC for the multi-playback (not used in this
5801 * driver yet).
5802 */
5803#ifdef CONFIG_SND_HDA_POWER_SAVE
5804#define alc662_loopbacks alc880_loopbacks
5805#endif
5806
5807/*
5808 * BIOS auto configuration
5809 */
5810
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005811static int alc662_parse_auto_config(struct hda_codec *codec)
5812{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005813 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005814 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5815 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5816 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005817
Kailang Yang6227cdc2010-02-25 08:36:52 +01005818 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5819 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005820 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005821 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005822 ssids = alc662_ssids;
5823 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005824}
5825
Todd Broch6be79482010-12-07 16:51:05 -08005826static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005827 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005828{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005829 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005830 return;
Todd Broch6be79482010-12-07 16:51:05 -08005831 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5832 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5833 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5834 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5835 (0 << AC_AMPCAP_MUTE_SHIFT)))
5836 printk(KERN_WARNING
5837 "hda_codec: failed to override amp caps for NID 0x2\n");
5838}
5839
David Henningsson6cb3b702010-09-09 08:51:44 +02005840enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005841 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005842 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005843 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005844 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005845 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005846 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005847 ALC662_FIXUP_ASUS_MODE1,
5848 ALC662_FIXUP_ASUS_MODE2,
5849 ALC662_FIXUP_ASUS_MODE3,
5850 ALC662_FIXUP_ASUS_MODE4,
5851 ALC662_FIXUP_ASUS_MODE5,
5852 ALC662_FIXUP_ASUS_MODE6,
5853 ALC662_FIXUP_ASUS_MODE7,
5854 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005855};
5856
5857static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005858 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005859 .type = ALC_FIXUP_PINS,
5860 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005861 { 0x15, 0x99130112 }, /* subwoofer */
5862 { }
5863 }
5864 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005865 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005866 .type = ALC_FIXUP_PINS,
5867 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005868 { 0x17, 0x99130112 }, /* subwoofer */
5869 { }
5870 }
5871 },
Todd Broch6be79482010-12-07 16:51:05 -08005872 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005873 .type = ALC_FIXUP_FUNC,
5874 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005875 },
5876 [ALC662_FIXUP_CZC_P10T] = {
5877 .type = ALC_FIXUP_VERBS,
5878 .v.verbs = (const struct hda_verb[]) {
5879 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5880 {}
5881 }
5882 },
David Henningsson94024cd2011-04-29 14:10:55 +02005883 [ALC662_FIXUP_SKU_IGNORE] = {
5884 .type = ALC_FIXUP_SKU,
5885 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005886 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005887 [ALC662_FIXUP_HP_RP5800] = {
5888 .type = ALC_FIXUP_PINS,
5889 .v.pins = (const struct alc_pincfg[]) {
5890 { 0x14, 0x0221201f }, /* HP out */
5891 { }
5892 },
5893 .chained = true,
5894 .chain_id = ALC662_FIXUP_SKU_IGNORE
5895 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005896 [ALC662_FIXUP_ASUS_MODE1] = {
5897 .type = ALC_FIXUP_PINS,
5898 .v.pins = (const struct alc_pincfg[]) {
5899 { 0x14, 0x99130110 }, /* speaker */
5900 { 0x18, 0x01a19c20 }, /* mic */
5901 { 0x19, 0x99a3092f }, /* int-mic */
5902 { 0x21, 0x0121401f }, /* HP out */
5903 { }
5904 },
5905 .chained = true,
5906 .chain_id = ALC662_FIXUP_SKU_IGNORE
5907 },
5908 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005909 .type = ALC_FIXUP_PINS,
5910 .v.pins = (const struct alc_pincfg[]) {
5911 { 0x14, 0x99130110 }, /* speaker */
5912 { 0x18, 0x01a19820 }, /* mic */
5913 { 0x19, 0x99a3092f }, /* int-mic */
5914 { 0x1b, 0x0121401f }, /* HP out */
5915 { }
5916 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005917 .chained = true,
5918 .chain_id = ALC662_FIXUP_SKU_IGNORE
5919 },
5920 [ALC662_FIXUP_ASUS_MODE3] = {
5921 .type = ALC_FIXUP_PINS,
5922 .v.pins = (const struct alc_pincfg[]) {
5923 { 0x14, 0x99130110 }, /* speaker */
5924 { 0x15, 0x0121441f }, /* HP */
5925 { 0x18, 0x01a19840 }, /* mic */
5926 { 0x19, 0x99a3094f }, /* int-mic */
5927 { 0x21, 0x01211420 }, /* HP2 */
5928 { }
5929 },
5930 .chained = true,
5931 .chain_id = ALC662_FIXUP_SKU_IGNORE
5932 },
5933 [ALC662_FIXUP_ASUS_MODE4] = {
5934 .type = ALC_FIXUP_PINS,
5935 .v.pins = (const struct alc_pincfg[]) {
5936 { 0x14, 0x99130110 }, /* speaker */
5937 { 0x16, 0x99130111 }, /* speaker */
5938 { 0x18, 0x01a19840 }, /* mic */
5939 { 0x19, 0x99a3094f }, /* int-mic */
5940 { 0x21, 0x0121441f }, /* HP */
5941 { }
5942 },
5943 .chained = true,
5944 .chain_id = ALC662_FIXUP_SKU_IGNORE
5945 },
5946 [ALC662_FIXUP_ASUS_MODE5] = {
5947 .type = ALC_FIXUP_PINS,
5948 .v.pins = (const struct alc_pincfg[]) {
5949 { 0x14, 0x99130110 }, /* speaker */
5950 { 0x15, 0x0121441f }, /* HP */
5951 { 0x16, 0x99130111 }, /* speaker */
5952 { 0x18, 0x01a19840 }, /* mic */
5953 { 0x19, 0x99a3094f }, /* int-mic */
5954 { }
5955 },
5956 .chained = true,
5957 .chain_id = ALC662_FIXUP_SKU_IGNORE
5958 },
5959 [ALC662_FIXUP_ASUS_MODE6] = {
5960 .type = ALC_FIXUP_PINS,
5961 .v.pins = (const struct alc_pincfg[]) {
5962 { 0x14, 0x99130110 }, /* speaker */
5963 { 0x15, 0x01211420 }, /* HP2 */
5964 { 0x18, 0x01a19840 }, /* mic */
5965 { 0x19, 0x99a3094f }, /* int-mic */
5966 { 0x1b, 0x0121441f }, /* HP */
5967 { }
5968 },
5969 .chained = true,
5970 .chain_id = ALC662_FIXUP_SKU_IGNORE
5971 },
5972 [ALC662_FIXUP_ASUS_MODE7] = {
5973 .type = ALC_FIXUP_PINS,
5974 .v.pins = (const struct alc_pincfg[]) {
5975 { 0x14, 0x99130110 }, /* speaker */
5976 { 0x17, 0x99130111 }, /* speaker */
5977 { 0x18, 0x01a19840 }, /* mic */
5978 { 0x19, 0x99a3094f }, /* int-mic */
5979 { 0x1b, 0x01214020 }, /* HP */
5980 { 0x21, 0x0121401f }, /* HP */
5981 { }
5982 },
5983 .chained = true,
5984 .chain_id = ALC662_FIXUP_SKU_IGNORE
5985 },
5986 [ALC662_FIXUP_ASUS_MODE8] = {
5987 .type = ALC_FIXUP_PINS,
5988 .v.pins = (const struct alc_pincfg[]) {
5989 { 0x14, 0x99130110 }, /* speaker */
5990 { 0x12, 0x99a30970 }, /* int-mic */
5991 { 0x15, 0x01214020 }, /* HP */
5992 { 0x17, 0x99130111 }, /* speaker */
5993 { 0x18, 0x01a19840 }, /* mic */
5994 { 0x21, 0x0121401f }, /* HP */
5995 { }
5996 },
5997 .chained = true,
5998 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005999 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006000};
6001
Takashi Iwaia9111322011-05-02 11:30:18 +02006002static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006003 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006004 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006005 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006006 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006007 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006008 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006009 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006010 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006011 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006012 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006013
6014#if 0
6015 /* Below is a quirk table taken from the old code.
6016 * Basically the device should work as is without the fixup table.
6017 * If BIOS doesn't give a proper info, enable the corresponding
6018 * fixup entry.
6019 */
6020 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6021 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6022 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6023 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6024 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6025 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6026 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6027 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6028 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6029 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6030 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6031 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6032 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6033 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6034 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6035 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6036 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6037 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6038 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6039 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6040 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6041 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6042 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6043 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6044 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6045 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6046 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6047 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6048 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6049 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6050 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6051 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6052 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6053 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6054 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6055 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6056 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6057 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6058 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6059 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6060 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6061 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6062 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6063 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6064 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6065 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6066 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6067 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6068 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6069 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6070#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006071 {}
6072};
6073
Todd Broch6be79482010-12-07 16:51:05 -08006074static const struct alc_model_fixup alc662_fixup_models[] = {
6075 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006076 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6077 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6078 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6079 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6080 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6081 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6082 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6083 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006084 {}
6085};
David Henningsson6cb3b702010-09-09 08:51:44 +02006086
6087
Takashi Iwai1d045db2011-07-07 18:23:21 +02006088/*
6089 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006090static int patch_alc662(struct hda_codec *codec)
6091{
6092 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006093 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006094
6095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6096 if (!spec)
6097 return -ENOMEM;
6098
6099 codec->spec = spec;
6100
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006101 spec->mixer_nid = 0x0b;
6102
Takashi Iwai53c334a2011-08-23 18:27:14 +02006103 /* handle multiple HPs as is */
6104 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6105
Kailang Yangda00c242010-03-19 11:23:45 +01006106 alc_auto_parse_customize_define(codec);
6107
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006108 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6109
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006110 err = alc_codec_rename_from_preset(codec);
6111 if (err < 0)
6112 goto error;
6113
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006114 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006115 codec->bus->pci->subsystem_vendor == 0x1025 &&
6116 spec->cdefine.platform_type == 1) {
6117 if (alc_codec_rename(codec, "ALC272X") < 0)
6118 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006119 }
Kailang Yang274693f2009-12-03 10:07:50 +01006120
Takashi Iwaib9c51062011-08-24 18:08:07 +02006121 alc_pick_fixup(codec, alc662_fixup_models,
6122 alc662_fixup_tbl, alc662_fixups);
6123 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6124 /* automatic parse from the BIOS config */
6125 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006126 if (err < 0)
6127 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006128
Takashi Iwai60a6a842011-07-27 14:01:24 +02006129 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006130 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006131 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006132 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006133 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006134
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006135 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006136 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006137
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006138 if (!spec->no_analog && has_cdefine_beep(codec)) {
6139 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006140 if (err < 0)
6141 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006142 switch (codec->vendor_id) {
6143 case 0x10ec0662:
6144 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6145 break;
6146 case 0x10ec0272:
6147 case 0x10ec0663:
6148 case 0x10ec0665:
6149 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6150 break;
6151 case 0x10ec0273:
6152 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6153 break;
6154 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006155 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006156
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006157 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6158
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006159 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006160 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c7161532011-04-07 10:37:16 +02006161 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006162
Takashi Iwaicb53c622007-08-10 17:21:45 +02006163#ifdef CONFIG_SND_HDA_POWER_SAVE
6164 if (!spec->loopback.amplist)
6165 spec->loopback.amplist = alc662_loopbacks;
6166#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006167
6168 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006169
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006170 error:
6171 alc_free(codec);
6172 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006173}
6174
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006175/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006176 * ALC680 support
6177 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006178
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006179static int alc680_parse_auto_config(struct hda_codec *codec)
6180{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006181 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006182}
6183
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006184/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006185 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006186static int patch_alc680(struct hda_codec *codec)
6187{
6188 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006189 int err;
6190
6191 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6192 if (spec == NULL)
6193 return -ENOMEM;
6194
6195 codec->spec = spec;
6196
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006197 /* ALC680 has no aa-loopback mixer */
6198
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006199 /* automatic parse from the BIOS config */
6200 err = alc680_parse_auto_config(codec);
6201 if (err < 0) {
6202 alc_free(codec);
6203 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006204 }
6205
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006206 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006207 set_capture_mixer(codec);
6208
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006209 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006210 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006211
6212 return 0;
6213}
6214
6215/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006216 * patch entries
6217 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006218static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006219 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006220 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006221 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006222 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006223 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006224 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006225 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006226 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006227 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006228 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006229 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006230 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006231 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6232 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6233 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006234 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006235 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006236 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6237 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006238 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6239 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006240 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006241 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006242 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006243 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006244 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006246 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006247 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006248 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006249 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006250 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006251 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006252 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006253 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006254 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006255 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006256 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006257 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006258 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006259 {} /* terminator */
6260};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006261
6262MODULE_ALIAS("snd-hda-codec-id:10ec*");
6263
6264MODULE_LICENSE("GPL");
6265MODULE_DESCRIPTION("Realtek HD-audio codec");
6266
6267static struct hda_codec_preset_list realtek_list = {
6268 .preset = snd_hda_preset_realtek,
6269 .owner = THIS_MODULE,
6270};
6271
6272static int __init patch_realtek_init(void)
6273{
6274 return snd_hda_add_codec_preset(&realtek_list);
6275}
6276
6277static void __exit patch_realtek_exit(void)
6278{
6279 snd_hda_delete_codec_preset(&realtek_list);
6280}
6281
6282module_init(patch_realtek_init)
6283module_exit(patch_realtek_exit)