blob: f5f3710362347e2f3e04e7f3c71860d260a9d63e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e42006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083struct alc_spec {
84 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020085 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010088 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Takashi Iwai2d9c6482009-10-13 08:06:55 +020090 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020091 * don't forget NULL
92 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020093 */
94 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Takashi Iwaiaa563af2009-07-31 10:05:11 +020096 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020097 const struct hda_pcm_stream *stream_analog_playback;
98 const struct hda_pcm_stream *stream_analog_capture;
99 const struct hda_pcm_stream *stream_analog_alt_playback;
100 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200102 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200103 const struct hda_pcm_stream *stream_digital_playback;
104 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200107 struct hda_multi_out multiout; /* playback set-up
108 * max_channels, dacs must be set
109 * dig_out_nid and hp_nid are optional
110 */
Takashi Iwai63300792008-01-24 15:31:36 +0100111 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100112 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100113 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* capture */
116 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200117 const hda_nid_t *adc_nids;
118 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200119 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200120 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwai527e4d72011-10-27 16:33:27 +0200121 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
122 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Takashi Iwai840b64c2010-07-13 22:49:01 +0200124 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200125 hda_nid_t cur_adc;
126 unsigned int cur_adc_stream_tag;
127 unsigned int cur_adc_format;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200130 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 const struct hda_input_mux *input_mux;
132 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200133 hda_nid_t ext_mic_pin;
134 hda_nid_t dock_mic_pin;
135 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100138 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200140 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200141 int const_channel_count;
142 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100145 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200146
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200147 /* dynamic controls, init_verbs and input_mux */
148 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100149 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200150 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200151 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200152 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai49535502009-06-30 15:28:30 +0200153 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200155 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
156 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
157 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100158
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100159 /* hooks */
160 void (*init_hook)(struct hda_codec *codec);
161 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100162#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500163 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200165 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200166 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100167
Takashi Iwai834be882006-03-01 14:16:17 +0100168 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200169 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200170 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200171 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200172 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200173 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200174 unsigned int automute_speaker:1; /* automute speaker outputs */
175 unsigned int automute_lo:1; /* automute LO outputs */
176 unsigned int detect_hp:1; /* Headphone detection enabled */
177 unsigned int detect_lo:1; /* Line-out detection enabled */
178 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
179 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100180 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200181
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100182 /* other flags */
183 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200184 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100185 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200186 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200187 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100188 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200189
190 /* auto-mute control */
191 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200192 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200193
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200194 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200195 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100196
Takashi Iwai2134ea42008-01-10 16:53:55 +0100197 /* for virtual master */
198 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200199#ifdef CONFIG_SND_HDA_POWER_SAVE
200 struct hda_loopback_check loopback;
201#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200202
203 /* for PLL fix */
204 hda_nid_t pll_nid;
205 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200206 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100207
208 /* fix-up list */
209 int fixup_id;
210 const struct alc_fixup *fixup_list;
211 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200212
213 /* multi-io */
214 int multi_ios;
215 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200216
217 /* bind volumes */
218 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100219};
220
Takashi Iwai1d045db2011-07-07 18:23:21 +0200221#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Takashi Iwai44c02402011-07-08 15:14:19 +0200223static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
224 int dir, unsigned int bits)
225{
226 if (!nid)
227 return false;
228 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
229 if (query_amp_caps(codec, nid, dir) & bits)
230 return true;
231 return false;
232}
233
234#define nid_has_mute(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
236#define nid_has_volume(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*
240 * input MUX handling
241 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200242static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
246 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200247 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
248 if (mux_idx >= spec->num_mux_defs)
249 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100250 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
251 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200252 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200255static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct alc_spec *spec = codec->spec;
260 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
261
262 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
263 return 0;
264}
265
Takashi Iwai21268962011-07-07 15:01:13 +0200266static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Takashi Iwai21268962011-07-07 15:01:13 +0200268 struct alc_spec *spec = codec->spec;
269 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
270
271 if (spec->cur_adc && spec->cur_adc != new_adc) {
272 /* stream is running, let's swap the current ADC */
273 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
274 spec->cur_adc = new_adc;
275 snd_hda_codec_setup_stream(codec, new_adc,
276 spec->cur_adc_stream_tag, 0,
277 spec->cur_adc_format);
278 return true;
279 }
280 return false;
281}
282
Takashi Iwai61071592011-11-23 07:52:15 +0100283static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
284{
285 return spec->capsrc_nids ?
286 spec->capsrc_nids[idx] : spec->adc_nids[idx];
287}
288
Takashi Iwai24de1832011-11-07 17:13:39 +0100289static void call_update_outputs(struct hda_codec *codec);
290
Takashi Iwai21268962011-07-07 15:01:13 +0200291/* select the given imux item; either unmute exclusively or select the route */
292static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
293 unsigned int idx, bool force)
294{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100296 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100297 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100298 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200299 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300
Takashi Iwaicd896c32008-11-18 12:36:33 +0100301 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
302 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100303 if (!imux->num_items && mux_idx > 0)
304 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100305 if (!imux->num_items)
306 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100307
Takashi Iwai21268962011-07-07 15:01:13 +0200308 if (idx >= imux->num_items)
309 idx = imux->num_items - 1;
310 if (spec->cur_mux[adc_idx] == idx && !force)
311 return 0;
312 spec->cur_mux[adc_idx] = idx;
313
Takashi Iwai24de1832011-11-07 17:13:39 +0100314 /* for shared I/O, change the pin-control accordingly */
315 if (spec->shared_mic_hp) {
316 /* NOTE: this assumes that there are only two inputs, the
317 * first is the real internal mic and the second is HP jack.
318 */
319 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
320 AC_VERB_SET_PIN_WIDGET_CONTROL,
321 spec->cur_mux[adc_idx] ?
322 PIN_VREF80 : PIN_HP);
323 spec->automute_speaker = !spec->cur_mux[adc_idx];
324 call_update_outputs(codec);
325 }
326
Takashi Iwai21268962011-07-07 15:01:13 +0200327 if (spec->dyn_adc_switch) {
328 alc_dyn_adc_pcm_resetup(codec, idx);
329 adc_idx = spec->dyn_adc_idx[idx];
330 }
331
Takashi Iwai61071592011-11-23 07:52:15 +0100332 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200333
334 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100335 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
336 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200337 return 1;
338
Takashi Iwaia22d5432009-07-27 12:54:26 +0200339 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200340 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100341 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100342 int active = imux->items[idx].index;
343 for (i = 0; i < num_conns; i++) {
344 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
345 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100346 HDA_AMP_MUTE, v);
347 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100348 } else {
349 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200350 snd_hda_codec_write_cache(codec, nid, 0,
351 AC_VERB_SET_CONNECT_SEL,
352 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100353 }
Takashi Iwai21268962011-07-07 15:01:13 +0200354 return 1;
355}
356
357static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
358 struct snd_ctl_elem_value *ucontrol)
359{
360 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
361 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
362 return alc_mux_select(codec, adc_idx,
363 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100364}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100367 * set up the input pin config (depending on the given auto-pin type)
368 */
369static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
370 int auto_pin_type)
371{
372 unsigned int val = PIN_IN;
373
Takashi Iwai86e29592010-09-09 14:50:17 +0200374 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100375 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200376 unsigned int oldval;
377 oldval = snd_hda_codec_read(codec, nid, 0,
378 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100379 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100380 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200381 /* if the default pin setup is vref50, we give it priority */
382 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100383 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200384 else if (pincap & AC_PINCAP_VREF_50)
385 val = PIN_VREF50;
386 else if (pincap & AC_PINCAP_VREF_100)
387 val = PIN_VREF100;
388 else if (pincap & AC_PINCAP_VREF_GRD)
389 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100390 }
391 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
392}
393
394/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200395 * Append the given mixer and verb elements for the later use
396 * The mixer array is referred in build_controls(), and init_verbs are
397 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100398 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200399static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100400{
401 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
402 return;
403 spec->mixers[spec->num_mixers++] = mix;
404}
405
406static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
407{
408 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
409 return;
410 spec->init_verbs[spec->num_init_verbs++] = verb;
411}
412
413/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200414 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100415 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200416/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200417static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200418 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
419 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
420 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
421 { }
422};
423
Takashi Iwaia9111322011-05-02 11:30:18 +0200424static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200425 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
427 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
428 { }
429};
430
Takashi Iwaia9111322011-05-02 11:30:18 +0200431static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200432 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
433 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
434 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
435 { }
436};
437
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200438/*
439 * Fix hardware PLL issue
440 * On some codecs, the analog PLL gating control must be off while
441 * the default value is 1.
442 */
443static void alc_fix_pll(struct hda_codec *codec)
444{
445 struct alc_spec *spec = codec->spec;
446 unsigned int val;
447
448 if (!spec->pll_nid)
449 return;
450 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
451 spec->pll_coef_idx);
452 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
453 AC_VERB_GET_PROC_COEF, 0);
454 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
455 spec->pll_coef_idx);
456 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
457 val & ~(1 << spec->pll_coef_bit));
458}
459
460static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
461 unsigned int coef_idx, unsigned int coef_bit)
462{
463 struct alc_spec *spec = codec->spec;
464 spec->pll_nid = nid;
465 spec->pll_coef_idx = coef_idx;
466 spec->pll_coef_bit = coef_bit;
467 alc_fix_pll(codec);
468}
469
Takashi Iwai1d045db2011-07-07 18:23:21 +0200470/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200471 * Jack detections for HP auto-mute and mic-switch
472 */
473
474/* check each pin in the given array; returns true if any of them is plugged */
475static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200476{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200477 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200478
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200479 for (i = 0; i < num_pins; i++) {
480 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200481 if (!nid)
482 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200483 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200484 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200485 return present;
486}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200487
Takashi Iwai1d045db2011-07-07 18:23:21 +0200488/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200489static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200490 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200491{
492 struct alc_spec *spec = codec->spec;
493 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200494 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495 int i;
496
497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100499 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200500 if (!nid)
501 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200502 switch (spec->automute_mode) {
503 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100504 /* don't reset VREF value in case it's controlling
505 * the amp (see alc861_fixup_asus_amp_vref_0f())
506 */
507 if (spec->keep_vref_in_automute) {
508 val = snd_hda_codec_read(codec, nid, 0,
509 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
510 val &= ~PIN_HP;
511 } else
512 val = 0;
513 val |= pin_bits;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200514 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200515 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai31150f22012-01-30 10:54:08 +0100516 val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200517 break;
518 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200519 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200520 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200521 break;
522 case ALC_AUTOMUTE_MIXER:
523 nid = spec->automute_mixer_nid[i];
524 if (!nid)
525 break;
526 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200527 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200528 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200530 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200531 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200532 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200533}
534
David Henningsson42cf0d02011-09-20 12:04:56 +0200535/* Toggle outputs muting */
536static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537{
538 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200539 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200540
Takashi Iwaic0a20262011-06-10 15:28:15 +0200541 /* Control HP pins/amps depending on master_mute state;
542 * in general, HP pins/amps control should be enabled in all cases,
543 * but currently set only for master_mute, just to be safe
544 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100545 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
546 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200547 spec->autocfg.hp_pins, spec->master_mute, true);
548
David Henningsson42cf0d02011-09-20 12:04:56 +0200549 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200550 on = 0;
551 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200552 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200553 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200554 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556
557 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200558 /* if LO is a copy of either HP or Speaker, don't need to handle it */
559 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
560 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200562 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200563 on = 0;
564 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200565 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200567 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200568 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200569}
570
David Henningsson42cf0d02011-09-20 12:04:56 +0200571static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200572{
573 struct alc_spec *spec = codec->spec;
574 if (spec->automute_hook)
575 spec->automute_hook(codec);
576 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200577 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200578}
579
Takashi Iwai1d045db2011-07-07 18:23:21 +0200580/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200581static void alc_hp_automute(struct hda_codec *codec)
582{
583 struct alc_spec *spec = codec->spec;
584
David Henningsson42cf0d02011-09-20 12:04:56 +0200585 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200586 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
587 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200588 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200589 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200590 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591}
592
Takashi Iwai1d045db2011-07-07 18:23:21 +0200593/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200594static void alc_line_automute(struct hda_codec *codec)
595{
596 struct alc_spec *spec = codec->spec;
597
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200598 /* check LO jack only when it's different from HP */
599 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
600 return;
601
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602 spec->line_jack_present =
603 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
604 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200605 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200606 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200607 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200608}
609
Takashi Iwai8d087c72011-06-28 12:45:47 +0200610#define get_connection_index(codec, mux, nid) \
611 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200612
Takashi Iwai1d045db2011-07-07 18:23:21 +0200613/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200614static void alc_mic_automute(struct hda_codec *codec)
615{
616 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200617 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200618
Takashi Iwai21268962011-07-07 15:01:13 +0200619 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200620 return;
621 if (snd_BUG_ON(!spec->adc_nids))
622 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200623 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200624 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200625
Takashi Iwai21268962011-07-07 15:01:13 +0200626 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
627 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
628 else if (spec->dock_mic_idx >= 0 &&
629 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
630 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
631 else
632 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200633}
634
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100635/* handle the specified unsol action (ALC_XXX_EVENT) */
636static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200637{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100638 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200639 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200640 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200641 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200642 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200643 alc_line_automute(codec);
644 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200645 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200646 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200647 break;
648 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200649 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200650}
651
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100652/* unsolicited event for HP jack sensing */
653static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
654{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100655 if (codec->vendor_id == 0x10ec0880)
656 res >>= 28;
657 else
658 res >>= 26;
Takashi Iwaia7309792012-01-19 15:03:48 +0100659 res = snd_hda_jack_get_action(codec, res);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100660 alc_exec_unsol_event(codec, res);
661}
662
Takashi Iwai1d045db2011-07-07 18:23:21 +0200663/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200664static void alc_inithook(struct hda_codec *codec)
665{
Takashi Iwaid922b512011-04-28 12:18:53 +0200666 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200667 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200668 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200669}
670
Kailang Yangf9423e72008-05-27 12:32:25 +0200671/* additional initialization for ALC888 variants */
672static void alc888_coef_init(struct hda_codec *codec)
673{
674 unsigned int tmp;
675
676 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
677 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
678 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100679 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200680 /* alc888S-VC */
681 snd_hda_codec_read(codec, 0x20, 0,
682 AC_VERB_SET_PROC_COEF, 0x830);
683 else
684 /* alc888-VB */
685 snd_hda_codec_read(codec, 0x20, 0,
686 AC_VERB_SET_PROC_COEF, 0x3030);
687}
688
Takashi Iwai1d045db2011-07-07 18:23:21 +0200689/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200690static void alc889_coef_init(struct hda_codec *codec)
691{
692 unsigned int tmp;
693
694 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
695 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
696 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
698}
699
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100700/* turn on/off EAPD control (only if available) */
701static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
702{
703 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
704 return;
705 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
706 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
707 on ? 2 : 0);
708}
709
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200710/* turn on/off EAPD controls of the codec */
711static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
712{
713 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200714 static hda_nid_t pins[] = {
715 0x0f, 0x10, 0x14, 0x15, 0
716 };
717 hda_nid_t *p;
718 for (p = pins; *p; p++)
719 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200720}
721
Takashi Iwai1c716152011-04-07 10:37:16 +0200722/* generic shutup callback;
723 * just turning off EPAD and a little pause for avoiding pop-noise
724 */
725static void alc_eapd_shutup(struct hda_codec *codec)
726{
727 alc_auto_setup_eapd(codec, false);
728 msleep(200);
729}
730
Takashi Iwai1d045db2011-07-07 18:23:21 +0200731/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200732static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200733{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200734 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200735
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200736 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200737 switch (type) {
738 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200739 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
740 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200741 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200742 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
743 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200744 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200745 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
746 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200747 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200748 switch (codec->vendor_id) {
749 case 0x10ec0260:
750 snd_hda_codec_write(codec, 0x1a, 0,
751 AC_VERB_SET_COEF_INDEX, 7);
752 tmp = snd_hda_codec_read(codec, 0x1a, 0,
753 AC_VERB_GET_PROC_COEF, 0);
754 snd_hda_codec_write(codec, 0x1a, 0,
755 AC_VERB_SET_COEF_INDEX, 7);
756 snd_hda_codec_write(codec, 0x1a, 0,
757 AC_VERB_SET_PROC_COEF,
758 tmp | 0x2010);
759 break;
760 case 0x10ec0262:
761 case 0x10ec0880:
762 case 0x10ec0882:
763 case 0x10ec0883:
764 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100765 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100766 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200767 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200768 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200769 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200771 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100772#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200773 case 0x10ec0267:
774 case 0x10ec0268:
775 snd_hda_codec_write(codec, 0x20, 0,
776 AC_VERB_SET_COEF_INDEX, 7);
777 tmp = snd_hda_codec_read(codec, 0x20, 0,
778 AC_VERB_GET_PROC_COEF, 0);
779 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200780 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200781 snd_hda_codec_write(codec, 0x20, 0,
782 AC_VERB_SET_PROC_COEF,
783 tmp | 0x3000);
784 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100785#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200786 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200787 break;
788 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200789}
Kailang Yangea1fb292008-08-26 12:58:38 +0200790
Takashi Iwai1d045db2011-07-07 18:23:21 +0200791/*
792 * Auto-Mute mode mixer enum support
793 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200794static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
795 struct snd_ctl_elem_info *uinfo)
796{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200797 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
798 struct alc_spec *spec = codec->spec;
799 static const char * const texts2[] = {
800 "Disabled", "Enabled"
801 };
802 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200803 "Disabled", "Speaker Only", "Line-Out+Speaker"
804 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200805 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200806
807 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
808 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200809 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200810 uinfo->value.enumerated.items = 3;
811 texts = texts3;
812 } else {
813 uinfo->value.enumerated.items = 2;
814 texts = texts2;
815 }
816 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
817 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200818 strcpy(uinfo->value.enumerated.name,
819 texts[uinfo->value.enumerated.item]);
820 return 0;
821}
822
823static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
824 struct snd_ctl_elem_value *ucontrol)
825{
826 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
827 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200828 unsigned int val = 0;
829 if (spec->automute_speaker)
830 val++;
831 if (spec->automute_lo)
832 val++;
833
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200834 ucontrol->value.enumerated.item[0] = val;
835 return 0;
836}
837
838static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
839 struct snd_ctl_elem_value *ucontrol)
840{
841 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
842 struct alc_spec *spec = codec->spec;
843
844 switch (ucontrol->value.enumerated.item[0]) {
845 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200846 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200847 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200848 spec->automute_speaker = 0;
849 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200850 break;
851 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200852 if (spec->automute_speaker_possible) {
853 if (!spec->automute_lo && spec->automute_speaker)
854 return 0;
855 spec->automute_speaker = 1;
856 spec->automute_lo = 0;
857 } else if (spec->automute_lo_possible) {
858 if (spec->automute_lo)
859 return 0;
860 spec->automute_lo = 1;
861 } else
862 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200863 break;
864 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200865 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200866 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200867 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200868 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200869 spec->automute_speaker = 1;
870 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200871 break;
872 default:
873 return -EINVAL;
874 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200875 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200876 return 1;
877}
878
Takashi Iwaia9111322011-05-02 11:30:18 +0200879static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
881 .name = "Auto-Mute Mode",
882 .info = alc_automute_mode_info,
883 .get = alc_automute_mode_get,
884 .put = alc_automute_mode_put,
885};
886
Takashi Iwai1d045db2011-07-07 18:23:21 +0200887static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
888{
889 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
890 return snd_array_new(&spec->kctls);
891}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200892
893static int alc_add_automute_mode_enum(struct hda_codec *codec)
894{
895 struct alc_spec *spec = codec->spec;
896 struct snd_kcontrol_new *knew;
897
898 knew = alc_kcontrol_new(spec);
899 if (!knew)
900 return -ENOMEM;
901 *knew = alc_automute_mode_enum;
902 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
903 if (!knew->name)
904 return -ENOMEM;
905 return 0;
906}
907
Takashi Iwai1d045db2011-07-07 18:23:21 +0200908/*
909 * Check the availability of HP/line-out auto-mute;
910 * Set up appropriately if really supported
911 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200912static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200913{
914 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200915 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200916 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200917 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200918
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200919 if (cfg->hp_pins[0])
920 present++;
921 if (cfg->line_out_pins[0])
922 present++;
923 if (cfg->speaker_pins[0])
924 present++;
925 if (present < 2) /* need two different output types */
926 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200927
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200928 if (!cfg->speaker_pins[0] &&
929 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200930 memcpy(cfg->speaker_pins, cfg->line_out_pins,
931 sizeof(cfg->speaker_pins));
932 cfg->speaker_outs = cfg->line_outs;
933 }
934
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200935 if (!cfg->hp_pins[0] &&
936 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200937 memcpy(cfg->hp_pins, cfg->line_out_pins,
938 sizeof(cfg->hp_pins));
939 cfg->hp_outs = cfg->line_outs;
940 }
941
David Henningsson42cf0d02011-09-20 12:04:56 +0200942 spec->automute_mode = ALC_AUTOMUTE_PIN;
943
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200944 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200945 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200946 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200947 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200948 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200949 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200950 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200951 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200952 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200953
David Henningsson42cf0d02011-09-20 12:04:56 +0200954 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
955 if (cfg->speaker_outs)
956 for (i = 0; i < cfg->line_outs; i++) {
957 hda_nid_t nid = cfg->line_out_pins[i];
958 if (!is_jack_detectable(codec, nid))
959 continue;
960 snd_printdd("realtek: Enable Line-Out "
961 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200962 snd_hda_jack_detect_enable(codec, nid,
963 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200964 spec->detect_lo = 1;
965 }
966 spec->automute_lo_possible = spec->detect_hp;
967 }
968
969 spec->automute_speaker_possible = cfg->speaker_outs &&
970 (spec->detect_hp || spec->detect_lo);
971
972 spec->automute_lo = spec->automute_lo_possible;
973 spec->automute_speaker = spec->automute_speaker_possible;
974
975 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200976 /* create a control for automute mode */
977 alc_add_automute_mode_enum(codec);
978 spec->unsol_event = alc_sku_unsol_event;
979 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200980}
981
Takashi Iwai1d045db2011-07-07 18:23:21 +0200982/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200983static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
984{
985 int i;
986 for (i = 0; i < nums; i++)
987 if (list[i] == nid)
988 return i;
989 return -1;
990}
991
Takashi Iwai1d045db2011-07-07 18:23:21 +0200992/* check whether dynamic ADC-switching is available */
993static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
994{
995 struct alc_spec *spec = codec->spec;
996 struct hda_input_mux *imux = &spec->private_imux[0];
997 int i, n, idx;
998 hda_nid_t cap, pin;
999
1000 if (imux != spec->input_mux) /* no dynamic imux? */
1001 return false;
1002
1003 for (n = 0; n < spec->num_adc_nids; n++) {
1004 cap = spec->private_capsrc_nids[n];
1005 for (i = 0; i < imux->num_items; i++) {
1006 pin = spec->imux_pins[i];
1007 if (!pin)
1008 return false;
1009 if (get_connection_index(codec, cap, pin) < 0)
1010 break;
1011 }
1012 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001013 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001014 }
1015
1016 for (i = 0; i < imux->num_items; i++) {
1017 pin = spec->imux_pins[i];
1018 for (n = 0; n < spec->num_adc_nids; n++) {
1019 cap = spec->private_capsrc_nids[n];
1020 idx = get_connection_index(codec, cap, pin);
1021 if (idx >= 0) {
1022 imux->items[i].index = idx;
1023 spec->dyn_adc_idx[i] = n;
1024 break;
1025 }
1026 }
1027 }
1028
1029 snd_printdd("realtek: enabling ADC switching\n");
1030 spec->dyn_adc_switch = 1;
1031 return true;
1032}
Takashi Iwai21268962011-07-07 15:01:13 +02001033
1034/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1035static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1036{
1037 struct alc_spec *spec = codec->spec;
1038 struct hda_input_mux *imux;
1039 static char * const texts[3] = {
1040 "Mic", "Internal Mic", "Dock Mic"
1041 };
1042 int i;
1043
1044 if (!spec->auto_mic)
1045 return false;
1046 imux = &spec->private_imux[0];
1047 if (spec->input_mux == imux)
1048 return true;
1049 spec->imux_pins[0] = spec->ext_mic_pin;
1050 spec->imux_pins[1] = spec->int_mic_pin;
1051 spec->imux_pins[2] = spec->dock_mic_pin;
1052 for (i = 0; i < 3; i++) {
1053 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001054 if (spec->imux_pins[i]) {
1055 hda_nid_t pin = spec->imux_pins[i];
1056 int c;
1057 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001058 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001059 int idx = get_connection_index(codec, cap, pin);
1060 if (idx >= 0) {
1061 imux->items[i].index = idx;
1062 break;
1063 }
1064 }
Takashi Iwai21268962011-07-07 15:01:13 +02001065 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001066 }
Takashi Iwai21268962011-07-07 15:01:13 +02001067 }
1068 spec->num_mux_defs = 1;
1069 spec->input_mux = imux;
1070 return true;
1071}
1072
1073/* check whether all auto-mic pins are valid; setup indices if OK */
1074static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1075{
1076 struct alc_spec *spec = codec->spec;
1077 const struct hda_input_mux *imux;
1078
1079 if (!spec->auto_mic)
1080 return false;
1081 if (spec->auto_mic_valid_imux)
1082 return true; /* already checked */
1083
1084 /* fill up imux indices */
1085 if (!alc_check_dyn_adc_switch(codec)) {
1086 spec->auto_mic = 0;
1087 return false;
1088 }
1089
1090 imux = spec->input_mux;
1091 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1092 spec->imux_pins, imux->num_items);
1093 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1094 spec->imux_pins, imux->num_items);
1095 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1096 spec->imux_pins, imux->num_items);
1097 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1098 spec->auto_mic = 0;
1099 return false; /* no corresponding imux */
1100 }
1101
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001102 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001103 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001104 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1105 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001106
1107 spec->auto_mic_valid_imux = 1;
1108 spec->auto_mic = 1;
1109 return true;
1110}
1111
Takashi Iwai1d045db2011-07-07 18:23:21 +02001112/*
1113 * Check the availability of auto-mic switch;
1114 * Set up if really supported
1115 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001116static void alc_init_auto_mic(struct hda_codec *codec)
1117{
1118 struct alc_spec *spec = codec->spec;
1119 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001120 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001121 int i;
1122
Takashi Iwai24de1832011-11-07 17:13:39 +01001123 if (spec->shared_mic_hp)
1124 return; /* no auto-mic for the shared I/O */
1125
Takashi Iwai21268962011-07-07 15:01:13 +02001126 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1127
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001128 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001129 for (i = 0; i < cfg->num_inputs; i++) {
1130 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001131 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001132 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001133 switch (snd_hda_get_input_pin_attr(defcfg)) {
1134 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001135 if (fixed)
1136 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001137 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1138 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001139 fixed = nid;
1140 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001141 case INPUT_PIN_ATTR_UNUSED:
1142 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001143 case INPUT_PIN_ATTR_DOCK:
1144 if (dock)
1145 return; /* already occupied */
1146 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1147 return; /* invalid type */
1148 dock = nid;
1149 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001150 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001151 if (ext)
1152 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001153 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1154 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001155 ext = nid;
1156 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001157 }
1158 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001159 if (!ext && dock) {
1160 ext = dock;
1161 dock = 0;
1162 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001163 if (!ext || !fixed)
1164 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001165 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001166 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001167 if (dock && !is_jack_detectable(codec, dock))
1168 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001169
1170 /* check imux indices */
1171 spec->ext_mic_pin = ext;
1172 spec->int_mic_pin = fixed;
1173 spec->dock_mic_pin = dock;
1174
1175 spec->auto_mic = 1;
1176 if (!alc_auto_mic_check_imux(codec))
1177 return;
1178
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001179 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1180 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001181 spec->unsol_event = alc_sku_unsol_event;
1182}
1183
Takashi Iwai1d045db2011-07-07 18:23:21 +02001184/* check the availabilities of auto-mute and auto-mic switches */
1185static void alc_auto_check_switches(struct hda_codec *codec)
1186{
David Henningsson42cf0d02011-09-20 12:04:56 +02001187 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001188 alc_init_auto_mic(codec);
1189}
1190
1191/*
1192 * Realtek SSID verification
1193 */
1194
David Henningsson90622912010-10-14 14:50:18 +02001195/* Could be any non-zero and even value. When used as fixup, tells
1196 * the driver to ignore any present sku defines.
1197 */
1198#define ALC_FIXUP_SKU_IGNORE (2)
1199
Kailang Yangda00c242010-03-19 11:23:45 +01001200static int alc_auto_parse_customize_define(struct hda_codec *codec)
1201{
1202 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001203 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001204 struct alc_spec *spec = codec->spec;
1205
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001206 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1207
David Henningsson90622912010-10-14 14:50:18 +02001208 if (spec->cdefine.fixup) {
1209 ass = spec->cdefine.sku_cfg;
1210 if (ass == ALC_FIXUP_SKU_IGNORE)
1211 return -1;
1212 goto do_sku;
1213 }
1214
Kailang Yangda00c242010-03-19 11:23:45 +01001215 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001216 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001217 goto do_sku;
1218
1219 nid = 0x1d;
1220 if (codec->vendor_id == 0x10ec0260)
1221 nid = 0x17;
1222 ass = snd_hda_codec_get_pincfg(codec, nid);
1223
1224 if (!(ass & 1)) {
1225 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1226 codec->chip_name, ass);
1227 return -1;
1228 }
1229
1230 /* check sum */
1231 tmp = 0;
1232 for (i = 1; i < 16; i++) {
1233 if ((ass >> i) & 1)
1234 tmp++;
1235 }
1236 if (((ass >> 16) & 0xf) != tmp)
1237 return -1;
1238
1239 spec->cdefine.port_connectivity = ass >> 30;
1240 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1241 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1242 spec->cdefine.customization = ass >> 8;
1243do_sku:
1244 spec->cdefine.sku_cfg = ass;
1245 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1246 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1247 spec->cdefine.swap = (ass & 0x2) >> 1;
1248 spec->cdefine.override = ass & 0x1;
1249
1250 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1251 nid, spec->cdefine.sku_cfg);
1252 snd_printd("SKU: port_connectivity=0x%x\n",
1253 spec->cdefine.port_connectivity);
1254 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1255 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1256 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1257 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1258 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1259 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1260 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1261
1262 return 0;
1263}
1264
Takashi Iwai1d045db2011-07-07 18:23:21 +02001265/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001266static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1267{
Takashi Iwai21268962011-07-07 15:01:13 +02001268 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001269}
1270
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001271/* check subsystem ID and set up device-specific initialization;
1272 * return 1 if initialized, 0 if invalid SSID
1273 */
1274/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1275 * 31 ~ 16 : Manufacture ID
1276 * 15 ~ 8 : SKU ID
1277 * 7 ~ 0 : Assembly ID
1278 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1279 */
1280static int alc_subsystem_id(struct hda_codec *codec,
1281 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001282 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001283{
1284 unsigned int ass, tmp, i;
1285 unsigned nid;
1286 struct alc_spec *spec = codec->spec;
1287
David Henningsson90622912010-10-14 14:50:18 +02001288 if (spec->cdefine.fixup) {
1289 ass = spec->cdefine.sku_cfg;
1290 if (ass == ALC_FIXUP_SKU_IGNORE)
1291 return 0;
1292 goto do_sku;
1293 }
1294
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001295 ass = codec->subsystem_id & 0xffff;
1296 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1297 goto do_sku;
1298
1299 /* invalid SSID, check the special NID pin defcfg instead */
1300 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001301 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001302 * 29~21 : reserve
1303 * 20 : PCBEEP input
1304 * 19~16 : Check sum (15:1)
1305 * 15~1 : Custom
1306 * 0 : override
1307 */
1308 nid = 0x1d;
1309 if (codec->vendor_id == 0x10ec0260)
1310 nid = 0x17;
1311 ass = snd_hda_codec_get_pincfg(codec, nid);
1312 snd_printd("realtek: No valid SSID, "
1313 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001314 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001315 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001316 return 0;
1317 if ((ass >> 30) != 1) /* no physical connection */
1318 return 0;
1319
1320 /* check sum */
1321 tmp = 0;
1322 for (i = 1; i < 16; i++) {
1323 if ((ass >> i) & 1)
1324 tmp++;
1325 }
1326 if (((ass >> 16) & 0xf) != tmp)
1327 return 0;
1328do_sku:
1329 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1330 ass & 0xffff, codec->vendor_id);
1331 /*
1332 * 0 : override
1333 * 1 : Swap Jack
1334 * 2 : 0 --> Desktop, 1 --> Laptop
1335 * 3~5 : External Amplifier control
1336 * 7~6 : Reserved
1337 */
1338 tmp = (ass & 0x38) >> 3; /* external Amp control */
1339 switch (tmp) {
1340 case 1:
1341 spec->init_amp = ALC_INIT_GPIO1;
1342 break;
1343 case 3:
1344 spec->init_amp = ALC_INIT_GPIO2;
1345 break;
1346 case 7:
1347 spec->init_amp = ALC_INIT_GPIO3;
1348 break;
1349 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001350 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001351 spec->init_amp = ALC_INIT_DEFAULT;
1352 break;
1353 }
1354
1355 /* is laptop or Desktop and enable the function "Mute internal speaker
1356 * when the external headphone out jack is plugged"
1357 */
1358 if (!(ass & 0x8000))
1359 return 1;
1360 /*
1361 * 10~8 : Jack location
1362 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1363 * 14~13: Resvered
1364 * 15 : 1 --> enable the function "Mute internal speaker
1365 * when the external headphone out jack is plugged"
1366 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001367 if (!spec->autocfg.hp_pins[0] &&
1368 !(spec->autocfg.line_out_pins[0] &&
1369 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001370 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001371 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1372 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001373 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001374 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001375 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001376 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001377 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001378 else if (tmp == 3)
1379 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001380 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001381 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001382 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1383 spec->autocfg.line_outs))
1384 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001385 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001386 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001387 return 1;
1388}
Kailang Yangea1fb292008-08-26 12:58:38 +02001389
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001390/* Check the validity of ALC subsystem-id
1391 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1392static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001393{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001394 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001395 struct alc_spec *spec = codec->spec;
1396 snd_printd("realtek: "
1397 "Enable default setup for auto mode as fallback\n");
1398 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001399 }
Takashi Iwai21268962011-07-07 15:01:13 +02001400}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001401
Takashi Iwai41e41f12005-06-08 14:48:49 +02001402/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001403 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001404 */
1405
1406struct alc_pincfg {
1407 hda_nid_t nid;
1408 u32 val;
1409};
1410
Todd Broche1eb5f12010-12-06 11:19:51 -08001411struct alc_model_fixup {
1412 const int id;
1413 const char *name;
1414};
1415
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001416struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001417 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001418 bool chained;
1419 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001420 union {
1421 unsigned int sku;
1422 const struct alc_pincfg *pins;
1423 const struct hda_verb *verbs;
1424 void (*func)(struct hda_codec *codec,
1425 const struct alc_fixup *fix,
1426 int action);
1427 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001428};
1429
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001430enum {
1431 ALC_FIXUP_INVALID,
1432 ALC_FIXUP_SKU,
1433 ALC_FIXUP_PINS,
1434 ALC_FIXUP_VERBS,
1435 ALC_FIXUP_FUNC,
1436};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001437
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001438enum {
1439 ALC_FIXUP_ACT_PRE_PROBE,
1440 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001441 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001442};
1443
1444static void alc_apply_fixup(struct hda_codec *codec, int action)
1445{
1446 struct alc_spec *spec = codec->spec;
1447 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001448#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001449 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001450#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001451 int depth = 0;
1452
1453 if (!spec->fixup_list)
1454 return;
1455
1456 while (id >= 0) {
1457 const struct alc_fixup *fix = spec->fixup_list + id;
1458 const struct alc_pincfg *cfg;
1459
1460 switch (fix->type) {
1461 case ALC_FIXUP_SKU:
1462 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001463 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001464 snd_printdd(KERN_INFO "hda_codec: %s: "
1465 "Apply sku override for %s\n",
1466 codec->chip_name, modelname);
1467 spec->cdefine.sku_cfg = fix->v.sku;
1468 spec->cdefine.fixup = 1;
1469 break;
1470 case ALC_FIXUP_PINS:
1471 cfg = fix->v.pins;
1472 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1473 break;
1474 snd_printdd(KERN_INFO "hda_codec: %s: "
1475 "Apply pincfg for %s\n",
1476 codec->chip_name, modelname);
1477 for (; cfg->nid; cfg++)
1478 snd_hda_codec_set_pincfg(codec, cfg->nid,
1479 cfg->val);
1480 break;
1481 case ALC_FIXUP_VERBS:
1482 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1483 break;
1484 snd_printdd(KERN_INFO "hda_codec: %s: "
1485 "Apply fix-verbs for %s\n",
1486 codec->chip_name, modelname);
1487 add_verb(codec->spec, fix->v.verbs);
1488 break;
1489 case ALC_FIXUP_FUNC:
1490 if (!fix->v.func)
1491 break;
1492 snd_printdd(KERN_INFO "hda_codec: %s: "
1493 "Apply fix-func for %s\n",
1494 codec->chip_name, modelname);
1495 fix->v.func(codec, fix, action);
1496 break;
1497 default:
1498 snd_printk(KERN_ERR "hda_codec: %s: "
1499 "Invalid fixup type %d\n",
1500 codec->chip_name, fix->type);
1501 break;
1502 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001503 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001504 break;
1505 if (++depth > 10)
1506 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001507 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001508 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001509}
1510
Todd Broche1eb5f12010-12-06 11:19:51 -08001511static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001512 const struct alc_model_fixup *models,
1513 const struct snd_pci_quirk *quirk,
1514 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001515{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001516 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001517 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001518 int id = -1;
1519 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001520
Todd Broche1eb5f12010-12-06 11:19:51 -08001521 if (codec->modelname && models) {
1522 while (models->name) {
1523 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001524 id = models->id;
1525 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001526 break;
1527 }
1528 models++;
1529 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001530 }
1531 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001532 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1533 if (q) {
1534 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001535#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001536 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001537#endif
1538 }
1539 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001540 if (id < 0) {
1541 for (q = quirk; q->subvendor; q++) {
1542 unsigned int vendorid =
1543 q->subdevice | (q->subvendor << 16);
1544 if (vendorid == codec->subsystem_id) {
1545 id = q->value;
1546#ifdef CONFIG_SND_DEBUG_VERBOSE
1547 name = q->name;
1548#endif
1549 break;
1550 }
1551 }
1552 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001553
1554 spec->fixup_id = id;
1555 if (id >= 0) {
1556 spec->fixup_list = fixlist;
1557 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001558 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001559}
1560
Takashi Iwai1d045db2011-07-07 18:23:21 +02001561/*
1562 * COEF access helper functions
1563 */
Kailang Yang274693f2009-12-03 10:07:50 +01001564static int alc_read_coef_idx(struct hda_codec *codec,
1565 unsigned int coef_idx)
1566{
1567 unsigned int val;
1568 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1569 coef_idx);
1570 val = snd_hda_codec_read(codec, 0x20, 0,
1571 AC_VERB_GET_PROC_COEF, 0);
1572 return val;
1573}
1574
Kailang Yang977ddd62010-09-15 10:02:29 +02001575static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1576 unsigned int coef_val)
1577{
1578 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1579 coef_idx);
1580 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1581 coef_val);
1582}
1583
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001584/* a special bypass for COEF 0; read the cached value at the second time */
1585static unsigned int alc_get_coef0(struct hda_codec *codec)
1586{
1587 struct alc_spec *spec = codec->spec;
1588 if (!spec->coef0)
1589 spec->coef0 = alc_read_coef_idx(codec, 0);
1590 return spec->coef0;
1591}
1592
Takashi Iwai1d045db2011-07-07 18:23:21 +02001593/*
1594 * Digital I/O handling
1595 */
1596
Takashi Iwai757899a2010-07-30 10:48:14 +02001597/* set right pin controls for digital I/O */
1598static void alc_auto_init_digital(struct hda_codec *codec)
1599{
1600 struct alc_spec *spec = codec->spec;
1601 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001602 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001603
1604 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1605 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001606 if (!pin)
1607 continue;
1608 snd_hda_codec_write(codec, pin, 0,
1609 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1610 if (!i)
1611 dac = spec->multiout.dig_out_nid;
1612 else
1613 dac = spec->slave_dig_outs[i - 1];
1614 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1615 continue;
1616 snd_hda_codec_write(codec, dac, 0,
1617 AC_VERB_SET_AMP_GAIN_MUTE,
1618 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001619 }
1620 pin = spec->autocfg.dig_in_pin;
1621 if (pin)
1622 snd_hda_codec_write(codec, pin, 0,
1623 AC_VERB_SET_PIN_WIDGET_CONTROL,
1624 PIN_IN);
1625}
1626
1627/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1628static void alc_auto_parse_digital(struct hda_codec *codec)
1629{
1630 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001631 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001632 hda_nid_t dig_nid;
1633
1634 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001635 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001636 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001637 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001638 err = snd_hda_get_connections(codec,
1639 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001640 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001641 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001642 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001643 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001644 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001645 spec->multiout.dig_out_nid = dig_nid;
1646 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1647 } else {
1648 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001649 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001650 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001651 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001652 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001653 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001654 }
1655
1656 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001657 dig_nid = codec->start_nid;
1658 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1659 unsigned int wcaps = get_wcaps(codec, dig_nid);
1660 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1661 continue;
1662 if (!(wcaps & AC_WCAP_DIGITAL))
1663 continue;
1664 if (!(wcaps & AC_WCAP_CONN_LIST))
1665 continue;
1666 err = get_connection_index(codec, dig_nid,
1667 spec->autocfg.dig_in_pin);
1668 if (err >= 0) {
1669 spec->dig_in_nid = dig_nid;
1670 break;
1671 }
1672 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001673 }
1674}
1675
Takashi Iwaif95474e2007-07-10 00:47:43 +02001676/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001677 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001678 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001679static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1680 struct snd_ctl_elem_info *uinfo)
1681{
1682 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1683 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001684 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001685 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001686
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001687 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001688 if (spec->vol_in_capsrc)
1689 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1690 else
1691 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1692 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001693 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001694 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001695 return err;
1696}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001698static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1699 unsigned int size, unsigned int __user *tlv)
1700{
1701 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1702 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001703 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001704 int err;
1705
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001706 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001707 if (spec->vol_in_capsrc)
1708 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1709 else
1710 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1711 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001712 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001713 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001714 return err;
1715}
1716
1717typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1718 struct snd_ctl_elem_value *ucontrol);
1719
1720static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1721 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001722 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001723{
1724 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1725 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001726 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001727
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001728 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001729 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001730 for (i = 0; i < spec->num_adc_nids; i++) {
1731 kcontrol->private_value =
1732 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1733 3, 0, HDA_INPUT);
1734 err = func(kcontrol, ucontrol);
1735 if (err < 0)
1736 goto error;
1737 }
1738 } else {
1739 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001740 if (spec->vol_in_capsrc)
1741 kcontrol->private_value =
1742 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1743 3, 0, HDA_OUTPUT);
1744 else
1745 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001746 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1747 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001748 err = func(kcontrol, ucontrol);
1749 }
1750 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001751 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001752 return err;
1753}
1754
1755static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1756 struct snd_ctl_elem_value *ucontrol)
1757{
1758 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001759 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001760}
1761
1762static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1763 struct snd_ctl_elem_value *ucontrol)
1764{
1765 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001766 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001767}
1768
1769/* capture mixer elements */
1770#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1771
1772static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1773 struct snd_ctl_elem_value *ucontrol)
1774{
1775 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001776 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001777}
1778
1779static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1780 struct snd_ctl_elem_value *ucontrol)
1781{
1782 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001783 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001784}
1785
Takashi Iwaia23b6882009-03-23 15:21:36 +01001786#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001787 { \
1788 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1789 .name = "Capture Switch", \
1790 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1791 .count = num, \
1792 .info = alc_cap_sw_info, \
1793 .get = alc_cap_sw_get, \
1794 .put = alc_cap_sw_put, \
1795 }, \
1796 { \
1797 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1798 .name = "Capture Volume", \
1799 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1800 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1801 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1802 .count = num, \
1803 .info = alc_cap_vol_info, \
1804 .get = alc_cap_vol_get, \
1805 .put = alc_cap_vol_put, \
1806 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001807 }
1808
1809#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001810 { \
1811 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1812 /* .name = "Capture Source", */ \
1813 .name = "Input Source", \
1814 .count = num, \
1815 .info = alc_mux_enum_info, \
1816 .get = alc_mux_enum_get, \
1817 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001818 }
1819
1820#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001821static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001822 _DEFINE_CAPMIX(num), \
1823 _DEFINE_CAPSRC(num), \
1824 { } /* end */ \
1825}
1826
1827#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001828static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001829 _DEFINE_CAPMIX(num), \
1830 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001831}
1832
1833/* up to three ADCs */
1834DEFINE_CAPMIX(1);
1835DEFINE_CAPMIX(2);
1836DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001837DEFINE_CAPMIX_NOSRC(1);
1838DEFINE_CAPMIX_NOSRC(2);
1839DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001840
1841/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001842 * virtual master controls
1843 */
1844
1845/*
1846 * slave controls for virtual master
1847 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001848static const char * const alc_slave_pfxs[] = {
1849 "Front", "Surround", "Center", "LFE", "Side",
1850 "Headphone", "Speaker", "Mono", "Line-Out",
1851 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001852 NULL,
1853};
1854
1855/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001856 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001858
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001859#define NID_MAPPING (-1)
1860
1861#define SUBDEV_SPEAKER_ (0 << 6)
1862#define SUBDEV_HP_ (1 << 6)
1863#define SUBDEV_LINE_ (2 << 6)
1864#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1865#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1866#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1867
Takashi Iwai603c4012008-07-30 15:01:44 +02001868static void alc_free_kctls(struct hda_codec *codec);
1869
Takashi Iwai67d634c2009-11-16 15:35:59 +01001870#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001871/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001872static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001873 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001874 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001875 { } /* end */
1876};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001877#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001878
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001879static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880{
1881 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001882 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001883 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001884 int i, j, err;
1885 unsigned int u;
1886 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
1888 for (i = 0; i < spec->num_mixers; i++) {
1889 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1890 if (err < 0)
1891 return err;
1892 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001893 if (spec->cap_mixer) {
1894 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1895 if (err < 0)
1896 return err;
1897 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001899 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001900 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001901 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 if (err < 0)
1903 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001904 if (!spec->no_analog) {
1905 err = snd_hda_create_spdif_share_sw(codec,
1906 &spec->multiout);
1907 if (err < 0)
1908 return err;
1909 spec->multiout.share_spdif = 1;
1910 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 }
1912 if (spec->dig_in_nid) {
1913 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1914 if (err < 0)
1915 return err;
1916 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001917
Takashi Iwai67d634c2009-11-16 15:35:59 +01001918#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001919 /* create beep controls if needed */
1920 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001921 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001922 for (knew = alc_beep_mixer; knew->name; knew++) {
1923 struct snd_kcontrol *kctl;
1924 kctl = snd_ctl_new1(knew, codec);
1925 if (!kctl)
1926 return -ENOMEM;
1927 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001928 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001929 if (err < 0)
1930 return err;
1931 }
1932 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001933#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001934
Takashi Iwai2134ea42008-01-10 16:53:55 +01001935 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001936 if (!spec->no_analog &&
1937 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001938 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001939 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001940 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001941 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001942 vmaster_tlv, alc_slave_pfxs,
1943 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001944 if (err < 0)
1945 return err;
1946 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001947 if (!spec->no_analog &&
1948 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001949 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001950 NULL, alc_slave_pfxs,
1951 "Playback Switch");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001952 if (err < 0)
1953 return err;
1954 }
1955
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001956 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001957 if (spec->capsrc_nids || spec->adc_nids) {
1958 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1959 if (!kctl)
1960 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1961 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001962 err = snd_hda_add_nid(codec, kctl, i,
1963 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001964 if (err < 0)
1965 return err;
1966 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001967 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001968 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001969 const char *kname = kctl ? kctl->id.name : NULL;
1970 for (knew = spec->cap_mixer; knew->name; knew++) {
1971 if (kname && strcmp(knew->name, kname) == 0)
1972 continue;
1973 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1974 for (i = 0; kctl && i < kctl->count; i++) {
1975 err = snd_hda_add_nid(codec, kctl, i,
1976 spec->adc_nids[i]);
1977 if (err < 0)
1978 return err;
1979 }
1980 }
1981 }
1982
1983 /* other nid->control mapping */
1984 for (i = 0; i < spec->num_mixers; i++) {
1985 for (knew = spec->mixers[i]; knew->name; knew++) {
1986 if (knew->iface != NID_MAPPING)
1987 continue;
1988 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1989 if (kctl == NULL)
1990 continue;
1991 u = knew->subdevice;
1992 for (j = 0; j < 4; j++, u >>= 8) {
1993 nid = u & 0x3f;
1994 if (nid == 0)
1995 continue;
1996 switch (u & 0xc0) {
1997 case SUBDEV_SPEAKER_:
1998 nid = spec->autocfg.speaker_pins[nid];
1999 break;
2000 case SUBDEV_LINE_:
2001 nid = spec->autocfg.line_out_pins[nid];
2002 break;
2003 case SUBDEV_HP_:
2004 nid = spec->autocfg.hp_pins[nid];
2005 break;
2006 default:
2007 continue;
2008 }
2009 err = snd_hda_add_nid(codec, kctl, 0, nid);
2010 if (err < 0)
2011 return err;
2012 }
2013 u = knew->private_value;
2014 for (j = 0; j < 4; j++, u >>= 8) {
2015 nid = u & 0xff;
2016 if (nid == 0)
2017 continue;
2018 err = snd_hda_add_nid(codec, kctl, 0, nid);
2019 if (err < 0)
2020 return err;
2021 }
2022 }
2023 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002024
2025 alc_free_kctls(codec); /* no longer needed */
2026
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002027 return 0;
2028}
2029
2030static int alc_build_controls(struct hda_codec *codec)
2031{
2032 struct alc_spec *spec = codec->spec;
2033 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002034 if (err < 0)
2035 return err;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002036 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037}
2038
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002039
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002041 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002042 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002043
Takashi Iwai584c0c42011-03-10 12:51:11 +01002044static void alc_init_special_input_src(struct hda_codec *codec);
2045
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046static int alc_init(struct hda_codec *codec)
2047{
2048 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002049 unsigned int i;
2050
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002051 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002052 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002053
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002054 for (i = 0; i < spec->num_init_verbs; i++)
2055 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002056 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002057
2058 if (spec->init_hook)
2059 spec->init_hook(codec);
2060
Takashi Iwai58701122011-01-13 15:41:45 +01002061 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2062
Takashi Iwai01a61e12011-10-28 00:03:22 +02002063 snd_hda_jack_report_sync(codec);
2064
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002065 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 return 0;
2067}
2068
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002069static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2070{
2071 struct alc_spec *spec = codec->spec;
2072
2073 if (spec->unsol_event)
2074 spec->unsol_event(codec, res);
2075}
2076
Takashi Iwaicb53c622007-08-10 17:21:45 +02002077#ifdef CONFIG_SND_HDA_POWER_SAVE
2078static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2079{
2080 struct alc_spec *spec = codec->spec;
2081 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2082}
2083#endif
2084
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085/*
2086 * Analog playback callbacks
2087 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002088static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002090 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091{
2092 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002093 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2094 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095}
2096
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002097static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 struct hda_codec *codec,
2099 unsigned int stream_tag,
2100 unsigned int format,
Takashi Iwaic8b6bf9b2005-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 Iwai9c7f8522006-06-28 15:08:22 +02002104 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2105 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106}
2107
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002108static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002110 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111{
2112 struct alc_spec *spec = codec->spec;
2113 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2114}
2115
2116/*
2117 * Digital out
2118 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002119static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002121 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122{
2123 struct alc_spec *spec = codec->spec;
2124 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2125}
2126
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002127static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002128 struct hda_codec *codec,
2129 unsigned int stream_tag,
2130 unsigned int format,
2131 struct snd_pcm_substream *substream)
2132{
2133 struct alc_spec *spec = codec->spec;
2134 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2135 stream_tag, format, substream);
2136}
2137
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002138static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002139 struct hda_codec *codec,
2140 struct snd_pcm_substream *substream)
2141{
2142 struct alc_spec *spec = codec->spec;
2143 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2144}
2145
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002146static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002148 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149{
2150 struct alc_spec *spec = codec->spec;
2151 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2152}
2153
2154/*
2155 * Analog capture
2156 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002157static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 struct hda_codec *codec,
2159 unsigned int stream_tag,
2160 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002161 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162{
2163 struct alc_spec *spec = codec->spec;
2164
Takashi Iwai63300792008-01-24 15:31:36 +01002165 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 stream_tag, 0, format);
2167 return 0;
2168}
2169
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002170static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-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 Iwai888afa12008-03-18 09:57:50 +01002176 snd_hda_codec_cleanup_stream(codec,
2177 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 return 0;
2179}
2180
Takashi Iwai840b64c2010-07-13 22:49:01 +02002181/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002182static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002183 struct hda_codec *codec,
2184 unsigned int stream_tag,
2185 unsigned int format,
2186 struct snd_pcm_substream *substream)
2187{
2188 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002189 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002190 spec->cur_adc_stream_tag = stream_tag;
2191 spec->cur_adc_format = format;
2192 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2193 return 0;
2194}
2195
Takashi Iwai21268962011-07-07 15:01:13 +02002196static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002197 struct hda_codec *codec,
2198 struct snd_pcm_substream *substream)
2199{
2200 struct alc_spec *spec = codec->spec;
2201 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2202 spec->cur_adc = 0;
2203 return 0;
2204}
2205
Takashi Iwai21268962011-07-07 15:01:13 +02002206static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002207 .substreams = 1,
2208 .channels_min = 2,
2209 .channels_max = 2,
2210 .nid = 0, /* fill later */
2211 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002212 .prepare = dyn_adc_capture_pcm_prepare,
2213 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002214 },
2215};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
2217/*
2218 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002219static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 .substreams = 1,
2221 .channels_min = 2,
2222 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002223 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002225 .open = alc_playback_pcm_open,
2226 .prepare = alc_playback_pcm_prepare,
2227 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 },
2229};
2230
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002231static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002232 .substreams = 1,
2233 .channels_min = 2,
2234 .channels_max = 2,
2235 /* NID is set in alc_build_pcms */
2236};
2237
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002238static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002239 .substreams = 1,
2240 .channels_min = 2,
2241 .channels_max = 2,
2242 /* NID is set in alc_build_pcms */
2243};
2244
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002245static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002246 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 .channels_min = 2,
2248 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002249 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002251 .prepare = alc_alt_capture_pcm_prepare,
2252 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 },
2254};
2255
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002256static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 .substreams = 1,
2258 .channels_min = 2,
2259 .channels_max = 2,
2260 /* NID is set in alc_build_pcms */
2261 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002262 .open = alc_dig_playback_pcm_open,
2263 .close = alc_dig_playback_pcm_close,
2264 .prepare = alc_dig_playback_pcm_prepare,
2265 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 },
2267};
2268
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002269static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 .substreams = 1,
2271 .channels_min = 2,
2272 .channels_max = 2,
2273 /* NID is set in alc_build_pcms */
2274};
2275
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002276/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002277static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002278 .substreams = 0,
2279 .channels_min = 0,
2280 .channels_max = 0,
2281};
2282
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283static int alc_build_pcms(struct hda_codec *codec)
2284{
2285 struct alc_spec *spec = codec->spec;
2286 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002287 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002288 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 int i;
2290
2291 codec->num_pcms = 1;
2292 codec->pcm_info = info;
2293
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002294 if (spec->no_analog)
2295 goto skip_analog;
2296
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002297 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2298 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002300
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002301 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002302 p = spec->stream_analog_playback;
2303 if (!p)
2304 p = &alc_pcm_analog_playback;
2305 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002306 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2307 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002308 if (spec->adc_nids) {
2309 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002310 if (!p) {
2311 if (spec->dyn_adc_switch)
2312 p = &dyn_adc_pcm_analog_capture;
2313 else
2314 p = &alc_pcm_analog_capture;
2315 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002316 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002317 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2318 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
Takashi Iwai4a471b72005-12-07 13:56:29 +01002320 if (spec->channel_mode) {
2321 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2322 for (i = 0; i < spec->num_channel_mode; i++) {
2323 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2324 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 }
2327 }
2328
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002329 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002330 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002332 snprintf(spec->stream_name_digital,
2333 sizeof(spec->stream_name_digital),
2334 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002335 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002336 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002337 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002339 if (spec->dig_out_type)
2340 info->pcm_type = spec->dig_out_type;
2341 else
2342 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002343 if (spec->multiout.dig_out_nid) {
2344 p = spec->stream_digital_playback;
2345 if (!p)
2346 p = &alc_pcm_digital_playback;
2347 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2349 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002350 if (spec->dig_in_nid) {
2351 p = spec->stream_digital_capture;
2352 if (!p)
2353 p = &alc_pcm_digital_capture;
2354 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2356 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002357 /* FIXME: do we need this for all Realtek codec models? */
2358 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 }
2360
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002361 if (spec->no_analog)
2362 return 0;
2363
Takashi Iwaie08a0072006-09-07 17:52:14 +02002364 /* If the use of more than one ADC is requested for the current
2365 * model, configure a second analog capture-only PCM.
2366 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002367 have_multi_adcs = (spec->num_adc_nids > 1) &&
2368 !spec->dyn_adc_switch && !spec->auto_mic &&
2369 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002370 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002371 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002372 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002373 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002374 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002375 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002376 p = spec->stream_analog_alt_playback;
2377 if (!p)
2378 p = &alc_pcm_analog_alt_playback;
2379 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002380 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2381 spec->alt_dac_nid;
2382 } else {
2383 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2384 alc_pcm_null_stream;
2385 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2386 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002387 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002388 p = spec->stream_analog_alt_capture;
2389 if (!p)
2390 p = &alc_pcm_analog_alt_capture;
2391 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002392 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2393 spec->adc_nids[1];
2394 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2395 spec->num_adc_nids - 1;
2396 } else {
2397 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2398 alc_pcm_null_stream;
2399 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002400 }
2401 }
2402
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 return 0;
2404}
2405
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002406static inline void alc_shutup(struct hda_codec *codec)
2407{
Takashi Iwai1c716152011-04-07 10:37:16 +02002408 struct alc_spec *spec = codec->spec;
2409
2410 if (spec && spec->shutup)
2411 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002412 snd_hda_shutup_pins(codec);
2413}
2414
Takashi Iwai603c4012008-07-30 15:01:44 +02002415static void alc_free_kctls(struct hda_codec *codec)
2416{
2417 struct alc_spec *spec = codec->spec;
2418
2419 if (spec->kctls.list) {
2420 struct snd_kcontrol_new *kctl = spec->kctls.list;
2421 int i;
2422 for (i = 0; i < spec->kctls.used; i++)
2423 kfree(kctl[i].name);
2424 }
2425 snd_array_free(&spec->kctls);
2426}
2427
Takashi Iwai23c09b02011-08-19 09:05:35 +02002428static void alc_free_bind_ctls(struct hda_codec *codec)
2429{
2430 struct alc_spec *spec = codec->spec;
2431 if (spec->bind_ctls.list) {
2432 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2433 int i;
2434 for (i = 0; i < spec->bind_ctls.used; i++)
2435 kfree(ctl[i]);
2436 }
2437 snd_array_free(&spec->bind_ctls);
2438}
2439
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440static void alc_free(struct hda_codec *codec)
2441{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002442 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002443
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002444 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002445 return;
2446
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002447 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002448 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002449 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002450 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002451 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452}
2453
Hector Martinf5de24b2009-12-20 22:51:31 +01002454#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002455static void alc_power_eapd(struct hda_codec *codec)
2456{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002457 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002458}
2459
Hector Martinf5de24b2009-12-20 22:51:31 +01002460static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2461{
2462 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002463 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002464 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002465 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002466 return 0;
2467}
2468#endif
2469
Takashi Iwai2a439522011-07-26 09:52:50 +02002470#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002471static int alc_resume(struct hda_codec *codec)
2472{
Takashi Iwai1c716152011-04-07 10:37:16 +02002473 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002474 codec->patch_ops.init(codec);
2475 snd_hda_codec_resume_amp(codec);
2476 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002477 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002478 return 0;
2479}
Takashi Iwaie044c392008-10-27 16:56:24 +01002480#endif
2481
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482/*
2483 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002484static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 .build_controls = alc_build_controls,
2486 .build_pcms = alc_build_pcms,
2487 .init = alc_init,
2488 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002489 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002490#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002491 .resume = alc_resume,
2492#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002493#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002494 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002495 .check_power_status = alc_check_power_status,
2496#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002497 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498};
2499
Kailang Yangc027ddc2010-03-19 11:33:06 +01002500/* replace the codec chip_name with the given string */
2501static int alc_codec_rename(struct hda_codec *codec, const char *name)
2502{
2503 kfree(codec->chip_name);
2504 codec->chip_name = kstrdup(name, GFP_KERNEL);
2505 if (!codec->chip_name) {
2506 alc_free(codec);
2507 return -ENOMEM;
2508 }
2509 return 0;
2510}
2511
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002512/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002513 * Rename codecs appropriately from COEF value
2514 */
2515struct alc_codec_rename_table {
2516 unsigned int vendor_id;
2517 unsigned short coef_mask;
2518 unsigned short coef_bits;
2519 const char *name;
2520};
2521
2522static struct alc_codec_rename_table rename_tbl[] = {
2523 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2524 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2525 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2526 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2527 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2528 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2529 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2530 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2531 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2532 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2533 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2534 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2535 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2536 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2537 { } /* terminator */
2538};
2539
2540static int alc_codec_rename_from_preset(struct hda_codec *codec)
2541{
2542 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002543
2544 for (p = rename_tbl; p->vendor_id; p++) {
2545 if (p->vendor_id != codec->vendor_id)
2546 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002547 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002548 return alc_codec_rename(codec, p->name);
2549 }
2550 return 0;
2551}
2552
2553/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002554 * Automatic parse of I/O pins from the BIOS configuration
2555 */
2556
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002557enum {
2558 ALC_CTL_WIDGET_VOL,
2559 ALC_CTL_WIDGET_MUTE,
2560 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002561 ALC_CTL_BIND_VOL,
2562 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002563};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002564static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002565 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2566 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002567 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002568 HDA_BIND_VOL(NULL, 0),
2569 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002570};
2571
2572/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002573static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002574 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002575{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002576 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002577
Takashi Iwaice764ab2011-04-27 16:35:23 +02002578 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002579 if (!knew)
2580 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002581 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002582 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002583 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002584 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002585 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002586 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002587 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002588 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002589 return 0;
2590}
2591
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002592static int add_control_with_pfx(struct alc_spec *spec, int type,
2593 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002594 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002595{
2596 char name[32];
2597 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002598 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002599}
2600
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002601#define add_pb_vol_ctrl(spec, type, pfx, val) \
2602 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2603#define add_pb_sw_ctrl(spec, type, pfx, val) \
2604 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2605#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2606 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2607#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2608 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002609
Takashi Iwai23c09b02011-08-19 09:05:35 +02002610static const char * const channel_name[4] = {
2611 "Front", "Surround", "CLFE", "Side"
2612};
2613
Takashi Iwai6843ca12011-06-24 11:03:58 +02002614static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2615 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002616{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002617 struct auto_pin_cfg *cfg = &spec->autocfg;
2618
Takashi Iwai6843ca12011-06-24 11:03:58 +02002619 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002620 if (cfg->line_outs == 1 && !spec->multi_ios &&
2621 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002622 return "Master";
2623
2624 switch (cfg->line_out_type) {
2625 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002626 if (cfg->line_outs == 1)
2627 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002628 if (cfg->line_outs == 2)
2629 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002630 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002631 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002632 /* for multi-io case, only the primary out */
2633 if (ch && spec->multi_ios)
2634 break;
2635 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002636 return "Headphone";
2637 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002638 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002639 return "PCM";
2640 break;
2641 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002642 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2643 return "PCM";
2644
2645 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002646}
2647
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002648/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002649static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002650 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002651 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002652{
Kailang Yangdf694da2005-12-05 19:42:22 +01002653 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002654
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002655 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002656 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2657 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002658 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002659 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002660 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2661 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002662 return err;
2663 return 0;
2664}
2665
Takashi Iwai05f5f472009-08-25 13:10:18 +02002666static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002667{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002668 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2669 return (pincap & AC_PINCAP_IN) != 0;
2670}
2671
Takashi Iwai1d045db2011-07-07 18:23:21 +02002672/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002673static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002674{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002675 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002676 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002677 hda_nid_t *adc_nids = spec->private_adc_nids;
2678 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2679 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002680 int i, nums = 0;
2681
Takashi Iwai24de1832011-11-07 17:13:39 +01002682 if (spec->shared_mic_hp)
2683 max_nums = 1; /* no multi streams with the shared HP/mic */
2684
Takashi Iwaib7821702011-07-06 15:12:46 +02002685 nid = codec->start_nid;
2686 for (i = 0; i < codec->num_nodes; i++, nid++) {
2687 hda_nid_t src;
2688 const hda_nid_t *list;
2689 unsigned int caps = get_wcaps(codec, nid);
2690 int type = get_wcaps_type(caps);
2691
2692 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2693 continue;
2694 adc_nids[nums] = nid;
2695 cap_nids[nums] = nid;
2696 src = nid;
2697 for (;;) {
2698 int n;
2699 type = get_wcaps_type(get_wcaps(codec, src));
2700 if (type == AC_WID_PIN)
2701 break;
2702 if (type == AC_WID_AUD_SEL) {
2703 cap_nids[nums] = src;
2704 break;
2705 }
2706 n = snd_hda_get_conn_list(codec, src, &list);
2707 if (n > 1) {
2708 cap_nids[nums] = src;
2709 break;
2710 } else if (n != 1)
2711 break;
2712 src = *list;
2713 }
2714 if (++nums >= max_nums)
2715 break;
2716 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002717 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002718 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002719 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002720 return nums;
2721}
2722
Takashi Iwai05f5f472009-08-25 13:10:18 +02002723/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002724static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002725{
2726 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002727 const struct auto_pin_cfg *cfg = &spec->autocfg;
2728 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002729 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002730 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002731 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002732 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002733
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002734 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002735 if (num_adcs < 0)
2736 return 0;
2737
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002738 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002739 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002740 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002741
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002742 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002743 if (!alc_is_input_pin(codec, pin))
2744 continue;
2745
David Henningsson5322bf22011-01-05 11:03:56 +01002746 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002747 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2748 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002749 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002750 type_idx++;
2751 else
2752 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002753 prev_label = label;
2754
Takashi Iwai05f5f472009-08-25 13:10:18 +02002755 if (mixer) {
2756 idx = get_connection_index(codec, mixer, pin);
2757 if (idx >= 0) {
2758 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002759 label, type_idx,
2760 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002761 if (err < 0)
2762 return err;
2763 }
2764 }
2765
Takashi Iwaib7821702011-07-06 15:12:46 +02002766 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002767 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002768 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002769 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002770 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002771 snd_hda_add_imux_item(imux, label, idx, NULL);
2772 break;
2773 }
2774 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002775 }
Takashi Iwai21268962011-07-07 15:01:13 +02002776
2777 spec->num_mux_defs = 1;
2778 spec->input_mux = imux;
2779
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002780 return 0;
2781}
2782
Takashi Iwai24de1832011-11-07 17:13:39 +01002783/* create a shared input with the headphone out */
2784static int alc_auto_create_shared_input(struct hda_codec *codec)
2785{
2786 struct alc_spec *spec = codec->spec;
2787 struct auto_pin_cfg *cfg = &spec->autocfg;
2788 unsigned int defcfg;
2789 hda_nid_t nid;
2790
2791 /* only one internal input pin? */
2792 if (cfg->num_inputs != 1)
2793 return 0;
2794 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2795 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2796 return 0;
2797
2798 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2799 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2800 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2801 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2802 else
2803 return 0; /* both not available */
2804
2805 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2806 return 0; /* no input */
2807
2808 cfg->inputs[1].pin = nid;
2809 cfg->inputs[1].type = AUTO_PIN_MIC;
2810 cfg->num_inputs = 2;
2811 spec->shared_mic_hp = 1;
2812 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2813 return 0;
2814}
2815
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002816static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2817 unsigned int pin_type)
2818{
2819 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2820 pin_type);
2821 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002822 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2823 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002824 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002825}
2826
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002827static int get_pin_type(int line_out_type)
2828{
2829 if (line_out_type == AUTO_PIN_HP_OUT)
2830 return PIN_HP;
2831 else
2832 return PIN_OUT;
2833}
2834
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002835static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002836{
2837 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002838 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002839 int i;
2840
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002841 for (i = 0; i < cfg->num_inputs; i++) {
2842 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002843 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002844 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002845 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002846 snd_hda_codec_write(codec, nid, 0,
2847 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002848 AMP_OUT_MUTE);
2849 }
2850 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002851
2852 /* mute all loopback inputs */
2853 if (spec->mixer_nid) {
2854 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2855 for (i = 0; i < nums; i++)
2856 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2857 AC_VERB_SET_AMP_GAIN_MUTE,
2858 AMP_IN_MUTE(i));
2859 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002860}
2861
Takashi Iwai7085ec12009-10-02 09:03:58 +02002862/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002863static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002864{
Takashi Iwai604401a2011-04-27 15:14:23 +02002865 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002866 int i, num;
2867
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002868 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2869 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002870 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2871 for (i = 0; i < num; i++) {
2872 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2873 return list[i];
2874 }
2875 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002876}
2877
Takashi Iwai604401a2011-04-27 15:14:23 +02002878/* go down to the selector widget before the mixer */
2879static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2880{
2881 hda_nid_t srcs[5];
2882 int num = snd_hda_get_connections(codec, pin, srcs,
2883 ARRAY_SIZE(srcs));
2884 if (num != 1 ||
2885 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2886 return pin;
2887 return srcs[0];
2888}
2889
Takashi Iwai7085ec12009-10-02 09:03:58 +02002890/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002891static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002892 hda_nid_t dac)
2893{
David Henningssoncc1c4522010-11-24 14:17:47 +01002894 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002895 int i, num;
2896
Takashi Iwai604401a2011-04-27 15:14:23 +02002897 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002898 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2899 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002900 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002901 return mix[i];
2902 }
2903 return 0;
2904}
2905
Takashi Iwaice764ab2011-04-27 16:35:23 +02002906/* select the connection from pin to DAC if needed */
2907static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2908 hda_nid_t dac)
2909{
2910 hda_nid_t mix[5];
2911 int i, num;
2912
2913 pin = alc_go_down_to_selector(codec, pin);
2914 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2915 if (num < 2)
2916 return 0;
2917 for (i = 0; i < num; i++) {
2918 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2919 snd_hda_codec_update_cache(codec, pin, 0,
2920 AC_VERB_SET_CONNECT_SEL, i);
2921 return 0;
2922 }
2923 }
2924 return 0;
2925}
2926
Takashi Iwai7085ec12009-10-02 09:03:58 +02002927/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002928static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002929{
2930 struct alc_spec *spec = codec->spec;
2931 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002932 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002933
Takashi Iwai604401a2011-04-27 15:14:23 +02002934 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002935 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002936 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002937 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002938 if (!nid)
2939 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002940 if (found_in_nid_list(nid, spec->multiout.dac_nids,
Takashi Iwai0a34b422011-12-07 17:20:30 +01002941 ARRAY_SIZE(spec->private_dac_nids)))
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002942 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002943 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2944 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2945 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002946 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2947 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2948 continue;
2949 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002950 }
2951 return 0;
2952}
2953
Takashi Iwai07b18f62011-11-10 15:42:54 +01002954/* check whether the DAC is reachable from the pin */
2955static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2956 hda_nid_t pin, hda_nid_t dac)
2957{
2958 hda_nid_t srcs[5];
2959 int i, num;
2960
2961 pin = alc_go_down_to_selector(codec, pin);
2962 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2963 for (i = 0; i < num; i++) {
2964 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2965 if (nid == dac)
2966 return true;
2967 }
2968 return false;
2969}
2970
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002971static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2972{
2973 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2974 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2975 return alc_auto_look_for_dac(codec, pin);
2976 return 0;
2977}
2978
Takashi Iwai0a34b422011-12-07 17:20:30 +01002979/* return 0 if no possible DAC is found, 1 if one or more found */
Takashi Iwaic2674682011-08-24 17:57:44 +02002980static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2981 const hda_nid_t *pins, hda_nid_t *dacs)
2982{
2983 int i;
2984
2985 if (num_outs && !dacs[0]) {
2986 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2987 if (!dacs[0])
2988 return 0;
2989 }
2990
2991 for (i = 1; i < num_outs; i++)
2992 dacs[i] = get_dac_if_single(codec, pins[i]);
2993 for (i = 1; i < num_outs; i++) {
2994 if (!dacs[i])
2995 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2996 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01002997 return 1;
Takashi Iwaic2674682011-08-24 17:57:44 +02002998}
2999
3000static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003001 unsigned int location, int offset);
David Henningssonfde48a12011-12-09 18:27:42 +08003002static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3003 hda_nid_t pin, hda_nid_t dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003004
Takashi Iwai7085ec12009-10-02 09:03:58 +02003005/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003006static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003007{
3008 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003009 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003010 unsigned int location, defcfg;
3011 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003012 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003013 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003014
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003015 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003016 /* set num_dacs once to full for alc_auto_look_for_dac() */
3017 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003018 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003019 spec->multiout.extra_out_nid[0] = 0;
3020 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3021 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003022 spec->multi_ios = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003023
3024 /* fill hard-wired DACs first */
3025 if (!redone) {
3026 for (i = 0; i < cfg->line_outs; i++)
3027 spec->private_dac_nids[i] =
3028 get_dac_if_single(codec, cfg->line_out_pins[i]);
3029 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003030 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003031 get_dac_if_single(codec, cfg->hp_pins[0]);
3032 if (cfg->speaker_outs)
3033 spec->multiout.extra_out_nid[0] =
3034 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003035 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003036
3037 for (i = 0; i < cfg->line_outs; i++) {
3038 hda_nid_t pin = cfg->line_out_pins[i];
3039 if (spec->private_dac_nids[i])
3040 continue;
3041 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3042 if (!spec->private_dac_nids[i] && !redone) {
3043 /* if we can't find primary DACs, re-probe without
3044 * checking the hard-wired DACs
3045 */
3046 redone = true;
3047 goto again;
3048 }
3049 }
3050
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003051 /* re-count num_dacs and squash invalid entries */
3052 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003053 for (i = 0; i < cfg->line_outs; i++) {
3054 if (spec->private_dac_nids[i])
3055 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003056 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003057 memmove(spec->private_dac_nids + i,
3058 spec->private_dac_nids + i + 1,
3059 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003060 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3061 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003062 }
3063
Takashi Iwaic2674682011-08-24 17:57:44 +02003064 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3065 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003066 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3067 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003068
Takashi Iwai07b18f62011-11-10 15:42:54 +01003069 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003070 if (num_pins > 0) {
3071 spec->multi_ios = num_pins;
3072 spec->ext_channel_count = 2;
3073 spec->multiout.num_dacs = num_pins + 1;
3074 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003075 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003076
Takashi Iwai716eef02011-10-21 15:07:42 +02003077 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3078 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003079 spec->multiout.hp_out_nid);
Takashi Iwai0a34b422011-12-07 17:20:30 +01003080 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3081 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3082 cfg->speaker_pins,
3083 spec->multiout.extra_out_nid);
3084 /* if no speaker volume is assigned, try again as the primary
3085 * output
3086 */
3087 if (!err && cfg->speaker_outs > 0 &&
3088 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3089 cfg->hp_outs = cfg->line_outs;
3090 memcpy(cfg->hp_pins, cfg->line_out_pins,
3091 sizeof(cfg->hp_pins));
3092 cfg->line_outs = cfg->speaker_outs;
3093 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3094 sizeof(cfg->speaker_pins));
3095 cfg->speaker_outs = 0;
3096 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3097 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3098 redone = false;
3099 goto again;
3100 }
3101 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003102
Takashi Iwai07b18f62011-11-10 15:42:54 +01003103 if (!spec->multi_ios &&
3104 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3105 cfg->hp_outs) {
3106 /* try multi-ios with HP + inputs */
3107 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3108 location = get_defcfg_location(defcfg);
3109
3110 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3111 if (num_pins > 0) {
3112 spec->multi_ios = num_pins;
3113 spec->ext_channel_count = 2;
3114 spec->multiout.num_dacs = num_pins + 1;
3115 }
3116 }
3117
David Henningssonfde48a12011-12-09 18:27:42 +08003118 if (cfg->line_out_pins[0])
3119 spec->vmaster_nid =
3120 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3121 spec->multiout.dac_nids[0]);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003122 return 0;
3123}
3124
Takashi Iwai527e4d72011-10-27 16:33:27 +02003125static inline unsigned int get_ctl_pos(unsigned int data)
3126{
3127 hda_nid_t nid = get_amp_nid_(data);
3128 unsigned int dir = get_amp_direction_(data);
3129 return (nid << 1) | dir;
3130}
3131
3132#define is_ctl_used(bits, data) \
3133 test_bit(get_ctl_pos(data), bits)
3134#define mark_ctl_usage(bits, data) \
3135 set_bit(get_ctl_pos(data), bits)
3136
Takashi Iwai343a04b2011-07-06 14:28:39 +02003137static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003138 const char *pfx, int cidx,
3139 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003140{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003141 struct alc_spec *spec = codec->spec;
3142 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003143 if (!nid)
3144 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003145 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3146 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3147 return 0;
3148 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003149 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003150 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003151}
3152
Takashi Iwaie29d3772011-11-14 17:13:23 +01003153static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3154 const char *pfx, int cidx,
3155 hda_nid_t nid)
3156{
3157 int chs = 1;
3158 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3159 chs = 3;
3160 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3161}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003162
3163/* create a mute-switch for the given mixer widget;
3164 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3165 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003166static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003167 const char *pfx, int cidx,
3168 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003169{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003170 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003171 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003172 int type;
3173 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003174 if (!nid)
3175 return 0;
3176 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3177 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3178 type = ALC_CTL_WIDGET_MUTE;
3179 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3180 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003181 type = ALC_CTL_WIDGET_MUTE;
3182 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3183 } else {
3184 type = ALC_CTL_BIND_MUTE;
3185 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3186 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003187 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3188 return 0;
3189 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003190 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003191}
3192
Takashi Iwaie29d3772011-11-14 17:13:23 +01003193static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3194 int cidx, hda_nid_t nid)
3195{
3196 int chs = 1;
3197 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3198 chs = 3;
3199 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3200}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003201
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003202static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3203 hda_nid_t pin, hda_nid_t dac)
3204{
3205 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3206 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3207 return pin;
3208 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3209 return mix;
3210 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3211 return dac;
3212 return 0;
3213}
3214
3215static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3216 hda_nid_t pin, hda_nid_t dac)
3217{
3218 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3219 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3220 return dac;
3221 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3222 return mix;
3223 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3224 return pin;
3225 return 0;
3226}
3227
Takashi Iwai7085ec12009-10-02 09:03:58 +02003228/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003229static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003230 const struct auto_pin_cfg *cfg)
3231{
3232 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003233 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003234
Takashi Iwaice764ab2011-04-27 16:35:23 +02003235 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003236 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003237 noutputs += spec->multi_ios;
3238
3239 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003240 const char *name;
3241 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003242 hda_nid_t dac, pin;
3243 hda_nid_t sw, vol;
3244
3245 dac = spec->multiout.dac_nids[i];
3246 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003247 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003248 if (i >= cfg->line_outs)
3249 pin = spec->multi_io[i - 1].pin;
3250 else
3251 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003252
3253 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3254 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003255 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003256 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003257 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003258 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003259 if (err < 0)
3260 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003261 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003262 if (err < 0)
3263 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003264 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003265 if (err < 0)
3266 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003267 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003268 if (err < 0)
3269 return err;
3270 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003271 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003272 if (err < 0)
3273 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003274 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003275 if (err < 0)
3276 return err;
3277 }
3278 }
3279 return 0;
3280}
3281
Takashi Iwai343a04b2011-07-06 14:28:39 +02003282static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003283 hda_nid_t dac, const char *pfx,
3284 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003285{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003286 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003287 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003288 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003289
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003290 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003291 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003292 /* the corresponding DAC is already occupied */
3293 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3294 return 0; /* no way */
3295 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003296 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3297 if (is_ctl_used(spec->sw_ctls, val))
3298 return 0; /* already created */
3299 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003300 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003301 }
3302
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003303 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3304 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003305 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003306 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003307 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003308 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003309 if (err < 0)
3310 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003311 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003312}
3313
Takashi Iwai23c09b02011-08-19 09:05:35 +02003314static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3315 unsigned int nums,
3316 struct hda_ctl_ops *ops)
3317{
3318 struct alc_spec *spec = codec->spec;
3319 struct hda_bind_ctls **ctlp, *ctl;
3320 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3321 ctlp = snd_array_new(&spec->bind_ctls);
3322 if (!ctlp)
3323 return NULL;
3324 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3325 *ctlp = ctl;
3326 if (ctl)
3327 ctl->ops = ops;
3328 return ctl;
3329}
3330
3331/* add playback controls for speaker and HP outputs */
3332static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3333 const hda_nid_t *pins,
3334 const hda_nid_t *dacs,
3335 const char *pfx)
3336{
3337 struct alc_spec *spec = codec->spec;
3338 struct hda_bind_ctls *ctl;
3339 char name[32];
3340 int i, n, err;
3341
3342 if (!num_pins || !pins[0])
3343 return 0;
3344
Takashi Iwai527e4d72011-10-27 16:33:27 +02003345 if (num_pins == 1) {
3346 hda_nid_t dac = *dacs;
3347 if (!dac)
3348 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003349 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003350 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003351
3352 if (dacs[num_pins - 1]) {
3353 /* OK, we have a multi-output system with individual volumes */
3354 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003355 if (num_pins >= 3) {
3356 snprintf(name, sizeof(name), "%s %s",
3357 pfx, channel_name[i]);
3358 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3359 name, 0);
3360 } else {
3361 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3362 pfx, i);
3363 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003364 if (err < 0)
3365 return err;
3366 }
3367 return 0;
3368 }
3369
3370 /* Let's create a bind-controls */
3371 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3372 if (!ctl)
3373 return -ENOMEM;
3374 n = 0;
3375 for (i = 0; i < num_pins; i++) {
3376 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3377 ctl->values[n++] =
3378 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3379 }
3380 if (n) {
3381 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3382 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3383 if (err < 0)
3384 return err;
3385 }
3386
3387 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3388 if (!ctl)
3389 return -ENOMEM;
3390 n = 0;
3391 for (i = 0; i < num_pins; i++) {
3392 hda_nid_t vol;
3393 if (!pins[i] || !dacs[i])
3394 continue;
3395 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3396 if (vol)
3397 ctl->values[n++] =
3398 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3399 }
3400 if (n) {
3401 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3402 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3403 if (err < 0)
3404 return err;
3405 }
3406 return 0;
3407}
3408
Takashi Iwai343a04b2011-07-06 14:28:39 +02003409static int alc_auto_create_hp_out(struct hda_codec *codec)
3410{
3411 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003412 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3413 spec->autocfg.hp_pins,
3414 spec->multiout.hp_out_nid,
3415 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003416}
3417
3418static int alc_auto_create_speaker_out(struct hda_codec *codec)
3419{
3420 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003421 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3422 spec->autocfg.speaker_pins,
3423 spec->multiout.extra_out_nid,
3424 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003425}
3426
Takashi Iwai343a04b2011-07-06 14:28:39 +02003427static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003428 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003429 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003430{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003431 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003432 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003433 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003434
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003435 alc_set_pin_output(codec, pin, pin_type);
3436 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003437 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003438 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003439 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003440 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003441 mix = srcs[i];
3442 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003443 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003444 if (!mix)
3445 return;
3446
3447 /* need the manual connection? */
3448 if (num > 1)
3449 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3450 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003451 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3452 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003453 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003454 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003455 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003456 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003457 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003458 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3459 if (nid)
3460 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3461 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003462
3463 /* unmute DAC if it's not assigned to a mixer */
3464 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3465 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3466 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3467 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003468}
3469
Takashi Iwai343a04b2011-07-06 14:28:39 +02003470static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003471{
3472 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003473 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003474 int i;
3475
3476 for (i = 0; i <= HDA_SIDE; i++) {
3477 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3478 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003479 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003480 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003481 }
3482}
3483
Takashi Iwai343a04b2011-07-06 14:28:39 +02003484static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003485{
3486 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003487 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003488 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003489
David Henningsson636030e2011-10-12 19:26:03 +02003490 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003491 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3492 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003493 pin = spec->autocfg.hp_pins[i];
3494 if (!pin)
3495 break;
3496 dac = spec->multiout.hp_out_nid[i];
3497 if (!dac) {
3498 if (i > 0 && spec->multiout.hp_out_nid[0])
3499 dac = spec->multiout.hp_out_nid[0];
3500 else
3501 dac = spec->multiout.dac_nids[0];
3502 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003503 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3504 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003505 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003506 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3507 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003508 pin = spec->autocfg.speaker_pins[i];
3509 if (!pin)
3510 break;
3511 dac = spec->multiout.extra_out_nid[i];
3512 if (!dac) {
3513 if (i > 0 && spec->multiout.extra_out_nid[0])
3514 dac = spec->multiout.extra_out_nid[0];
3515 else
3516 dac = spec->multiout.dac_nids[0];
3517 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003518 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3519 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003520}
3521
Takashi Iwaice764ab2011-04-27 16:35:23 +02003522/*
3523 * multi-io helper
3524 */
3525static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003526 unsigned int location,
3527 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003528{
3529 struct alc_spec *spec = codec->spec;
3530 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003531 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003532 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003533
Takashi Iwai07b18f62011-11-10 15:42:54 +01003534 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003535 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3536 for (i = 0; i < cfg->num_inputs; i++) {
3537 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003538 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003539 unsigned int defcfg, caps;
3540 if (cfg->inputs[i].type != type)
3541 continue;
3542 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3543 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3544 continue;
3545 if (location && get_defcfg_location(defcfg) != location)
3546 continue;
3547 caps = snd_hda_query_pin_caps(codec, nid);
3548 if (!(caps & AC_PINCAP_OUT))
3549 continue;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003550 if (offset && offset + num_pins < dacs) {
3551 dac = spec->private_dac_nids[offset + num_pins];
3552 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3553 dac = 0;
3554 }
3555 if (!dac)
3556 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003557 if (!dac)
3558 continue;
3559 spec->multi_io[num_pins].pin = nid;
3560 spec->multi_io[num_pins].dac = dac;
3561 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003562 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003563 }
3564 }
Takashi Iwai07b18f62011-11-10 15:42:54 +01003565 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003566 if (num_pins < 2) {
3567 /* clear up again */
Takashi Iwai07b18f62011-11-10 15:42:54 +01003568 memset(spec->private_dac_nids + dacs, 0,
3569 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003570 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003571 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003572 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003573 return num_pins;
3574}
3575
3576static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3577 struct snd_ctl_elem_info *uinfo)
3578{
3579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3580 struct alc_spec *spec = codec->spec;
3581
3582 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3583 uinfo->count = 1;
3584 uinfo->value.enumerated.items = spec->multi_ios + 1;
3585 if (uinfo->value.enumerated.item > spec->multi_ios)
3586 uinfo->value.enumerated.item = spec->multi_ios;
3587 sprintf(uinfo->value.enumerated.name, "%dch",
3588 (uinfo->value.enumerated.item + 1) * 2);
3589 return 0;
3590}
3591
3592static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3593 struct snd_ctl_elem_value *ucontrol)
3594{
3595 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3596 struct alc_spec *spec = codec->spec;
3597 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3598 return 0;
3599}
3600
3601static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3602{
3603 struct alc_spec *spec = codec->spec;
3604 hda_nid_t nid = spec->multi_io[idx].pin;
3605
3606 if (!spec->multi_io[idx].ctl_in)
3607 spec->multi_io[idx].ctl_in =
3608 snd_hda_codec_read(codec, nid, 0,
3609 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3610 if (output) {
3611 snd_hda_codec_update_cache(codec, nid, 0,
3612 AC_VERB_SET_PIN_WIDGET_CONTROL,
3613 PIN_OUT);
3614 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3615 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3616 HDA_AMP_MUTE, 0);
3617 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3618 } else {
3619 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3620 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3621 HDA_AMP_MUTE, HDA_AMP_MUTE);
3622 snd_hda_codec_update_cache(codec, nid, 0,
3623 AC_VERB_SET_PIN_WIDGET_CONTROL,
3624 spec->multi_io[idx].ctl_in);
3625 }
3626 return 0;
3627}
3628
3629static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3630 struct snd_ctl_elem_value *ucontrol)
3631{
3632 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3633 struct alc_spec *spec = codec->spec;
3634 int i, ch;
3635
3636 ch = ucontrol->value.enumerated.item[0];
3637 if (ch < 0 || ch > spec->multi_ios)
3638 return -EINVAL;
3639 if (ch == (spec->ext_channel_count - 1) / 2)
3640 return 0;
3641 spec->ext_channel_count = (ch + 1) * 2;
3642 for (i = 0; i < spec->multi_ios; i++)
3643 alc_set_multi_io(codec, i, i < ch);
3644 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003645 if (spec->need_dac_fix && !spec->const_channel_count)
3646 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003647 return 1;
3648}
3649
Takashi Iwaia9111322011-05-02 11:30:18 +02003650static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003651 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3652 .name = "Channel Mode",
3653 .info = alc_auto_ch_mode_info,
3654 .get = alc_auto_ch_mode_get,
3655 .put = alc_auto_ch_mode_put,
3656};
3657
Takashi Iwai23c09b02011-08-19 09:05:35 +02003658static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003659{
3660 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003661
Takashi Iwaic2674682011-08-24 17:57:44 +02003662 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003663 struct snd_kcontrol_new *knew;
3664
3665 knew = alc_kcontrol_new(spec);
3666 if (!knew)
3667 return -ENOMEM;
3668 *knew = alc_auto_channel_mode_enum;
3669 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3670 if (!knew->name)
3671 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003672 }
3673 return 0;
3674}
3675
Takashi Iwai1d045db2011-07-07 18:23:21 +02003676/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3677 * active input pins
3678 */
3679static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3680{
3681 struct alc_spec *spec = codec->spec;
3682 const struct hda_input_mux *imux;
3683 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3684 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3685 int i, n, nums;
3686
3687 imux = spec->input_mux;
3688 if (!imux)
3689 return;
3690 if (spec->dyn_adc_switch)
3691 return;
3692
3693 nums = 0;
3694 for (n = 0; n < spec->num_adc_nids; n++) {
3695 hda_nid_t cap = spec->private_capsrc_nids[n];
3696 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3697 for (i = 0; i < imux->num_items; i++) {
3698 hda_nid_t pin = spec->imux_pins[i];
3699 if (pin) {
3700 if (get_connection_index(codec, cap, pin) < 0)
3701 break;
3702 } else if (num_conns <= imux->items[i].index)
3703 break;
3704 }
3705 if (i >= imux->num_items) {
3706 adc_nids[nums] = spec->private_adc_nids[n];
3707 capsrc_nids[nums++] = cap;
3708 }
3709 }
3710 if (!nums) {
3711 /* check whether ADC-switch is possible */
3712 if (!alc_check_dyn_adc_switch(codec)) {
3713 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3714 " using fallback 0x%x\n",
3715 codec->chip_name, spec->private_adc_nids[0]);
3716 spec->num_adc_nids = 1;
3717 spec->auto_mic = 0;
3718 return;
3719 }
3720 } else if (nums != spec->num_adc_nids) {
3721 memcpy(spec->private_adc_nids, adc_nids,
3722 nums * sizeof(hda_nid_t));
3723 memcpy(spec->private_capsrc_nids, capsrc_nids,
3724 nums * sizeof(hda_nid_t));
3725 spec->num_adc_nids = nums;
3726 }
3727
3728 if (spec->auto_mic)
3729 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3730 else if (spec->input_mux->num_items == 1)
3731 spec->num_adc_nids = 1; /* reduce to a single ADC */
3732}
3733
3734/*
3735 * initialize ADC paths
3736 */
3737static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3738{
3739 struct alc_spec *spec = codec->spec;
3740 hda_nid_t nid;
3741
3742 nid = spec->adc_nids[adc_idx];
3743 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003744 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003745 snd_hda_codec_write(codec, nid, 0,
3746 AC_VERB_SET_AMP_GAIN_MUTE,
3747 AMP_IN_MUTE(0));
3748 return;
3749 }
3750 if (!spec->capsrc_nids)
3751 return;
3752 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003753 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003754 snd_hda_codec_write(codec, nid, 0,
3755 AC_VERB_SET_AMP_GAIN_MUTE,
3756 AMP_OUT_MUTE);
3757}
3758
3759static void alc_auto_init_input_src(struct hda_codec *codec)
3760{
3761 struct alc_spec *spec = codec->spec;
3762 int c, nums;
3763
3764 for (c = 0; c < spec->num_adc_nids; c++)
3765 alc_auto_init_adc(codec, c);
3766 if (spec->dyn_adc_switch)
3767 nums = 1;
3768 else
3769 nums = spec->num_adc_nids;
3770 for (c = 0; c < nums; c++)
3771 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3772}
3773
3774/* add mic boosts if needed */
3775static int alc_auto_add_mic_boost(struct hda_codec *codec)
3776{
3777 struct alc_spec *spec = codec->spec;
3778 struct auto_pin_cfg *cfg = &spec->autocfg;
3779 int i, err;
3780 int type_idx = 0;
3781 hda_nid_t nid;
3782 const char *prev_label = NULL;
3783
3784 for (i = 0; i < cfg->num_inputs; i++) {
3785 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3786 break;
3787 nid = cfg->inputs[i].pin;
3788 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3789 const char *label;
3790 char boost_label[32];
3791
3792 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003793 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3794 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003795 if (prev_label && !strcmp(label, prev_label))
3796 type_idx++;
3797 else
3798 type_idx = 0;
3799 prev_label = label;
3800
3801 snprintf(boost_label, sizeof(boost_label),
3802 "%s Boost Volume", label);
3803 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3804 boost_label, type_idx,
3805 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3806 if (err < 0)
3807 return err;
3808 }
3809 }
3810 return 0;
3811}
3812
3813/* select or unmute the given capsrc route */
3814static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3815 int idx)
3816{
3817 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3818 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3819 HDA_AMP_MUTE, 0);
3820 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3821 snd_hda_codec_write_cache(codec, cap, 0,
3822 AC_VERB_SET_CONNECT_SEL, idx);
3823 }
3824}
3825
3826/* set the default connection to that pin */
3827static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3828{
3829 struct alc_spec *spec = codec->spec;
3830 int i;
3831
3832 if (!pin)
3833 return 0;
3834 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01003835 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003836 int idx;
3837
3838 idx = get_connection_index(codec, cap, pin);
3839 if (idx < 0)
3840 continue;
3841 select_or_unmute_capsrc(codec, cap, idx);
3842 return i; /* return the found index */
3843 }
3844 return -1; /* not found */
3845}
3846
3847/* initialize some special cases for input sources */
3848static void alc_init_special_input_src(struct hda_codec *codec)
3849{
3850 struct alc_spec *spec = codec->spec;
3851 int i;
3852
3853 for (i = 0; i < spec->autocfg.num_inputs; i++)
3854 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3855}
3856
3857/* assign appropriate capture mixers */
3858static void set_capture_mixer(struct hda_codec *codec)
3859{
3860 struct alc_spec *spec = codec->spec;
3861 static const struct snd_kcontrol_new *caps[2][3] = {
3862 { alc_capture_mixer_nosrc1,
3863 alc_capture_mixer_nosrc2,
3864 alc_capture_mixer_nosrc3 },
3865 { alc_capture_mixer1,
3866 alc_capture_mixer2,
3867 alc_capture_mixer3 },
3868 };
3869
3870 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003871 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003872 if (!spec->capsrc_nids)
3873 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003874 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003875 return; /* no volume in capsrc, too */
3876 spec->vol_in_capsrc = 1;
3877 }
3878
3879 if (spec->num_adc_nids > 0) {
3880 int mux = 0;
3881 int num_adcs = 0;
3882
3883 if (spec->input_mux && spec->input_mux->num_items > 1)
3884 mux = 1;
3885 if (spec->auto_mic) {
3886 num_adcs = 1;
3887 mux = 0;
3888 } else if (spec->dyn_adc_switch)
3889 num_adcs = 1;
3890 if (!num_adcs) {
3891 if (spec->num_adc_nids > 3)
3892 spec->num_adc_nids = 3;
3893 else if (!spec->num_adc_nids)
3894 return;
3895 num_adcs = spec->num_adc_nids;
3896 }
3897 spec->cap_mixer = caps[mux][num_adcs - 1];
3898 }
3899}
3900
3901/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003902 * standard auto-parser initializations
3903 */
3904static void alc_auto_init_std(struct hda_codec *codec)
3905{
3906 struct alc_spec *spec = codec->spec;
3907 alc_auto_init_multi_out(codec);
3908 alc_auto_init_extra_out(codec);
3909 alc_auto_init_analog_input(codec);
3910 alc_auto_init_input_src(codec);
3911 alc_auto_init_digital(codec);
3912 if (spec->unsol_event)
3913 alc_inithook(codec);
3914}
3915
3916/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003917 * Digital-beep handlers
3918 */
3919#ifdef CONFIG_SND_HDA_INPUT_BEEP
3920#define set_beep_amp(spec, nid, idx, dir) \
3921 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3922
3923static const struct snd_pci_quirk beep_white_list[] = {
3924 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3925 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3926 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3927 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3928 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3929 {}
3930};
3931
3932static inline int has_cdefine_beep(struct hda_codec *codec)
3933{
3934 struct alc_spec *spec = codec->spec;
3935 const struct snd_pci_quirk *q;
3936 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3937 if (q)
3938 return q->value;
3939 return spec->cdefine.enable_pcbeep;
3940}
3941#else
3942#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3943#define has_cdefine_beep(codec) 0
3944#endif
3945
3946/* parse the BIOS configuration and set up the alc_spec */
3947/* return 1 if successful, 0 if the proper config is not found,
3948 * or a negative error code
3949 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003950static int alc_parse_auto_config(struct hda_codec *codec,
3951 const hda_nid_t *ignore_nids,
3952 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003953{
3954 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003955 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003956 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003957
Takashi Iwai53c334a2011-08-23 18:27:14 +02003958 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3959 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003960 if (err < 0)
3961 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003962 if (!cfg->line_outs) {
3963 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003964 spec->multiout.max_channels = 2;
3965 spec->no_analog = 1;
3966 goto dig_only;
3967 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003968 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003969 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003970
Takashi Iwai06503672011-10-06 08:27:19 +02003971 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3972 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003973 /* use HP as primary out */
3974 cfg->speaker_outs = cfg->line_outs;
3975 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3976 sizeof(cfg->speaker_pins));
3977 cfg->line_outs = cfg->hp_outs;
3978 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3979 cfg->hp_outs = 0;
3980 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3981 cfg->line_out_type = AUTO_PIN_HP_OUT;
3982 }
3983
Takashi Iwai1d045db2011-07-07 18:23:21 +02003984 err = alc_auto_fill_dac_nids(codec);
3985 if (err < 0)
3986 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003987 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003988 if (err < 0)
3989 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003990 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003991 if (err < 0)
3992 return err;
3993 err = alc_auto_create_hp_out(codec);
3994 if (err < 0)
3995 return err;
3996 err = alc_auto_create_speaker_out(codec);
3997 if (err < 0)
3998 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01003999 err = alc_auto_create_shared_input(codec);
4000 if (err < 0)
4001 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004002 err = alc_auto_create_input_ctls(codec);
4003 if (err < 0)
4004 return err;
4005
4006 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4007
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004008 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004009 alc_auto_parse_digital(codec);
4010
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004011 if (!spec->no_analog)
4012 alc_remove_invalid_adc_nids(codec);
4013
4014 if (ssid_nids)
4015 alc_ssid_check(codec, ssid_nids);
4016
4017 if (!spec->no_analog) {
4018 alc_auto_check_switches(codec);
4019 err = alc_auto_add_mic_boost(codec);
4020 if (err < 0)
4021 return err;
4022 }
4023
Takashi Iwai1d045db2011-07-07 18:23:21 +02004024 if (spec->kctls.list)
4025 add_mixer(spec, spec->kctls.list);
4026
Takashi Iwai1d045db2011-07-07 18:23:21 +02004027 return 1;
4028}
4029
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004030static int alc880_parse_auto_config(struct hda_codec *codec)
4031{
4032 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4033 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4034 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4035}
4036
Takashi Iwai1d045db2011-07-07 18:23:21 +02004037#ifdef CONFIG_SND_HDA_POWER_SAVE
4038static const struct hda_amp_list alc880_loopbacks[] = {
4039 { 0x0b, HDA_INPUT, 0 },
4040 { 0x0b, HDA_INPUT, 1 },
4041 { 0x0b, HDA_INPUT, 2 },
4042 { 0x0b, HDA_INPUT, 3 },
4043 { 0x0b, HDA_INPUT, 4 },
4044 { } /* end */
4045};
4046#endif
4047
4048/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004049 * ALC880 fix-ups
4050 */
4051enum {
4052 ALC880_FIXUP_GPIO2,
4053 ALC880_FIXUP_MEDION_RIM,
4054};
4055
4056static const struct alc_fixup alc880_fixups[] = {
4057 [ALC880_FIXUP_GPIO2] = {
4058 .type = ALC_FIXUP_VERBS,
4059 .v.verbs = alc_gpio2_init_verbs,
4060 },
4061 [ALC880_FIXUP_MEDION_RIM] = {
4062 .type = ALC_FIXUP_VERBS,
4063 .v.verbs = (const struct hda_verb[]) {
4064 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4065 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4066 { }
4067 },
4068 .chained = true,
4069 .chain_id = ALC880_FIXUP_GPIO2,
4070 },
4071};
4072
4073static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4074 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4075 {}
4076};
4077
4078
4079/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004080 * board setups
4081 */
4082#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4083#define alc_board_config \
4084 snd_hda_check_board_config
4085#define alc_board_codec_sid_config \
4086 snd_hda_check_board_codec_sid_config
4087#include "alc_quirks.c"
4088#else
4089#define alc_board_config(codec, nums, models, tbl) -1
4090#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4091#define setup_preset(codec, x) /* NOP */
4092#endif
4093
4094/*
4095 * OK, here we have finally the patch for ALC880
4096 */
4097#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4098#include "alc880_quirks.c"
4099#endif
4100
4101static int patch_alc880(struct hda_codec *codec)
4102{
4103 struct alc_spec *spec;
4104 int board_config;
4105 int err;
4106
4107 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4108 if (spec == NULL)
4109 return -ENOMEM;
4110
4111 codec->spec = spec;
4112
4113 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004114 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004115
4116 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4117 alc880_models, alc880_cfg_tbl);
4118 if (board_config < 0) {
4119 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4120 codec->chip_name);
4121 board_config = ALC_MODEL_AUTO;
4122 }
4123
4124 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004125 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4126 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4127 }
4128
4129 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004130 /* automatic parse from the BIOS config */
4131 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004132 if (err < 0)
4133 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004134#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4135 else if (!err) {
4136 printk(KERN_INFO
4137 "hda_codec: Cannot set up configuration "
4138 "from BIOS. Using 3-stack mode...\n");
4139 board_config = ALC880_3ST;
4140 }
4141#endif
4142 }
4143
David Henningssonfde48a12011-12-09 18:27:42 +08004144 if (board_config != ALC_MODEL_AUTO) {
4145 spec->vmaster_nid = 0x0c;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004146 setup_preset(codec, &alc880_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004147 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004148
Takashi Iwai60a6a842011-07-27 14:01:24 +02004149 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004150 alc_auto_fill_adc_caps(codec);
4151 alc_rebuild_imux_for_auto_mic(codec);
4152 alc_remove_invalid_adc_nids(codec);
4153 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004154
4155 if (!spec->no_analog && !spec->cap_mixer)
4156 set_capture_mixer(codec);
4157
4158 if (!spec->no_analog) {
4159 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004160 if (err < 0)
4161 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004162 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4163 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004164
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004165 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4166
Takashi Iwai1d045db2011-07-07 18:23:21 +02004167 codec->patch_ops = alc_patch_ops;
4168 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004169 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004170 else
4171 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004172#ifdef CONFIG_SND_HDA_POWER_SAVE
4173 if (!spec->loopback.amplist)
4174 spec->loopback.amplist = alc880_loopbacks;
4175#endif
4176
4177 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004178
4179 error:
4180 alc_free(codec);
4181 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004182}
4183
4184
4185/*
4186 * ALC260 support
4187 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004188static int alc260_parse_auto_config(struct hda_codec *codec)
4189{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004190 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004191 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4192 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004193}
4194
Takashi Iwai1d045db2011-07-07 18:23:21 +02004195#ifdef CONFIG_SND_HDA_POWER_SAVE
4196static const struct hda_amp_list alc260_loopbacks[] = {
4197 { 0x07, HDA_INPUT, 0 },
4198 { 0x07, HDA_INPUT, 1 },
4199 { 0x07, HDA_INPUT, 2 },
4200 { 0x07, HDA_INPUT, 3 },
4201 { 0x07, HDA_INPUT, 4 },
4202 { } /* end */
4203};
4204#endif
4205
4206/*
4207 * Pin config fixes
4208 */
4209enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004210 ALC260_FIXUP_HP_DC5750,
4211 ALC260_FIXUP_HP_PIN_0F,
4212 ALC260_FIXUP_COEF,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004213};
4214
4215static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004216 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004217 .type = ALC_FIXUP_PINS,
4218 .v.pins = (const struct alc_pincfg[]) {
4219 { 0x11, 0x90130110 }, /* speaker */
4220 { }
4221 }
4222 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004223 [ALC260_FIXUP_HP_PIN_0F] = {
4224 .type = ALC_FIXUP_PINS,
4225 .v.pins = (const struct alc_pincfg[]) {
4226 { 0x0f, 0x01214000 }, /* HP */
4227 { }
4228 }
4229 },
4230 [ALC260_FIXUP_COEF] = {
4231 .type = ALC_FIXUP_VERBS,
4232 .v.verbs = (const struct hda_verb[]) {
4233 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4234 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4235 { }
4236 },
4237 .chained = true,
4238 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4239 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004240};
4241
4242static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004243 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
4244 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
4245 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004246 {}
4247};
4248
4249/*
4250 */
4251#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4252#include "alc260_quirks.c"
4253#endif
4254
4255static int patch_alc260(struct hda_codec *codec)
4256{
4257 struct alc_spec *spec;
4258 int err, board_config;
4259
4260 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4261 if (spec == NULL)
4262 return -ENOMEM;
4263
4264 codec->spec = spec;
4265
4266 spec->mixer_nid = 0x07;
4267
4268 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4269 alc260_models, alc260_cfg_tbl);
4270 if (board_config < 0) {
4271 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4272 codec->chip_name);
4273 board_config = ALC_MODEL_AUTO;
4274 }
4275
4276 if (board_config == ALC_MODEL_AUTO) {
4277 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4278 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4279 }
4280
4281 if (board_config == ALC_MODEL_AUTO) {
4282 /* automatic parse from the BIOS config */
4283 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004284 if (err < 0)
4285 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004286#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4287 else if (!err) {
4288 printk(KERN_INFO
4289 "hda_codec: Cannot set up configuration "
4290 "from BIOS. Using base mode...\n");
4291 board_config = ALC260_BASIC;
4292 }
4293#endif
4294 }
4295
David Henningssonfde48a12011-12-09 18:27:42 +08004296 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004297 setup_preset(codec, &alc260_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004298 spec->vmaster_nid = 0x08;
4299 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004300
Takashi Iwai60a6a842011-07-27 14:01:24 +02004301 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004302 alc_auto_fill_adc_caps(codec);
4303 alc_rebuild_imux_for_auto_mic(codec);
4304 alc_remove_invalid_adc_nids(codec);
4305 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004306
4307 if (!spec->no_analog && !spec->cap_mixer)
4308 set_capture_mixer(codec);
4309
4310 if (!spec->no_analog) {
4311 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004312 if (err < 0)
4313 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004314 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4315 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004316
4317 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4318
Takashi Iwai1d045db2011-07-07 18:23:21 +02004319 codec->patch_ops = alc_patch_ops;
4320 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004321 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004322 else
4323 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004324 spec->shutup = alc_eapd_shutup;
4325#ifdef CONFIG_SND_HDA_POWER_SAVE
4326 if (!spec->loopback.amplist)
4327 spec->loopback.amplist = alc260_loopbacks;
4328#endif
4329
4330 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004331
4332 error:
4333 alc_free(codec);
4334 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004335}
4336
4337
4338/*
4339 * ALC882/883/885/888/889 support
4340 *
4341 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4342 * configuration. Each pin widget can choose any input DACs and a mixer.
4343 * Each ADC is connected from a mixer of all inputs. This makes possible
4344 * 6-channel independent captures.
4345 *
4346 * In addition, an independent DAC for the multi-playback (not used in this
4347 * driver yet).
4348 */
4349#ifdef CONFIG_SND_HDA_POWER_SAVE
4350#define alc882_loopbacks alc880_loopbacks
4351#endif
4352
4353/*
4354 * Pin config fixes
4355 */
4356enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004357 ALC882_FIXUP_ABIT_AW9D_MAX,
4358 ALC882_FIXUP_LENOVO_Y530,
4359 ALC882_FIXUP_PB_M5210,
4360 ALC882_FIXUP_ACER_ASPIRE_7736,
4361 ALC882_FIXUP_ASUS_W90V,
4362 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004363 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004364 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004365 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004366 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004367 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004368 ALC889_FIXUP_COEF,
4369 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004370 ALC882_FIXUP_ACER_ASPIRE_4930G,
4371 ALC882_FIXUP_ACER_ASPIRE_8930G,
4372 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004373 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004374};
4375
Takashi Iwai68ef0562011-11-09 18:24:44 +01004376static void alc889_fixup_coef(struct hda_codec *codec,
4377 const struct alc_fixup *fix, int action)
4378{
4379 if (action != ALC_FIXUP_ACT_INIT)
4380 return;
4381 alc889_coef_init(codec);
4382}
4383
Takashi Iwai56710872011-11-14 17:42:11 +01004384/* toggle speaker-output according to the hp-jack state */
4385static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4386{
4387 unsigned int gpiostate, gpiomask, gpiodir;
4388
4389 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4390 AC_VERB_GET_GPIO_DATA, 0);
4391
4392 if (!muted)
4393 gpiostate |= (1 << pin);
4394 else
4395 gpiostate &= ~(1 << pin);
4396
4397 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4398 AC_VERB_GET_GPIO_MASK, 0);
4399 gpiomask |= (1 << pin);
4400
4401 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4402 AC_VERB_GET_GPIO_DIRECTION, 0);
4403 gpiodir |= (1 << pin);
4404
4405
4406 snd_hda_codec_write(codec, codec->afg, 0,
4407 AC_VERB_SET_GPIO_MASK, gpiomask);
4408 snd_hda_codec_write(codec, codec->afg, 0,
4409 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4410
4411 msleep(1);
4412
4413 snd_hda_codec_write(codec, codec->afg, 0,
4414 AC_VERB_SET_GPIO_DATA, gpiostate);
4415}
4416
4417/* set up GPIO at initialization */
4418static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4419 const struct alc_fixup *fix, int action)
4420{
4421 if (action != ALC_FIXUP_ACT_INIT)
4422 return;
4423 alc882_gpio_mute(codec, 0, 0);
4424 alc882_gpio_mute(codec, 1, 0);
4425}
4426
Takashi Iwai1d045db2011-07-07 18:23:21 +02004427static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004428 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004429 .type = ALC_FIXUP_PINS,
4430 .v.pins = (const struct alc_pincfg[]) {
4431 { 0x15, 0x01080104 }, /* side */
4432 { 0x16, 0x01011012 }, /* rear */
4433 { 0x17, 0x01016011 }, /* clfe */
4434 { }
4435 }
4436 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004437 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004438 .type = ALC_FIXUP_PINS,
4439 .v.pins = (const struct alc_pincfg[]) {
4440 { 0x15, 0x99130112 }, /* rear int speakers */
4441 { 0x16, 0x99130111 }, /* subwoofer */
4442 { }
4443 }
4444 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004445 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004446 .type = ALC_FIXUP_VERBS,
4447 .v.verbs = (const struct hda_verb[]) {
4448 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4449 {}
4450 }
4451 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004452 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004453 .type = ALC_FIXUP_SKU,
4454 .v.sku = ALC_FIXUP_SKU_IGNORE,
4455 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004456 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004457 .type = ALC_FIXUP_PINS,
4458 .v.pins = (const struct alc_pincfg[]) {
4459 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4460 { }
4461 }
4462 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004463 [ALC889_FIXUP_VAIO_TT] = {
4464 .type = ALC_FIXUP_PINS,
4465 .v.pins = (const struct alc_pincfg[]) {
4466 { 0x17, 0x90170111 }, /* hidden surround speaker */
4467 { }
4468 }
4469 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004470 [ALC888_FIXUP_EEE1601] = {
4471 .type = ALC_FIXUP_VERBS,
4472 .v.verbs = (const struct hda_verb[]) {
4473 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4474 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4475 { }
4476 }
Takashi Iwai177943a2011-11-09 12:55:18 +01004477 },
4478 [ALC882_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, 0x3060 },
4484 { }
4485 }
4486 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004487 [ALC883_FIXUP_EAPD] = {
4488 .type = ALC_FIXUP_VERBS,
4489 .v.verbs = (const struct hda_verb[]) {
4490 /* change to EAPD mode */
4491 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4492 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4493 { }
4494 }
4495 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004496 [ALC883_FIXUP_ACER_EAPD] = {
4497 .type = ALC_FIXUP_VERBS,
4498 .v.verbs = (const struct hda_verb[]) {
4499 /* eanable EAPD on Acer laptops */
4500 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4501 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4502 { }
4503 }
4504 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004505 [ALC882_FIXUP_GPIO3] = {
4506 .type = ALC_FIXUP_VERBS,
4507 .v.verbs = alc_gpio3_init_verbs,
4508 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004509 [ALC882_FIXUP_ASUS_W2JC] = {
4510 .type = ALC_FIXUP_VERBS,
4511 .v.verbs = alc_gpio1_init_verbs,
4512 .chained = true,
4513 .chain_id = ALC882_FIXUP_EAPD,
4514 },
4515 [ALC889_FIXUP_COEF] = {
4516 .type = ALC_FIXUP_FUNC,
4517 .v.func = alc889_fixup_coef,
4518 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004519 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4520 .type = ALC_FIXUP_PINS,
4521 .v.pins = (const struct alc_pincfg[]) {
4522 { 0x16, 0x99130111 }, /* CLFE speaker */
4523 { 0x17, 0x99130112 }, /* surround speaker */
4524 { }
4525 }
4526 },
4527 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4528 .type = ALC_FIXUP_PINS,
4529 .v.pins = (const struct alc_pincfg[]) {
4530 { 0x16, 0x99130111 }, /* CLFE speaker */
4531 { 0x1b, 0x99130112 }, /* surround speaker */
4532 { }
4533 },
4534 .chained = true,
4535 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4536 },
4537 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4538 /* additional init verbs for Acer Aspire 8930G */
4539 .type = ALC_FIXUP_VERBS,
4540 .v.verbs = (const struct hda_verb[]) {
4541 /* Enable all DACs */
4542 /* DAC DISABLE/MUTE 1? */
4543 /* setting bits 1-5 disables DAC nids 0x02-0x06
4544 * apparently. Init=0x38 */
4545 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4546 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4547 /* DAC DISABLE/MUTE 2? */
4548 /* some bit here disables the other DACs.
4549 * Init=0x4900 */
4550 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4551 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4552 /* DMIC fix
4553 * This laptop has a stereo digital microphone.
4554 * The mics are only 1cm apart which makes the stereo
4555 * useless. However, either the mic or the ALC889
4556 * makes the signal become a difference/sum signal
4557 * instead of standard stereo, which is annoying.
4558 * So instead we flip this bit which makes the
4559 * codec replicate the sum signal to both channels,
4560 * turning it into a normal mono mic.
4561 */
4562 /* DMIC_CONTROL? Init value = 0x0001 */
4563 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4564 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4565 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4566 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4567 { }
4568 }
4569 },
Takashi Iwai56710872011-11-14 17:42:11 +01004570 [ALC885_FIXUP_MACPRO_GPIO] = {
4571 .type = ALC_FIXUP_FUNC,
4572 .v.func = alc885_fixup_macpro_gpio,
4573 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004574};
4575
4576static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004577 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4578 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4579 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4580 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4581 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4582 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004583 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4584 ALC882_FIXUP_ACER_ASPIRE_4930G),
4585 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4586 ALC882_FIXUP_ACER_ASPIRE_4930G),
4587 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4588 ALC882_FIXUP_ACER_ASPIRE_8930G),
4589 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4590 ALC882_FIXUP_ACER_ASPIRE_8930G),
4591 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4592 ALC882_FIXUP_ACER_ASPIRE_4930G),
4593 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4594 ALC882_FIXUP_ACER_ASPIRE_4930G),
4595 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4596 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004597 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004598 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01004599 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004600 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004601 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004602 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004603 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01004604
4605 /* All Apple entries are in codec SSIDs */
4606 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4607 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4608 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4609 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4610 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4611
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004612 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004613 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004614 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004615 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4616 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004617 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004618 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004619 {}
4620};
4621
4622/*
4623 * BIOS auto configuration
4624 */
4625/* almost identical with ALC880 parser... */
4626static int alc882_parse_auto_config(struct hda_codec *codec)
4627{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004628 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004629 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4630 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004631}
4632
Takashi Iwai1d045db2011-07-07 18:23:21 +02004633/*
4634 */
4635#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4636#include "alc882_quirks.c"
4637#endif
4638
4639static int patch_alc882(struct hda_codec *codec)
4640{
4641 struct alc_spec *spec;
4642 int err, board_config;
4643
4644 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4645 if (spec == NULL)
4646 return -ENOMEM;
4647
4648 codec->spec = spec;
4649
4650 spec->mixer_nid = 0x0b;
4651
4652 switch (codec->vendor_id) {
4653 case 0x10ec0882:
4654 case 0x10ec0885:
4655 break;
4656 default:
4657 /* ALC883 and variants */
4658 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4659 break;
4660 }
4661
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004662 err = alc_codec_rename_from_preset(codec);
4663 if (err < 0)
4664 goto error;
4665
Takashi Iwaib2539692011-11-14 17:32:17 +01004666 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4667 alc882_models, NULL);
4668 if (board_config < 0)
4669 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004670 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4671
4672 if (board_config < 0) {
4673 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4674 codec->chip_name);
4675 board_config = ALC_MODEL_AUTO;
4676 }
4677
4678 if (board_config == ALC_MODEL_AUTO) {
4679 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4680 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4681 }
4682
4683 alc_auto_parse_customize_define(codec);
4684
4685 if (board_config == ALC_MODEL_AUTO) {
4686 /* automatic parse from the BIOS config */
4687 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004688 if (err < 0)
4689 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004690 }
4691
David Henningssonfde48a12011-12-09 18:27:42 +08004692 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004693 setup_preset(codec, &alc882_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004694 spec->vmaster_nid = 0x0c;
4695 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004696
Takashi Iwai60a6a842011-07-27 14:01:24 +02004697 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004698 alc_auto_fill_adc_caps(codec);
4699 alc_rebuild_imux_for_auto_mic(codec);
4700 alc_remove_invalid_adc_nids(codec);
4701 }
4702
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004703 if (!spec->no_analog && !spec->cap_mixer)
4704 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004705
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004706 if (!spec->no_analog && has_cdefine_beep(codec)) {
4707 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004708 if (err < 0)
4709 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004710 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004711 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004712
4713 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4714
Takashi Iwai1d045db2011-07-07 18:23:21 +02004715 codec->patch_ops = alc_patch_ops;
4716 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004717 spec->init_hook = alc_auto_init_std;
Takashi Iwaif21d78e2012-01-19 12:10:29 +01004718 else
4719 codec->patch_ops.build_controls = __alc_build_controls;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004720
Takashi Iwai1d045db2011-07-07 18:23:21 +02004721#ifdef CONFIG_SND_HDA_POWER_SAVE
4722 if (!spec->loopback.amplist)
4723 spec->loopback.amplist = alc882_loopbacks;
4724#endif
4725
4726 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004727
4728 error:
4729 alc_free(codec);
4730 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004731}
4732
4733
4734/*
4735 * ALC262 support
4736 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004737static int alc262_parse_auto_config(struct hda_codec *codec)
4738{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004739 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004740 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4741 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004742}
4743
4744/*
4745 * Pin config fixes
4746 */
4747enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004748 ALC262_FIXUP_FSC_H270,
4749 ALC262_FIXUP_HP_Z200,
4750 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01004751 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004752 ALC262_FIXUP_BENQ,
4753 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004754};
4755
4756static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004757 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004758 .type = ALC_FIXUP_PINS,
4759 .v.pins = (const struct alc_pincfg[]) {
4760 { 0x14, 0x99130110 }, /* speaker */
4761 { 0x15, 0x0221142f }, /* front HP */
4762 { 0x1b, 0x0121141f }, /* rear HP */
4763 { }
4764 }
4765 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004766 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004767 .type = ALC_FIXUP_PINS,
4768 .v.pins = (const struct alc_pincfg[]) {
4769 { 0x16, 0x99130120 }, /* internal speaker */
4770 { }
4771 }
4772 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004773 [ALC262_FIXUP_TYAN] = {
4774 .type = ALC_FIXUP_PINS,
4775 .v.pins = (const struct alc_pincfg[]) {
4776 { 0x14, 0x1993e1f0 }, /* int AUX */
4777 { }
4778 }
4779 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004780 [ALC262_FIXUP_LENOVO_3000] = {
4781 .type = ALC_FIXUP_VERBS,
4782 .v.verbs = (const struct hda_verb[]) {
4783 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004784 {}
4785 },
4786 .chained = true,
4787 .chain_id = ALC262_FIXUP_BENQ,
4788 },
4789 [ALC262_FIXUP_BENQ] = {
4790 .type = ALC_FIXUP_VERBS,
4791 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004792 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4793 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4794 {}
4795 }
4796 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004797 [ALC262_FIXUP_BENQ_T31] = {
4798 .type = ALC_FIXUP_VERBS,
4799 .v.verbs = (const struct hda_verb[]) {
4800 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4801 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4802 {}
4803 }
4804 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004805};
4806
4807static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004808 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004809 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4810 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004811 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
4812 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004813 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004814 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4815 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004816 {}
4817};
4818
4819
4820#ifdef CONFIG_SND_HDA_POWER_SAVE
4821#define alc262_loopbacks alc880_loopbacks
4822#endif
4823
Takashi Iwai1d045db2011-07-07 18:23:21 +02004824/*
4825 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004826static int patch_alc262(struct hda_codec *codec)
4827{
4828 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004829 int err;
4830
4831 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4832 if (spec == NULL)
4833 return -ENOMEM;
4834
4835 codec->spec = spec;
4836
4837 spec->mixer_nid = 0x0b;
4838
4839#if 0
4840 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4841 * under-run
4842 */
4843 {
4844 int tmp;
4845 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4846 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4847 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4848 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4849 }
4850#endif
4851 alc_auto_parse_customize_define(codec);
4852
4853 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4854
Takashi Iwai42399f72011-11-07 17:18:44 +01004855 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4856 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004857
Takashi Iwai42399f72011-11-07 17:18:44 +01004858 /* automatic parse from the BIOS config */
4859 err = alc262_parse_auto_config(codec);
4860 if (err < 0)
4861 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004862
Takashi Iwai60a6a842011-07-27 14:01:24 +02004863 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004864 alc_auto_fill_adc_caps(codec);
4865 alc_rebuild_imux_for_auto_mic(codec);
4866 alc_remove_invalid_adc_nids(codec);
4867 }
4868
4869 if (!spec->no_analog && !spec->cap_mixer)
4870 set_capture_mixer(codec);
4871
Takashi Iwai1d045db2011-07-07 18:23:21 +02004872 if (!spec->no_analog && has_cdefine_beep(codec)) {
4873 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004874 if (err < 0)
4875 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004876 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004877 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004878
4879 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4880
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004882 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004883 spec->shutup = alc_eapd_shutup;
4884
Takashi Iwai1d045db2011-07-07 18:23:21 +02004885#ifdef CONFIG_SND_HDA_POWER_SAVE
4886 if (!spec->loopback.amplist)
4887 spec->loopback.amplist = alc262_loopbacks;
4888#endif
4889
4890 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004891
4892 error:
4893 alc_free(codec);
4894 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004895}
4896
4897/*
4898 * ALC268
4899 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004900/* bind Beep switches of both NID 0x0f and 0x10 */
4901static const struct hda_bind_ctls alc268_bind_beep_sw = {
4902 .ops = &snd_hda_bind_sw,
4903 .values = {
4904 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4905 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4906 0
4907 },
4908};
4909
4910static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4911 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4912 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4913 { }
4914};
4915
4916/* set PCBEEP vol = 0, mute connections */
4917static const struct hda_verb alc268_beep_init_verbs[] = {
4918 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4919 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4920 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4921 { }
4922};
4923
4924/*
4925 * BIOS auto configuration
4926 */
4927static int alc268_parse_auto_config(struct hda_codec *codec)
4928{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004929 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004930 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004931 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4932 if (err > 0) {
4933 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4934 add_mixer(spec, alc268_beep_mixer);
4935 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004936 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004937 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004938 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004939}
4940
Takashi Iwai1d045db2011-07-07 18:23:21 +02004941/*
4942 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004943static int patch_alc268(struct hda_codec *codec)
4944{
4945 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004946 int i, has_beep, err;
4947
4948 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4949 if (spec == NULL)
4950 return -ENOMEM;
4951
4952 codec->spec = spec;
4953
4954 /* ALC268 has no aa-loopback mixer */
4955
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004956 /* automatic parse from the BIOS config */
4957 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004958 if (err < 0)
4959 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004960
Takashi Iwai1d045db2011-07-07 18:23:21 +02004961 has_beep = 0;
4962 for (i = 0; i < spec->num_mixers; i++) {
4963 if (spec->mixers[i] == alc268_beep_mixer) {
4964 has_beep = 1;
4965 break;
4966 }
4967 }
4968
4969 if (has_beep) {
4970 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004971 if (err < 0)
4972 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004973 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4974 /* override the amp caps for beep generator */
4975 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4976 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4977 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4978 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4979 (0 << AC_AMPCAP_MUTE_SHIFT));
4980 }
4981
Takashi Iwai60a6a842011-07-27 14:01:24 +02004982 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004983 alc_auto_fill_adc_caps(codec);
4984 alc_rebuild_imux_for_auto_mic(codec);
4985 alc_remove_invalid_adc_nids(codec);
4986 }
4987
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004988 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989 set_capture_mixer(codec);
4990
Takashi Iwai1d045db2011-07-07 18:23:21 +02004991 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004992 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993 spec->shutup = alc_eapd_shutup;
4994
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004996
4997 error:
4998 alc_free(codec);
4999 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000}
5001
5002/*
5003 * ALC269
5004 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005#ifdef CONFIG_SND_HDA_POWER_SAVE
5006#define alc269_loopbacks alc880_loopbacks
5007#endif
5008
5009static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5010 .substreams = 1,
5011 .channels_min = 2,
5012 .channels_max = 8,
5013 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5014 /* NID is set in alc_build_pcms */
5015 .ops = {
5016 .open = alc_playback_pcm_open,
5017 .prepare = alc_playback_pcm_prepare,
5018 .cleanup = alc_playback_pcm_cleanup
5019 },
5020};
5021
5022static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5023 .substreams = 1,
5024 .channels_min = 2,
5025 .channels_max = 2,
5026 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5027 /* NID is set in alc_build_pcms */
5028};
5029
5030#ifdef CONFIG_SND_HDA_POWER_SAVE
5031static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5032{
5033 switch (codec->subsystem_id) {
5034 case 0x103c1586:
5035 return 1;
5036 }
5037 return 0;
5038}
5039
5040static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5041{
5042 /* update mute-LED according to the speaker mute state */
5043 if (nid == 0x01 || nid == 0x14) {
5044 int pinval;
5045 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5046 HDA_AMP_MUTE)
5047 pinval = 0x24;
5048 else
5049 pinval = 0x20;
5050 /* mic2 vref pin is used for mute LED control */
5051 snd_hda_codec_update_cache(codec, 0x19, 0,
5052 AC_VERB_SET_PIN_WIDGET_CONTROL,
5053 pinval);
5054 }
5055 return alc_check_power_status(codec, nid);
5056}
5057#endif /* CONFIG_SND_HDA_POWER_SAVE */
5058
5059/* different alc269-variants */
5060enum {
5061 ALC269_TYPE_ALC269VA,
5062 ALC269_TYPE_ALC269VB,
5063 ALC269_TYPE_ALC269VC,
5064};
5065
5066/*
5067 * BIOS auto configuration
5068 */
5069static int alc269_parse_auto_config(struct hda_codec *codec)
5070{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005071 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005072 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5073 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5074 struct alc_spec *spec = codec->spec;
5075 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5076 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005077
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005078 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005079}
5080
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5082{
5083 int val = alc_read_coef_idx(codec, 0x04);
5084 if (power_up)
5085 val |= 1 << 11;
5086 else
5087 val &= ~(1 << 11);
5088 alc_write_coef_idx(codec, 0x04, val);
5089}
5090
5091static void alc269_shutup(struct hda_codec *codec)
5092{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005093 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005094 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005095 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005096 alc269_toggle_power_output(codec, 0);
5097 msleep(150);
5098 }
5099}
5100
Takashi Iwai2a439522011-07-26 09:52:50 +02005101#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005102static int alc269_resume(struct hda_codec *codec)
5103{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005104 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005105 alc269_toggle_power_output(codec, 0);
5106 msleep(150);
5107 }
5108
5109 codec->patch_ops.init(codec);
5110
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005111 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005112 alc269_toggle_power_output(codec, 1);
5113 msleep(200);
5114 }
5115
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005116 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005117 alc269_toggle_power_output(codec, 1);
5118
5119 snd_hda_codec_resume_amp(codec);
5120 snd_hda_codec_resume_cache(codec);
5121 hda_call_check_power_status(codec, 0x01);
5122 return 0;
5123}
Takashi Iwai2a439522011-07-26 09:52:50 +02005124#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005125
5126static void alc269_fixup_hweq(struct hda_codec *codec,
5127 const struct alc_fixup *fix, int action)
5128{
5129 int coef;
5130
5131 if (action != ALC_FIXUP_ACT_INIT)
5132 return;
5133 coef = alc_read_coef_idx(codec, 0x1e);
5134 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5135}
5136
5137static void alc271_fixup_dmic(struct hda_codec *codec,
5138 const struct alc_fixup *fix, int action)
5139{
5140 static const struct hda_verb verbs[] = {
5141 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5142 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5143 {}
5144 };
5145 unsigned int cfg;
5146
5147 if (strcmp(codec->chip_name, "ALC271X"))
5148 return;
5149 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5150 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5151 snd_hda_sequence_write(codec, verbs);
5152}
5153
Takashi Iwai017f2a12011-07-09 14:42:25 +02005154static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5155 const struct alc_fixup *fix, int action)
5156{
5157 struct alc_spec *spec = codec->spec;
5158
5159 if (action != ALC_FIXUP_ACT_PROBE)
5160 return;
5161
5162 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5163 * fix the sample rate of analog I/O to 44.1kHz
5164 */
5165 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5166 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5167}
5168
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005169static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5170 const struct alc_fixup *fix, int action)
5171{
5172 int coef;
5173
5174 if (action != ALC_FIXUP_ACT_INIT)
5175 return;
5176 /* The digital-mic unit sends PDM (differential signal) instead of
5177 * the standard PCM, thus you can't record a valid mono stream as is.
5178 * Below is a workaround specific to ALC269 to control the dmic
5179 * signal source as mono.
5180 */
5181 coef = alc_read_coef_idx(codec, 0x07);
5182 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5183}
5184
Takashi Iwai24519912011-08-16 15:08:49 +02005185static void alc269_quanta_automute(struct hda_codec *codec)
5186{
David Henningsson42cf0d02011-09-20 12:04:56 +02005187 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005188
5189 snd_hda_codec_write(codec, 0x20, 0,
5190 AC_VERB_SET_COEF_INDEX, 0x0c);
5191 snd_hda_codec_write(codec, 0x20, 0,
5192 AC_VERB_SET_PROC_COEF, 0x680);
5193
5194 snd_hda_codec_write(codec, 0x20, 0,
5195 AC_VERB_SET_COEF_INDEX, 0x0c);
5196 snd_hda_codec_write(codec, 0x20, 0,
5197 AC_VERB_SET_PROC_COEF, 0x480);
5198}
5199
5200static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5201 const struct alc_fixup *fix, int action)
5202{
5203 struct alc_spec *spec = codec->spec;
5204 if (action != ALC_FIXUP_ACT_PROBE)
5205 return;
5206 spec->automute_hook = alc269_quanta_automute;
5207}
5208
Takashi Iwai1d045db2011-07-07 18:23:21 +02005209enum {
5210 ALC269_FIXUP_SONY_VAIO,
5211 ALC275_FIXUP_SONY_VAIO_GPIO2,
5212 ALC269_FIXUP_DELL_M101Z,
5213 ALC269_FIXUP_SKU_IGNORE,
5214 ALC269_FIXUP_ASUS_G73JW,
5215 ALC269_FIXUP_LENOVO_EAPD,
5216 ALC275_FIXUP_SONY_HWEQ,
5217 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005218 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005219 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005220 ALC269_FIXUP_QUANTA_MUTE,
5221 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005222 ALC269_FIXUP_AMIC,
5223 ALC269_FIXUP_DMIC,
5224 ALC269VB_FIXUP_AMIC,
5225 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005226};
5227
5228static const struct alc_fixup alc269_fixups[] = {
5229 [ALC269_FIXUP_SONY_VAIO] = {
5230 .type = ALC_FIXUP_VERBS,
5231 .v.verbs = (const struct hda_verb[]) {
5232 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5233 {}
5234 }
5235 },
5236 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5237 .type = ALC_FIXUP_VERBS,
5238 .v.verbs = (const struct hda_verb[]) {
5239 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5240 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5241 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5242 { }
5243 },
5244 .chained = true,
5245 .chain_id = ALC269_FIXUP_SONY_VAIO
5246 },
5247 [ALC269_FIXUP_DELL_M101Z] = {
5248 .type = ALC_FIXUP_VERBS,
5249 .v.verbs = (const struct hda_verb[]) {
5250 /* Enables internal speaker */
5251 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5252 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5253 {}
5254 }
5255 },
5256 [ALC269_FIXUP_SKU_IGNORE] = {
5257 .type = ALC_FIXUP_SKU,
5258 .v.sku = ALC_FIXUP_SKU_IGNORE,
5259 },
5260 [ALC269_FIXUP_ASUS_G73JW] = {
5261 .type = ALC_FIXUP_PINS,
5262 .v.pins = (const struct alc_pincfg[]) {
5263 { 0x17, 0x99130111 }, /* subwoofer */
5264 { }
5265 }
5266 },
5267 [ALC269_FIXUP_LENOVO_EAPD] = {
5268 .type = ALC_FIXUP_VERBS,
5269 .v.verbs = (const struct hda_verb[]) {
5270 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5271 {}
5272 }
5273 },
5274 [ALC275_FIXUP_SONY_HWEQ] = {
5275 .type = ALC_FIXUP_FUNC,
5276 .v.func = alc269_fixup_hweq,
5277 .chained = true,
5278 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5279 },
5280 [ALC271_FIXUP_DMIC] = {
5281 .type = ALC_FIXUP_FUNC,
5282 .v.func = alc271_fixup_dmic,
5283 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005284 [ALC269_FIXUP_PCM_44K] = {
5285 .type = ALC_FIXUP_FUNC,
5286 .v.func = alc269_fixup_pcm_44k,
5287 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005288 [ALC269_FIXUP_STEREO_DMIC] = {
5289 .type = ALC_FIXUP_FUNC,
5290 .v.func = alc269_fixup_stereo_dmic,
5291 },
Takashi Iwai24519912011-08-16 15:08:49 +02005292 [ALC269_FIXUP_QUANTA_MUTE] = {
5293 .type = ALC_FIXUP_FUNC,
5294 .v.func = alc269_fixup_quanta_mute,
5295 },
5296 [ALC269_FIXUP_LIFEBOOK] = {
5297 .type = ALC_FIXUP_PINS,
5298 .v.pins = (const struct alc_pincfg[]) {
5299 { 0x1a, 0x2101103f }, /* dock line-out */
5300 { 0x1b, 0x23a11040 }, /* dock mic-in */
5301 { }
5302 },
5303 .chained = true,
5304 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5305 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005306 [ALC269_FIXUP_AMIC] = {
5307 .type = ALC_FIXUP_PINS,
5308 .v.pins = (const struct alc_pincfg[]) {
5309 { 0x14, 0x99130110 }, /* speaker */
5310 { 0x15, 0x0121401f }, /* HP out */
5311 { 0x18, 0x01a19c20 }, /* mic */
5312 { 0x19, 0x99a3092f }, /* int-mic */
5313 { }
5314 },
5315 },
5316 [ALC269_FIXUP_DMIC] = {
5317 .type = ALC_FIXUP_PINS,
5318 .v.pins = (const struct alc_pincfg[]) {
5319 { 0x12, 0x99a3092f }, /* int-mic */
5320 { 0x14, 0x99130110 }, /* speaker */
5321 { 0x15, 0x0121401f }, /* HP out */
5322 { 0x18, 0x01a19c20 }, /* mic */
5323 { }
5324 },
5325 },
5326 [ALC269VB_FIXUP_AMIC] = {
5327 .type = ALC_FIXUP_PINS,
5328 .v.pins = (const struct alc_pincfg[]) {
5329 { 0x14, 0x99130110 }, /* speaker */
5330 { 0x18, 0x01a19c20 }, /* mic */
5331 { 0x19, 0x99a3092f }, /* int-mic */
5332 { 0x21, 0x0121401f }, /* HP out */
5333 { }
5334 },
5335 },
David Henningsson2267ea92012-01-03 08:45:56 +01005336 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02005337 .type = ALC_FIXUP_PINS,
5338 .v.pins = (const struct alc_pincfg[]) {
5339 { 0x12, 0x99a3092f }, /* int-mic */
5340 { 0x14, 0x99130110 }, /* speaker */
5341 { 0x18, 0x01a19c20 }, /* mic */
5342 { 0x21, 0x0121401f }, /* HP out */
5343 { }
5344 },
5345 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005346};
5347
5348static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005349 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005350 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5351 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5352 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5353 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5354 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005355 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5356 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5357 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5358 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5359 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5360 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005361 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005362 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5363 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5364 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5365 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5366 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005367 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005368 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005369 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005370
5371#if 1
5372 /* Below is a quirk table taken from the old code.
5373 * Basically the device should work as is without the fixup table.
5374 * If BIOS doesn't give a proper info, enable the corresponding
5375 * fixup entry.
5376 */
5377 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5378 ALC269_FIXUP_AMIC),
5379 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005380 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5381 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5382 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5383 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5384 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5385 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5386 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5387 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5388 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5389 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5390 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5391 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5392 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5393 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5394 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5395 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5396 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5397 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5398 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5399 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5400 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5401 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5402 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5403 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5404 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5405 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5406 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5407 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5408 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5409 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5410 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5411 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5412 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5413 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5414 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5415 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5416 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5417 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5418#endif
5419 {}
5420};
5421
5422static const struct alc_model_fixup alc269_fixup_models[] = {
5423 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5424 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005425 {}
5426};
5427
5428
5429static int alc269_fill_coef(struct hda_codec *codec)
5430{
5431 int val;
5432
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005433 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005434 alc_write_coef_idx(codec, 0xf, 0x960b);
5435 alc_write_coef_idx(codec, 0xe, 0x8817);
5436 }
5437
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005438 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005439 alc_write_coef_idx(codec, 0xf, 0x960b);
5440 alc_write_coef_idx(codec, 0xe, 0x8814);
5441 }
5442
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005443 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005444 val = alc_read_coef_idx(codec, 0x04);
5445 /* Power up output pin */
5446 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5447 }
5448
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005449 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005450 val = alc_read_coef_idx(codec, 0xd);
5451 if ((val & 0x0c00) >> 10 != 0x1) {
5452 /* Capless ramp up clock control */
5453 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5454 }
5455 val = alc_read_coef_idx(codec, 0x17);
5456 if ((val & 0x01c0) >> 6 != 0x4) {
5457 /* Class D power on reset */
5458 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5459 }
5460 }
5461
5462 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5463 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5464
5465 val = alc_read_coef_idx(codec, 0x4); /* HP */
5466 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5467
5468 return 0;
5469}
5470
5471/*
5472 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005473static int patch_alc269(struct hda_codec *codec)
5474{
5475 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005476 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005477
5478 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5479 if (spec == NULL)
5480 return -ENOMEM;
5481
5482 codec->spec = spec;
5483
5484 spec->mixer_nid = 0x0b;
5485
5486 alc_auto_parse_customize_define(codec);
5487
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005488 err = alc_codec_rename_from_preset(codec);
5489 if (err < 0)
5490 goto error;
5491
Takashi Iwai1d045db2011-07-07 18:23:21 +02005492 if (codec->vendor_id == 0x10ec0269) {
5493 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005494 switch (alc_get_coef0(codec) & 0x00f0) {
5495 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005496 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005497 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005498 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005500 break;
5501 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005502 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5503 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005504 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005506 break;
5507 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005509 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005510 if (err < 0)
5511 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512 alc269_fill_coef(codec);
5513 }
5514
Takashi Iwaia4297b52011-08-23 18:40:12 +02005515 alc_pick_fixup(codec, alc269_fixup_models,
5516 alc269_fixup_tbl, alc269_fixups);
5517 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005518
Takashi Iwaia4297b52011-08-23 18:40:12 +02005519 /* automatic parse from the BIOS config */
5520 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005521 if (err < 0)
5522 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005523
Takashi Iwai60a6a842011-07-27 14:01:24 +02005524 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005525 alc_auto_fill_adc_caps(codec);
5526 alc_rebuild_imux_for_auto_mic(codec);
5527 alc_remove_invalid_adc_nids(codec);
5528 }
5529
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005530 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005531 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005532
5533 if (!spec->no_analog && has_cdefine_beep(codec)) {
5534 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005535 if (err < 0)
5536 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005537 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005538 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005539
5540 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5541
Takashi Iwai1d045db2011-07-07 18:23:21 +02005542 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005543#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005544 codec->patch_ops.resume = alc269_resume;
5545#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005546 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005547 spec->shutup = alc269_shutup;
5548
Takashi Iwai1d045db2011-07-07 18:23:21 +02005549#ifdef CONFIG_SND_HDA_POWER_SAVE
5550 if (!spec->loopback.amplist)
5551 spec->loopback.amplist = alc269_loopbacks;
5552 if (alc269_mic2_for_mute_led(codec))
5553 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5554#endif
5555
5556 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005557
5558 error:
5559 alc_free(codec);
5560 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005561}
5562
5563/*
5564 * ALC861
5565 */
5566
Takashi Iwai1d045db2011-07-07 18:23:21 +02005567static int alc861_parse_auto_config(struct hda_codec *codec)
5568{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005569 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005570 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5571 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005572}
5573
Takashi Iwai1d045db2011-07-07 18:23:21 +02005574#ifdef CONFIG_SND_HDA_POWER_SAVE
5575static const struct hda_amp_list alc861_loopbacks[] = {
5576 { 0x15, HDA_INPUT, 0 },
5577 { 0x15, HDA_INPUT, 1 },
5578 { 0x15, HDA_INPUT, 2 },
5579 { 0x15, HDA_INPUT, 3 },
5580 { } /* end */
5581};
5582#endif
5583
5584
5585/* Pin config fixes */
5586enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01005587 ALC861_FIXUP_FSC_AMILO_PI1505,
5588 ALC861_FIXUP_AMP_VREF_0F,
5589 ALC861_FIXUP_NO_JACK_DETECT,
5590 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005591};
5592
Takashi Iwai31150f22012-01-30 10:54:08 +01005593/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
5594static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
5595 const struct alc_fixup *fix, int action)
5596{
5597 struct alc_spec *spec = codec->spec;
5598 unsigned int val;
5599
5600 if (action != ALC_FIXUP_ACT_INIT)
5601 return;
5602 val = snd_hda_codec_read(codec, 0x0f, 0,
5603 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5604 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
5605 val |= AC_PINCTL_IN_EN;
5606 val |= AC_PINCTL_VREF_50;
5607 snd_hda_codec_write(codec, 0x0f, 0,
5608 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5609 spec->keep_vref_in_automute = 1;
5610}
5611
Takashi Iwaie652f4c2012-02-13 11:56:25 +01005612/* suppress the jack-detection */
5613static void alc_fixup_no_jack_detect(struct hda_codec *codec,
5614 const struct alc_fixup *fix, int action)
5615{
5616 if (action == ALC_FIXUP_ACT_PRE_PROBE)
5617 codec->no_jack_detect = 1;
5618}
5619
Takashi Iwai1d045db2011-07-07 18:23:21 +02005620static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01005621 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005622 .type = ALC_FIXUP_PINS,
5623 .v.pins = (const struct alc_pincfg[]) {
5624 { 0x0b, 0x0221101f }, /* HP */
5625 { 0x0f, 0x90170310 }, /* speaker */
5626 { }
5627 }
5628 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01005629 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01005630 .type = ALC_FIXUP_FUNC,
5631 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01005632 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01005633 [ALC861_FIXUP_NO_JACK_DETECT] = {
5634 .type = ALC_FIXUP_FUNC,
5635 .v.func = alc_fixup_no_jack_detect,
5636 },
5637 [ALC861_FIXUP_ASUS_A6RP] = {
5638 .type = ALC_FIXUP_FUNC,
5639 .v.func = alc861_fixup_asus_amp_vref_0f,
5640 .chained = true,
5641 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
5642 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643};
5644
5645static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01005646 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
5647 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
5648 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
5649 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
5650 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
5651 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652 {}
5653};
5654
5655/*
5656 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657static int patch_alc861(struct hda_codec *codec)
5658{
5659 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005660 int err;
5661
5662 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5663 if (spec == NULL)
5664 return -ENOMEM;
5665
5666 codec->spec = spec;
5667
5668 spec->mixer_nid = 0x15;
5669
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005670 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5671 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005672
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005673 /* automatic parse from the BIOS config */
5674 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005675 if (err < 0)
5676 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005677
Takashi Iwai60a6a842011-07-27 14:01:24 +02005678 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005679 alc_auto_fill_adc_caps(codec);
5680 alc_rebuild_imux_for_auto_mic(codec);
5681 alc_remove_invalid_adc_nids(codec);
5682 }
5683
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005684 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005685 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005686
5687 if (!spec->no_analog) {
5688 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005689 if (err < 0)
5690 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005691 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5692 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005693
Takashi Iwai1d045db2011-07-07 18:23:21 +02005694 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5695
5696 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005697 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005698#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005699 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005700 if (!spec->loopback.amplist)
5701 spec->loopback.amplist = alc861_loopbacks;
5702#endif
5703
5704 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005705
5706 error:
5707 alc_free(codec);
5708 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005709}
5710
5711/*
5712 * ALC861-VD support
5713 *
5714 * Based on ALC882
5715 *
5716 * In addition, an independent DAC
5717 */
5718#ifdef CONFIG_SND_HDA_POWER_SAVE
5719#define alc861vd_loopbacks alc880_loopbacks
5720#endif
5721
Takashi Iwai1d045db2011-07-07 18:23:21 +02005722static int alc861vd_parse_auto_config(struct hda_codec *codec)
5723{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005724 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005725 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5726 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727}
5728
Takashi Iwai1d045db2011-07-07 18:23:21 +02005729enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005730 ALC660VD_FIX_ASUS_GPIO1,
5731 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005732};
5733
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005734/* exclude VREF80 */
5735static void alc861vd_fixup_dallas(struct hda_codec *codec,
5736 const struct alc_fixup *fix, int action)
5737{
5738 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5739 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5740 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5741 }
5742}
5743
Takashi Iwai1d045db2011-07-07 18:23:21 +02005744static const struct alc_fixup alc861vd_fixups[] = {
5745 [ALC660VD_FIX_ASUS_GPIO1] = {
5746 .type = ALC_FIXUP_VERBS,
5747 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005748 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005749 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5750 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5751 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5752 { }
5753 }
5754 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005755 [ALC861VD_FIX_DALLAS] = {
5756 .type = ALC_FIXUP_FUNC,
5757 .v.func = alc861vd_fixup_dallas,
5758 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005759};
5760
5761static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005762 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005763 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005764 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005765 {}
5766};
5767
5768static const struct hda_verb alc660vd_eapd_verbs[] = {
5769 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5770 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5771 { }
5772};
5773
5774/*
5775 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005776static int patch_alc861vd(struct hda_codec *codec)
5777{
5778 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005779 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005780
5781 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5782 if (spec == NULL)
5783 return -ENOMEM;
5784
5785 codec->spec = spec;
5786
5787 spec->mixer_nid = 0x0b;
5788
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005789 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5790 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005791
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005792 /* automatic parse from the BIOS config */
5793 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005794 if (err < 0)
5795 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005796
Takashi Iwai1d045db2011-07-07 18:23:21 +02005797 if (codec->vendor_id == 0x10ec0660) {
5798 /* always turn on EAPD */
5799 add_verb(spec, alc660vd_eapd_verbs);
5800 }
5801
Takashi Iwai60a6a842011-07-27 14:01:24 +02005802 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005803 alc_auto_fill_adc_caps(codec);
5804 alc_rebuild_imux_for_auto_mic(codec);
5805 alc_remove_invalid_adc_nids(codec);
5806 }
5807
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005808 if (!spec->no_analog && !spec->cap_mixer)
5809 set_capture_mixer(codec);
5810
5811 if (!spec->no_analog) {
5812 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005813 if (err < 0)
5814 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005815 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5816 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005817
Takashi Iwai1d045db2011-07-07 18:23:21 +02005818 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5819
5820 codec->patch_ops = alc_patch_ops;
5821
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005822 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005823 spec->shutup = alc_eapd_shutup;
5824#ifdef CONFIG_SND_HDA_POWER_SAVE
5825 if (!spec->loopback.amplist)
5826 spec->loopback.amplist = alc861vd_loopbacks;
5827#endif
5828
5829 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005830
5831 error:
5832 alc_free(codec);
5833 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005834}
5835
5836/*
5837 * ALC662 support
5838 *
5839 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5840 * configuration. Each pin widget can choose any input DACs and a mixer.
5841 * Each ADC is connected from a mixer of all inputs. This makes possible
5842 * 6-channel independent captures.
5843 *
5844 * In addition, an independent DAC for the multi-playback (not used in this
5845 * driver yet).
5846 */
5847#ifdef CONFIG_SND_HDA_POWER_SAVE
5848#define alc662_loopbacks alc880_loopbacks
5849#endif
5850
5851/*
5852 * BIOS auto configuration
5853 */
5854
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005855static int alc662_parse_auto_config(struct hda_codec *codec)
5856{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005857 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005858 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5859 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5860 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005861
Kailang Yang6227cdc2010-02-25 08:36:52 +01005862 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5863 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005864 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005865 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005866 ssids = alc662_ssids;
5867 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005868}
5869
Todd Broch6be79482010-12-07 16:51:05 -08005870static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005871 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005872{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005873 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005874 return;
Todd Broch6be79482010-12-07 16:51:05 -08005875 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5876 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5877 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5878 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5879 (0 << AC_AMPCAP_MUTE_SHIFT)))
5880 printk(KERN_WARNING
5881 "hda_codec: failed to override amp caps for NID 0x2\n");
5882}
5883
David Henningsson6cb3b702010-09-09 08:51:44 +02005884enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005885 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005886 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005887 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005888 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005889 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005890 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005891 ALC662_FIXUP_ASUS_MODE1,
5892 ALC662_FIXUP_ASUS_MODE2,
5893 ALC662_FIXUP_ASUS_MODE3,
5894 ALC662_FIXUP_ASUS_MODE4,
5895 ALC662_FIXUP_ASUS_MODE5,
5896 ALC662_FIXUP_ASUS_MODE6,
5897 ALC662_FIXUP_ASUS_MODE7,
5898 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01005899 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02005900};
5901
5902static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005903 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005904 .type = ALC_FIXUP_PINS,
5905 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005906 { 0x15, 0x99130112 }, /* subwoofer */
5907 { }
5908 }
5909 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005910 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005911 .type = ALC_FIXUP_PINS,
5912 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005913 { 0x17, 0x99130112 }, /* subwoofer */
5914 { }
5915 }
5916 },
Todd Broch6be79482010-12-07 16:51:05 -08005917 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005918 .type = ALC_FIXUP_FUNC,
5919 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005920 },
5921 [ALC662_FIXUP_CZC_P10T] = {
5922 .type = ALC_FIXUP_VERBS,
5923 .v.verbs = (const struct hda_verb[]) {
5924 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5925 {}
5926 }
5927 },
David Henningsson94024cd2011-04-29 14:10:55 +02005928 [ALC662_FIXUP_SKU_IGNORE] = {
5929 .type = ALC_FIXUP_SKU,
5930 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005931 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005932 [ALC662_FIXUP_HP_RP5800] = {
5933 .type = ALC_FIXUP_PINS,
5934 .v.pins = (const struct alc_pincfg[]) {
5935 { 0x14, 0x0221201f }, /* HP out */
5936 { }
5937 },
5938 .chained = true,
5939 .chain_id = ALC662_FIXUP_SKU_IGNORE
5940 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005941 [ALC662_FIXUP_ASUS_MODE1] = {
5942 .type = ALC_FIXUP_PINS,
5943 .v.pins = (const struct alc_pincfg[]) {
5944 { 0x14, 0x99130110 }, /* speaker */
5945 { 0x18, 0x01a19c20 }, /* mic */
5946 { 0x19, 0x99a3092f }, /* int-mic */
5947 { 0x21, 0x0121401f }, /* HP out */
5948 { }
5949 },
5950 .chained = true,
5951 .chain_id = ALC662_FIXUP_SKU_IGNORE
5952 },
5953 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005954 .type = ALC_FIXUP_PINS,
5955 .v.pins = (const struct alc_pincfg[]) {
5956 { 0x14, 0x99130110 }, /* speaker */
5957 { 0x18, 0x01a19820 }, /* mic */
5958 { 0x19, 0x99a3092f }, /* int-mic */
5959 { 0x1b, 0x0121401f }, /* HP out */
5960 { }
5961 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005962 .chained = true,
5963 .chain_id = ALC662_FIXUP_SKU_IGNORE
5964 },
5965 [ALC662_FIXUP_ASUS_MODE3] = {
5966 .type = ALC_FIXUP_PINS,
5967 .v.pins = (const struct alc_pincfg[]) {
5968 { 0x14, 0x99130110 }, /* speaker */
5969 { 0x15, 0x0121441f }, /* HP */
5970 { 0x18, 0x01a19840 }, /* mic */
5971 { 0x19, 0x99a3094f }, /* int-mic */
5972 { 0x21, 0x01211420 }, /* HP2 */
5973 { }
5974 },
5975 .chained = true,
5976 .chain_id = ALC662_FIXUP_SKU_IGNORE
5977 },
5978 [ALC662_FIXUP_ASUS_MODE4] = {
5979 .type = ALC_FIXUP_PINS,
5980 .v.pins = (const struct alc_pincfg[]) {
5981 { 0x14, 0x99130110 }, /* speaker */
5982 { 0x16, 0x99130111 }, /* speaker */
5983 { 0x18, 0x01a19840 }, /* mic */
5984 { 0x19, 0x99a3094f }, /* int-mic */
5985 { 0x21, 0x0121441f }, /* HP */
5986 { }
5987 },
5988 .chained = true,
5989 .chain_id = ALC662_FIXUP_SKU_IGNORE
5990 },
5991 [ALC662_FIXUP_ASUS_MODE5] = {
5992 .type = ALC_FIXUP_PINS,
5993 .v.pins = (const struct alc_pincfg[]) {
5994 { 0x14, 0x99130110 }, /* speaker */
5995 { 0x15, 0x0121441f }, /* HP */
5996 { 0x16, 0x99130111 }, /* speaker */
5997 { 0x18, 0x01a19840 }, /* mic */
5998 { 0x19, 0x99a3094f }, /* int-mic */
5999 { }
6000 },
6001 .chained = true,
6002 .chain_id = ALC662_FIXUP_SKU_IGNORE
6003 },
6004 [ALC662_FIXUP_ASUS_MODE6] = {
6005 .type = ALC_FIXUP_PINS,
6006 .v.pins = (const struct alc_pincfg[]) {
6007 { 0x14, 0x99130110 }, /* speaker */
6008 { 0x15, 0x01211420 }, /* HP2 */
6009 { 0x18, 0x01a19840 }, /* mic */
6010 { 0x19, 0x99a3094f }, /* int-mic */
6011 { 0x1b, 0x0121441f }, /* HP */
6012 { }
6013 },
6014 .chained = true,
6015 .chain_id = ALC662_FIXUP_SKU_IGNORE
6016 },
6017 [ALC662_FIXUP_ASUS_MODE7] = {
6018 .type = ALC_FIXUP_PINS,
6019 .v.pins = (const struct alc_pincfg[]) {
6020 { 0x14, 0x99130110 }, /* speaker */
6021 { 0x17, 0x99130111 }, /* speaker */
6022 { 0x18, 0x01a19840 }, /* mic */
6023 { 0x19, 0x99a3094f }, /* int-mic */
6024 { 0x1b, 0x01214020 }, /* HP */
6025 { 0x21, 0x0121401f }, /* HP */
6026 { }
6027 },
6028 .chained = true,
6029 .chain_id = ALC662_FIXUP_SKU_IGNORE
6030 },
6031 [ALC662_FIXUP_ASUS_MODE8] = {
6032 .type = ALC_FIXUP_PINS,
6033 .v.pins = (const struct alc_pincfg[]) {
6034 { 0x14, 0x99130110 }, /* speaker */
6035 { 0x12, 0x99a30970 }, /* int-mic */
6036 { 0x15, 0x01214020 }, /* HP */
6037 { 0x17, 0x99130111 }, /* speaker */
6038 { 0x18, 0x01a19840 }, /* mic */
6039 { 0x21, 0x0121401f }, /* HP */
6040 { }
6041 },
6042 .chained = true,
6043 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006044 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006045 [ALC662_FIXUP_NO_JACK_DETECT] = {
6046 .type = ALC_FIXUP_FUNC,
6047 .v.func = alc_fixup_no_jack_detect,
6048 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006049};
6050
Takashi Iwaia9111322011-05-02 11:30:18 +02006051static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006052 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006053 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006054 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006055 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006056 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006057 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006058 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006059 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006060 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006061 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006062 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006063
6064#if 0
6065 /* Below is a quirk table taken from the old code.
6066 * Basically the device should work as is without the fixup table.
6067 * If BIOS doesn't give a proper info, enable the corresponding
6068 * fixup entry.
6069 */
6070 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6071 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6072 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6073 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6074 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6075 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6076 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6077 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6078 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6079 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6080 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6081 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6082 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6083 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6084 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6085 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6086 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6087 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6088 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6089 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6090 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6091 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6092 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6093 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6094 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6095 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6096 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6097 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6098 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6099 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6100 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6101 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6102 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6103 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6104 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6105 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6106 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6107 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6108 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6109 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6110 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6111 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6112 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6113 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6114 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6115 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6116 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6117 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6118 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6119 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6120#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006121 {}
6122};
6123
Todd Broch6be79482010-12-07 16:51:05 -08006124static const struct alc_model_fixup alc662_fixup_models[] = {
6125 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006126 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6127 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6128 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6129 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6130 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6131 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6132 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6133 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006134 {}
6135};
David Henningsson6cb3b702010-09-09 08:51:44 +02006136
6137
Takashi Iwai1d045db2011-07-07 18:23:21 +02006138/*
6139 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006140static int patch_alc662(struct hda_codec *codec)
6141{
6142 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006143 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006144
6145 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6146 if (!spec)
6147 return -ENOMEM;
6148
6149 codec->spec = spec;
6150
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006151 spec->mixer_nid = 0x0b;
6152
Takashi Iwai53c334a2011-08-23 18:27:14 +02006153 /* handle multiple HPs as is */
6154 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6155
Kailang Yangda00c242010-03-19 11:23:45 +01006156 alc_auto_parse_customize_define(codec);
6157
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006158 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6159
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006160 err = alc_codec_rename_from_preset(codec);
6161 if (err < 0)
6162 goto error;
6163
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006164 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006165 codec->bus->pci->subsystem_vendor == 0x1025 &&
6166 spec->cdefine.platform_type == 1) {
6167 if (alc_codec_rename(codec, "ALC272X") < 0)
6168 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006169 }
Kailang Yang274693f2009-12-03 10:07:50 +01006170
Takashi Iwaib9c51062011-08-24 18:08:07 +02006171 alc_pick_fixup(codec, alc662_fixup_models,
6172 alc662_fixup_tbl, alc662_fixups);
6173 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6174 /* automatic parse from the BIOS config */
6175 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006176 if (err < 0)
6177 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006178
Takashi Iwai60a6a842011-07-27 14:01:24 +02006179 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006180 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006181 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006182 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006183 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006184
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006185 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006186 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006187
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006188 if (!spec->no_analog && has_cdefine_beep(codec)) {
6189 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006190 if (err < 0)
6191 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006192 switch (codec->vendor_id) {
6193 case 0x10ec0662:
6194 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6195 break;
6196 case 0x10ec0272:
6197 case 0x10ec0663:
6198 case 0x10ec0665:
6199 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6200 break;
6201 case 0x10ec0273:
6202 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6203 break;
6204 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006205 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006206
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006207 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6208
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006209 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006210 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006211 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006212
Takashi Iwaicb53c622007-08-10 17:21:45 +02006213#ifdef CONFIG_SND_HDA_POWER_SAVE
6214 if (!spec->loopback.amplist)
6215 spec->loopback.amplist = alc662_loopbacks;
6216#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006217
6218 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006219
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006220 error:
6221 alc_free(codec);
6222 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006223}
6224
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006225/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006226 * ALC680 support
6227 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006228
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006229static int alc680_parse_auto_config(struct hda_codec *codec)
6230{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006231 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006232}
6233
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006234/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006235 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006236static int patch_alc680(struct hda_codec *codec)
6237{
6238 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006239 int err;
6240
6241 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6242 if (spec == NULL)
6243 return -ENOMEM;
6244
6245 codec->spec = spec;
6246
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006247 /* ALC680 has no aa-loopback mixer */
6248
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006249 /* automatic parse from the BIOS config */
6250 err = alc680_parse_auto_config(codec);
6251 if (err < 0) {
6252 alc_free(codec);
6253 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006254 }
6255
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006256 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006257 set_capture_mixer(codec);
6258
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006259 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006260 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006261
6262 return 0;
6263}
6264
6265/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006266 * patch entries
6267 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006268static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006269 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006271 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006272 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006273 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006274 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006275 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006276 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006277 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006278 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006279 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006280 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006281 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6282 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6283 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006284 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02006285 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006286 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6287 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006288 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6289 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006290 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006291 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006292 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006293 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006294 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006295 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006296 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006297 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006298 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006299 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006300 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006301 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006302 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006303 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02006304 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006305 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006306 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006307 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006308 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006309 {} /* terminator */
6310};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006311
6312MODULE_ALIAS("snd-hda-codec-id:10ec*");
6313
6314MODULE_LICENSE("GPL");
6315MODULE_DESCRIPTION("Realtek HD-audio codec");
6316
6317static struct hda_codec_preset_list realtek_list = {
6318 .preset = snd_hda_preset_realtek,
6319 .owner = THIS_MODULE,
6320};
6321
6322static int __init patch_realtek_init(void)
6323{
6324 return snd_hda_add_codec_preset(&realtek_list);
6325}
6326
6327static void __exit patch_realtek_exit(void)
6328{
6329 snd_hda_delete_codec_preset(&realtek_list);
6330}
6331
6332module_init(patch_realtek_init)
6333module_exit(patch_realtek_exit)