blob: 8194c0725b6d93f1c441b48da3ec44ab20fe1716 [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Takashi Iwai1d045db2011-07-07 18:23:21 +020037/* unsol event tags */
38#define ALC_FRONT_EVENT 0x01
39#define ALC_DCVOL_EVENT 0x02
40#define ALC_HP_EVENT 0x04
41#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020042
Kailang Yangdf694da2005-12-05 19:42:22 +010043/* for GPIO Poll */
44#define GPIO_MASK 0x03
45
Takashi Iwai4a79ba32009-04-22 16:31:35 +020046/* extra amp-initialization sequence types */
47enum {
48 ALC_INIT_NONE,
49 ALC_INIT_DEFAULT,
50 ALC_INIT_GPIO1,
51 ALC_INIT_GPIO2,
52 ALC_INIT_GPIO3,
53};
54
Kailang Yangda00c242010-03-19 11:23:45 +010055struct alc_customize_define {
56 unsigned int sku_cfg;
57 unsigned char port_connectivity;
58 unsigned char check_sum;
59 unsigned char customization;
60 unsigned char external_amp;
61 unsigned int enable_pcbeep:1;
62 unsigned int platform_type:1;
63 unsigned int swap:1;
64 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020065 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010066};
67
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010068struct alc_fixup;
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwaid922b512011-04-28 12:18:53 +020076enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020077 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020080};
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082struct alc_spec {
83 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020084 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020086 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010087 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Takashi Iwai2d9c6482009-10-13 08:06:55 +020089 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020090 * don't forget NULL
91 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020092 */
93 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Takashi Iwaiaa563af2009-07-31 10:05:11 +020095 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020096 const struct hda_pcm_stream *stream_analog_playback;
97 const struct hda_pcm_stream *stream_analog_capture;
98 const struct hda_pcm_stream *stream_analog_alt_playback;
99 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200101 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200102 const struct hda_pcm_stream *stream_digital_playback;
103 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200106 struct hda_multi_out multiout; /* playback set-up
107 * max_channels, dacs must be set
108 * dig_out_nid and hp_nid are optional
109 */
Takashi Iwai63300792008-01-24 15:31:36 +0100110 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100111 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100112 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 /* capture */
115 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200116 const hda_nid_t *adc_nids;
117 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200118 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200119 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwai527e4d72011-10-27 16:33:27 +0200120 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
121 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Takashi Iwai840b64c2010-07-13 22:49:01 +0200123 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200124 hda_nid_t cur_adc;
125 unsigned int cur_adc_stream_tag;
126 unsigned int cur_adc_format;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200129 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 const struct hda_input_mux *input_mux;
131 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200132 hda_nid_t ext_mic_pin;
133 hda_nid_t dock_mic_pin;
134 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100137 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200139 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200140 int const_channel_count;
141 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100144 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200145
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200146 /* dynamic controls, init_verbs and input_mux */
147 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100148 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200149 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200150 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200151 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai49535502009-06-30 15:28:30 +0200152 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
153 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200154 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
155 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
156 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100157
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100158 /* hooks */
159 void (*init_hook)(struct hda_codec *codec);
160 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100161#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500162 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100163#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200164 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200165 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100166
Takashi Iwai834be882006-03-01 14:16:17 +0100167 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200168 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200169 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200170 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200171 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200172 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200173 unsigned int automute_speaker:1; /* automute speaker outputs */
174 unsigned int automute_lo:1; /* automute LO outputs */
175 unsigned int detect_hp:1; /* Headphone detection enabled */
176 unsigned int detect_lo:1; /* Line-out detection enabled */
177 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
178 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200179
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100180 /* other flags */
181 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200182 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100183 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200184 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200185 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100186 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200187
188 /* auto-mute control */
189 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200190 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200191
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200192 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200193 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100194
Takashi Iwai2134ea42008-01-10 16:53:55 +0100195 /* for virtual master */
196 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200197#ifdef CONFIG_SND_HDA_POWER_SAVE
198 struct hda_loopback_check loopback;
199#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200200
201 /* for PLL fix */
202 hda_nid_t pll_nid;
203 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200204 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100205
206 /* fix-up list */
207 int fixup_id;
208 const struct alc_fixup *fixup_list;
209 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200210
211 /* multi-io */
212 int multi_ios;
213 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200214
215 /* bind volumes */
216 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100217};
218
Takashi Iwai1d045db2011-07-07 18:23:21 +0200219#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Takashi Iwai44c02402011-07-08 15:14:19 +0200221static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
222 int dir, unsigned int bits)
223{
224 if (!nid)
225 return false;
226 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
227 if (query_amp_caps(codec, nid, dir) & bits)
228 return true;
229 return false;
230}
231
232#define nid_has_mute(codec, nid, dir) \
233 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
234#define nid_has_volume(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237/*
238 * input MUX handling
239 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200240static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
241 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
244 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200245 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
246 if (mux_idx >= spec->num_mux_defs)
247 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100248 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
249 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200250 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200253static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
254 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
257 struct alc_spec *spec = codec->spec;
258 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
259
260 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
261 return 0;
262}
263
Takashi Iwai21268962011-07-07 15:01:13 +0200264static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Takashi Iwai21268962011-07-07 15:01:13 +0200266 struct alc_spec *spec = codec->spec;
267 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
268
269 if (spec->cur_adc && spec->cur_adc != new_adc) {
270 /* stream is running, let's swap the current ADC */
271 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
272 spec->cur_adc = new_adc;
273 snd_hda_codec_setup_stream(codec, new_adc,
274 spec->cur_adc_stream_tag, 0,
275 spec->cur_adc_format);
276 return true;
277 }
278 return false;
279}
280
Takashi Iwai24de1832011-11-07 17:13:39 +0100281static void call_update_outputs(struct hda_codec *codec);
282
Takashi Iwai21268962011-07-07 15:01:13 +0200283/* select the given imux item; either unmute exclusively or select the route */
284static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
285 unsigned int idx, bool force)
286{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100288 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100289 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100290 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200291 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292
Takashi Iwaicd896c32008-11-18 12:36:33 +0100293 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
294 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100295 if (!imux->num_items && mux_idx > 0)
296 imux = &spec->input_mux[0];
Takashi Iwaicd896c32008-11-18 12:36:33 +0100297
Takashi Iwai21268962011-07-07 15:01:13 +0200298 if (idx >= imux->num_items)
299 idx = imux->num_items - 1;
300 if (spec->cur_mux[adc_idx] == idx && !force)
301 return 0;
302 spec->cur_mux[adc_idx] = idx;
303
Takashi Iwai24de1832011-11-07 17:13:39 +0100304 /* for shared I/O, change the pin-control accordingly */
305 if (spec->shared_mic_hp) {
306 /* NOTE: this assumes that there are only two inputs, the
307 * first is the real internal mic and the second is HP jack.
308 */
309 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
310 AC_VERB_SET_PIN_WIDGET_CONTROL,
311 spec->cur_mux[adc_idx] ?
312 PIN_VREF80 : PIN_HP);
313 spec->automute_speaker = !spec->cur_mux[adc_idx];
314 call_update_outputs(codec);
315 }
316
Takashi Iwai21268962011-07-07 15:01:13 +0200317 if (spec->dyn_adc_switch) {
318 alc_dyn_adc_pcm_resetup(codec, idx);
319 adc_idx = spec->dyn_adc_idx[idx];
320 }
321
322 nid = spec->capsrc_nids ?
323 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
324
325 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100326 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
327 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200328 return 1;
329
Takashi Iwaia22d5432009-07-27 12:54:26 +0200330 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200331 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100332 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100333 int active = imux->items[idx].index;
334 for (i = 0; i < num_conns; i++) {
335 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
336 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100337 HDA_AMP_MUTE, v);
338 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100339 } else {
340 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200341 snd_hda_codec_write_cache(codec, nid, 0,
342 AC_VERB_SET_CONNECT_SEL,
343 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100344 }
Takashi Iwai21268962011-07-07 15:01:13 +0200345 return 1;
346}
347
348static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
349 struct snd_ctl_elem_value *ucontrol)
350{
351 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
352 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
353 return alc_mux_select(codec, adc_idx,
354 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100355}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100358 * set up the input pin config (depending on the given auto-pin type)
359 */
360static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
361 int auto_pin_type)
362{
363 unsigned int val = PIN_IN;
364
Takashi Iwai86e29592010-09-09 14:50:17 +0200365 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100366 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200367 unsigned int oldval;
368 oldval = snd_hda_codec_read(codec, nid, 0,
369 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100370 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100371 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200372 /* if the default pin setup is vref50, we give it priority */
373 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100374 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200375 else if (pincap & AC_PINCAP_VREF_50)
376 val = PIN_VREF50;
377 else if (pincap & AC_PINCAP_VREF_100)
378 val = PIN_VREF100;
379 else if (pincap & AC_PINCAP_VREF_GRD)
380 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100381 }
382 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
383}
384
385/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200386 * Append the given mixer and verb elements for the later use
387 * The mixer array is referred in build_controls(), and init_verbs are
388 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100389 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200390static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100391{
392 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
393 return;
394 spec->mixers[spec->num_mixers++] = mix;
395}
396
397static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
398{
399 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
400 return;
401 spec->init_verbs[spec->num_init_verbs++] = verb;
402}
403
404/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200405 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100406 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200407/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200408static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200409 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
410 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
411 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
412 { }
413};
414
Takashi Iwaia9111322011-05-02 11:30:18 +0200415static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200416 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
417 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
418 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
419 { }
420};
421
Takashi Iwaia9111322011-05-02 11:30:18 +0200422static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200423 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
424 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
425 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
426 { }
427};
428
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200429/*
430 * Fix hardware PLL issue
431 * On some codecs, the analog PLL gating control must be off while
432 * the default value is 1.
433 */
434static void alc_fix_pll(struct hda_codec *codec)
435{
436 struct alc_spec *spec = codec->spec;
437 unsigned int val;
438
439 if (!spec->pll_nid)
440 return;
441 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
442 spec->pll_coef_idx);
443 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
444 AC_VERB_GET_PROC_COEF, 0);
445 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
446 spec->pll_coef_idx);
447 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
448 val & ~(1 << spec->pll_coef_bit));
449}
450
451static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
452 unsigned int coef_idx, unsigned int coef_bit)
453{
454 struct alc_spec *spec = codec->spec;
455 spec->pll_nid = nid;
456 spec->pll_coef_idx = coef_idx;
457 spec->pll_coef_bit = coef_bit;
458 alc_fix_pll(codec);
459}
460
Takashi Iwai1d045db2011-07-07 18:23:21 +0200461/*
462 * Jack-reporting via input-jack layer
463 */
464
465/* initialization of jacks; currently checks only a few known pins */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200466static int alc_init_jacks(struct hda_codec *codec)
467{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100468#ifdef CONFIG_SND_HDA_INPUT_JACK
Kailang Yang9ad0e492010-09-14 23:22:00 +0200469 struct alc_spec *spec = codec->spec;
470 int err;
471 unsigned int hp_nid = spec->autocfg.hp_pins[0];
Takashi Iwai21268962011-07-07 15:01:13 +0200472 unsigned int mic_nid = spec->ext_mic_pin;
473 unsigned int dock_nid = spec->dock_mic_pin;
Kailang Yang9ad0e492010-09-14 23:22:00 +0200474
Takashi Iwai265a0242010-09-21 11:26:21 +0200475 if (hp_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100476 err = snd_hda_input_jack_add(codec, hp_nid,
477 SND_JACK_HEADPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200478 if (err < 0)
479 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100480 snd_hda_input_jack_report(codec, hp_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200481 }
Kailang Yang9ad0e492010-09-14 23:22:00 +0200482
Takashi Iwai265a0242010-09-21 11:26:21 +0200483 if (mic_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100484 err = snd_hda_input_jack_add(codec, mic_nid,
485 SND_JACK_MICROPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200486 if (err < 0)
487 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100488 snd_hda_input_jack_report(codec, mic_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200489 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200490 if (dock_nid) {
491 err = snd_hda_input_jack_add(codec, dock_nid,
492 SND_JACK_MICROPHONE, NULL);
493 if (err < 0)
494 return err;
495 snd_hda_input_jack_report(codec, dock_nid);
496 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100497#endif /* CONFIG_SND_HDA_INPUT_JACK */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200498 return 0;
499}
Kailang Yang9ad0e492010-09-14 23:22:00 +0200500
Takashi Iwai1d045db2011-07-07 18:23:21 +0200501/*
502 * Jack detections for HP auto-mute and mic-switch
503 */
504
505/* check each pin in the given array; returns true if any of them is plugged */
506static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200507{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200508 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200509
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200510 for (i = 0; i < num_pins; i++) {
511 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200512 if (!nid)
513 break;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100514 snd_hda_input_jack_report(codec, nid);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200515 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200516 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 return present;
518}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200519
Takashi Iwai1d045db2011-07-07 18:23:21 +0200520/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200521static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200522 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200523{
524 struct alc_spec *spec = codec->spec;
525 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200526 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200527 int i;
528
529 for (i = 0; i < num_pins; i++) {
530 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200531 if (!nid)
532 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200533 switch (spec->automute_mode) {
534 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200535 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200536 AC_VERB_SET_PIN_WIDGET_CONTROL,
537 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200538 break;
539 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200540 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200541 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200542 break;
543 case ALC_AUTOMUTE_MIXER:
544 nid = spec->automute_mixer_nid[i];
545 if (!nid)
546 break;
547 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200548 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200549 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200550 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200551 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200552 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200553 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200554}
555
David Henningsson42cf0d02011-09-20 12:04:56 +0200556/* Toggle outputs muting */
557static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558{
559 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561
Takashi Iwaic0a20262011-06-10 15:28:15 +0200562 /* Control HP pins/amps depending on master_mute state;
563 * in general, HP pins/amps control should be enabled in all cases,
564 * but currently set only for master_mute, just to be safe
565 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100566 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
567 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200568 spec->autocfg.hp_pins, spec->master_mute, true);
569
David Henningsson42cf0d02011-09-20 12:04:56 +0200570 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200571 on = 0;
572 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200573 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200574 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200575 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200576 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577
578 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200579 /* if LO is a copy of either HP or Speaker, don't need to handle it */
580 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
581 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200583 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200584 on = 0;
585 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200586 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200587 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200589 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590}
591
David Henningsson42cf0d02011-09-20 12:04:56 +0200592static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200593{
594 struct alc_spec *spec = codec->spec;
595 if (spec->automute_hook)
596 spec->automute_hook(codec);
597 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200598 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200599}
600
Takashi Iwai1d045db2011-07-07 18:23:21 +0200601/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602static void alc_hp_automute(struct hda_codec *codec)
603{
604 struct alc_spec *spec = codec->spec;
605
David Henningsson42cf0d02011-09-20 12:04:56 +0200606 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
608 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200609 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200610 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200611 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200612}
613
Takashi Iwai1d045db2011-07-07 18:23:21 +0200614/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200615static void alc_line_automute(struct hda_codec *codec)
616{
617 struct alc_spec *spec = codec->spec;
618
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200619 /* check LO jack only when it's different from HP */
620 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
621 return;
622
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200623 spec->line_jack_present =
624 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
625 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200626 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200627 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200628 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200629}
630
Takashi Iwai8d087c72011-06-28 12:45:47 +0200631#define get_connection_index(codec, mux, nid) \
632 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200633
Takashi Iwai1d045db2011-07-07 18:23:21 +0200634/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200635static void alc_mic_automute(struct hda_codec *codec)
636{
637 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200638 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200639
Takashi Iwai21268962011-07-07 15:01:13 +0200640 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200641 return;
642 if (snd_BUG_ON(!spec->adc_nids))
643 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200644 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200645 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200646
Takashi Iwai21268962011-07-07 15:01:13 +0200647 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
648 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
649 else if (spec->dock_mic_idx >= 0 &&
650 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
651 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
652 else
653 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Takashi Iwai6c819492009-08-10 18:47:44 +0200654
Takashi Iwai21268962011-07-07 15:01:13 +0200655 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
656 if (spec->dock_mic_idx >= 0)
657 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200658}
659
Kailang Yangc9b58002007-10-16 14:30:01 +0200660/* unsolicited event for HP jack sensing */
661static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
662{
663 if (codec->vendor_id == 0x10ec0880)
664 res >>= 28;
665 else
666 res >>= 26;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200667 switch (res) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200668 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200669 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200670 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200671 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200672 alc_line_automute(codec);
673 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200674 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200675 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200676 break;
677 }
Kailang Yang7fb0d782008-10-15 11:12:35 +0200678}
679
Takashi Iwai1d045db2011-07-07 18:23:21 +0200680/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200681static void alc_inithook(struct hda_codec *codec)
682{
Takashi Iwaid922b512011-04-28 12:18:53 +0200683 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200684 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200685 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200686}
687
Kailang Yangf9423e72008-05-27 12:32:25 +0200688/* additional initialization for ALC888 variants */
689static void alc888_coef_init(struct hda_codec *codec)
690{
691 unsigned int tmp;
692
693 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
694 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
695 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100696 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200697 /* alc888S-VC */
698 snd_hda_codec_read(codec, 0x20, 0,
699 AC_VERB_SET_PROC_COEF, 0x830);
700 else
701 /* alc888-VB */
702 snd_hda_codec_read(codec, 0x20, 0,
703 AC_VERB_SET_PROC_COEF, 0x3030);
704}
705
Takashi Iwai1d045db2011-07-07 18:23:21 +0200706/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200707static void alc889_coef_init(struct hda_codec *codec)
708{
709 unsigned int tmp;
710
711 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
712 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
713 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
714 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
715}
716
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100717/* turn on/off EAPD control (only if available) */
718static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
719{
720 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
721 return;
722 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
723 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
724 on ? 2 : 0);
725}
726
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200727/* turn on/off EAPD controls of the codec */
728static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
729{
730 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200731 static hda_nid_t pins[] = {
732 0x0f, 0x10, 0x14, 0x15, 0
733 };
734 hda_nid_t *p;
735 for (p = pins; *p; p++)
736 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200737}
738
Takashi Iwai1c716152011-04-07 10:37:16 +0200739/* generic shutup callback;
740 * just turning off EPAD and a little pause for avoiding pop-noise
741 */
742static void alc_eapd_shutup(struct hda_codec *codec)
743{
744 alc_auto_setup_eapd(codec, false);
745 msleep(200);
746}
747
Takashi Iwai1d045db2011-07-07 18:23:21 +0200748/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200749static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200750{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200751 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200752
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200753 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200754 switch (type) {
755 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200756 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
757 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200758 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200759 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
760 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200761 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200762 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
763 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200764 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200765 switch (codec->vendor_id) {
766 case 0x10ec0260:
767 snd_hda_codec_write(codec, 0x1a, 0,
768 AC_VERB_SET_COEF_INDEX, 7);
769 tmp = snd_hda_codec_read(codec, 0x1a, 0,
770 AC_VERB_GET_PROC_COEF, 0);
771 snd_hda_codec_write(codec, 0x1a, 0,
772 AC_VERB_SET_COEF_INDEX, 7);
773 snd_hda_codec_write(codec, 0x1a, 0,
774 AC_VERB_SET_PROC_COEF,
775 tmp | 0x2010);
776 break;
777 case 0x10ec0262:
778 case 0x10ec0880:
779 case 0x10ec0882:
780 case 0x10ec0883:
781 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100782 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100783 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200784 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200785 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200786 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200787 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200788 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100789#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200790 case 0x10ec0267:
791 case 0x10ec0268:
792 snd_hda_codec_write(codec, 0x20, 0,
793 AC_VERB_SET_COEF_INDEX, 7);
794 tmp = snd_hda_codec_read(codec, 0x20, 0,
795 AC_VERB_GET_PROC_COEF, 0);
796 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200797 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200798 snd_hda_codec_write(codec, 0x20, 0,
799 AC_VERB_SET_PROC_COEF,
800 tmp | 0x3000);
801 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100802#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200803 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200804 break;
805 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200806}
Kailang Yangea1fb292008-08-26 12:58:38 +0200807
Takashi Iwai1d045db2011-07-07 18:23:21 +0200808/*
809 * Auto-Mute mode mixer enum support
810 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200811static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_info *uinfo)
813{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct alc_spec *spec = codec->spec;
816 static const char * const texts2[] = {
817 "Disabled", "Enabled"
818 };
819 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200820 "Disabled", "Speaker Only", "Line-Out+Speaker"
821 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200822 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200823
824 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
825 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200826 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200827 uinfo->value.enumerated.items = 3;
828 texts = texts3;
829 } else {
830 uinfo->value.enumerated.items = 2;
831 texts = texts2;
832 }
833 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
834 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200835 strcpy(uinfo->value.enumerated.name,
836 texts[uinfo->value.enumerated.item]);
837 return 0;
838}
839
840static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
841 struct snd_ctl_elem_value *ucontrol)
842{
843 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
844 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200845 unsigned int val = 0;
846 if (spec->automute_speaker)
847 val++;
848 if (spec->automute_lo)
849 val++;
850
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200851 ucontrol->value.enumerated.item[0] = val;
852 return 0;
853}
854
855static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
856 struct snd_ctl_elem_value *ucontrol)
857{
858 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
859 struct alc_spec *spec = codec->spec;
860
861 switch (ucontrol->value.enumerated.item[0]) {
862 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200863 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200864 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200865 spec->automute_speaker = 0;
866 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200867 break;
868 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200869 if (spec->automute_speaker_possible) {
870 if (!spec->automute_lo && spec->automute_speaker)
871 return 0;
872 spec->automute_speaker = 1;
873 spec->automute_lo = 0;
874 } else if (spec->automute_lo_possible) {
875 if (spec->automute_lo)
876 return 0;
877 spec->automute_lo = 1;
878 } else
879 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 break;
881 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200882 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200883 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200885 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200886 spec->automute_speaker = 1;
887 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200888 break;
889 default:
890 return -EINVAL;
891 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200892 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200893 return 1;
894}
895
Takashi Iwaia9111322011-05-02 11:30:18 +0200896static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200897 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
898 .name = "Auto-Mute Mode",
899 .info = alc_automute_mode_info,
900 .get = alc_automute_mode_get,
901 .put = alc_automute_mode_put,
902};
903
Takashi Iwai1d045db2011-07-07 18:23:21 +0200904static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
905{
906 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
907 return snd_array_new(&spec->kctls);
908}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909
910static int alc_add_automute_mode_enum(struct hda_codec *codec)
911{
912 struct alc_spec *spec = codec->spec;
913 struct snd_kcontrol_new *knew;
914
915 knew = alc_kcontrol_new(spec);
916 if (!knew)
917 return -ENOMEM;
918 *knew = alc_automute_mode_enum;
919 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
920 if (!knew->name)
921 return -ENOMEM;
922 return 0;
923}
924
Takashi Iwai1d045db2011-07-07 18:23:21 +0200925/*
926 * Check the availability of HP/line-out auto-mute;
927 * Set up appropriately if really supported
928 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200929static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200930{
931 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200932 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200933 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200934 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200935
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200936 if (cfg->hp_pins[0])
937 present++;
938 if (cfg->line_out_pins[0])
939 present++;
940 if (cfg->speaker_pins[0])
941 present++;
942 if (present < 2) /* need two different output types */
943 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200944
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200945 if (!cfg->speaker_pins[0] &&
946 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200947 memcpy(cfg->speaker_pins, cfg->line_out_pins,
948 sizeof(cfg->speaker_pins));
949 cfg->speaker_outs = cfg->line_outs;
950 }
951
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200952 if (!cfg->hp_pins[0] &&
953 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200954 memcpy(cfg->hp_pins, cfg->line_out_pins,
955 sizeof(cfg->hp_pins));
956 cfg->hp_outs = cfg->line_outs;
957 }
958
David Henningsson42cf0d02011-09-20 12:04:56 +0200959 spec->automute_mode = ALC_AUTOMUTE_PIN;
960
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200961 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200962 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200963 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200964 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200965 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200966 nid);
967 snd_hda_codec_write_cache(codec, nid, 0,
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200968 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +0200969 AC_USRSP_EN | ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200970 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200971 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200972
David Henningsson42cf0d02011-09-20 12:04:56 +0200973 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
974 if (cfg->speaker_outs)
975 for (i = 0; i < cfg->line_outs; i++) {
976 hda_nid_t nid = cfg->line_out_pins[i];
977 if (!is_jack_detectable(codec, nid))
978 continue;
979 snd_printdd("realtek: Enable Line-Out "
980 "auto-muting on NID 0x%x\n", nid);
981 snd_hda_codec_write_cache(codec, nid, 0,
982 AC_VERB_SET_UNSOLICITED_ENABLE,
983 AC_USRSP_EN | ALC_FRONT_EVENT);
984 spec->detect_lo = 1;
985 }
986 spec->automute_lo_possible = spec->detect_hp;
987 }
988
989 spec->automute_speaker_possible = cfg->speaker_outs &&
990 (spec->detect_hp || spec->detect_lo);
991
992 spec->automute_lo = spec->automute_lo_possible;
993 spec->automute_speaker = spec->automute_speaker_possible;
994
995 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200996 /* create a control for automute mode */
997 alc_add_automute_mode_enum(codec);
998 spec->unsol_event = alc_sku_unsol_event;
999 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001000}
1001
Takashi Iwai1d045db2011-07-07 18:23:21 +02001002/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001003static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1004{
1005 int i;
1006 for (i = 0; i < nums; i++)
1007 if (list[i] == nid)
1008 return i;
1009 return -1;
1010}
1011
Takashi Iwai1d045db2011-07-07 18:23:21 +02001012/* check whether dynamic ADC-switching is available */
1013static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1014{
1015 struct alc_spec *spec = codec->spec;
1016 struct hda_input_mux *imux = &spec->private_imux[0];
1017 int i, n, idx;
1018 hda_nid_t cap, pin;
1019
1020 if (imux != spec->input_mux) /* no dynamic imux? */
1021 return false;
1022
1023 for (n = 0; n < spec->num_adc_nids; n++) {
1024 cap = spec->private_capsrc_nids[n];
1025 for (i = 0; i < imux->num_items; i++) {
1026 pin = spec->imux_pins[i];
1027 if (!pin)
1028 return false;
1029 if (get_connection_index(codec, cap, pin) < 0)
1030 break;
1031 }
1032 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001033 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001034 }
1035
1036 for (i = 0; i < imux->num_items; i++) {
1037 pin = spec->imux_pins[i];
1038 for (n = 0; n < spec->num_adc_nids; n++) {
1039 cap = spec->private_capsrc_nids[n];
1040 idx = get_connection_index(codec, cap, pin);
1041 if (idx >= 0) {
1042 imux->items[i].index = idx;
1043 spec->dyn_adc_idx[i] = n;
1044 break;
1045 }
1046 }
1047 }
1048
1049 snd_printdd("realtek: enabling ADC switching\n");
1050 spec->dyn_adc_switch = 1;
1051 return true;
1052}
Takashi Iwai21268962011-07-07 15:01:13 +02001053
1054/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1055static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1056{
1057 struct alc_spec *spec = codec->spec;
1058 struct hda_input_mux *imux;
1059 static char * const texts[3] = {
1060 "Mic", "Internal Mic", "Dock Mic"
1061 };
1062 int i;
1063
1064 if (!spec->auto_mic)
1065 return false;
1066 imux = &spec->private_imux[0];
1067 if (spec->input_mux == imux)
1068 return true;
1069 spec->imux_pins[0] = spec->ext_mic_pin;
1070 spec->imux_pins[1] = spec->int_mic_pin;
1071 spec->imux_pins[2] = spec->dock_mic_pin;
1072 for (i = 0; i < 3; i++) {
1073 strcpy(imux->items[i].label, texts[i]);
1074 if (spec->imux_pins[i])
1075 imux->num_items = i + 1;
1076 }
1077 spec->num_mux_defs = 1;
1078 spec->input_mux = imux;
1079 return true;
1080}
1081
1082/* check whether all auto-mic pins are valid; setup indices if OK */
1083static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1084{
1085 struct alc_spec *spec = codec->spec;
1086 const struct hda_input_mux *imux;
1087
1088 if (!spec->auto_mic)
1089 return false;
1090 if (spec->auto_mic_valid_imux)
1091 return true; /* already checked */
1092
1093 /* fill up imux indices */
1094 if (!alc_check_dyn_adc_switch(codec)) {
1095 spec->auto_mic = 0;
1096 return false;
1097 }
1098
1099 imux = spec->input_mux;
1100 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1101 spec->imux_pins, imux->num_items);
1102 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1103 spec->imux_pins, imux->num_items);
1104 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1105 spec->imux_pins, imux->num_items);
1106 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1107 spec->auto_mic = 0;
1108 return false; /* no corresponding imux */
1109 }
1110
1111 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1112 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001113 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001114 if (spec->dock_mic_pin)
1115 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1116 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001117 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001118
1119 spec->auto_mic_valid_imux = 1;
1120 spec->auto_mic = 1;
1121 return true;
1122}
1123
Takashi Iwai1d045db2011-07-07 18:23:21 +02001124/*
1125 * Check the availability of auto-mic switch;
1126 * Set up if really supported
1127 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001128static void alc_init_auto_mic(struct hda_codec *codec)
1129{
1130 struct alc_spec *spec = codec->spec;
1131 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001132 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001133 int i;
1134
Takashi Iwai24de1832011-11-07 17:13:39 +01001135 if (spec->shared_mic_hp)
1136 return; /* no auto-mic for the shared I/O */
1137
Takashi Iwai21268962011-07-07 15:01:13 +02001138 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1139
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001140 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001141 for (i = 0; i < cfg->num_inputs; i++) {
1142 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001143 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001144 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001145 switch (snd_hda_get_input_pin_attr(defcfg)) {
1146 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001147 if (fixed)
1148 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001149 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1150 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001151 fixed = nid;
1152 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001153 case INPUT_PIN_ATTR_UNUSED:
1154 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001155 case INPUT_PIN_ATTR_DOCK:
1156 if (dock)
1157 return; /* already occupied */
1158 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1159 return; /* invalid type */
1160 dock = nid;
1161 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001162 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001163 if (ext)
1164 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001165 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1166 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001167 ext = nid;
1168 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001169 }
1170 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001171 if (!ext && dock) {
1172 ext = dock;
1173 dock = 0;
1174 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001175 if (!ext || !fixed)
1176 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001177 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001178 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001179 if (dock && !is_jack_detectable(codec, dock))
1180 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001181
1182 /* check imux indices */
1183 spec->ext_mic_pin = ext;
1184 spec->int_mic_pin = fixed;
1185 spec->dock_mic_pin = dock;
1186
1187 spec->auto_mic = 1;
1188 if (!alc_auto_mic_check_imux(codec))
1189 return;
1190
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001191 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1192 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001193 spec->unsol_event = alc_sku_unsol_event;
1194}
1195
Takashi Iwai1d045db2011-07-07 18:23:21 +02001196/* check the availabilities of auto-mute and auto-mic switches */
1197static void alc_auto_check_switches(struct hda_codec *codec)
1198{
David Henningsson42cf0d02011-09-20 12:04:56 +02001199 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001200 alc_init_auto_mic(codec);
1201}
1202
1203/*
1204 * Realtek SSID verification
1205 */
1206
David Henningsson90622912010-10-14 14:50:18 +02001207/* Could be any non-zero and even value. When used as fixup, tells
1208 * the driver to ignore any present sku defines.
1209 */
1210#define ALC_FIXUP_SKU_IGNORE (2)
1211
Kailang Yangda00c242010-03-19 11:23:45 +01001212static int alc_auto_parse_customize_define(struct hda_codec *codec)
1213{
1214 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001215 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001216 struct alc_spec *spec = codec->spec;
1217
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001218 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1219
David Henningsson90622912010-10-14 14:50:18 +02001220 if (spec->cdefine.fixup) {
1221 ass = spec->cdefine.sku_cfg;
1222 if (ass == ALC_FIXUP_SKU_IGNORE)
1223 return -1;
1224 goto do_sku;
1225 }
1226
Kailang Yangda00c242010-03-19 11:23:45 +01001227 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001228 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001229 goto do_sku;
1230
1231 nid = 0x1d;
1232 if (codec->vendor_id == 0x10ec0260)
1233 nid = 0x17;
1234 ass = snd_hda_codec_get_pincfg(codec, nid);
1235
1236 if (!(ass & 1)) {
1237 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1238 codec->chip_name, ass);
1239 return -1;
1240 }
1241
1242 /* check sum */
1243 tmp = 0;
1244 for (i = 1; i < 16; i++) {
1245 if ((ass >> i) & 1)
1246 tmp++;
1247 }
1248 if (((ass >> 16) & 0xf) != tmp)
1249 return -1;
1250
1251 spec->cdefine.port_connectivity = ass >> 30;
1252 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1253 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1254 spec->cdefine.customization = ass >> 8;
1255do_sku:
1256 spec->cdefine.sku_cfg = ass;
1257 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1258 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1259 spec->cdefine.swap = (ass & 0x2) >> 1;
1260 spec->cdefine.override = ass & 0x1;
1261
1262 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1263 nid, spec->cdefine.sku_cfg);
1264 snd_printd("SKU: port_connectivity=0x%x\n",
1265 spec->cdefine.port_connectivity);
1266 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1267 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1268 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1269 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1270 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1271 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1272 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1273
1274 return 0;
1275}
1276
Takashi Iwai1d045db2011-07-07 18:23:21 +02001277/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001278static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1279{
Takashi Iwai21268962011-07-07 15:01:13 +02001280 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001281}
1282
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001283/* check subsystem ID and set up device-specific initialization;
1284 * return 1 if initialized, 0 if invalid SSID
1285 */
1286/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1287 * 31 ~ 16 : Manufacture ID
1288 * 15 ~ 8 : SKU ID
1289 * 7 ~ 0 : Assembly ID
1290 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1291 */
1292static int alc_subsystem_id(struct hda_codec *codec,
1293 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001294 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001295{
1296 unsigned int ass, tmp, i;
1297 unsigned nid;
1298 struct alc_spec *spec = codec->spec;
1299
David Henningsson90622912010-10-14 14:50:18 +02001300 if (spec->cdefine.fixup) {
1301 ass = spec->cdefine.sku_cfg;
1302 if (ass == ALC_FIXUP_SKU_IGNORE)
1303 return 0;
1304 goto do_sku;
1305 }
1306
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001307 ass = codec->subsystem_id & 0xffff;
1308 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1309 goto do_sku;
1310
1311 /* invalid SSID, check the special NID pin defcfg instead */
1312 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001313 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001314 * 29~21 : reserve
1315 * 20 : PCBEEP input
1316 * 19~16 : Check sum (15:1)
1317 * 15~1 : Custom
1318 * 0 : override
1319 */
1320 nid = 0x1d;
1321 if (codec->vendor_id == 0x10ec0260)
1322 nid = 0x17;
1323 ass = snd_hda_codec_get_pincfg(codec, nid);
1324 snd_printd("realtek: No valid SSID, "
1325 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001326 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001327 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001328 return 0;
1329 if ((ass >> 30) != 1) /* no physical connection */
1330 return 0;
1331
1332 /* check sum */
1333 tmp = 0;
1334 for (i = 1; i < 16; i++) {
1335 if ((ass >> i) & 1)
1336 tmp++;
1337 }
1338 if (((ass >> 16) & 0xf) != tmp)
1339 return 0;
1340do_sku:
1341 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1342 ass & 0xffff, codec->vendor_id);
1343 /*
1344 * 0 : override
1345 * 1 : Swap Jack
1346 * 2 : 0 --> Desktop, 1 --> Laptop
1347 * 3~5 : External Amplifier control
1348 * 7~6 : Reserved
1349 */
1350 tmp = (ass & 0x38) >> 3; /* external Amp control */
1351 switch (tmp) {
1352 case 1:
1353 spec->init_amp = ALC_INIT_GPIO1;
1354 break;
1355 case 3:
1356 spec->init_amp = ALC_INIT_GPIO2;
1357 break;
1358 case 7:
1359 spec->init_amp = ALC_INIT_GPIO3;
1360 break;
1361 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001362 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001363 spec->init_amp = ALC_INIT_DEFAULT;
1364 break;
1365 }
1366
1367 /* is laptop or Desktop and enable the function "Mute internal speaker
1368 * when the external headphone out jack is plugged"
1369 */
1370 if (!(ass & 0x8000))
1371 return 1;
1372 /*
1373 * 10~8 : Jack location
1374 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1375 * 14~13: Resvered
1376 * 15 : 1 --> enable the function "Mute internal speaker
1377 * when the external headphone out jack is plugged"
1378 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001379 if (!spec->autocfg.hp_pins[0] &&
1380 !(spec->autocfg.line_out_pins[0] &&
1381 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001382 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001383 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1384 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001385 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001386 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001387 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001388 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001389 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001390 else if (tmp == 3)
1391 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001392 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001393 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001394 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1395 spec->autocfg.line_outs))
1396 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001397 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001398 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001399 return 1;
1400}
Kailang Yangea1fb292008-08-26 12:58:38 +02001401
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001402/* Check the validity of ALC subsystem-id
1403 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1404static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001405{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001406 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001407 struct alc_spec *spec = codec->spec;
1408 snd_printd("realtek: "
1409 "Enable default setup for auto mode as fallback\n");
1410 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001411 }
Takashi Iwai21268962011-07-07 15:01:13 +02001412}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001413
Takashi Iwai41e41f12005-06-08 14:48:49 +02001414/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001415 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001416 */
1417
1418struct alc_pincfg {
1419 hda_nid_t nid;
1420 u32 val;
1421};
1422
Todd Broche1eb5f12010-12-06 11:19:51 -08001423struct alc_model_fixup {
1424 const int id;
1425 const char *name;
1426};
1427
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001428struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001429 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001430 bool chained;
1431 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001432 union {
1433 unsigned int sku;
1434 const struct alc_pincfg *pins;
1435 const struct hda_verb *verbs;
1436 void (*func)(struct hda_codec *codec,
1437 const struct alc_fixup *fix,
1438 int action);
1439 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001440};
1441
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001442enum {
1443 ALC_FIXUP_INVALID,
1444 ALC_FIXUP_SKU,
1445 ALC_FIXUP_PINS,
1446 ALC_FIXUP_VERBS,
1447 ALC_FIXUP_FUNC,
1448};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001449
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001450enum {
1451 ALC_FIXUP_ACT_PRE_PROBE,
1452 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001453 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001454};
1455
1456static void alc_apply_fixup(struct hda_codec *codec, int action)
1457{
1458 struct alc_spec *spec = codec->spec;
1459 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001460#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001461 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001462#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001463 int depth = 0;
1464
1465 if (!spec->fixup_list)
1466 return;
1467
1468 while (id >= 0) {
1469 const struct alc_fixup *fix = spec->fixup_list + id;
1470 const struct alc_pincfg *cfg;
1471
1472 switch (fix->type) {
1473 case ALC_FIXUP_SKU:
1474 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1475 break;;
1476 snd_printdd(KERN_INFO "hda_codec: %s: "
1477 "Apply sku override for %s\n",
1478 codec->chip_name, modelname);
1479 spec->cdefine.sku_cfg = fix->v.sku;
1480 spec->cdefine.fixup = 1;
1481 break;
1482 case ALC_FIXUP_PINS:
1483 cfg = fix->v.pins;
1484 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1485 break;
1486 snd_printdd(KERN_INFO "hda_codec: %s: "
1487 "Apply pincfg for %s\n",
1488 codec->chip_name, modelname);
1489 for (; cfg->nid; cfg++)
1490 snd_hda_codec_set_pincfg(codec, cfg->nid,
1491 cfg->val);
1492 break;
1493 case ALC_FIXUP_VERBS:
1494 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1495 break;
1496 snd_printdd(KERN_INFO "hda_codec: %s: "
1497 "Apply fix-verbs for %s\n",
1498 codec->chip_name, modelname);
1499 add_verb(codec->spec, fix->v.verbs);
1500 break;
1501 case ALC_FIXUP_FUNC:
1502 if (!fix->v.func)
1503 break;
1504 snd_printdd(KERN_INFO "hda_codec: %s: "
1505 "Apply fix-func for %s\n",
1506 codec->chip_name, modelname);
1507 fix->v.func(codec, fix, action);
1508 break;
1509 default:
1510 snd_printk(KERN_ERR "hda_codec: %s: "
1511 "Invalid fixup type %d\n",
1512 codec->chip_name, fix->type);
1513 break;
1514 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001515 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001516 break;
1517 if (++depth > 10)
1518 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001519 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001520 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001521}
1522
Todd Broche1eb5f12010-12-06 11:19:51 -08001523static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001524 const struct alc_model_fixup *models,
1525 const struct snd_pci_quirk *quirk,
1526 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001527{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001528 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001529 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001530 int id = -1;
1531 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001532
Todd Broche1eb5f12010-12-06 11:19:51 -08001533 if (codec->modelname && models) {
1534 while (models->name) {
1535 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001536 id = models->id;
1537 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001538 break;
1539 }
1540 models++;
1541 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001542 }
1543 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001544 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1545 if (q) {
1546 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001547#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001548 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001549#endif
1550 }
1551 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001552 if (id < 0) {
1553 for (q = quirk; q->subvendor; q++) {
1554 unsigned int vendorid =
1555 q->subdevice | (q->subvendor << 16);
1556 if (vendorid == codec->subsystem_id) {
1557 id = q->value;
1558#ifdef CONFIG_SND_DEBUG_VERBOSE
1559 name = q->name;
1560#endif
1561 break;
1562 }
1563 }
1564 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001565
1566 spec->fixup_id = id;
1567 if (id >= 0) {
1568 spec->fixup_list = fixlist;
1569 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001570 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001571}
1572
Takashi Iwai1d045db2011-07-07 18:23:21 +02001573/*
1574 * COEF access helper functions
1575 */
Kailang Yang274693f2009-12-03 10:07:50 +01001576static int alc_read_coef_idx(struct hda_codec *codec,
1577 unsigned int coef_idx)
1578{
1579 unsigned int val;
1580 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1581 coef_idx);
1582 val = snd_hda_codec_read(codec, 0x20, 0,
1583 AC_VERB_GET_PROC_COEF, 0);
1584 return val;
1585}
1586
Kailang Yang977ddd62010-09-15 10:02:29 +02001587static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1588 unsigned int coef_val)
1589{
1590 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1591 coef_idx);
1592 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1593 coef_val);
1594}
1595
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001596/* a special bypass for COEF 0; read the cached value at the second time */
1597static unsigned int alc_get_coef0(struct hda_codec *codec)
1598{
1599 struct alc_spec *spec = codec->spec;
1600 if (!spec->coef0)
1601 spec->coef0 = alc_read_coef_idx(codec, 0);
1602 return spec->coef0;
1603}
1604
Takashi Iwai1d045db2011-07-07 18:23:21 +02001605/*
1606 * Digital I/O handling
1607 */
1608
Takashi Iwai757899a2010-07-30 10:48:14 +02001609/* set right pin controls for digital I/O */
1610static void alc_auto_init_digital(struct hda_codec *codec)
1611{
1612 struct alc_spec *spec = codec->spec;
1613 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001614 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001615
1616 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1617 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001618 if (!pin)
1619 continue;
1620 snd_hda_codec_write(codec, pin, 0,
1621 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1622 if (!i)
1623 dac = spec->multiout.dig_out_nid;
1624 else
1625 dac = spec->slave_dig_outs[i - 1];
1626 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1627 continue;
1628 snd_hda_codec_write(codec, dac, 0,
1629 AC_VERB_SET_AMP_GAIN_MUTE,
1630 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001631 }
1632 pin = spec->autocfg.dig_in_pin;
1633 if (pin)
1634 snd_hda_codec_write(codec, pin, 0,
1635 AC_VERB_SET_PIN_WIDGET_CONTROL,
1636 PIN_IN);
1637}
1638
1639/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1640static void alc_auto_parse_digital(struct hda_codec *codec)
1641{
1642 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001643 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001644 hda_nid_t dig_nid;
1645
1646 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001647 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001648 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001649 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001650 err = snd_hda_get_connections(codec,
1651 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001652 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001653 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001654 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001655 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001656 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001657 spec->multiout.dig_out_nid = dig_nid;
1658 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1659 } else {
1660 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001661 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001662 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001663 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001664 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001665 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001666 }
1667
1668 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001669 dig_nid = codec->start_nid;
1670 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1671 unsigned int wcaps = get_wcaps(codec, dig_nid);
1672 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1673 continue;
1674 if (!(wcaps & AC_WCAP_DIGITAL))
1675 continue;
1676 if (!(wcaps & AC_WCAP_CONN_LIST))
1677 continue;
1678 err = get_connection_index(codec, dig_nid,
1679 spec->autocfg.dig_in_pin);
1680 if (err >= 0) {
1681 spec->dig_in_nid = dig_nid;
1682 break;
1683 }
1684 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001685 }
1686}
1687
Takashi Iwaif95474e2007-07-10 00:47:43 +02001688/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001689 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001690 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001691static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1692 struct snd_ctl_elem_info *uinfo)
1693{
1694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1695 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001696 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001697 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001698
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001699 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001700 if (spec->vol_in_capsrc)
1701 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1702 else
1703 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1704 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001705 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001706 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001707 return err;
1708}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001710static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1711 unsigned int size, unsigned int __user *tlv)
1712{
1713 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1714 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001715 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001716 int err;
1717
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001718 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001719 if (spec->vol_in_capsrc)
1720 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1721 else
1722 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1723 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001724 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001725 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001726 return err;
1727}
1728
1729typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol);
1731
1732static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1733 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001734 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001735{
1736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1737 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001738 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001739
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001740 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001741 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001742 for (i = 0; i < spec->num_adc_nids; i++) {
1743 kcontrol->private_value =
1744 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1745 3, 0, HDA_INPUT);
1746 err = func(kcontrol, ucontrol);
1747 if (err < 0)
1748 goto error;
1749 }
1750 } else {
1751 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001752 if (spec->vol_in_capsrc)
1753 kcontrol->private_value =
1754 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1755 3, 0, HDA_OUTPUT);
1756 else
1757 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001758 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1759 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001760 err = func(kcontrol, ucontrol);
1761 }
1762 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001763 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001764 return err;
1765}
1766
1767static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1768 struct snd_ctl_elem_value *ucontrol)
1769{
1770 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001771 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001772}
1773
1774static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1775 struct snd_ctl_elem_value *ucontrol)
1776{
1777 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001778 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001779}
1780
1781/* capture mixer elements */
1782#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1783
1784static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1785 struct snd_ctl_elem_value *ucontrol)
1786{
1787 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001788 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001789}
1790
1791static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1792 struct snd_ctl_elem_value *ucontrol)
1793{
1794 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001795 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001796}
1797
Takashi Iwaia23b6882009-03-23 15:21:36 +01001798#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001799 { \
1800 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1801 .name = "Capture Switch", \
1802 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1803 .count = num, \
1804 .info = alc_cap_sw_info, \
1805 .get = alc_cap_sw_get, \
1806 .put = alc_cap_sw_put, \
1807 }, \
1808 { \
1809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1810 .name = "Capture Volume", \
1811 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1812 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1813 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1814 .count = num, \
1815 .info = alc_cap_vol_info, \
1816 .get = alc_cap_vol_get, \
1817 .put = alc_cap_vol_put, \
1818 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001819 }
1820
1821#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001822 { \
1823 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1824 /* .name = "Capture Source", */ \
1825 .name = "Input Source", \
1826 .count = num, \
1827 .info = alc_mux_enum_info, \
1828 .get = alc_mux_enum_get, \
1829 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001830 }
1831
1832#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001833static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001834 _DEFINE_CAPMIX(num), \
1835 _DEFINE_CAPSRC(num), \
1836 { } /* end */ \
1837}
1838
1839#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001840static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001841 _DEFINE_CAPMIX(num), \
1842 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001843}
1844
1845/* up to three ADCs */
1846DEFINE_CAPMIX(1);
1847DEFINE_CAPMIX(2);
1848DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001849DEFINE_CAPMIX_NOSRC(1);
1850DEFINE_CAPMIX_NOSRC(2);
1851DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001852
1853/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001854 * virtual master controls
1855 */
1856
1857/*
1858 * slave controls for virtual master
1859 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001860static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001861 "Front Playback Volume",
1862 "Surround Playback Volume",
1863 "Center Playback Volume",
1864 "LFE Playback Volume",
1865 "Side Playback Volume",
1866 "Headphone Playback Volume",
1867 "Speaker Playback Volume",
1868 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001869 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001870 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001871 NULL,
1872};
1873
Takashi Iwaiea734962011-01-17 11:29:34 +01001874static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001875 "Front Playback Switch",
1876 "Surround Playback Switch",
1877 "Center Playback Switch",
1878 "LFE Playback Switch",
1879 "Side Playback Switch",
1880 "Headphone Playback Switch",
1881 "Speaker Playback Switch",
1882 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001883 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001884 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001885 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001886 NULL,
1887};
1888
1889/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001890 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001892
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001893#define NID_MAPPING (-1)
1894
1895#define SUBDEV_SPEAKER_ (0 << 6)
1896#define SUBDEV_HP_ (1 << 6)
1897#define SUBDEV_LINE_ (2 << 6)
1898#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1899#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1900#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1901
Takashi Iwai603c4012008-07-30 15:01:44 +02001902static void alc_free_kctls(struct hda_codec *codec);
1903
Takashi Iwai67d634c2009-11-16 15:35:59 +01001904#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001905/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001906static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001907 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001908 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001909 { } /* end */
1910};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001911#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001912
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913static int alc_build_controls(struct hda_codec *codec)
1914{
1915 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001916 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001917 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001918 int i, j, err;
1919 unsigned int u;
1920 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 for (i = 0; i < spec->num_mixers; i++) {
1923 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1924 if (err < 0)
1925 return err;
1926 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001927 if (spec->cap_mixer) {
1928 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1929 if (err < 0)
1930 return err;
1931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001933 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001934 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001935 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 if (err < 0)
1937 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001938 if (!spec->no_analog) {
1939 err = snd_hda_create_spdif_share_sw(codec,
1940 &spec->multiout);
1941 if (err < 0)
1942 return err;
1943 spec->multiout.share_spdif = 1;
1944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 }
1946 if (spec->dig_in_nid) {
1947 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1948 if (err < 0)
1949 return err;
1950 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001951
Takashi Iwai67d634c2009-11-16 15:35:59 +01001952#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001953 /* create beep controls if needed */
1954 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001955 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001956 for (knew = alc_beep_mixer; knew->name; knew++) {
1957 struct snd_kcontrol *kctl;
1958 kctl = snd_ctl_new1(knew, codec);
1959 if (!kctl)
1960 return -ENOMEM;
1961 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001962 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001963 if (err < 0)
1964 return err;
1965 }
1966 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001967#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001968
Takashi Iwai2134ea42008-01-10 16:53:55 +01001969 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001970 if (!spec->no_analog &&
1971 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001972 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001973 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001974 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001975 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001976 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001977 if (err < 0)
1978 return err;
1979 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001980 if (!spec->no_analog &&
1981 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001982 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1983 NULL, alc_slave_sws);
1984 if (err < 0)
1985 return err;
1986 }
1987
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001988 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001989 if (spec->capsrc_nids || spec->adc_nids) {
1990 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1991 if (!kctl)
1992 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1993 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02001994 const hda_nid_t *nids = spec->capsrc_nids;
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001995 if (!nids)
1996 nids = spec->adc_nids;
1997 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1998 if (err < 0)
1999 return err;
2000 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002001 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02002002 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002003 const char *kname = kctl ? kctl->id.name : NULL;
2004 for (knew = spec->cap_mixer; knew->name; knew++) {
2005 if (kname && strcmp(knew->name, kname) == 0)
2006 continue;
2007 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2008 for (i = 0; kctl && i < kctl->count; i++) {
2009 err = snd_hda_add_nid(codec, kctl, i,
2010 spec->adc_nids[i]);
2011 if (err < 0)
2012 return err;
2013 }
2014 }
2015 }
2016
2017 /* other nid->control mapping */
2018 for (i = 0; i < spec->num_mixers; i++) {
2019 for (knew = spec->mixers[i]; knew->name; knew++) {
2020 if (knew->iface != NID_MAPPING)
2021 continue;
2022 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2023 if (kctl == NULL)
2024 continue;
2025 u = knew->subdevice;
2026 for (j = 0; j < 4; j++, u >>= 8) {
2027 nid = u & 0x3f;
2028 if (nid == 0)
2029 continue;
2030 switch (u & 0xc0) {
2031 case SUBDEV_SPEAKER_:
2032 nid = spec->autocfg.speaker_pins[nid];
2033 break;
2034 case SUBDEV_LINE_:
2035 nid = spec->autocfg.line_out_pins[nid];
2036 break;
2037 case SUBDEV_HP_:
2038 nid = spec->autocfg.hp_pins[nid];
2039 break;
2040 default:
2041 continue;
2042 }
2043 err = snd_hda_add_nid(codec, kctl, 0, nid);
2044 if (err < 0)
2045 return err;
2046 }
2047 u = knew->private_value;
2048 for (j = 0; j < 4; j++, u >>= 8) {
2049 nid = u & 0xff;
2050 if (nid == 0)
2051 continue;
2052 err = snd_hda_add_nid(codec, kctl, 0, nid);
2053 if (err < 0)
2054 return err;
2055 }
2056 }
2057 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002058
2059 alc_free_kctls(codec); /* no longer needed */
2060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 return 0;
2062}
2063
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002064
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002066 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002067 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002068
Takashi Iwai584c0c42011-03-10 12:51:11 +01002069static void alc_init_special_input_src(struct hda_codec *codec);
2070
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071static int alc_init(struct hda_codec *codec)
2072{
2073 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002074 unsigned int i;
2075
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002076 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002077 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002078
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002079 for (i = 0; i < spec->num_init_verbs; i++)
2080 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002081 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002082
2083 if (spec->init_hook)
2084 spec->init_hook(codec);
2085
Takashi Iwai58701122011-01-13 15:41:45 +01002086 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2087
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002088 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 return 0;
2090}
2091
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002092static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2093{
2094 struct alc_spec *spec = codec->spec;
2095
2096 if (spec->unsol_event)
2097 spec->unsol_event(codec, res);
2098}
2099
Takashi Iwaicb53c622007-08-10 17:21:45 +02002100#ifdef CONFIG_SND_HDA_POWER_SAVE
2101static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2102{
2103 struct alc_spec *spec = codec->spec;
2104 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2105}
2106#endif
2107
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108/*
2109 * Analog playback callbacks
2110 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002111static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002113 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114{
2115 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002116 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2117 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118}
2119
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002120static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 struct hda_codec *codec,
2122 unsigned int stream_tag,
2123 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002124 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125{
2126 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002127 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2128 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129}
2130
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002131static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002133 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134{
2135 struct alc_spec *spec = codec->spec;
2136 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2137}
2138
2139/*
2140 * Digital out
2141 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002142static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002144 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
2146 struct alc_spec *spec = codec->spec;
2147 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2148}
2149
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002150static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002151 struct hda_codec *codec,
2152 unsigned int stream_tag,
2153 unsigned int format,
2154 struct snd_pcm_substream *substream)
2155{
2156 struct alc_spec *spec = codec->spec;
2157 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2158 stream_tag, format, substream);
2159}
2160
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002161static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002162 struct hda_codec *codec,
2163 struct snd_pcm_substream *substream)
2164{
2165 struct alc_spec *spec = codec->spec;
2166 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2167}
2168
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002169static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002171 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
2173 struct alc_spec *spec = codec->spec;
2174 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2175}
2176
2177/*
2178 * Analog capture
2179 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002180static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 struct hda_codec *codec,
2182 unsigned int stream_tag,
2183 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002184 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185{
2186 struct alc_spec *spec = codec->spec;
2187
Takashi Iwai63300792008-01-24 15:31:36 +01002188 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 stream_tag, 0, format);
2190 return 0;
2191}
2192
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002193static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002195 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196{
2197 struct alc_spec *spec = codec->spec;
2198
Takashi Iwai888afa12008-03-18 09:57:50 +01002199 snd_hda_codec_cleanup_stream(codec,
2200 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 return 0;
2202}
2203
Takashi Iwai840b64c2010-07-13 22:49:01 +02002204/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002205static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002206 struct hda_codec *codec,
2207 unsigned int stream_tag,
2208 unsigned int format,
2209 struct snd_pcm_substream *substream)
2210{
2211 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002212 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002213 spec->cur_adc_stream_tag = stream_tag;
2214 spec->cur_adc_format = format;
2215 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2216 return 0;
2217}
2218
Takashi Iwai21268962011-07-07 15:01:13 +02002219static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002220 struct hda_codec *codec,
2221 struct snd_pcm_substream *substream)
2222{
2223 struct alc_spec *spec = codec->spec;
2224 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2225 spec->cur_adc = 0;
2226 return 0;
2227}
2228
Takashi Iwai21268962011-07-07 15:01:13 +02002229static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002230 .substreams = 1,
2231 .channels_min = 2,
2232 .channels_max = 2,
2233 .nid = 0, /* fill later */
2234 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002235 .prepare = dyn_adc_capture_pcm_prepare,
2236 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002237 },
2238};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
2240/*
2241 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002242static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 .substreams = 1,
2244 .channels_min = 2,
2245 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002246 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002248 .open = alc_playback_pcm_open,
2249 .prepare = alc_playback_pcm_prepare,
2250 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 },
2252};
2253
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002254static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002255 .substreams = 1,
2256 .channels_min = 2,
2257 .channels_max = 2,
2258 /* NID is set in alc_build_pcms */
2259};
2260
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002261static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002262 .substreams = 1,
2263 .channels_min = 2,
2264 .channels_max = 2,
2265 /* NID is set in alc_build_pcms */
2266};
2267
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002268static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002269 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 .channels_min = 2,
2271 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002272 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002274 .prepare = alc_alt_capture_pcm_prepare,
2275 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 },
2277};
2278
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002279static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 .substreams = 1,
2281 .channels_min = 2,
2282 .channels_max = 2,
2283 /* NID is set in alc_build_pcms */
2284 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002285 .open = alc_dig_playback_pcm_open,
2286 .close = alc_dig_playback_pcm_close,
2287 .prepare = alc_dig_playback_pcm_prepare,
2288 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 },
2290};
2291
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002292static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 .substreams = 1,
2294 .channels_min = 2,
2295 .channels_max = 2,
2296 /* NID is set in alc_build_pcms */
2297};
2298
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002299/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002300static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002301 .substreams = 0,
2302 .channels_min = 0,
2303 .channels_max = 0,
2304};
2305
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306static int alc_build_pcms(struct hda_codec *codec)
2307{
2308 struct alc_spec *spec = codec->spec;
2309 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002310 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002311 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 int i;
2313
2314 codec->num_pcms = 1;
2315 codec->pcm_info = info;
2316
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002317 if (spec->no_analog)
2318 goto skip_analog;
2319
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002320 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2321 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002323
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002324 if (spec->multiout.dac_nids > 0) {
2325 p = spec->stream_analog_playback;
2326 if (!p)
2327 p = &alc_pcm_analog_playback;
2328 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2330 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002331 if (spec->adc_nids) {
2332 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002333 if (!p) {
2334 if (spec->dyn_adc_switch)
2335 p = &dyn_adc_pcm_analog_capture;
2336 else
2337 p = &alc_pcm_analog_capture;
2338 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002339 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002340 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2341 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002342
Takashi Iwai4a471b72005-12-07 13:56:29 +01002343 if (spec->channel_mode) {
2344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2345 for (i = 0; i < spec->num_channel_mode; i++) {
2346 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2347 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2348 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 }
2350 }
2351
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002352 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002353 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002355 snprintf(spec->stream_name_digital,
2356 sizeof(spec->stream_name_digital),
2357 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002358 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002359 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002360 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002362 if (spec->dig_out_type)
2363 info->pcm_type = spec->dig_out_type;
2364 else
2365 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002366 if (spec->multiout.dig_out_nid) {
2367 p = spec->stream_digital_playback;
2368 if (!p)
2369 p = &alc_pcm_digital_playback;
2370 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2372 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002373 if (spec->dig_in_nid) {
2374 p = spec->stream_digital_capture;
2375 if (!p)
2376 p = &alc_pcm_digital_capture;
2377 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2379 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002380 /* FIXME: do we need this for all Realtek codec models? */
2381 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 }
2383
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002384 if (spec->no_analog)
2385 return 0;
2386
Takashi Iwaie08a0072006-09-07 17:52:14 +02002387 /* If the use of more than one ADC is requested for the current
2388 * model, configure a second analog capture-only PCM.
2389 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002390 have_multi_adcs = (spec->num_adc_nids > 1) &&
2391 !spec->dyn_adc_switch && !spec->auto_mic &&
2392 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002393 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002394 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002395 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002396 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002397 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002398 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002399 p = spec->stream_analog_alt_playback;
2400 if (!p)
2401 p = &alc_pcm_analog_alt_playback;
2402 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002403 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2404 spec->alt_dac_nid;
2405 } else {
2406 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2407 alc_pcm_null_stream;
2408 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2409 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002410 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002411 p = spec->stream_analog_alt_capture;
2412 if (!p)
2413 p = &alc_pcm_analog_alt_capture;
2414 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002415 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2416 spec->adc_nids[1];
2417 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2418 spec->num_adc_nids - 1;
2419 } else {
2420 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2421 alc_pcm_null_stream;
2422 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002423 }
2424 }
2425
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 return 0;
2427}
2428
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002429static inline void alc_shutup(struct hda_codec *codec)
2430{
Takashi Iwai1c716152011-04-07 10:37:16 +02002431 struct alc_spec *spec = codec->spec;
2432
2433 if (spec && spec->shutup)
2434 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002435 snd_hda_shutup_pins(codec);
2436}
2437
Takashi Iwai603c4012008-07-30 15:01:44 +02002438static void alc_free_kctls(struct hda_codec *codec)
2439{
2440 struct alc_spec *spec = codec->spec;
2441
2442 if (spec->kctls.list) {
2443 struct snd_kcontrol_new *kctl = spec->kctls.list;
2444 int i;
2445 for (i = 0; i < spec->kctls.used; i++)
2446 kfree(kctl[i].name);
2447 }
2448 snd_array_free(&spec->kctls);
2449}
2450
Takashi Iwai23c09b02011-08-19 09:05:35 +02002451static void alc_free_bind_ctls(struct hda_codec *codec)
2452{
2453 struct alc_spec *spec = codec->spec;
2454 if (spec->bind_ctls.list) {
2455 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2456 int i;
2457 for (i = 0; i < spec->bind_ctls.used; i++)
2458 kfree(ctl[i]);
2459 }
2460 snd_array_free(&spec->bind_ctls);
2461}
2462
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463static void alc_free(struct hda_codec *codec)
2464{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002465 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002466
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002467 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002468 return;
2469
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002470 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002471 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002472 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002473 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002474 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002475 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476}
2477
Hector Martinf5de24b2009-12-20 22:51:31 +01002478#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002479static void alc_power_eapd(struct hda_codec *codec)
2480{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002481 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002482}
2483
Hector Martinf5de24b2009-12-20 22:51:31 +01002484static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2485{
2486 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002487 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002488 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002489 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002490 return 0;
2491}
2492#endif
2493
Takashi Iwai2a439522011-07-26 09:52:50 +02002494#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002495static int alc_resume(struct hda_codec *codec)
2496{
Takashi Iwai1c716152011-04-07 10:37:16 +02002497 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002498 codec->patch_ops.init(codec);
2499 snd_hda_codec_resume_amp(codec);
2500 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002501 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002502 return 0;
2503}
Takashi Iwaie044c392008-10-27 16:56:24 +01002504#endif
2505
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506/*
2507 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002508static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509 .build_controls = alc_build_controls,
2510 .build_pcms = alc_build_pcms,
2511 .init = alc_init,
2512 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002513 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002514#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002515 .resume = alc_resume,
2516#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002517#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002518 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002519 .check_power_status = alc_check_power_status,
2520#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002521 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522};
2523
Kailang Yangc027ddc2010-03-19 11:33:06 +01002524/* replace the codec chip_name with the given string */
2525static int alc_codec_rename(struct hda_codec *codec, const char *name)
2526{
2527 kfree(codec->chip_name);
2528 codec->chip_name = kstrdup(name, GFP_KERNEL);
2529 if (!codec->chip_name) {
2530 alc_free(codec);
2531 return -ENOMEM;
2532 }
2533 return 0;
2534}
2535
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002536/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002537 * Rename codecs appropriately from COEF value
2538 */
2539struct alc_codec_rename_table {
2540 unsigned int vendor_id;
2541 unsigned short coef_mask;
2542 unsigned short coef_bits;
2543 const char *name;
2544};
2545
2546static struct alc_codec_rename_table rename_tbl[] = {
2547 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2548 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2549 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2550 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2551 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2552 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2553 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2554 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2555 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2556 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2557 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2558 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2559 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2560 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2561 { } /* terminator */
2562};
2563
2564static int alc_codec_rename_from_preset(struct hda_codec *codec)
2565{
2566 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002567
2568 for (p = rename_tbl; p->vendor_id; p++) {
2569 if (p->vendor_id != codec->vendor_id)
2570 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002571 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002572 return alc_codec_rename(codec, p->name);
2573 }
2574 return 0;
2575}
2576
2577/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002578 * Automatic parse of I/O pins from the BIOS configuration
2579 */
2580
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002581enum {
2582 ALC_CTL_WIDGET_VOL,
2583 ALC_CTL_WIDGET_MUTE,
2584 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002585 ALC_CTL_BIND_VOL,
2586 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002587};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002588static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002589 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2590 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002591 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002592 HDA_BIND_VOL(NULL, 0),
2593 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002594};
2595
2596/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002597static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002598 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002599{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002600 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002601
Takashi Iwaice764ab2011-04-27 16:35:23 +02002602 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002603 if (!knew)
2604 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002605 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002606 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002607 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002608 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002609 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002610 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002611 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002612 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002613 return 0;
2614}
2615
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002616static int add_control_with_pfx(struct alc_spec *spec, int type,
2617 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002618 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002619{
2620 char name[32];
2621 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002622 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002623}
2624
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002625#define add_pb_vol_ctrl(spec, type, pfx, val) \
2626 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2627#define add_pb_sw_ctrl(spec, type, pfx, val) \
2628 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2629#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2630 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2631#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2632 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002633
Takashi Iwai23c09b02011-08-19 09:05:35 +02002634static const char * const channel_name[4] = {
2635 "Front", "Surround", "CLFE", "Side"
2636};
2637
Takashi Iwai6843ca12011-06-24 11:03:58 +02002638static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2639 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002640{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002641 struct auto_pin_cfg *cfg = &spec->autocfg;
2642
Takashi Iwai6843ca12011-06-24 11:03:58 +02002643 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002644 if (cfg->line_outs == 1 && !spec->multi_ios &&
2645 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002646 return "Master";
2647
2648 switch (cfg->line_out_type) {
2649 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002650 if (cfg->line_outs == 1)
2651 return "Speaker";
2652 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002653 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002654 /* for multi-io case, only the primary out */
2655 if (ch && spec->multi_ios)
2656 break;
2657 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002658 return "Headphone";
2659 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002660 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002661 return "PCM";
2662 break;
2663 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002664 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2665 return "PCM";
2666
2667 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002668}
2669
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002670/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002671static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002672 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002673 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002674{
Kailang Yangdf694da2005-12-05 19:42:22 +01002675 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002676
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002677 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002678 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2679 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002680 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002681 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002682 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2683 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002684 return err;
2685 return 0;
2686}
2687
Takashi Iwai05f5f472009-08-25 13:10:18 +02002688static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002689{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002690 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2691 return (pincap & AC_PINCAP_IN) != 0;
2692}
2693
Takashi Iwai1d045db2011-07-07 18:23:21 +02002694/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002695static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002696{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002697 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002698 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002699 hda_nid_t *adc_nids = spec->private_adc_nids;
2700 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2701 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002702 int i, nums = 0;
2703
Takashi Iwai24de1832011-11-07 17:13:39 +01002704 if (spec->shared_mic_hp)
2705 max_nums = 1; /* no multi streams with the shared HP/mic */
2706
Takashi Iwaib7821702011-07-06 15:12:46 +02002707 nid = codec->start_nid;
2708 for (i = 0; i < codec->num_nodes; i++, nid++) {
2709 hda_nid_t src;
2710 const hda_nid_t *list;
2711 unsigned int caps = get_wcaps(codec, nid);
2712 int type = get_wcaps_type(caps);
2713
2714 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2715 continue;
2716 adc_nids[nums] = nid;
2717 cap_nids[nums] = nid;
2718 src = nid;
2719 for (;;) {
2720 int n;
2721 type = get_wcaps_type(get_wcaps(codec, src));
2722 if (type == AC_WID_PIN)
2723 break;
2724 if (type == AC_WID_AUD_SEL) {
2725 cap_nids[nums] = src;
2726 break;
2727 }
2728 n = snd_hda_get_conn_list(codec, src, &list);
2729 if (n > 1) {
2730 cap_nids[nums] = src;
2731 break;
2732 } else if (n != 1)
2733 break;
2734 src = *list;
2735 }
2736 if (++nums >= max_nums)
2737 break;
2738 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002739 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002740 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002741 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002742 return nums;
2743}
2744
Takashi Iwai05f5f472009-08-25 13:10:18 +02002745/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002746static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002747{
2748 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002749 const struct auto_pin_cfg *cfg = &spec->autocfg;
2750 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002751 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002752 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002753 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002754 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002755
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002756 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002757 if (num_adcs < 0)
2758 return 0;
2759
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002760 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002761 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002762 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002763
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002764 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002765 if (!alc_is_input_pin(codec, pin))
2766 continue;
2767
David Henningsson5322bf22011-01-05 11:03:56 +01002768 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002769 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2770 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002771 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002772 type_idx++;
2773 else
2774 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002775 prev_label = label;
2776
Takashi Iwai05f5f472009-08-25 13:10:18 +02002777 if (mixer) {
2778 idx = get_connection_index(codec, mixer, pin);
2779 if (idx >= 0) {
2780 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002781 label, type_idx,
2782 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002783 if (err < 0)
2784 return err;
2785 }
2786 }
2787
Takashi Iwaib7821702011-07-06 15:12:46 +02002788 for (c = 0; c < num_adcs; c++) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002789 hda_nid_t cap = spec->capsrc_nids ?
2790 spec->capsrc_nids[c] : spec->adc_nids[c];
2791 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002792 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002793 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002794 snd_hda_add_imux_item(imux, label, idx, NULL);
2795 break;
2796 }
2797 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002798 }
Takashi Iwai21268962011-07-07 15:01:13 +02002799
2800 spec->num_mux_defs = 1;
2801 spec->input_mux = imux;
2802
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002803 return 0;
2804}
2805
Takashi Iwai24de1832011-11-07 17:13:39 +01002806/* create a shared input with the headphone out */
2807static int alc_auto_create_shared_input(struct hda_codec *codec)
2808{
2809 struct alc_spec *spec = codec->spec;
2810 struct auto_pin_cfg *cfg = &spec->autocfg;
2811 unsigned int defcfg;
2812 hda_nid_t nid;
2813
2814 /* only one internal input pin? */
2815 if (cfg->num_inputs != 1)
2816 return 0;
2817 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2818 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2819 return 0;
2820
2821 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2822 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2823 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2824 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2825 else
2826 return 0; /* both not available */
2827
2828 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2829 return 0; /* no input */
2830
2831 cfg->inputs[1].pin = nid;
2832 cfg->inputs[1].type = AUTO_PIN_MIC;
2833 cfg->num_inputs = 2;
2834 spec->shared_mic_hp = 1;
2835 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2836 return 0;
2837}
2838
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002839static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2840 unsigned int pin_type)
2841{
2842 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2843 pin_type);
2844 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002845 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2846 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002847 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002848}
2849
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002850static int get_pin_type(int line_out_type)
2851{
2852 if (line_out_type == AUTO_PIN_HP_OUT)
2853 return PIN_HP;
2854 else
2855 return PIN_OUT;
2856}
2857
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002858static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002859{
2860 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002861 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002862 int i;
2863
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002864 for (i = 0; i < cfg->num_inputs; i++) {
2865 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002866 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002867 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002868 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002869 snd_hda_codec_write(codec, nid, 0,
2870 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002871 AMP_OUT_MUTE);
2872 }
2873 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002874
2875 /* mute all loopback inputs */
2876 if (spec->mixer_nid) {
2877 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2878 for (i = 0; i < nums; i++)
2879 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2880 AC_VERB_SET_AMP_GAIN_MUTE,
2881 AMP_IN_MUTE(i));
2882 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002883}
2884
Takashi Iwai7085ec12009-10-02 09:03:58 +02002885/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002886static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002887{
Takashi Iwai604401a2011-04-27 15:14:23 +02002888 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002889 int i, num;
2890
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002891 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2892 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002893 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2894 for (i = 0; i < num; i++) {
2895 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2896 return list[i];
2897 }
2898 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002899}
2900
Takashi Iwai604401a2011-04-27 15:14:23 +02002901/* go down to the selector widget before the mixer */
2902static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2903{
2904 hda_nid_t srcs[5];
2905 int num = snd_hda_get_connections(codec, pin, srcs,
2906 ARRAY_SIZE(srcs));
2907 if (num != 1 ||
2908 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2909 return pin;
2910 return srcs[0];
2911}
2912
Takashi Iwai7085ec12009-10-02 09:03:58 +02002913/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002914static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002915 hda_nid_t dac)
2916{
David Henningssoncc1c4522010-11-24 14:17:47 +01002917 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002918 int i, num;
2919
Takashi Iwai604401a2011-04-27 15:14:23 +02002920 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002921 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2922 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002923 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002924 return mix[i];
2925 }
2926 return 0;
2927}
2928
Takashi Iwaice764ab2011-04-27 16:35:23 +02002929/* select the connection from pin to DAC if needed */
2930static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2931 hda_nid_t dac)
2932{
2933 hda_nid_t mix[5];
2934 int i, num;
2935
2936 pin = alc_go_down_to_selector(codec, pin);
2937 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2938 if (num < 2)
2939 return 0;
2940 for (i = 0; i < num; i++) {
2941 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2942 snd_hda_codec_update_cache(codec, pin, 0,
2943 AC_VERB_SET_CONNECT_SEL, i);
2944 return 0;
2945 }
2946 }
2947 return 0;
2948}
2949
Takashi Iwai7085ec12009-10-02 09:03:58 +02002950/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002951static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002952{
2953 struct alc_spec *spec = codec->spec;
2954 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002955 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002956
Takashi Iwai604401a2011-04-27 15:14:23 +02002957 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002958 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002959 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002960 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002961 if (!nid)
2962 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002963 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2964 spec->multiout.num_dacs))
2965 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002966 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2967 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2968 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002969 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2970 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2971 continue;
2972 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002973 }
2974 return 0;
2975}
2976
Takashi Iwai07b18f62011-11-10 15:42:54 +01002977/* check whether the DAC is reachable from the pin */
2978static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2979 hda_nid_t pin, hda_nid_t dac)
2980{
2981 hda_nid_t srcs[5];
2982 int i, num;
2983
2984 pin = alc_go_down_to_selector(codec, pin);
2985 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2986 for (i = 0; i < num; i++) {
2987 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2988 if (nid == dac)
2989 return true;
2990 }
2991 return false;
2992}
2993
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002994static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2995{
2996 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2997 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2998 return alc_auto_look_for_dac(codec, pin);
2999 return 0;
3000}
3001
Takashi Iwaic2674682011-08-24 17:57:44 +02003002static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3003 const hda_nid_t *pins, hda_nid_t *dacs)
3004{
3005 int i;
3006
3007 if (num_outs && !dacs[0]) {
3008 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3009 if (!dacs[0])
3010 return 0;
3011 }
3012
3013 for (i = 1; i < num_outs; i++)
3014 dacs[i] = get_dac_if_single(codec, pins[i]);
3015 for (i = 1; i < num_outs; i++) {
3016 if (!dacs[i])
3017 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3018 }
3019 return 0;
3020}
3021
3022static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003023 unsigned int location, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003024
Takashi Iwai7085ec12009-10-02 09:03:58 +02003025/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003026static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003027{
3028 struct alc_spec *spec = codec->spec;
Takashi Iwaicb053a82011-06-27 11:32:07 +02003029 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003030 unsigned int location, defcfg;
3031 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003032 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003033 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003034
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003035 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003036 /* set num_dacs once to full for alc_auto_look_for_dac() */
3037 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003038 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003039 spec->multiout.extra_out_nid[0] = 0;
3040 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3041 spec->multiout.dac_nids = spec->private_dac_nids;
3042
3043 /* fill hard-wired DACs first */
3044 if (!redone) {
3045 for (i = 0; i < cfg->line_outs; i++)
3046 spec->private_dac_nids[i] =
3047 get_dac_if_single(codec, cfg->line_out_pins[i]);
3048 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003049 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003050 get_dac_if_single(codec, cfg->hp_pins[0]);
3051 if (cfg->speaker_outs)
3052 spec->multiout.extra_out_nid[0] =
3053 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003054 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003055
3056 for (i = 0; i < cfg->line_outs; i++) {
3057 hda_nid_t pin = cfg->line_out_pins[i];
3058 if (spec->private_dac_nids[i])
3059 continue;
3060 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3061 if (!spec->private_dac_nids[i] && !redone) {
3062 /* if we can't find primary DACs, re-probe without
3063 * checking the hard-wired DACs
3064 */
3065 redone = true;
3066 goto again;
3067 }
3068 }
3069
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003070 /* re-count num_dacs and squash invalid entries */
3071 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003072 for (i = 0; i < cfg->line_outs; i++) {
3073 if (spec->private_dac_nids[i])
3074 spec->multiout.num_dacs++;
3075 else
3076 memmove(spec->private_dac_nids + i,
3077 spec->private_dac_nids + i + 1,
3078 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3079 }
3080
Takashi Iwaic2674682011-08-24 17:57:44 +02003081 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3082 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003083 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3084 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003085
Takashi Iwai07b18f62011-11-10 15:42:54 +01003086 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003087 if (num_pins > 0) {
3088 spec->multi_ios = num_pins;
3089 spec->ext_channel_count = 2;
3090 spec->multiout.num_dacs = num_pins + 1;
3091 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003092 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003093
Takashi Iwai716eef02011-10-21 15:07:42 +02003094 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3095 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003096 spec->multiout.hp_out_nid);
Takashi Iwai716eef02011-10-21 15:07:42 +02003097 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3098 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003099 spec->multiout.extra_out_nid);
3100
Takashi Iwai07b18f62011-11-10 15:42:54 +01003101 if (!spec->multi_ios &&
3102 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3103 cfg->hp_outs) {
3104 /* try multi-ios with HP + inputs */
3105 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3106 location = get_defcfg_location(defcfg);
3107
3108 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3109 if (num_pins > 0) {
3110 spec->multi_ios = num_pins;
3111 spec->ext_channel_count = 2;
3112 spec->multiout.num_dacs = num_pins + 1;
3113 }
3114 }
3115
Takashi Iwai23c09b02011-08-19 09:05:35 +02003116 return 0;
3117}
3118
Takashi Iwai527e4d72011-10-27 16:33:27 +02003119static inline unsigned int get_ctl_pos(unsigned int data)
3120{
3121 hda_nid_t nid = get_amp_nid_(data);
3122 unsigned int dir = get_amp_direction_(data);
3123 return (nid << 1) | dir;
3124}
3125
3126#define is_ctl_used(bits, data) \
3127 test_bit(get_ctl_pos(data), bits)
3128#define mark_ctl_usage(bits, data) \
3129 set_bit(get_ctl_pos(data), bits)
3130
Takashi Iwai343a04b2011-07-06 14:28:39 +02003131static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003132 const char *pfx, int cidx,
3133 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003134{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003135 struct alc_spec *spec = codec->spec;
3136 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003137 if (!nid)
3138 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003139 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3140 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3141 return 0;
3142 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003143 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003144 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003145}
3146
Takashi Iwai343a04b2011-07-06 14:28:39 +02003147#define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
3148 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai97aaab72011-07-06 14:02:55 +02003149
3150/* create a mute-switch for the given mixer widget;
3151 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3152 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003153static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003154 const char *pfx, int cidx,
3155 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003156{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003157 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003158 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003159 int type;
3160 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003161 if (!nid)
3162 return 0;
3163 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3164 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3165 type = ALC_CTL_WIDGET_MUTE;
3166 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3167 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003168 type = ALC_CTL_WIDGET_MUTE;
3169 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3170 } else {
3171 type = ALC_CTL_BIND_MUTE;
3172 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3173 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003174 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3175 return 0;
3176 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003177 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003178}
3179
Takashi Iwai343a04b2011-07-06 14:28:39 +02003180#define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
3181 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003182
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003183static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3184 hda_nid_t pin, hda_nid_t dac)
3185{
3186 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3187 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3188 return pin;
3189 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3190 return mix;
3191 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3192 return dac;
3193 return 0;
3194}
3195
3196static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3197 hda_nid_t pin, hda_nid_t dac)
3198{
3199 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3200 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3201 return dac;
3202 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3203 return mix;
3204 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3205 return pin;
3206 return 0;
3207}
3208
Takashi Iwai7085ec12009-10-02 09:03:58 +02003209/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003210static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003211 const struct auto_pin_cfg *cfg)
3212{
3213 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003214 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003215
Takashi Iwaice764ab2011-04-27 16:35:23 +02003216 noutputs = cfg->line_outs;
3217 if (spec->multi_ios > 0)
3218 noutputs += spec->multi_ios;
3219
3220 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003221 const char *name;
3222 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003223 hda_nid_t dac, pin;
3224 hda_nid_t sw, vol;
3225
3226 dac = spec->multiout.dac_nids[i];
3227 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003228 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003229 if (i >= cfg->line_outs)
3230 pin = spec->multi_io[i - 1].pin;
3231 else
3232 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003233
3234 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3235 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003236 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003237 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003238 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003239 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003240 if (err < 0)
3241 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003242 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003243 if (err < 0)
3244 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003245 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003246 if (err < 0)
3247 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003248 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003249 if (err < 0)
3250 return err;
3251 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003252 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003253 if (err < 0)
3254 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003255 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003256 if (err < 0)
3257 return err;
3258 }
3259 }
3260 return 0;
3261}
3262
Takashi Iwai343a04b2011-07-06 14:28:39 +02003263static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai23c09b02011-08-19 09:05:35 +02003264 hda_nid_t dac, const char *pfx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003265{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003266 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003267 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003268 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003269
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003270 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003271 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003272 /* the corresponding DAC is already occupied */
3273 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3274 return 0; /* no way */
3275 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003276 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3277 if (is_ctl_used(spec->sw_ctls, val))
3278 return 0; /* already created */
3279 mark_ctl_usage(spec->sw_ctls, val);
3280 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003281 }
3282
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003283 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3284 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3285 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003286 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003287 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003288 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003289 if (err < 0)
3290 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003291 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003292}
3293
Takashi Iwai23c09b02011-08-19 09:05:35 +02003294static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3295 unsigned int nums,
3296 struct hda_ctl_ops *ops)
3297{
3298 struct alc_spec *spec = codec->spec;
3299 struct hda_bind_ctls **ctlp, *ctl;
3300 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3301 ctlp = snd_array_new(&spec->bind_ctls);
3302 if (!ctlp)
3303 return NULL;
3304 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3305 *ctlp = ctl;
3306 if (ctl)
3307 ctl->ops = ops;
3308 return ctl;
3309}
3310
3311/* add playback controls for speaker and HP outputs */
3312static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3313 const hda_nid_t *pins,
3314 const hda_nid_t *dacs,
3315 const char *pfx)
3316{
3317 struct alc_spec *spec = codec->spec;
3318 struct hda_bind_ctls *ctl;
3319 char name[32];
3320 int i, n, err;
3321
3322 if (!num_pins || !pins[0])
3323 return 0;
3324
Takashi Iwai527e4d72011-10-27 16:33:27 +02003325 if (num_pins == 1) {
3326 hda_nid_t dac = *dacs;
3327 if (!dac)
3328 dac = spec->multiout.dac_nids[0];
3329 return alc_auto_create_extra_out(codec, *pins, dac, pfx);
3330 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003331
3332 if (dacs[num_pins - 1]) {
3333 /* OK, we have a multi-output system with individual volumes */
3334 for (i = 0; i < num_pins; i++) {
3335 snprintf(name, sizeof(name), "%s %s",
3336 pfx, channel_name[i]);
3337 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3338 name);
3339 if (err < 0)
3340 return err;
3341 }
3342 return 0;
3343 }
3344
3345 /* Let's create a bind-controls */
3346 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3347 if (!ctl)
3348 return -ENOMEM;
3349 n = 0;
3350 for (i = 0; i < num_pins; i++) {
3351 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3352 ctl->values[n++] =
3353 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3354 }
3355 if (n) {
3356 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3357 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3358 if (err < 0)
3359 return err;
3360 }
3361
3362 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3363 if (!ctl)
3364 return -ENOMEM;
3365 n = 0;
3366 for (i = 0; i < num_pins; i++) {
3367 hda_nid_t vol;
3368 if (!pins[i] || !dacs[i])
3369 continue;
3370 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3371 if (vol)
3372 ctl->values[n++] =
3373 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3374 }
3375 if (n) {
3376 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3377 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3378 if (err < 0)
3379 return err;
3380 }
3381 return 0;
3382}
3383
Takashi Iwai343a04b2011-07-06 14:28:39 +02003384static int alc_auto_create_hp_out(struct hda_codec *codec)
3385{
3386 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003387 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3388 spec->autocfg.hp_pins,
3389 spec->multiout.hp_out_nid,
3390 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003391}
3392
3393static int alc_auto_create_speaker_out(struct hda_codec *codec)
3394{
3395 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003396 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3397 spec->autocfg.speaker_pins,
3398 spec->multiout.extra_out_nid,
3399 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003400}
3401
Takashi Iwai343a04b2011-07-06 14:28:39 +02003402static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003403 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003404 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003405{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003406 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003407 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003408 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003409
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003410 alc_set_pin_output(codec, pin, pin_type);
3411 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003412 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003413 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003414 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003415 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003416 mix = srcs[i];
3417 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003418 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003419 if (!mix)
3420 return;
3421
3422 /* need the manual connection? */
3423 if (num > 1)
3424 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3425 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003426 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3427 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003428 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003429 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003430 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003431 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003432 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003433 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3434 if (nid)
3435 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3436 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003437
3438 /* unmute DAC if it's not assigned to a mixer */
3439 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3440 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3441 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3442 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003443}
3444
Takashi Iwai343a04b2011-07-06 14:28:39 +02003445static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003446{
3447 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003448 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003449 int i;
3450
3451 for (i = 0; i <= HDA_SIDE; i++) {
3452 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3453 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003454 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003455 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003456 }
3457}
3458
Takashi Iwai343a04b2011-07-06 14:28:39 +02003459static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003460{
3461 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003462 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003463 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003464
David Henningsson636030e2011-10-12 19:26:03 +02003465 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003466 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3467 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003468 pin = spec->autocfg.hp_pins[i];
3469 if (!pin)
3470 break;
3471 dac = spec->multiout.hp_out_nid[i];
3472 if (!dac) {
3473 if (i > 0 && spec->multiout.hp_out_nid[0])
3474 dac = spec->multiout.hp_out_nid[0];
3475 else
3476 dac = spec->multiout.dac_nids[0];
3477 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003478 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3479 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003480 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003481 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3482 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003483 pin = spec->autocfg.speaker_pins[i];
3484 if (!pin)
3485 break;
3486 dac = spec->multiout.extra_out_nid[i];
3487 if (!dac) {
3488 if (i > 0 && spec->multiout.extra_out_nid[0])
3489 dac = spec->multiout.extra_out_nid[0];
3490 else
3491 dac = spec->multiout.dac_nids[0];
3492 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003493 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3494 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003495}
3496
Takashi Iwaice764ab2011-04-27 16:35:23 +02003497/*
3498 * multi-io helper
3499 */
3500static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003501 unsigned int location,
3502 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003503{
3504 struct alc_spec *spec = codec->spec;
3505 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003506 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003507 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003508
Takashi Iwai07b18f62011-11-10 15:42:54 +01003509 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003510 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3511 for (i = 0; i < cfg->num_inputs; i++) {
3512 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003513 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003514 unsigned int defcfg, caps;
3515 if (cfg->inputs[i].type != type)
3516 continue;
3517 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3518 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3519 continue;
3520 if (location && get_defcfg_location(defcfg) != location)
3521 continue;
3522 caps = snd_hda_query_pin_caps(codec, nid);
3523 if (!(caps & AC_PINCAP_OUT))
3524 continue;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003525 if (offset && offset + num_pins < dacs) {
3526 dac = spec->private_dac_nids[offset + num_pins];
3527 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3528 dac = 0;
3529 }
3530 if (!dac)
3531 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003532 if (!dac)
3533 continue;
3534 spec->multi_io[num_pins].pin = nid;
3535 spec->multi_io[num_pins].dac = dac;
3536 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003537 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003538 }
3539 }
Takashi Iwai07b18f62011-11-10 15:42:54 +01003540 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003541 if (num_pins < 2) {
3542 /* clear up again */
Takashi Iwai07b18f62011-11-10 15:42:54 +01003543 memset(spec->private_dac_nids + dacs, 0,
3544 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003545 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003546 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003547 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003548 return num_pins;
3549}
3550
3551static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3552 struct snd_ctl_elem_info *uinfo)
3553{
3554 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3555 struct alc_spec *spec = codec->spec;
3556
3557 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3558 uinfo->count = 1;
3559 uinfo->value.enumerated.items = spec->multi_ios + 1;
3560 if (uinfo->value.enumerated.item > spec->multi_ios)
3561 uinfo->value.enumerated.item = spec->multi_ios;
3562 sprintf(uinfo->value.enumerated.name, "%dch",
3563 (uinfo->value.enumerated.item + 1) * 2);
3564 return 0;
3565}
3566
3567static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3568 struct snd_ctl_elem_value *ucontrol)
3569{
3570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3571 struct alc_spec *spec = codec->spec;
3572 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3573 return 0;
3574}
3575
3576static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3577{
3578 struct alc_spec *spec = codec->spec;
3579 hda_nid_t nid = spec->multi_io[idx].pin;
3580
3581 if (!spec->multi_io[idx].ctl_in)
3582 spec->multi_io[idx].ctl_in =
3583 snd_hda_codec_read(codec, nid, 0,
3584 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3585 if (output) {
3586 snd_hda_codec_update_cache(codec, nid, 0,
3587 AC_VERB_SET_PIN_WIDGET_CONTROL,
3588 PIN_OUT);
3589 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3590 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3591 HDA_AMP_MUTE, 0);
3592 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3593 } else {
3594 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3595 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3596 HDA_AMP_MUTE, HDA_AMP_MUTE);
3597 snd_hda_codec_update_cache(codec, nid, 0,
3598 AC_VERB_SET_PIN_WIDGET_CONTROL,
3599 spec->multi_io[idx].ctl_in);
3600 }
3601 return 0;
3602}
3603
3604static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3605 struct snd_ctl_elem_value *ucontrol)
3606{
3607 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3608 struct alc_spec *spec = codec->spec;
3609 int i, ch;
3610
3611 ch = ucontrol->value.enumerated.item[0];
3612 if (ch < 0 || ch > spec->multi_ios)
3613 return -EINVAL;
3614 if (ch == (spec->ext_channel_count - 1) / 2)
3615 return 0;
3616 spec->ext_channel_count = (ch + 1) * 2;
3617 for (i = 0; i < spec->multi_ios; i++)
3618 alc_set_multi_io(codec, i, i < ch);
3619 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003620 if (spec->need_dac_fix && !spec->const_channel_count)
3621 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003622 return 1;
3623}
3624
Takashi Iwaia9111322011-05-02 11:30:18 +02003625static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003626 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3627 .name = "Channel Mode",
3628 .info = alc_auto_ch_mode_info,
3629 .get = alc_auto_ch_mode_get,
3630 .put = alc_auto_ch_mode_put,
3631};
3632
Takashi Iwai23c09b02011-08-19 09:05:35 +02003633static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003634{
3635 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003636
Takashi Iwaic2674682011-08-24 17:57:44 +02003637 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003638 struct snd_kcontrol_new *knew;
3639
3640 knew = alc_kcontrol_new(spec);
3641 if (!knew)
3642 return -ENOMEM;
3643 *knew = alc_auto_channel_mode_enum;
3644 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3645 if (!knew->name)
3646 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003647 }
3648 return 0;
3649}
3650
Takashi Iwai1d045db2011-07-07 18:23:21 +02003651/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3652 * active input pins
3653 */
3654static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3655{
3656 struct alc_spec *spec = codec->spec;
3657 const struct hda_input_mux *imux;
3658 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3659 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3660 int i, n, nums;
3661
3662 imux = spec->input_mux;
3663 if (!imux)
3664 return;
3665 if (spec->dyn_adc_switch)
3666 return;
3667
3668 nums = 0;
3669 for (n = 0; n < spec->num_adc_nids; n++) {
3670 hda_nid_t cap = spec->private_capsrc_nids[n];
3671 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3672 for (i = 0; i < imux->num_items; i++) {
3673 hda_nid_t pin = spec->imux_pins[i];
3674 if (pin) {
3675 if (get_connection_index(codec, cap, pin) < 0)
3676 break;
3677 } else if (num_conns <= imux->items[i].index)
3678 break;
3679 }
3680 if (i >= imux->num_items) {
3681 adc_nids[nums] = spec->private_adc_nids[n];
3682 capsrc_nids[nums++] = cap;
3683 }
3684 }
3685 if (!nums) {
3686 /* check whether ADC-switch is possible */
3687 if (!alc_check_dyn_adc_switch(codec)) {
3688 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3689 " using fallback 0x%x\n",
3690 codec->chip_name, spec->private_adc_nids[0]);
3691 spec->num_adc_nids = 1;
3692 spec->auto_mic = 0;
3693 return;
3694 }
3695 } else if (nums != spec->num_adc_nids) {
3696 memcpy(spec->private_adc_nids, adc_nids,
3697 nums * sizeof(hda_nid_t));
3698 memcpy(spec->private_capsrc_nids, capsrc_nids,
3699 nums * sizeof(hda_nid_t));
3700 spec->num_adc_nids = nums;
3701 }
3702
3703 if (spec->auto_mic)
3704 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3705 else if (spec->input_mux->num_items == 1)
3706 spec->num_adc_nids = 1; /* reduce to a single ADC */
3707}
3708
3709/*
3710 * initialize ADC paths
3711 */
3712static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3713{
3714 struct alc_spec *spec = codec->spec;
3715 hda_nid_t nid;
3716
3717 nid = spec->adc_nids[adc_idx];
3718 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003719 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003720 snd_hda_codec_write(codec, nid, 0,
3721 AC_VERB_SET_AMP_GAIN_MUTE,
3722 AMP_IN_MUTE(0));
3723 return;
3724 }
3725 if (!spec->capsrc_nids)
3726 return;
3727 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003728 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003729 snd_hda_codec_write(codec, nid, 0,
3730 AC_VERB_SET_AMP_GAIN_MUTE,
3731 AMP_OUT_MUTE);
3732}
3733
3734static void alc_auto_init_input_src(struct hda_codec *codec)
3735{
3736 struct alc_spec *spec = codec->spec;
3737 int c, nums;
3738
3739 for (c = 0; c < spec->num_adc_nids; c++)
3740 alc_auto_init_adc(codec, c);
3741 if (spec->dyn_adc_switch)
3742 nums = 1;
3743 else
3744 nums = spec->num_adc_nids;
3745 for (c = 0; c < nums; c++)
3746 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3747}
3748
3749/* add mic boosts if needed */
3750static int alc_auto_add_mic_boost(struct hda_codec *codec)
3751{
3752 struct alc_spec *spec = codec->spec;
3753 struct auto_pin_cfg *cfg = &spec->autocfg;
3754 int i, err;
3755 int type_idx = 0;
3756 hda_nid_t nid;
3757 const char *prev_label = NULL;
3758
3759 for (i = 0; i < cfg->num_inputs; i++) {
3760 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3761 break;
3762 nid = cfg->inputs[i].pin;
3763 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3764 const char *label;
3765 char boost_label[32];
3766
3767 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003768 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3769 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003770 if (prev_label && !strcmp(label, prev_label))
3771 type_idx++;
3772 else
3773 type_idx = 0;
3774 prev_label = label;
3775
3776 snprintf(boost_label, sizeof(boost_label),
3777 "%s Boost Volume", label);
3778 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3779 boost_label, type_idx,
3780 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3781 if (err < 0)
3782 return err;
3783 }
3784 }
3785 return 0;
3786}
3787
3788/* select or unmute the given capsrc route */
3789static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3790 int idx)
3791{
3792 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3793 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3794 HDA_AMP_MUTE, 0);
3795 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3796 snd_hda_codec_write_cache(codec, cap, 0,
3797 AC_VERB_SET_CONNECT_SEL, idx);
3798 }
3799}
3800
3801/* set the default connection to that pin */
3802static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3803{
3804 struct alc_spec *spec = codec->spec;
3805 int i;
3806
3807 if (!pin)
3808 return 0;
3809 for (i = 0; i < spec->num_adc_nids; i++) {
3810 hda_nid_t cap = spec->capsrc_nids ?
3811 spec->capsrc_nids[i] : spec->adc_nids[i];
3812 int idx;
3813
3814 idx = get_connection_index(codec, cap, pin);
3815 if (idx < 0)
3816 continue;
3817 select_or_unmute_capsrc(codec, cap, idx);
3818 return i; /* return the found index */
3819 }
3820 return -1; /* not found */
3821}
3822
3823/* initialize some special cases for input sources */
3824static void alc_init_special_input_src(struct hda_codec *codec)
3825{
3826 struct alc_spec *spec = codec->spec;
3827 int i;
3828
3829 for (i = 0; i < spec->autocfg.num_inputs; i++)
3830 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3831}
3832
3833/* assign appropriate capture mixers */
3834static void set_capture_mixer(struct hda_codec *codec)
3835{
3836 struct alc_spec *spec = codec->spec;
3837 static const struct snd_kcontrol_new *caps[2][3] = {
3838 { alc_capture_mixer_nosrc1,
3839 alc_capture_mixer_nosrc2,
3840 alc_capture_mixer_nosrc3 },
3841 { alc_capture_mixer1,
3842 alc_capture_mixer2,
3843 alc_capture_mixer3 },
3844 };
3845
3846 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003847 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003848 if (!spec->capsrc_nids)
3849 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003850 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003851 return; /* no volume in capsrc, too */
3852 spec->vol_in_capsrc = 1;
3853 }
3854
3855 if (spec->num_adc_nids > 0) {
3856 int mux = 0;
3857 int num_adcs = 0;
3858
3859 if (spec->input_mux && spec->input_mux->num_items > 1)
3860 mux = 1;
3861 if (spec->auto_mic) {
3862 num_adcs = 1;
3863 mux = 0;
3864 } else if (spec->dyn_adc_switch)
3865 num_adcs = 1;
3866 if (!num_adcs) {
3867 if (spec->num_adc_nids > 3)
3868 spec->num_adc_nids = 3;
3869 else if (!spec->num_adc_nids)
3870 return;
3871 num_adcs = spec->num_adc_nids;
3872 }
3873 spec->cap_mixer = caps[mux][num_adcs - 1];
3874 }
3875}
3876
3877/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003878 * standard auto-parser initializations
3879 */
3880static void alc_auto_init_std(struct hda_codec *codec)
3881{
3882 struct alc_spec *spec = codec->spec;
3883 alc_auto_init_multi_out(codec);
3884 alc_auto_init_extra_out(codec);
3885 alc_auto_init_analog_input(codec);
3886 alc_auto_init_input_src(codec);
3887 alc_auto_init_digital(codec);
3888 if (spec->unsol_event)
3889 alc_inithook(codec);
3890}
3891
3892/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003893 * Digital-beep handlers
3894 */
3895#ifdef CONFIG_SND_HDA_INPUT_BEEP
3896#define set_beep_amp(spec, nid, idx, dir) \
3897 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3898
3899static const struct snd_pci_quirk beep_white_list[] = {
3900 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3901 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3902 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3903 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3904 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3905 {}
3906};
3907
3908static inline int has_cdefine_beep(struct hda_codec *codec)
3909{
3910 struct alc_spec *spec = codec->spec;
3911 const struct snd_pci_quirk *q;
3912 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3913 if (q)
3914 return q->value;
3915 return spec->cdefine.enable_pcbeep;
3916}
3917#else
3918#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3919#define has_cdefine_beep(codec) 0
3920#endif
3921
3922/* parse the BIOS configuration and set up the alc_spec */
3923/* return 1 if successful, 0 if the proper config is not found,
3924 * or a negative error code
3925 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003926static int alc_parse_auto_config(struct hda_codec *codec,
3927 const hda_nid_t *ignore_nids,
3928 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003929{
3930 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003931 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003932 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003933
Takashi Iwai53c334a2011-08-23 18:27:14 +02003934 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3935 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003936 if (err < 0)
3937 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003938 if (!cfg->line_outs) {
3939 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003940 spec->multiout.max_channels = 2;
3941 spec->no_analog = 1;
3942 goto dig_only;
3943 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003944 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003945 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003946
Takashi Iwai06503672011-10-06 08:27:19 +02003947 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3948 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003949 /* use HP as primary out */
3950 cfg->speaker_outs = cfg->line_outs;
3951 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3952 sizeof(cfg->speaker_pins));
3953 cfg->line_outs = cfg->hp_outs;
3954 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3955 cfg->hp_outs = 0;
3956 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3957 cfg->line_out_type = AUTO_PIN_HP_OUT;
3958 }
3959
Takashi Iwai1d045db2011-07-07 18:23:21 +02003960 err = alc_auto_fill_dac_nids(codec);
3961 if (err < 0)
3962 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003963 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003964 if (err < 0)
3965 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003966 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003967 if (err < 0)
3968 return err;
3969 err = alc_auto_create_hp_out(codec);
3970 if (err < 0)
3971 return err;
3972 err = alc_auto_create_speaker_out(codec);
3973 if (err < 0)
3974 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01003975 err = alc_auto_create_shared_input(codec);
3976 if (err < 0)
3977 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003978 err = alc_auto_create_input_ctls(codec);
3979 if (err < 0)
3980 return err;
3981
3982 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3983
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003984 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02003985 alc_auto_parse_digital(codec);
3986
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003987 if (!spec->no_analog)
3988 alc_remove_invalid_adc_nids(codec);
3989
3990 if (ssid_nids)
3991 alc_ssid_check(codec, ssid_nids);
3992
3993 if (!spec->no_analog) {
3994 alc_auto_check_switches(codec);
3995 err = alc_auto_add_mic_boost(codec);
3996 if (err < 0)
3997 return err;
3998 }
3999
Takashi Iwai1d045db2011-07-07 18:23:21 +02004000 if (spec->kctls.list)
4001 add_mixer(spec, spec->kctls.list);
4002
Takashi Iwai1d045db2011-07-07 18:23:21 +02004003 return 1;
4004}
4005
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004006static int alc880_parse_auto_config(struct hda_codec *codec)
4007{
4008 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4009 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4010 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4011}
4012
Takashi Iwai1d045db2011-07-07 18:23:21 +02004013#ifdef CONFIG_SND_HDA_POWER_SAVE
4014static const struct hda_amp_list alc880_loopbacks[] = {
4015 { 0x0b, HDA_INPUT, 0 },
4016 { 0x0b, HDA_INPUT, 1 },
4017 { 0x0b, HDA_INPUT, 2 },
4018 { 0x0b, HDA_INPUT, 3 },
4019 { 0x0b, HDA_INPUT, 4 },
4020 { } /* end */
4021};
4022#endif
4023
4024/*
4025 * board setups
4026 */
4027#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4028#define alc_board_config \
4029 snd_hda_check_board_config
4030#define alc_board_codec_sid_config \
4031 snd_hda_check_board_codec_sid_config
4032#include "alc_quirks.c"
4033#else
4034#define alc_board_config(codec, nums, models, tbl) -1
4035#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4036#define setup_preset(codec, x) /* NOP */
4037#endif
4038
4039/*
4040 * OK, here we have finally the patch for ALC880
4041 */
4042#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4043#include "alc880_quirks.c"
4044#endif
4045
4046static int patch_alc880(struct hda_codec *codec)
4047{
4048 struct alc_spec *spec;
4049 int board_config;
4050 int err;
4051
4052 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4053 if (spec == NULL)
4054 return -ENOMEM;
4055
4056 codec->spec = spec;
4057
4058 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004059 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004060
4061 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4062 alc880_models, alc880_cfg_tbl);
4063 if (board_config < 0) {
4064 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4065 codec->chip_name);
4066 board_config = ALC_MODEL_AUTO;
4067 }
4068
4069 if (board_config == ALC_MODEL_AUTO) {
4070 /* automatic parse from the BIOS config */
4071 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004072 if (err < 0)
4073 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004074#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4075 else if (!err) {
4076 printk(KERN_INFO
4077 "hda_codec: Cannot set up configuration "
4078 "from BIOS. Using 3-stack mode...\n");
4079 board_config = ALC880_3ST;
4080 }
4081#endif
4082 }
4083
Takashi Iwai1d045db2011-07-07 18:23:21 +02004084 if (board_config != ALC_MODEL_AUTO)
4085 setup_preset(codec, &alc880_presets[board_config]);
4086
Takashi Iwai60a6a842011-07-27 14:01:24 +02004087 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004088 alc_auto_fill_adc_caps(codec);
4089 alc_rebuild_imux_for_auto_mic(codec);
4090 alc_remove_invalid_adc_nids(codec);
4091 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004092
4093 if (!spec->no_analog && !spec->cap_mixer)
4094 set_capture_mixer(codec);
4095
4096 if (!spec->no_analog) {
4097 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004098 if (err < 0)
4099 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004100 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4101 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004102
4103 spec->vmaster_nid = 0x0c;
4104
4105 codec->patch_ops = alc_patch_ops;
4106 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004107 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004108#ifdef CONFIG_SND_HDA_POWER_SAVE
4109 if (!spec->loopback.amplist)
4110 spec->loopback.amplist = alc880_loopbacks;
4111#endif
4112
4113 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004114
4115 error:
4116 alc_free(codec);
4117 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004118}
4119
4120
4121/*
4122 * ALC260 support
4123 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004124static int alc260_parse_auto_config(struct hda_codec *codec)
4125{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004126 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004127 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4128 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004129}
4130
Takashi Iwai1d045db2011-07-07 18:23:21 +02004131#ifdef CONFIG_SND_HDA_POWER_SAVE
4132static const struct hda_amp_list alc260_loopbacks[] = {
4133 { 0x07, HDA_INPUT, 0 },
4134 { 0x07, HDA_INPUT, 1 },
4135 { 0x07, HDA_INPUT, 2 },
4136 { 0x07, HDA_INPUT, 3 },
4137 { 0x07, HDA_INPUT, 4 },
4138 { } /* end */
4139};
4140#endif
4141
4142/*
4143 * Pin config fixes
4144 */
4145enum {
4146 PINFIX_HP_DC5750,
4147};
4148
4149static const struct alc_fixup alc260_fixups[] = {
4150 [PINFIX_HP_DC5750] = {
4151 .type = ALC_FIXUP_PINS,
4152 .v.pins = (const struct alc_pincfg[]) {
4153 { 0x11, 0x90130110 }, /* speaker */
4154 { }
4155 }
4156 },
4157};
4158
4159static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4160 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4161 {}
4162};
4163
4164/*
4165 */
4166#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4167#include "alc260_quirks.c"
4168#endif
4169
4170static int patch_alc260(struct hda_codec *codec)
4171{
4172 struct alc_spec *spec;
4173 int err, board_config;
4174
4175 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4176 if (spec == NULL)
4177 return -ENOMEM;
4178
4179 codec->spec = spec;
4180
4181 spec->mixer_nid = 0x07;
4182
4183 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4184 alc260_models, alc260_cfg_tbl);
4185 if (board_config < 0) {
4186 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4187 codec->chip_name);
4188 board_config = ALC_MODEL_AUTO;
4189 }
4190
4191 if (board_config == ALC_MODEL_AUTO) {
4192 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4193 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4194 }
4195
4196 if (board_config == ALC_MODEL_AUTO) {
4197 /* automatic parse from the BIOS config */
4198 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004199 if (err < 0)
4200 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004201#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4202 else if (!err) {
4203 printk(KERN_INFO
4204 "hda_codec: Cannot set up configuration "
4205 "from BIOS. Using base mode...\n");
4206 board_config = ALC260_BASIC;
4207 }
4208#endif
4209 }
4210
Takashi Iwai1d045db2011-07-07 18:23:21 +02004211 if (board_config != ALC_MODEL_AUTO)
4212 setup_preset(codec, &alc260_presets[board_config]);
4213
Takashi Iwai60a6a842011-07-27 14:01:24 +02004214 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004215 alc_auto_fill_adc_caps(codec);
4216 alc_rebuild_imux_for_auto_mic(codec);
4217 alc_remove_invalid_adc_nids(codec);
4218 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004219
4220 if (!spec->no_analog && !spec->cap_mixer)
4221 set_capture_mixer(codec);
4222
4223 if (!spec->no_analog) {
4224 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004225 if (err < 0)
4226 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004227 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4228 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004229
4230 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4231
4232 spec->vmaster_nid = 0x08;
4233
4234 codec->patch_ops = alc_patch_ops;
4235 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004236 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004237 spec->shutup = alc_eapd_shutup;
4238#ifdef CONFIG_SND_HDA_POWER_SAVE
4239 if (!spec->loopback.amplist)
4240 spec->loopback.amplist = alc260_loopbacks;
4241#endif
4242
4243 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004244
4245 error:
4246 alc_free(codec);
4247 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004248}
4249
4250
4251/*
4252 * ALC882/883/885/888/889 support
4253 *
4254 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4255 * configuration. Each pin widget can choose any input DACs and a mixer.
4256 * Each ADC is connected from a mixer of all inputs. This makes possible
4257 * 6-channel independent captures.
4258 *
4259 * In addition, an independent DAC for the multi-playback (not used in this
4260 * driver yet).
4261 */
4262#ifdef CONFIG_SND_HDA_POWER_SAVE
4263#define alc882_loopbacks alc880_loopbacks
4264#endif
4265
4266/*
4267 * Pin config fixes
4268 */
4269enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004270 ALC882_FIXUP_ABIT_AW9D_MAX,
4271 ALC882_FIXUP_LENOVO_Y530,
4272 ALC882_FIXUP_PB_M5210,
4273 ALC882_FIXUP_ACER_ASPIRE_7736,
4274 ALC882_FIXUP_ASUS_W90V,
4275 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004276 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004277 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004278 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004279 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004280 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004281 ALC889_FIXUP_COEF,
4282 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004283};
4284
Takashi Iwai68ef0562011-11-09 18:24:44 +01004285static void alc889_fixup_coef(struct hda_codec *codec,
4286 const struct alc_fixup *fix, int action)
4287{
4288 if (action != ALC_FIXUP_ACT_INIT)
4289 return;
4290 alc889_coef_init(codec);
4291}
4292
Takashi Iwai1d045db2011-07-07 18:23:21 +02004293static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004294 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004295 .type = ALC_FIXUP_PINS,
4296 .v.pins = (const struct alc_pincfg[]) {
4297 { 0x15, 0x01080104 }, /* side */
4298 { 0x16, 0x01011012 }, /* rear */
4299 { 0x17, 0x01016011 }, /* clfe */
4300 { }
4301 }
4302 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004303 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004304 .type = ALC_FIXUP_PINS,
4305 .v.pins = (const struct alc_pincfg[]) {
4306 { 0x15, 0x99130112 }, /* rear int speakers */
4307 { 0x16, 0x99130111 }, /* subwoofer */
4308 { }
4309 }
4310 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004311 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004312 .type = ALC_FIXUP_VERBS,
4313 .v.verbs = (const struct hda_verb[]) {
4314 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4315 {}
4316 }
4317 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004318 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004319 .type = ALC_FIXUP_SKU,
4320 .v.sku = ALC_FIXUP_SKU_IGNORE,
4321 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004322 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004323 .type = ALC_FIXUP_PINS,
4324 .v.pins = (const struct alc_pincfg[]) {
4325 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4326 { }
4327 }
4328 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004329 [ALC889_FIXUP_VAIO_TT] = {
4330 .type = ALC_FIXUP_PINS,
4331 .v.pins = (const struct alc_pincfg[]) {
4332 { 0x17, 0x90170111 }, /* hidden surround speaker */
4333 { }
4334 }
4335 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004336 [ALC888_FIXUP_EEE1601] = {
4337 .type = ALC_FIXUP_VERBS,
4338 .v.verbs = (const struct hda_verb[]) {
4339 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4340 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4341 { }
4342 }
Takashi Iwai177943a2011-11-09 12:55:18 +01004343 },
4344 [ALC882_FIXUP_EAPD] = {
4345 .type = ALC_FIXUP_VERBS,
4346 .v.verbs = (const struct hda_verb[]) {
4347 /* change to EAPD mode */
4348 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4349 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4350 { }
4351 }
4352 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004353 [ALC883_FIXUP_EAPD] = {
4354 .type = ALC_FIXUP_VERBS,
4355 .v.verbs = (const struct hda_verb[]) {
4356 /* change to EAPD mode */
4357 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4358 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4359 { }
4360 }
4361 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004362 [ALC883_FIXUP_ACER_EAPD] = {
4363 .type = ALC_FIXUP_VERBS,
4364 .v.verbs = (const struct hda_verb[]) {
4365 /* eanable EAPD on Acer laptops */
4366 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4367 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4368 { }
4369 }
4370 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004371 [ALC882_FIXUP_GPIO3] = {
4372 .type = ALC_FIXUP_VERBS,
4373 .v.verbs = alc_gpio3_init_verbs,
4374 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004375 [ALC882_FIXUP_ASUS_W2JC] = {
4376 .type = ALC_FIXUP_VERBS,
4377 .v.verbs = alc_gpio1_init_verbs,
4378 .chained = true,
4379 .chain_id = ALC882_FIXUP_EAPD,
4380 },
4381 [ALC889_FIXUP_COEF] = {
4382 .type = ALC_FIXUP_FUNC,
4383 .v.func = alc889_fixup_coef,
4384 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385};
4386
4387static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004388 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4389 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4390 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4391 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4392 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4393 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004394 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004395 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01004396 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004397 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004398 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004399 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004400 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai177943a2011-11-09 12:55:18 +01004401 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD), /* codec SSID */
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004402 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004403 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004404 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004405 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4406 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004407 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004408 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004409 {}
4410};
4411
4412/*
4413 * BIOS auto configuration
4414 */
4415/* almost identical with ALC880 parser... */
4416static int alc882_parse_auto_config(struct hda_codec *codec)
4417{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004418 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004419 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4420 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004421}
4422
Takashi Iwai1d045db2011-07-07 18:23:21 +02004423/*
4424 */
4425#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4426#include "alc882_quirks.c"
4427#endif
4428
4429static int patch_alc882(struct hda_codec *codec)
4430{
4431 struct alc_spec *spec;
4432 int err, board_config;
4433
4434 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4435 if (spec == NULL)
4436 return -ENOMEM;
4437
4438 codec->spec = spec;
4439
4440 spec->mixer_nid = 0x0b;
4441
4442 switch (codec->vendor_id) {
4443 case 0x10ec0882:
4444 case 0x10ec0885:
4445 break;
4446 default:
4447 /* ALC883 and variants */
4448 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4449 break;
4450 }
4451
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004452 err = alc_codec_rename_from_preset(codec);
4453 if (err < 0)
4454 goto error;
4455
Takashi Iwai1d045db2011-07-07 18:23:21 +02004456 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4457 alc882_models, alc882_cfg_tbl);
4458
4459 if (board_config < 0)
4460 board_config = alc_board_codec_sid_config(codec,
4461 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4462
4463 if (board_config < 0) {
4464 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4465 codec->chip_name);
4466 board_config = ALC_MODEL_AUTO;
4467 }
4468
4469 if (board_config == ALC_MODEL_AUTO) {
4470 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4471 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4472 }
4473
4474 alc_auto_parse_customize_define(codec);
4475
4476 if (board_config == ALC_MODEL_AUTO) {
4477 /* automatic parse from the BIOS config */
4478 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004479 if (err < 0)
4480 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004481 }
4482
Takashi Iwai1d045db2011-07-07 18:23:21 +02004483 if (board_config != ALC_MODEL_AUTO)
4484 setup_preset(codec, &alc882_presets[board_config]);
4485
Takashi Iwai60a6a842011-07-27 14:01:24 +02004486 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004487 alc_auto_fill_adc_caps(codec);
4488 alc_rebuild_imux_for_auto_mic(codec);
4489 alc_remove_invalid_adc_nids(codec);
4490 }
4491
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004492 if (!spec->no_analog && !spec->cap_mixer)
4493 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004494
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004495 if (!spec->no_analog && has_cdefine_beep(codec)) {
4496 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004497 if (err < 0)
4498 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004499 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004500 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004501
4502 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4503
4504 spec->vmaster_nid = 0x0c;
4505
4506 codec->patch_ops = alc_patch_ops;
4507 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004508 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004509
4510 alc_init_jacks(codec);
4511#ifdef CONFIG_SND_HDA_POWER_SAVE
4512 if (!spec->loopback.amplist)
4513 spec->loopback.amplist = alc882_loopbacks;
4514#endif
4515
4516 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004517
4518 error:
4519 alc_free(codec);
4520 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004521}
4522
4523
4524/*
4525 * ALC262 support
4526 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004527static int alc262_parse_auto_config(struct hda_codec *codec)
4528{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004529 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004530 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4531 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004532}
4533
4534/*
4535 * Pin config fixes
4536 */
4537enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004538 ALC262_FIXUP_FSC_H270,
4539 ALC262_FIXUP_HP_Z200,
4540 ALC262_FIXUP_TYAN,
Takashi Iwai12837c92011-11-07 12:45:24 +01004541 ALC262_FIXUP_TOSHIBA_RX1,
Takashi Iwaic4701502011-11-07 14:20:07 +01004542 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004543 ALC262_FIXUP_BENQ,
4544 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004545};
4546
4547static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004548 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004549 .type = ALC_FIXUP_PINS,
4550 .v.pins = (const struct alc_pincfg[]) {
4551 { 0x14, 0x99130110 }, /* speaker */
4552 { 0x15, 0x0221142f }, /* front HP */
4553 { 0x1b, 0x0121141f }, /* rear HP */
4554 { }
4555 }
4556 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004557 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004558 .type = ALC_FIXUP_PINS,
4559 .v.pins = (const struct alc_pincfg[]) {
4560 { 0x16, 0x99130120 }, /* internal speaker */
4561 { }
4562 }
4563 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004564 [ALC262_FIXUP_TYAN] = {
4565 .type = ALC_FIXUP_PINS,
4566 .v.pins = (const struct alc_pincfg[]) {
4567 { 0x14, 0x1993e1f0 }, /* int AUX */
4568 { }
4569 }
4570 },
Takashi Iwai12837c92011-11-07 12:45:24 +01004571 [ALC262_FIXUP_TOSHIBA_RX1] = {
4572 .type = ALC_FIXUP_PINS,
4573 .v.pins = (const struct alc_pincfg[]) {
4574 { 0x14, 0x90170110 }, /* speaker */
4575 { 0x15, 0x0421101f }, /* HP */
4576 { 0x1a, 0x40f000f0 }, /* N/A */
4577 { 0x1b, 0x40f000f0 }, /* N/A */
4578 { 0x1e, 0x40f000f0 }, /* N/A */
4579 }
4580 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004581 [ALC262_FIXUP_LENOVO_3000] = {
4582 .type = ALC_FIXUP_VERBS,
4583 .v.verbs = (const struct hda_verb[]) {
4584 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004585 {}
4586 },
4587 .chained = true,
4588 .chain_id = ALC262_FIXUP_BENQ,
4589 },
4590 [ALC262_FIXUP_BENQ] = {
4591 .type = ALC_FIXUP_VERBS,
4592 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004593 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4594 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4595 {}
4596 }
4597 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004598 [ALC262_FIXUP_BENQ_T31] = {
4599 .type = ALC_FIXUP_VERBS,
4600 .v.verbs = (const struct hda_verb[]) {
4601 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4602 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4603 {}
4604 }
4605 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004606};
4607
4608static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004609 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004610 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4611 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004612 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
Takashi Iwai12837c92011-11-07 12:45:24 +01004613 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4614 ALC262_FIXUP_TOSHIBA_RX1),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004615 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004616 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004617 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4618 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004619 {}
4620};
4621
4622
4623#ifdef CONFIG_SND_HDA_POWER_SAVE
4624#define alc262_loopbacks alc880_loopbacks
4625#endif
4626
Takashi Iwai1d045db2011-07-07 18:23:21 +02004627/*
4628 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004629static int patch_alc262(struct hda_codec *codec)
4630{
4631 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004632 int err;
4633
4634 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4635 if (spec == NULL)
4636 return -ENOMEM;
4637
4638 codec->spec = spec;
4639
4640 spec->mixer_nid = 0x0b;
4641
4642#if 0
4643 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4644 * under-run
4645 */
4646 {
4647 int tmp;
4648 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4649 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4650 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4651 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4652 }
4653#endif
4654 alc_auto_parse_customize_define(codec);
4655
4656 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4657
Takashi Iwai42399f72011-11-07 17:18:44 +01004658 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4659 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004660
Takashi Iwai42399f72011-11-07 17:18:44 +01004661 /* automatic parse from the BIOS config */
4662 err = alc262_parse_auto_config(codec);
4663 if (err < 0)
4664 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004665
Takashi Iwai60a6a842011-07-27 14:01:24 +02004666 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004667 alc_auto_fill_adc_caps(codec);
4668 alc_rebuild_imux_for_auto_mic(codec);
4669 alc_remove_invalid_adc_nids(codec);
4670 }
4671
4672 if (!spec->no_analog && !spec->cap_mixer)
4673 set_capture_mixer(codec);
4674
Takashi Iwai1d045db2011-07-07 18:23:21 +02004675 if (!spec->no_analog && has_cdefine_beep(codec)) {
4676 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004677 if (err < 0)
4678 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004679 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004680 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004681
4682 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4683
4684 spec->vmaster_nid = 0x0c;
4685
4686 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004687 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004688 spec->shutup = alc_eapd_shutup;
4689
4690 alc_init_jacks(codec);
4691#ifdef CONFIG_SND_HDA_POWER_SAVE
4692 if (!spec->loopback.amplist)
4693 spec->loopback.amplist = alc262_loopbacks;
4694#endif
4695
4696 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004697
4698 error:
4699 alc_free(codec);
4700 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004701}
4702
4703/*
4704 * ALC268
4705 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004706/* bind Beep switches of both NID 0x0f and 0x10 */
4707static const struct hda_bind_ctls alc268_bind_beep_sw = {
4708 .ops = &snd_hda_bind_sw,
4709 .values = {
4710 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4711 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4712 0
4713 },
4714};
4715
4716static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4717 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4718 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4719 { }
4720};
4721
4722/* set PCBEEP vol = 0, mute connections */
4723static const struct hda_verb alc268_beep_init_verbs[] = {
4724 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4725 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4726 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4727 { }
4728};
4729
4730/*
4731 * BIOS auto configuration
4732 */
4733static int alc268_parse_auto_config(struct hda_codec *codec)
4734{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004735 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004736 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004737 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4738 if (err > 0) {
4739 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4740 add_mixer(spec, alc268_beep_mixer);
4741 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004742 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004743 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004744 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004745}
4746
Takashi Iwai1d045db2011-07-07 18:23:21 +02004747/*
4748 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004749static int patch_alc268(struct hda_codec *codec)
4750{
4751 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004752 int i, has_beep, err;
4753
4754 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4755 if (spec == NULL)
4756 return -ENOMEM;
4757
4758 codec->spec = spec;
4759
4760 /* ALC268 has no aa-loopback mixer */
4761
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004762 /* automatic parse from the BIOS config */
4763 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004764 if (err < 0)
4765 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004766
Takashi Iwai1d045db2011-07-07 18:23:21 +02004767 has_beep = 0;
4768 for (i = 0; i < spec->num_mixers; i++) {
4769 if (spec->mixers[i] == alc268_beep_mixer) {
4770 has_beep = 1;
4771 break;
4772 }
4773 }
4774
4775 if (has_beep) {
4776 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004777 if (err < 0)
4778 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004779 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4780 /* override the amp caps for beep generator */
4781 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4782 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4783 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4784 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4785 (0 << AC_AMPCAP_MUTE_SHIFT));
4786 }
4787
Takashi Iwai60a6a842011-07-27 14:01:24 +02004788 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004789 alc_auto_fill_adc_caps(codec);
4790 alc_rebuild_imux_for_auto_mic(codec);
4791 alc_remove_invalid_adc_nids(codec);
4792 }
4793
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004794 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004795 set_capture_mixer(codec);
4796
4797 spec->vmaster_nid = 0x02;
4798
4799 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004800 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004801 spec->shutup = alc_eapd_shutup;
4802
4803 alc_init_jacks(codec);
4804
4805 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004806
4807 error:
4808 alc_free(codec);
4809 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004810}
4811
4812/*
4813 * ALC269
4814 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004815#ifdef CONFIG_SND_HDA_POWER_SAVE
4816#define alc269_loopbacks alc880_loopbacks
4817#endif
4818
4819static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4820 .substreams = 1,
4821 .channels_min = 2,
4822 .channels_max = 8,
4823 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4824 /* NID is set in alc_build_pcms */
4825 .ops = {
4826 .open = alc_playback_pcm_open,
4827 .prepare = alc_playback_pcm_prepare,
4828 .cleanup = alc_playback_pcm_cleanup
4829 },
4830};
4831
4832static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4833 .substreams = 1,
4834 .channels_min = 2,
4835 .channels_max = 2,
4836 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4837 /* NID is set in alc_build_pcms */
4838};
4839
4840#ifdef CONFIG_SND_HDA_POWER_SAVE
4841static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4842{
4843 switch (codec->subsystem_id) {
4844 case 0x103c1586:
4845 return 1;
4846 }
4847 return 0;
4848}
4849
4850static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4851{
4852 /* update mute-LED according to the speaker mute state */
4853 if (nid == 0x01 || nid == 0x14) {
4854 int pinval;
4855 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4856 HDA_AMP_MUTE)
4857 pinval = 0x24;
4858 else
4859 pinval = 0x20;
4860 /* mic2 vref pin is used for mute LED control */
4861 snd_hda_codec_update_cache(codec, 0x19, 0,
4862 AC_VERB_SET_PIN_WIDGET_CONTROL,
4863 pinval);
4864 }
4865 return alc_check_power_status(codec, nid);
4866}
4867#endif /* CONFIG_SND_HDA_POWER_SAVE */
4868
4869/* different alc269-variants */
4870enum {
4871 ALC269_TYPE_ALC269VA,
4872 ALC269_TYPE_ALC269VB,
4873 ALC269_TYPE_ALC269VC,
4874};
4875
4876/*
4877 * BIOS auto configuration
4878 */
4879static int alc269_parse_auto_config(struct hda_codec *codec)
4880{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004882 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4883 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4884 struct alc_spec *spec = codec->spec;
4885 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4886 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004887
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004888 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004889}
4890
Takashi Iwai1d045db2011-07-07 18:23:21 +02004891static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4892{
4893 int val = alc_read_coef_idx(codec, 0x04);
4894 if (power_up)
4895 val |= 1 << 11;
4896 else
4897 val &= ~(1 << 11);
4898 alc_write_coef_idx(codec, 0x04, val);
4899}
4900
4901static void alc269_shutup(struct hda_codec *codec)
4902{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004903 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004904 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004905 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004906 alc269_toggle_power_output(codec, 0);
4907 msleep(150);
4908 }
4909}
4910
Takashi Iwai2a439522011-07-26 09:52:50 +02004911#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02004912static int alc269_resume(struct hda_codec *codec)
4913{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004914 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004915 alc269_toggle_power_output(codec, 0);
4916 msleep(150);
4917 }
4918
4919 codec->patch_ops.init(codec);
4920
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004921 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004922 alc269_toggle_power_output(codec, 1);
4923 msleep(200);
4924 }
4925
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004926 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004927 alc269_toggle_power_output(codec, 1);
4928
4929 snd_hda_codec_resume_amp(codec);
4930 snd_hda_codec_resume_cache(codec);
4931 hda_call_check_power_status(codec, 0x01);
4932 return 0;
4933}
Takashi Iwai2a439522011-07-26 09:52:50 +02004934#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004935
4936static void alc269_fixup_hweq(struct hda_codec *codec,
4937 const struct alc_fixup *fix, int action)
4938{
4939 int coef;
4940
4941 if (action != ALC_FIXUP_ACT_INIT)
4942 return;
4943 coef = alc_read_coef_idx(codec, 0x1e);
4944 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4945}
4946
4947static void alc271_fixup_dmic(struct hda_codec *codec,
4948 const struct alc_fixup *fix, int action)
4949{
4950 static const struct hda_verb verbs[] = {
4951 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4952 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4953 {}
4954 };
4955 unsigned int cfg;
4956
4957 if (strcmp(codec->chip_name, "ALC271X"))
4958 return;
4959 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4960 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4961 snd_hda_sequence_write(codec, verbs);
4962}
4963
Takashi Iwai017f2a12011-07-09 14:42:25 +02004964static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4965 const struct alc_fixup *fix, int action)
4966{
4967 struct alc_spec *spec = codec->spec;
4968
4969 if (action != ALC_FIXUP_ACT_PROBE)
4970 return;
4971
4972 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4973 * fix the sample rate of analog I/O to 44.1kHz
4974 */
4975 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4976 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4977}
4978
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004979static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4980 const struct alc_fixup *fix, int action)
4981{
4982 int coef;
4983
4984 if (action != ALC_FIXUP_ACT_INIT)
4985 return;
4986 /* The digital-mic unit sends PDM (differential signal) instead of
4987 * the standard PCM, thus you can't record a valid mono stream as is.
4988 * Below is a workaround specific to ALC269 to control the dmic
4989 * signal source as mono.
4990 */
4991 coef = alc_read_coef_idx(codec, 0x07);
4992 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4993}
4994
Takashi Iwai24519912011-08-16 15:08:49 +02004995static void alc269_quanta_automute(struct hda_codec *codec)
4996{
David Henningsson42cf0d02011-09-20 12:04:56 +02004997 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02004998
4999 snd_hda_codec_write(codec, 0x20, 0,
5000 AC_VERB_SET_COEF_INDEX, 0x0c);
5001 snd_hda_codec_write(codec, 0x20, 0,
5002 AC_VERB_SET_PROC_COEF, 0x680);
5003
5004 snd_hda_codec_write(codec, 0x20, 0,
5005 AC_VERB_SET_COEF_INDEX, 0x0c);
5006 snd_hda_codec_write(codec, 0x20, 0,
5007 AC_VERB_SET_PROC_COEF, 0x480);
5008}
5009
5010static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5011 const struct alc_fixup *fix, int action)
5012{
5013 struct alc_spec *spec = codec->spec;
5014 if (action != ALC_FIXUP_ACT_PROBE)
5015 return;
5016 spec->automute_hook = alc269_quanta_automute;
5017}
5018
Takashi Iwai1d045db2011-07-07 18:23:21 +02005019enum {
5020 ALC269_FIXUP_SONY_VAIO,
5021 ALC275_FIXUP_SONY_VAIO_GPIO2,
5022 ALC269_FIXUP_DELL_M101Z,
5023 ALC269_FIXUP_SKU_IGNORE,
5024 ALC269_FIXUP_ASUS_G73JW,
5025 ALC269_FIXUP_LENOVO_EAPD,
5026 ALC275_FIXUP_SONY_HWEQ,
5027 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005028 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005029 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005030 ALC269_FIXUP_QUANTA_MUTE,
5031 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005032 ALC269_FIXUP_AMIC,
5033 ALC269_FIXUP_DMIC,
5034 ALC269VB_FIXUP_AMIC,
5035 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005036};
5037
5038static const struct alc_fixup alc269_fixups[] = {
5039 [ALC269_FIXUP_SONY_VAIO] = {
5040 .type = ALC_FIXUP_VERBS,
5041 .v.verbs = (const struct hda_verb[]) {
5042 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5043 {}
5044 }
5045 },
5046 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5047 .type = ALC_FIXUP_VERBS,
5048 .v.verbs = (const struct hda_verb[]) {
5049 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5050 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5051 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5052 { }
5053 },
5054 .chained = true,
5055 .chain_id = ALC269_FIXUP_SONY_VAIO
5056 },
5057 [ALC269_FIXUP_DELL_M101Z] = {
5058 .type = ALC_FIXUP_VERBS,
5059 .v.verbs = (const struct hda_verb[]) {
5060 /* Enables internal speaker */
5061 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5062 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5063 {}
5064 }
5065 },
5066 [ALC269_FIXUP_SKU_IGNORE] = {
5067 .type = ALC_FIXUP_SKU,
5068 .v.sku = ALC_FIXUP_SKU_IGNORE,
5069 },
5070 [ALC269_FIXUP_ASUS_G73JW] = {
5071 .type = ALC_FIXUP_PINS,
5072 .v.pins = (const struct alc_pincfg[]) {
5073 { 0x17, 0x99130111 }, /* subwoofer */
5074 { }
5075 }
5076 },
5077 [ALC269_FIXUP_LENOVO_EAPD] = {
5078 .type = ALC_FIXUP_VERBS,
5079 .v.verbs = (const struct hda_verb[]) {
5080 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5081 {}
5082 }
5083 },
5084 [ALC275_FIXUP_SONY_HWEQ] = {
5085 .type = ALC_FIXUP_FUNC,
5086 .v.func = alc269_fixup_hweq,
5087 .chained = true,
5088 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5089 },
5090 [ALC271_FIXUP_DMIC] = {
5091 .type = ALC_FIXUP_FUNC,
5092 .v.func = alc271_fixup_dmic,
5093 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005094 [ALC269_FIXUP_PCM_44K] = {
5095 .type = ALC_FIXUP_FUNC,
5096 .v.func = alc269_fixup_pcm_44k,
5097 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005098 [ALC269_FIXUP_STEREO_DMIC] = {
5099 .type = ALC_FIXUP_FUNC,
5100 .v.func = alc269_fixup_stereo_dmic,
5101 },
Takashi Iwai24519912011-08-16 15:08:49 +02005102 [ALC269_FIXUP_QUANTA_MUTE] = {
5103 .type = ALC_FIXUP_FUNC,
5104 .v.func = alc269_fixup_quanta_mute,
5105 },
5106 [ALC269_FIXUP_LIFEBOOK] = {
5107 .type = ALC_FIXUP_PINS,
5108 .v.pins = (const struct alc_pincfg[]) {
5109 { 0x1a, 0x2101103f }, /* dock line-out */
5110 { 0x1b, 0x23a11040 }, /* dock mic-in */
5111 { }
5112 },
5113 .chained = true,
5114 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5115 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005116 [ALC269_FIXUP_AMIC] = {
5117 .type = ALC_FIXUP_PINS,
5118 .v.pins = (const struct alc_pincfg[]) {
5119 { 0x14, 0x99130110 }, /* speaker */
5120 { 0x15, 0x0121401f }, /* HP out */
5121 { 0x18, 0x01a19c20 }, /* mic */
5122 { 0x19, 0x99a3092f }, /* int-mic */
5123 { }
5124 },
5125 },
5126 [ALC269_FIXUP_DMIC] = {
5127 .type = ALC_FIXUP_PINS,
5128 .v.pins = (const struct alc_pincfg[]) {
5129 { 0x12, 0x99a3092f }, /* int-mic */
5130 { 0x14, 0x99130110 }, /* speaker */
5131 { 0x15, 0x0121401f }, /* HP out */
5132 { 0x18, 0x01a19c20 }, /* mic */
5133 { }
5134 },
5135 },
5136 [ALC269VB_FIXUP_AMIC] = {
5137 .type = ALC_FIXUP_PINS,
5138 .v.pins = (const struct alc_pincfg[]) {
5139 { 0x14, 0x99130110 }, /* speaker */
5140 { 0x18, 0x01a19c20 }, /* mic */
5141 { 0x19, 0x99a3092f }, /* int-mic */
5142 { 0x21, 0x0121401f }, /* HP out */
5143 { }
5144 },
5145 },
5146 [ALC269_FIXUP_DMIC] = {
5147 .type = ALC_FIXUP_PINS,
5148 .v.pins = (const struct alc_pincfg[]) {
5149 { 0x12, 0x99a3092f }, /* int-mic */
5150 { 0x14, 0x99130110 }, /* speaker */
5151 { 0x18, 0x01a19c20 }, /* mic */
5152 { 0x21, 0x0121401f }, /* HP out */
5153 { }
5154 },
5155 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005156};
5157
5158static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005159 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005160 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5161 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5162 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5163 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5164 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005165 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5166 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5167 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5168 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5169 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5170 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005171 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005172 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5173 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5174 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5175 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5176 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005177 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005178 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005179 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005180
5181#if 1
5182 /* Below is a quirk table taken from the old code.
5183 * Basically the device should work as is without the fixup table.
5184 * If BIOS doesn't give a proper info, enable the corresponding
5185 * fixup entry.
5186 */
5187 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5188 ALC269_FIXUP_AMIC),
5189 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5190 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
5191 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5192 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5193 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5194 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5195 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5196 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5197 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5198 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5199 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5200 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5201 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5202 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5203 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5204 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5205 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5206 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5207 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5208 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5209 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5210 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5211 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5212 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5213 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5214 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5215 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5216 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5217 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5218 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5219 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5220 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5221 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5222 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5223 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5224 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5225 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5226 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5227 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5228 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5229#endif
5230 {}
5231};
5232
5233static const struct alc_model_fixup alc269_fixup_models[] = {
5234 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5235 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005236 {}
5237};
5238
5239
5240static int alc269_fill_coef(struct hda_codec *codec)
5241{
5242 int val;
5243
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005244 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005245 alc_write_coef_idx(codec, 0xf, 0x960b);
5246 alc_write_coef_idx(codec, 0xe, 0x8817);
5247 }
5248
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005249 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005250 alc_write_coef_idx(codec, 0xf, 0x960b);
5251 alc_write_coef_idx(codec, 0xe, 0x8814);
5252 }
5253
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005254 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005255 val = alc_read_coef_idx(codec, 0x04);
5256 /* Power up output pin */
5257 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5258 }
5259
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005260 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005261 val = alc_read_coef_idx(codec, 0xd);
5262 if ((val & 0x0c00) >> 10 != 0x1) {
5263 /* Capless ramp up clock control */
5264 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5265 }
5266 val = alc_read_coef_idx(codec, 0x17);
5267 if ((val & 0x01c0) >> 6 != 0x4) {
5268 /* Class D power on reset */
5269 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5270 }
5271 }
5272
5273 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5274 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5275
5276 val = alc_read_coef_idx(codec, 0x4); /* HP */
5277 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5278
5279 return 0;
5280}
5281
5282/*
5283 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005284static int patch_alc269(struct hda_codec *codec)
5285{
5286 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005287 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005288
5289 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5290 if (spec == NULL)
5291 return -ENOMEM;
5292
5293 codec->spec = spec;
5294
5295 spec->mixer_nid = 0x0b;
5296
5297 alc_auto_parse_customize_define(codec);
5298
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005299 err = alc_codec_rename_from_preset(codec);
5300 if (err < 0)
5301 goto error;
5302
Takashi Iwai1d045db2011-07-07 18:23:21 +02005303 if (codec->vendor_id == 0x10ec0269) {
5304 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005305 switch (alc_get_coef0(codec) & 0x00f0) {
5306 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005307 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005308 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005309 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005310 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005311 break;
5312 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005313 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5314 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005315 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005316 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005317 break;
5318 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005319 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005320 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005321 if (err < 0)
5322 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005323 alc269_fill_coef(codec);
5324 }
5325
Takashi Iwaia4297b52011-08-23 18:40:12 +02005326 alc_pick_fixup(codec, alc269_fixup_models,
5327 alc269_fixup_tbl, alc269_fixups);
5328 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005329
Takashi Iwaia4297b52011-08-23 18:40:12 +02005330 /* automatic parse from the BIOS config */
5331 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005332 if (err < 0)
5333 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005334
Takashi Iwai60a6a842011-07-27 14:01:24 +02005335 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005336 alc_auto_fill_adc_caps(codec);
5337 alc_rebuild_imux_for_auto_mic(codec);
5338 alc_remove_invalid_adc_nids(codec);
5339 }
5340
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005341 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005342 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005343
5344 if (!spec->no_analog && has_cdefine_beep(codec)) {
5345 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005346 if (err < 0)
5347 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005348 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005349 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005350
5351 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5352
5353 spec->vmaster_nid = 0x02;
5354
5355 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005356#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005357 codec->patch_ops.resume = alc269_resume;
5358#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005359 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005360 spec->shutup = alc269_shutup;
5361
5362 alc_init_jacks(codec);
5363#ifdef CONFIG_SND_HDA_POWER_SAVE
5364 if (!spec->loopback.amplist)
5365 spec->loopback.amplist = alc269_loopbacks;
5366 if (alc269_mic2_for_mute_led(codec))
5367 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5368#endif
5369
5370 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005371
5372 error:
5373 alc_free(codec);
5374 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005375}
5376
5377/*
5378 * ALC861
5379 */
5380
Takashi Iwai1d045db2011-07-07 18:23:21 +02005381static int alc861_parse_auto_config(struct hda_codec *codec)
5382{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005383 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005384 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5385 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005386}
5387
Takashi Iwai1d045db2011-07-07 18:23:21 +02005388#ifdef CONFIG_SND_HDA_POWER_SAVE
5389static const struct hda_amp_list alc861_loopbacks[] = {
5390 { 0x15, HDA_INPUT, 0 },
5391 { 0x15, HDA_INPUT, 1 },
5392 { 0x15, HDA_INPUT, 2 },
5393 { 0x15, HDA_INPUT, 3 },
5394 { } /* end */
5395};
5396#endif
5397
5398
5399/* Pin config fixes */
5400enum {
5401 PINFIX_FSC_AMILO_PI1505,
5402};
5403
5404static const struct alc_fixup alc861_fixups[] = {
5405 [PINFIX_FSC_AMILO_PI1505] = {
5406 .type = ALC_FIXUP_PINS,
5407 .v.pins = (const struct alc_pincfg[]) {
5408 { 0x0b, 0x0221101f }, /* HP */
5409 { 0x0f, 0x90170310 }, /* speaker */
5410 { }
5411 }
5412 },
5413};
5414
5415static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5416 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5417 {}
5418};
5419
5420/*
5421 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005422static int patch_alc861(struct hda_codec *codec)
5423{
5424 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005425 int err;
5426
5427 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5428 if (spec == NULL)
5429 return -ENOMEM;
5430
5431 codec->spec = spec;
5432
5433 spec->mixer_nid = 0x15;
5434
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005435 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5436 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005437
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005438 /* automatic parse from the BIOS config */
5439 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005440 if (err < 0)
5441 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005442
Takashi Iwai60a6a842011-07-27 14:01:24 +02005443 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005444 alc_auto_fill_adc_caps(codec);
5445 alc_rebuild_imux_for_auto_mic(codec);
5446 alc_remove_invalid_adc_nids(codec);
5447 }
5448
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005449 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005450 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005451
5452 if (!spec->no_analog) {
5453 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005454 if (err < 0)
5455 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005456 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5457 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005458
5459 spec->vmaster_nid = 0x03;
5460
5461 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5462
5463 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005464 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005465#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005466 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005467 if (!spec->loopback.amplist)
5468 spec->loopback.amplist = alc861_loopbacks;
5469#endif
5470
5471 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005472
5473 error:
5474 alc_free(codec);
5475 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005476}
5477
5478/*
5479 * ALC861-VD support
5480 *
5481 * Based on ALC882
5482 *
5483 * In addition, an independent DAC
5484 */
5485#ifdef CONFIG_SND_HDA_POWER_SAVE
5486#define alc861vd_loopbacks alc880_loopbacks
5487#endif
5488
Takashi Iwai1d045db2011-07-07 18:23:21 +02005489static int alc861vd_parse_auto_config(struct hda_codec *codec)
5490{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005491 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005492 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5493 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005494}
5495
Takashi Iwai1d045db2011-07-07 18:23:21 +02005496enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005497 ALC660VD_FIX_ASUS_GPIO1,
5498 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499};
5500
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005501/* exclude VREF80 */
5502static void alc861vd_fixup_dallas(struct hda_codec *codec,
5503 const struct alc_fixup *fix, int action)
5504{
5505 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5506 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5507 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5508 }
5509}
5510
Takashi Iwai1d045db2011-07-07 18:23:21 +02005511static const struct alc_fixup alc861vd_fixups[] = {
5512 [ALC660VD_FIX_ASUS_GPIO1] = {
5513 .type = ALC_FIXUP_VERBS,
5514 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005515 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005516 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5517 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5518 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5519 { }
5520 }
5521 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005522 [ALC861VD_FIX_DALLAS] = {
5523 .type = ALC_FIXUP_FUNC,
5524 .v.func = alc861vd_fixup_dallas,
5525 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005526};
5527
5528static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005529 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005530 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005531 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005532 {}
5533};
5534
5535static const struct hda_verb alc660vd_eapd_verbs[] = {
5536 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5537 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5538 { }
5539};
5540
5541/*
5542 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005543static int patch_alc861vd(struct hda_codec *codec)
5544{
5545 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005546 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005547
5548 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5549 if (spec == NULL)
5550 return -ENOMEM;
5551
5552 codec->spec = spec;
5553
5554 spec->mixer_nid = 0x0b;
5555
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005556 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5557 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005558
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005559 /* automatic parse from the BIOS config */
5560 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005561 if (err < 0)
5562 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005563
Takashi Iwai1d045db2011-07-07 18:23:21 +02005564 if (codec->vendor_id == 0x10ec0660) {
5565 /* always turn on EAPD */
5566 add_verb(spec, alc660vd_eapd_verbs);
5567 }
5568
Takashi Iwai60a6a842011-07-27 14:01:24 +02005569 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005570 alc_auto_fill_adc_caps(codec);
5571 alc_rebuild_imux_for_auto_mic(codec);
5572 alc_remove_invalid_adc_nids(codec);
5573 }
5574
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005575 if (!spec->no_analog && !spec->cap_mixer)
5576 set_capture_mixer(codec);
5577
5578 if (!spec->no_analog) {
5579 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005580 if (err < 0)
5581 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005582 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5583 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005584
5585 spec->vmaster_nid = 0x02;
5586
5587 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5588
5589 codec->patch_ops = alc_patch_ops;
5590
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005591 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005592 spec->shutup = alc_eapd_shutup;
5593#ifdef CONFIG_SND_HDA_POWER_SAVE
5594 if (!spec->loopback.amplist)
5595 spec->loopback.amplist = alc861vd_loopbacks;
5596#endif
5597
5598 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005599
5600 error:
5601 alc_free(codec);
5602 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005603}
5604
5605/*
5606 * ALC662 support
5607 *
5608 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5609 * configuration. Each pin widget can choose any input DACs and a mixer.
5610 * Each ADC is connected from a mixer of all inputs. This makes possible
5611 * 6-channel independent captures.
5612 *
5613 * In addition, an independent DAC for the multi-playback (not used in this
5614 * driver yet).
5615 */
5616#ifdef CONFIG_SND_HDA_POWER_SAVE
5617#define alc662_loopbacks alc880_loopbacks
5618#endif
5619
5620/*
5621 * BIOS auto configuration
5622 */
5623
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005624static int alc662_parse_auto_config(struct hda_codec *codec)
5625{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005626 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005627 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5628 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5629 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005630
Kailang Yang6227cdc2010-02-25 08:36:52 +01005631 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5632 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005633 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005634 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005635 ssids = alc662_ssids;
5636 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005637}
5638
Todd Broch6be79482010-12-07 16:51:05 -08005639static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005640 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005641{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005642 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005643 return;
Todd Broch6be79482010-12-07 16:51:05 -08005644 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5645 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5646 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5647 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5648 (0 << AC_AMPCAP_MUTE_SHIFT)))
5649 printk(KERN_WARNING
5650 "hda_codec: failed to override amp caps for NID 0x2\n");
5651}
5652
David Henningsson6cb3b702010-09-09 08:51:44 +02005653enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005654 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005655 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005656 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005657 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005658 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005659 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005660 ALC662_FIXUP_ASUS_MODE1,
5661 ALC662_FIXUP_ASUS_MODE2,
5662 ALC662_FIXUP_ASUS_MODE3,
5663 ALC662_FIXUP_ASUS_MODE4,
5664 ALC662_FIXUP_ASUS_MODE5,
5665 ALC662_FIXUP_ASUS_MODE6,
5666 ALC662_FIXUP_ASUS_MODE7,
5667 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005668};
5669
5670static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005671 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005672 .type = ALC_FIXUP_PINS,
5673 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005674 { 0x15, 0x99130112 }, /* subwoofer */
5675 { }
5676 }
5677 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005678 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005679 .type = ALC_FIXUP_PINS,
5680 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005681 { 0x17, 0x99130112 }, /* subwoofer */
5682 { }
5683 }
5684 },
Todd Broch6be79482010-12-07 16:51:05 -08005685 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005686 .type = ALC_FIXUP_FUNC,
5687 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005688 },
5689 [ALC662_FIXUP_CZC_P10T] = {
5690 .type = ALC_FIXUP_VERBS,
5691 .v.verbs = (const struct hda_verb[]) {
5692 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5693 {}
5694 }
5695 },
David Henningsson94024cd2011-04-29 14:10:55 +02005696 [ALC662_FIXUP_SKU_IGNORE] = {
5697 .type = ALC_FIXUP_SKU,
5698 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005699 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005700 [ALC662_FIXUP_HP_RP5800] = {
5701 .type = ALC_FIXUP_PINS,
5702 .v.pins = (const struct alc_pincfg[]) {
5703 { 0x14, 0x0221201f }, /* HP out */
5704 { }
5705 },
5706 .chained = true,
5707 .chain_id = ALC662_FIXUP_SKU_IGNORE
5708 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005709 [ALC662_FIXUP_ASUS_MODE1] = {
5710 .type = ALC_FIXUP_PINS,
5711 .v.pins = (const struct alc_pincfg[]) {
5712 { 0x14, 0x99130110 }, /* speaker */
5713 { 0x18, 0x01a19c20 }, /* mic */
5714 { 0x19, 0x99a3092f }, /* int-mic */
5715 { 0x21, 0x0121401f }, /* HP out */
5716 { }
5717 },
5718 .chained = true,
5719 .chain_id = ALC662_FIXUP_SKU_IGNORE
5720 },
5721 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005722 .type = ALC_FIXUP_PINS,
5723 .v.pins = (const struct alc_pincfg[]) {
5724 { 0x14, 0x99130110 }, /* speaker */
5725 { 0x18, 0x01a19820 }, /* mic */
5726 { 0x19, 0x99a3092f }, /* int-mic */
5727 { 0x1b, 0x0121401f }, /* HP out */
5728 { }
5729 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005730 .chained = true,
5731 .chain_id = ALC662_FIXUP_SKU_IGNORE
5732 },
5733 [ALC662_FIXUP_ASUS_MODE3] = {
5734 .type = ALC_FIXUP_PINS,
5735 .v.pins = (const struct alc_pincfg[]) {
5736 { 0x14, 0x99130110 }, /* speaker */
5737 { 0x15, 0x0121441f }, /* HP */
5738 { 0x18, 0x01a19840 }, /* mic */
5739 { 0x19, 0x99a3094f }, /* int-mic */
5740 { 0x21, 0x01211420 }, /* HP2 */
5741 { }
5742 },
5743 .chained = true,
5744 .chain_id = ALC662_FIXUP_SKU_IGNORE
5745 },
5746 [ALC662_FIXUP_ASUS_MODE4] = {
5747 .type = ALC_FIXUP_PINS,
5748 .v.pins = (const struct alc_pincfg[]) {
5749 { 0x14, 0x99130110 }, /* speaker */
5750 { 0x16, 0x99130111 }, /* speaker */
5751 { 0x18, 0x01a19840 }, /* mic */
5752 { 0x19, 0x99a3094f }, /* int-mic */
5753 { 0x21, 0x0121441f }, /* HP */
5754 { }
5755 },
5756 .chained = true,
5757 .chain_id = ALC662_FIXUP_SKU_IGNORE
5758 },
5759 [ALC662_FIXUP_ASUS_MODE5] = {
5760 .type = ALC_FIXUP_PINS,
5761 .v.pins = (const struct alc_pincfg[]) {
5762 { 0x14, 0x99130110 }, /* speaker */
5763 { 0x15, 0x0121441f }, /* HP */
5764 { 0x16, 0x99130111 }, /* speaker */
5765 { 0x18, 0x01a19840 }, /* mic */
5766 { 0x19, 0x99a3094f }, /* int-mic */
5767 { }
5768 },
5769 .chained = true,
5770 .chain_id = ALC662_FIXUP_SKU_IGNORE
5771 },
5772 [ALC662_FIXUP_ASUS_MODE6] = {
5773 .type = ALC_FIXUP_PINS,
5774 .v.pins = (const struct alc_pincfg[]) {
5775 { 0x14, 0x99130110 }, /* speaker */
5776 { 0x15, 0x01211420 }, /* HP2 */
5777 { 0x18, 0x01a19840 }, /* mic */
5778 { 0x19, 0x99a3094f }, /* int-mic */
5779 { 0x1b, 0x0121441f }, /* HP */
5780 { }
5781 },
5782 .chained = true,
5783 .chain_id = ALC662_FIXUP_SKU_IGNORE
5784 },
5785 [ALC662_FIXUP_ASUS_MODE7] = {
5786 .type = ALC_FIXUP_PINS,
5787 .v.pins = (const struct alc_pincfg[]) {
5788 { 0x14, 0x99130110 }, /* speaker */
5789 { 0x17, 0x99130111 }, /* speaker */
5790 { 0x18, 0x01a19840 }, /* mic */
5791 { 0x19, 0x99a3094f }, /* int-mic */
5792 { 0x1b, 0x01214020 }, /* HP */
5793 { 0x21, 0x0121401f }, /* HP */
5794 { }
5795 },
5796 .chained = true,
5797 .chain_id = ALC662_FIXUP_SKU_IGNORE
5798 },
5799 [ALC662_FIXUP_ASUS_MODE8] = {
5800 .type = ALC_FIXUP_PINS,
5801 .v.pins = (const struct alc_pincfg[]) {
5802 { 0x14, 0x99130110 }, /* speaker */
5803 { 0x12, 0x99a30970 }, /* int-mic */
5804 { 0x15, 0x01214020 }, /* HP */
5805 { 0x17, 0x99130111 }, /* speaker */
5806 { 0x18, 0x01a19840 }, /* mic */
5807 { 0x21, 0x0121401f }, /* HP */
5808 { }
5809 },
5810 .chained = true,
5811 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005812 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005813};
5814
Takashi Iwaia9111322011-05-02 11:30:18 +02005815static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02005816 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01005817 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02005818 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04005819 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005820 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005821 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05005822 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06005823 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02005824 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01005825 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005826
5827#if 0
5828 /* Below is a quirk table taken from the old code.
5829 * Basically the device should work as is without the fixup table.
5830 * If BIOS doesn't give a proper info, enable the corresponding
5831 * fixup entry.
5832 */
5833 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5834 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5835 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5836 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5837 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5838 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5839 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5840 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5841 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5842 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5843 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5844 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5845 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5846 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5847 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5848 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5849 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5850 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5851 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5852 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5853 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5854 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5855 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5856 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5857 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5858 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5859 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5860 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5861 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5862 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5863 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5864 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5865 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5866 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5867 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5868 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5869 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5870 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5871 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5872 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5873 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5874 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5875 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5876 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5877 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5878 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5879 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5880 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5881 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5882 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5883#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02005884 {}
5885};
5886
Todd Broch6be79482010-12-07 16:51:05 -08005887static const struct alc_model_fixup alc662_fixup_models[] = {
5888 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02005889 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5890 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5891 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5892 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5893 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5894 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5895 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5896 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08005897 {}
5898};
David Henningsson6cb3b702010-09-09 08:51:44 +02005899
5900
Takashi Iwai1d045db2011-07-07 18:23:21 +02005901/*
5902 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005903static int patch_alc662(struct hda_codec *codec)
5904{
5905 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005906 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005907
5908 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5909 if (!spec)
5910 return -ENOMEM;
5911
5912 codec->spec = spec;
5913
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005914 spec->mixer_nid = 0x0b;
5915
Takashi Iwai53c334a2011-08-23 18:27:14 +02005916 /* handle multiple HPs as is */
5917 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5918
Kailang Yangda00c242010-03-19 11:23:45 +01005919 alc_auto_parse_customize_define(codec);
5920
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02005921 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5922
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005923 err = alc_codec_rename_from_preset(codec);
5924 if (err < 0)
5925 goto error;
5926
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005927 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005928 codec->bus->pci->subsystem_vendor == 0x1025 &&
5929 spec->cdefine.platform_type == 1) {
5930 if (alc_codec_rename(codec, "ALC272X") < 0)
5931 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005932 }
Kailang Yang274693f2009-12-03 10:07:50 +01005933
Takashi Iwaib9c51062011-08-24 18:08:07 +02005934 alc_pick_fixup(codec, alc662_fixup_models,
5935 alc662_fixup_tbl, alc662_fixups);
5936 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5937 /* automatic parse from the BIOS config */
5938 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005939 if (err < 0)
5940 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005941
Takashi Iwai60a6a842011-07-27 14:01:24 +02005942 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005943 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02005944 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005945 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02005946 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005947
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005948 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02005949 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01005950
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005951 if (!spec->no_analog && has_cdefine_beep(codec)) {
5952 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005953 if (err < 0)
5954 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01005955 switch (codec->vendor_id) {
5956 case 0x10ec0662:
5957 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5958 break;
5959 case 0x10ec0272:
5960 case 0x10ec0663:
5961 case 0x10ec0665:
5962 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5963 break;
5964 case 0x10ec0273:
5965 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5966 break;
5967 }
Kailang Yangcec27c82010-02-04 14:18:18 +01005968 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01005969 spec->vmaster_nid = 0x02;
5970
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005971 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5972
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005973 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02005974 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02005975 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02005976
Kailang Yangbf1b0222010-10-21 08:49:56 +02005977 alc_init_jacks(codec);
5978
Takashi Iwaicb53c622007-08-10 17:21:45 +02005979#ifdef CONFIG_SND_HDA_POWER_SAVE
5980 if (!spec->loopback.amplist)
5981 spec->loopback.amplist = alc662_loopbacks;
5982#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005983
5984 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005985
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005986 error:
5987 alc_free(codec);
5988 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02005989}
5990
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005991/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005992 * ALC680 support
5993 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005994
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005995static int alc680_parse_auto_config(struct hda_codec *codec)
5996{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005997 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005998}
5999
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006000/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006001 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006002static int patch_alc680(struct hda_codec *codec)
6003{
6004 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006005 int err;
6006
6007 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6008 if (spec == NULL)
6009 return -ENOMEM;
6010
6011 codec->spec = spec;
6012
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006013 /* ALC680 has no aa-loopback mixer */
6014
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006015 /* automatic parse from the BIOS config */
6016 err = alc680_parse_auto_config(codec);
6017 if (err < 0) {
6018 alc_free(codec);
6019 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006020 }
6021
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006022 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006023 set_capture_mixer(codec);
6024
6025 spec->vmaster_nid = 0x02;
6026
6027 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006028 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006029
6030 return 0;
6031}
6032
6033/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006034 * patch entries
6035 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006036static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006037 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006038 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006039 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006040 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006041 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006042 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006043 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006044 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006045 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006046 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006047 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006048 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006049 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6050 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6051 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006052 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02006053 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006054 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6055 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006056 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6057 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006058 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006059 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006060 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006061 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006062 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006063 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006064 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006065 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006066 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006067 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006068 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006069 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006070 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006071 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02006072 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006073 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006074 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006075 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006076 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 {} /* terminator */
6078};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006079
6080MODULE_ALIAS("snd-hda-codec-id:10ec*");
6081
6082MODULE_LICENSE("GPL");
6083MODULE_DESCRIPTION("Realtek HD-audio codec");
6084
6085static struct hda_codec_preset_list realtek_list = {
6086 .preset = snd_hda_preset_realtek,
6087 .owner = THIS_MODULE,
6088};
6089
6090static int __init patch_realtek_init(void)
6091{
6092 return snd_hda_add_codec_preset(&realtek_list);
6093}
6094
6095static void __exit patch_realtek_exit(void)
6096{
6097 snd_hda_delete_codec_preset(&realtek_list);
6098}
6099
6100module_init(patch_realtek_init)
6101module_exit(patch_realtek_exit)