blob: f9d24c33ce93b230719b4c2e1fbfec3351ca1106 [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>
30#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020031#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include "hda_codec.h"
33#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090034#include "hda_beep.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Takashi Iwai1d045db2011-07-07 18:23:21 +020036/* unsol event tags */
37#define ALC_FRONT_EVENT 0x01
38#define ALC_DCVOL_EVENT 0x02
39#define ALC_HP_EVENT 0x04
40#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020041
Kailang Yangdf694da2005-12-05 19:42:22 +010042/* for GPIO Poll */
43#define GPIO_MASK 0x03
44
Takashi Iwai4a79ba32009-04-22 16:31:35 +020045/* extra amp-initialization sequence types */
46enum {
47 ALC_INIT_NONE,
48 ALC_INIT_DEFAULT,
49 ALC_INIT_GPIO1,
50 ALC_INIT_GPIO2,
51 ALC_INIT_GPIO3,
52};
53
Kailang Yangda00c242010-03-19 11:23:45 +010054struct alc_customize_define {
55 unsigned int sku_cfg;
56 unsigned char port_connectivity;
57 unsigned char check_sum;
58 unsigned char customization;
59 unsigned char external_amp;
60 unsigned int enable_pcbeep:1;
61 unsigned int platform_type:1;
62 unsigned int swap:1;
63 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020064 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010065};
66
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010067struct alc_fixup;
68
Takashi Iwaice764ab2011-04-27 16:35:23 +020069struct alc_multi_io {
70 hda_nid_t pin; /* multi-io widget pin NID */
71 hda_nid_t dac; /* DAC to be connected */
72 unsigned int ctl_in; /* cached input-pin control value */
73};
74
Takashi Iwaid922b512011-04-28 12:18:53 +020075enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020076 ALC_AUTOMUTE_PIN, /* change the pin control */
77 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
78 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020079};
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081struct alc_spec {
82 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020083 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020085 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010086 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Takashi Iwai2d9c6482009-10-13 08:06:55 +020088 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020089 * don't forget NULL
90 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020091 */
92 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070093
Takashi Iwaiaa563af2009-07-31 10:05:11 +020094 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020095 const struct hda_pcm_stream *stream_analog_playback;
96 const struct hda_pcm_stream *stream_analog_capture;
97 const struct hda_pcm_stream *stream_analog_alt_playback;
98 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200100 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200101 const struct hda_pcm_stream *stream_digital_playback;
102 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200105 struct hda_multi_out multiout; /* playback set-up
106 * max_channels, dacs must be set
107 * dig_out_nid and hp_nid are optional
108 */
Takashi Iwai63300792008-01-24 15:31:36 +0100109 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100110 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100111 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113 /* capture */
114 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200115 const hda_nid_t *adc_nids;
116 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200117 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200118 hda_nid_t mixer_nid; /* analog-mixer NID */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Takashi Iwai840b64c2010-07-13 22:49:01 +0200120 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200121 hda_nid_t cur_adc;
122 unsigned int cur_adc_stream_tag;
123 unsigned int cur_adc_format;
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200126 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 const struct hda_input_mux *input_mux;
128 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200129 hda_nid_t ext_mic_pin;
130 hda_nid_t dock_mic_pin;
131 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100134 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200136 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200137 int const_channel_count;
138 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100141 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200142
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200143 /* dynamic controls, init_verbs and input_mux */
144 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100145 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200146 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200147 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200148 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai49535502009-06-30 15:28:30 +0200149 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
150 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200151 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
152 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
153 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100154
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100155 /* hooks */
156 void (*init_hook)(struct hda_codec *codec);
157 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100158#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500159 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100160#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200161 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200162 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100163
Takashi Iwai834be882006-03-01 14:16:17 +0100164 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200165 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200166 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200167 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200168 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200169 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200170 unsigned int automute_speaker:1; /* automute speaker outputs */
171 unsigned int automute_lo:1; /* automute LO outputs */
172 unsigned int detect_hp:1; /* Headphone detection enabled */
173 unsigned int detect_lo:1; /* Line-out detection enabled */
174 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
175 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200176
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100177 /* other flags */
178 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200179 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100180 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200181 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200182 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwaid922b512011-04-28 12:18:53 +0200183
184 /* auto-mute control */
185 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200186 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200187
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200188 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200189 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100190
Takashi Iwai2134ea42008-01-10 16:53:55 +0100191 /* for virtual master */
192 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200193#ifdef CONFIG_SND_HDA_POWER_SAVE
194 struct hda_loopback_check loopback;
195#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200196
197 /* for PLL fix */
198 hda_nid_t pll_nid;
199 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200200 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100201
202 /* fix-up list */
203 int fixup_id;
204 const struct alc_fixup *fixup_list;
205 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200206
207 /* multi-io */
208 int multi_ios;
209 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200210
211 /* bind volumes */
212 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100213};
214
Takashi Iwai1d045db2011-07-07 18:23:21 +0200215#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Takashi Iwai44c02402011-07-08 15:14:19 +0200217static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
218 int dir, unsigned int bits)
219{
220 if (!nid)
221 return false;
222 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
223 if (query_amp_caps(codec, nid, dir) & bits)
224 return true;
225 return false;
226}
227
228#define nid_has_mute(codec, nid, dir) \
229 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
230#define nid_has_volume(codec, nid, dir) \
231 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233/*
234 * input MUX handling
235 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200236static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
237 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238{
239 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
240 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200241 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
242 if (mux_idx >= spec->num_mux_defs)
243 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100244 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
245 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200246 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247}
248
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200249static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
250 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
252 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
253 struct alc_spec *spec = codec->spec;
254 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
255
256 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
257 return 0;
258}
259
Takashi Iwai21268962011-07-07 15:01:13 +0200260static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261{
Takashi Iwai21268962011-07-07 15:01:13 +0200262 struct alc_spec *spec = codec->spec;
263 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
264
265 if (spec->cur_adc && spec->cur_adc != new_adc) {
266 /* stream is running, let's swap the current ADC */
267 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
268 spec->cur_adc = new_adc;
269 snd_hda_codec_setup_stream(codec, new_adc,
270 spec->cur_adc_stream_tag, 0,
271 spec->cur_adc_format);
272 return true;
273 }
274 return false;
275}
276
277/* select the given imux item; either unmute exclusively or select the route */
278static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
279 unsigned int idx, bool force)
280{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100282 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100283 unsigned int mux_idx;
Takashi Iwai21268962011-07-07 15:01:13 +0200284 int i, type;
285 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Takashi Iwaicd896c32008-11-18 12:36:33 +0100287 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
288 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100289 if (!imux->num_items && mux_idx > 0)
290 imux = &spec->input_mux[0];
Takashi Iwaicd896c32008-11-18 12:36:33 +0100291
Takashi Iwai21268962011-07-07 15:01:13 +0200292 if (idx >= imux->num_items)
293 idx = imux->num_items - 1;
294 if (spec->cur_mux[adc_idx] == idx && !force)
295 return 0;
296 spec->cur_mux[adc_idx] = idx;
297
298 if (spec->dyn_adc_switch) {
299 alc_dyn_adc_pcm_resetup(codec, idx);
300 adc_idx = spec->dyn_adc_idx[idx];
301 }
302
303 nid = spec->capsrc_nids ?
304 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
305
306 /* no selection? */
307 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
308 return 1;
309
Takashi Iwaia22d5432009-07-27 12:54:26 +0200310 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200311 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100312 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100313 for (i = 0; i < imux->num_items; i++) {
314 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
315 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
316 imux->items[i].index,
317 HDA_AMP_MUTE, v);
318 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100319 } else {
320 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200321 snd_hda_codec_write_cache(codec, nid, 0,
322 AC_VERB_SET_CONNECT_SEL,
323 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100324 }
Takashi Iwai21268962011-07-07 15:01:13 +0200325 return 1;
326}
327
328static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
329 struct snd_ctl_elem_value *ucontrol)
330{
331 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
332 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
333 return alc_mux_select(codec, adc_idx,
334 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100335}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100338 * set up the input pin config (depending on the given auto-pin type)
339 */
340static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
341 int auto_pin_type)
342{
343 unsigned int val = PIN_IN;
344
Takashi Iwai86e29592010-09-09 14:50:17 +0200345 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100346 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200347 unsigned int oldval;
348 oldval = snd_hda_codec_read(codec, nid, 0,
349 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100350 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100351 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200352 /* if the default pin setup is vref50, we give it priority */
353 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100354 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200355 else if (pincap & AC_PINCAP_VREF_50)
356 val = PIN_VREF50;
357 else if (pincap & AC_PINCAP_VREF_100)
358 val = PIN_VREF100;
359 else if (pincap & AC_PINCAP_VREF_GRD)
360 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100361 }
362 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
363}
364
365/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200366 * Append the given mixer and verb elements for the later use
367 * The mixer array is referred in build_controls(), and init_verbs are
368 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100369 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200370static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100371{
372 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
373 return;
374 spec->mixers[spec->num_mixers++] = mix;
375}
376
377static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
378{
379 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
380 return;
381 spec->init_verbs[spec->num_init_verbs++] = verb;
382}
383
384/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200385 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100386 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200387/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200388static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200389 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
390 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
391 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
392 { }
393};
394
Takashi Iwaia9111322011-05-02 11:30:18 +0200395static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200396 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
397 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
398 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
399 { }
400};
401
Takashi Iwaia9111322011-05-02 11:30:18 +0200402static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200403 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
404 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
405 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
406 { }
407};
408
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200409/*
410 * Fix hardware PLL issue
411 * On some codecs, the analog PLL gating control must be off while
412 * the default value is 1.
413 */
414static void alc_fix_pll(struct hda_codec *codec)
415{
416 struct alc_spec *spec = codec->spec;
417 unsigned int val;
418
419 if (!spec->pll_nid)
420 return;
421 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
422 spec->pll_coef_idx);
423 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
424 AC_VERB_GET_PROC_COEF, 0);
425 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
426 spec->pll_coef_idx);
427 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
428 val & ~(1 << spec->pll_coef_bit));
429}
430
431static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
432 unsigned int coef_idx, unsigned int coef_bit)
433{
434 struct alc_spec *spec = codec->spec;
435 spec->pll_nid = nid;
436 spec->pll_coef_idx = coef_idx;
437 spec->pll_coef_bit = coef_bit;
438 alc_fix_pll(codec);
439}
440
Takashi Iwai1d045db2011-07-07 18:23:21 +0200441/*
442 * Jack-reporting via input-jack layer
443 */
444
445/* initialization of jacks; currently checks only a few known pins */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200446static int alc_init_jacks(struct hda_codec *codec)
447{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100448#ifdef CONFIG_SND_HDA_INPUT_JACK
Kailang Yang9ad0e492010-09-14 23:22:00 +0200449 struct alc_spec *spec = codec->spec;
450 int err;
451 unsigned int hp_nid = spec->autocfg.hp_pins[0];
Takashi Iwai21268962011-07-07 15:01:13 +0200452 unsigned int mic_nid = spec->ext_mic_pin;
453 unsigned int dock_nid = spec->dock_mic_pin;
Kailang Yang9ad0e492010-09-14 23:22:00 +0200454
Takashi Iwai265a0242010-09-21 11:26:21 +0200455 if (hp_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100456 err = snd_hda_input_jack_add(codec, hp_nid,
457 SND_JACK_HEADPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200458 if (err < 0)
459 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100460 snd_hda_input_jack_report(codec, hp_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200461 }
Kailang Yang9ad0e492010-09-14 23:22:00 +0200462
Takashi Iwai265a0242010-09-21 11:26:21 +0200463 if (mic_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100464 err = snd_hda_input_jack_add(codec, mic_nid,
465 SND_JACK_MICROPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200466 if (err < 0)
467 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100468 snd_hda_input_jack_report(codec, mic_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200469 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200470 if (dock_nid) {
471 err = snd_hda_input_jack_add(codec, dock_nid,
472 SND_JACK_MICROPHONE, NULL);
473 if (err < 0)
474 return err;
475 snd_hda_input_jack_report(codec, dock_nid);
476 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100477#endif /* CONFIG_SND_HDA_INPUT_JACK */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200478 return 0;
479}
Kailang Yang9ad0e492010-09-14 23:22:00 +0200480
Takashi Iwai1d045db2011-07-07 18:23:21 +0200481/*
482 * Jack detections for HP auto-mute and mic-switch
483 */
484
485/* check each pin in the given array; returns true if any of them is plugged */
486static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200487{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200488 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200489
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200490 for (i = 0; i < num_pins; i++) {
491 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200492 if (!nid)
493 break;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100494 snd_hda_input_jack_report(codec, nid);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200496 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200497 return present;
498}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200499
Takashi Iwai1d045db2011-07-07 18:23:21 +0200500/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200502 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200503{
504 struct alc_spec *spec = codec->spec;
505 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200506 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507 int i;
508
509 for (i = 0; i < num_pins; i++) {
510 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200511 if (!nid)
512 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200513 switch (spec->automute_mode) {
514 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200515 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200516 AC_VERB_SET_PIN_WIDGET_CONTROL,
517 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200518 break;
519 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200520 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200521 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200522 break;
523 case ALC_AUTOMUTE_MIXER:
524 nid = spec->automute_mixer_nid[i];
525 if (!nid)
526 break;
527 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200528 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200529 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200530 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200531 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200532 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200533 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200534}
535
David Henningsson42cf0d02011-09-20 12:04:56 +0200536/* Toggle outputs muting */
537static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200538{
539 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200540 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200541
Takashi Iwaic0a20262011-06-10 15:28:15 +0200542 /* Control HP pins/amps depending on master_mute state;
543 * in general, HP pins/amps control should be enabled in all cases,
544 * but currently set only for master_mute, just to be safe
545 */
546 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
547 spec->autocfg.hp_pins, spec->master_mute, true);
548
David Henningsson42cf0d02011-09-20 12:04:56 +0200549 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200550 on = 0;
551 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200552 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200553 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200554 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556
557 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200558 /* if LO is a copy of either HP or Speaker, don't need to handle it */
559 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
560 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200562 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200563 on = 0;
564 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200565 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200567 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200568 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200569}
570
David Henningsson42cf0d02011-09-20 12:04:56 +0200571static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200572{
573 struct alc_spec *spec = codec->spec;
574 if (spec->automute_hook)
575 spec->automute_hook(codec);
576 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200577 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200578}
579
Takashi Iwai1d045db2011-07-07 18:23:21 +0200580/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200581static void alc_hp_automute(struct hda_codec *codec)
582{
583 struct alc_spec *spec = codec->spec;
584
David Henningsson42cf0d02011-09-20 12:04:56 +0200585 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200586 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
587 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200588 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200589 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200590 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591}
592
Takashi Iwai1d045db2011-07-07 18:23:21 +0200593/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200594static void alc_line_automute(struct hda_codec *codec)
595{
596 struct alc_spec *spec = codec->spec;
597
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200598 /* check LO jack only when it's different from HP */
599 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
600 return;
601
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602 spec->line_jack_present =
603 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
604 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200605 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200606 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200607 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200608}
609
Takashi Iwai8d087c72011-06-28 12:45:47 +0200610#define get_connection_index(codec, mux, nid) \
611 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200612
Takashi Iwai1d045db2011-07-07 18:23:21 +0200613/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200614static void alc_mic_automute(struct hda_codec *codec)
615{
616 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200617 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200618
Takashi Iwai21268962011-07-07 15:01:13 +0200619 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200620 return;
621 if (snd_BUG_ON(!spec->adc_nids))
622 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200623 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200624 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200625
Takashi Iwai21268962011-07-07 15:01:13 +0200626 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
627 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
628 else if (spec->dock_mic_idx >= 0 &&
629 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
630 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
631 else
632 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Takashi Iwai6c819492009-08-10 18:47:44 +0200633
Takashi Iwai21268962011-07-07 15:01:13 +0200634 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
635 if (spec->dock_mic_idx >= 0)
636 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200637}
638
Kailang Yangc9b58002007-10-16 14:30:01 +0200639/* unsolicited event for HP jack sensing */
640static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
641{
642 if (codec->vendor_id == 0x10ec0880)
643 res >>= 28;
644 else
645 res >>= 26;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200646 switch (res) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200647 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200648 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200649 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200650 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200651 alc_line_automute(codec);
652 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200653 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200654 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200655 break;
656 }
Kailang Yang7fb0d782008-10-15 11:12:35 +0200657}
658
Takashi Iwai1d045db2011-07-07 18:23:21 +0200659/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200660static void alc_inithook(struct hda_codec *codec)
661{
Takashi Iwaid922b512011-04-28 12:18:53 +0200662 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200663 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200664 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200665}
666
Kailang Yangf9423e72008-05-27 12:32:25 +0200667/* additional initialization for ALC888 variants */
668static void alc888_coef_init(struct hda_codec *codec)
669{
670 unsigned int tmp;
671
672 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
673 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
674 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100675 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200676 /* alc888S-VC */
677 snd_hda_codec_read(codec, 0x20, 0,
678 AC_VERB_SET_PROC_COEF, 0x830);
679 else
680 /* alc888-VB */
681 snd_hda_codec_read(codec, 0x20, 0,
682 AC_VERB_SET_PROC_COEF, 0x3030);
683}
684
Takashi Iwai1d045db2011-07-07 18:23:21 +0200685/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200686static void alc889_coef_init(struct hda_codec *codec)
687{
688 unsigned int tmp;
689
690 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
691 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
692 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
693 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
694}
695
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100696/* turn on/off EAPD control (only if available) */
697static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
698{
699 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
700 return;
701 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
702 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
703 on ? 2 : 0);
704}
705
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200706/* turn on/off EAPD controls of the codec */
707static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
708{
709 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200710 static hda_nid_t pins[] = {
711 0x0f, 0x10, 0x14, 0x15, 0
712 };
713 hda_nid_t *p;
714 for (p = pins; *p; p++)
715 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200716}
717
Takashi Iwai1c716152011-04-07 10:37:16 +0200718/* generic shutup callback;
719 * just turning off EPAD and a little pause for avoiding pop-noise
720 */
721static void alc_eapd_shutup(struct hda_codec *codec)
722{
723 alc_auto_setup_eapd(codec, false);
724 msleep(200);
725}
726
Takashi Iwai1d045db2011-07-07 18:23:21 +0200727/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200728static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200729{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200730 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200731
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200732 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200733 switch (type) {
734 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200735 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
736 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200737 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200738 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
739 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200740 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200741 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
742 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200743 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200744 switch (codec->vendor_id) {
745 case 0x10ec0260:
746 snd_hda_codec_write(codec, 0x1a, 0,
747 AC_VERB_SET_COEF_INDEX, 7);
748 tmp = snd_hda_codec_read(codec, 0x1a, 0,
749 AC_VERB_GET_PROC_COEF, 0);
750 snd_hda_codec_write(codec, 0x1a, 0,
751 AC_VERB_SET_COEF_INDEX, 7);
752 snd_hda_codec_write(codec, 0x1a, 0,
753 AC_VERB_SET_PROC_COEF,
754 tmp | 0x2010);
755 break;
756 case 0x10ec0262:
757 case 0x10ec0880:
758 case 0x10ec0882:
759 case 0x10ec0883:
760 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100761 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100762 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200763 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200764 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200765 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200766 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200767 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100768#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200769 case 0x10ec0267:
770 case 0x10ec0268:
771 snd_hda_codec_write(codec, 0x20, 0,
772 AC_VERB_SET_COEF_INDEX, 7);
773 tmp = snd_hda_codec_read(codec, 0x20, 0,
774 AC_VERB_GET_PROC_COEF, 0);
775 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200776 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200777 snd_hda_codec_write(codec, 0x20, 0,
778 AC_VERB_SET_PROC_COEF,
779 tmp | 0x3000);
780 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100781#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200782 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200783 break;
784 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200785}
Kailang Yangea1fb292008-08-26 12:58:38 +0200786
Takashi Iwai1d045db2011-07-07 18:23:21 +0200787/*
788 * Auto-Mute mode mixer enum support
789 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200790static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
791 struct snd_ctl_elem_info *uinfo)
792{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200793 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
794 struct alc_spec *spec = codec->spec;
795 static const char * const texts2[] = {
796 "Disabled", "Enabled"
797 };
798 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200799 "Disabled", "Speaker Only", "Line-Out+Speaker"
800 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200801 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200802
803 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
804 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200805 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200806 uinfo->value.enumerated.items = 3;
807 texts = texts3;
808 } else {
809 uinfo->value.enumerated.items = 2;
810 texts = texts2;
811 }
812 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
813 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200814 strcpy(uinfo->value.enumerated.name,
815 texts[uinfo->value.enumerated.item]);
816 return 0;
817}
818
819static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
820 struct snd_ctl_elem_value *ucontrol)
821{
822 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
823 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200824 unsigned int val = 0;
825 if (spec->automute_speaker)
826 val++;
827 if (spec->automute_lo)
828 val++;
829
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200830 ucontrol->value.enumerated.item[0] = val;
831 return 0;
832}
833
834static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
835 struct snd_ctl_elem_value *ucontrol)
836{
837 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
838 struct alc_spec *spec = codec->spec;
839
840 switch (ucontrol->value.enumerated.item[0]) {
841 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200842 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200843 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200844 spec->automute_speaker = 0;
845 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200846 break;
847 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200848 if (spec->automute_speaker_possible) {
849 if (!spec->automute_lo && spec->automute_speaker)
850 return 0;
851 spec->automute_speaker = 1;
852 spec->automute_lo = 0;
853 } else if (spec->automute_lo_possible) {
854 if (spec->automute_lo)
855 return 0;
856 spec->automute_lo = 1;
857 } else
858 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200859 break;
860 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200861 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200862 return -EINVAL;
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 = 1;
866 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200867 break;
868 default:
869 return -EINVAL;
870 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200871 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200872 return 1;
873}
874
Takashi Iwaia9111322011-05-02 11:30:18 +0200875static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200876 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
877 .name = "Auto-Mute Mode",
878 .info = alc_automute_mode_info,
879 .get = alc_automute_mode_get,
880 .put = alc_automute_mode_put,
881};
882
Takashi Iwai1d045db2011-07-07 18:23:21 +0200883static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
884{
885 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
886 return snd_array_new(&spec->kctls);
887}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200888
889static int alc_add_automute_mode_enum(struct hda_codec *codec)
890{
891 struct alc_spec *spec = codec->spec;
892 struct snd_kcontrol_new *knew;
893
894 knew = alc_kcontrol_new(spec);
895 if (!knew)
896 return -ENOMEM;
897 *knew = alc_automute_mode_enum;
898 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
899 if (!knew->name)
900 return -ENOMEM;
901 return 0;
902}
903
Takashi Iwai1d045db2011-07-07 18:23:21 +0200904/*
905 * Check the availability of HP/line-out auto-mute;
906 * Set up appropriately if really supported
907 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200908static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200909{
910 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200911 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200912 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200913 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200914
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200915 if (cfg->hp_pins[0])
916 present++;
917 if (cfg->line_out_pins[0])
918 present++;
919 if (cfg->speaker_pins[0])
920 present++;
921 if (present < 2) /* need two different output types */
922 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200923
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200924 if (!cfg->speaker_pins[0] &&
925 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200926 memcpy(cfg->speaker_pins, cfg->line_out_pins,
927 sizeof(cfg->speaker_pins));
928 cfg->speaker_outs = cfg->line_outs;
929 }
930
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200931 if (!cfg->hp_pins[0] &&
932 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200933 memcpy(cfg->hp_pins, cfg->line_out_pins,
934 sizeof(cfg->hp_pins));
935 cfg->hp_outs = cfg->line_outs;
936 }
937
David Henningsson42cf0d02011-09-20 12:04:56 +0200938 spec->automute_mode = ALC_AUTOMUTE_PIN;
939
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200940 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200941 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200942 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200943 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200944 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200945 nid);
946 snd_hda_codec_write_cache(codec, nid, 0,
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200947 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +0200948 AC_USRSP_EN | ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200949 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200950 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200951
David Henningsson42cf0d02011-09-20 12:04:56 +0200952 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
953 if (cfg->speaker_outs)
954 for (i = 0; i < cfg->line_outs; i++) {
955 hda_nid_t nid = cfg->line_out_pins[i];
956 if (!is_jack_detectable(codec, nid))
957 continue;
958 snd_printdd("realtek: Enable Line-Out "
959 "auto-muting on NID 0x%x\n", nid);
960 snd_hda_codec_write_cache(codec, nid, 0,
961 AC_VERB_SET_UNSOLICITED_ENABLE,
962 AC_USRSP_EN | ALC_FRONT_EVENT);
963 spec->detect_lo = 1;
964 }
965 spec->automute_lo_possible = spec->detect_hp;
966 }
967
968 spec->automute_speaker_possible = cfg->speaker_outs &&
969 (spec->detect_hp || spec->detect_lo);
970
971 spec->automute_lo = spec->automute_lo_possible;
972 spec->automute_speaker = spec->automute_speaker_possible;
973
974 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200975 /* create a control for automute mode */
976 alc_add_automute_mode_enum(codec);
977 spec->unsol_event = alc_sku_unsol_event;
978 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200979}
980
Takashi Iwai1d045db2011-07-07 18:23:21 +0200981/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200982static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
983{
984 int i;
985 for (i = 0; i < nums; i++)
986 if (list[i] == nid)
987 return i;
988 return -1;
989}
990
Takashi Iwai1d045db2011-07-07 18:23:21 +0200991/* check whether dynamic ADC-switching is available */
992static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
993{
994 struct alc_spec *spec = codec->spec;
995 struct hda_input_mux *imux = &spec->private_imux[0];
996 int i, n, idx;
997 hda_nid_t cap, pin;
998
999 if (imux != spec->input_mux) /* no dynamic imux? */
1000 return false;
1001
1002 for (n = 0; n < spec->num_adc_nids; n++) {
1003 cap = spec->private_capsrc_nids[n];
1004 for (i = 0; i < imux->num_items; i++) {
1005 pin = spec->imux_pins[i];
1006 if (!pin)
1007 return false;
1008 if (get_connection_index(codec, cap, pin) < 0)
1009 break;
1010 }
1011 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001012 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001013 }
1014
1015 for (i = 0; i < imux->num_items; i++) {
1016 pin = spec->imux_pins[i];
1017 for (n = 0; n < spec->num_adc_nids; n++) {
1018 cap = spec->private_capsrc_nids[n];
1019 idx = get_connection_index(codec, cap, pin);
1020 if (idx >= 0) {
1021 imux->items[i].index = idx;
1022 spec->dyn_adc_idx[i] = n;
1023 break;
1024 }
1025 }
1026 }
1027
1028 snd_printdd("realtek: enabling ADC switching\n");
1029 spec->dyn_adc_switch = 1;
1030 return true;
1031}
Takashi Iwai21268962011-07-07 15:01:13 +02001032
1033/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1034static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1035{
1036 struct alc_spec *spec = codec->spec;
1037 struct hda_input_mux *imux;
1038 static char * const texts[3] = {
1039 "Mic", "Internal Mic", "Dock Mic"
1040 };
1041 int i;
1042
1043 if (!spec->auto_mic)
1044 return false;
1045 imux = &spec->private_imux[0];
1046 if (spec->input_mux == imux)
1047 return true;
1048 spec->imux_pins[0] = spec->ext_mic_pin;
1049 spec->imux_pins[1] = spec->int_mic_pin;
1050 spec->imux_pins[2] = spec->dock_mic_pin;
1051 for (i = 0; i < 3; i++) {
1052 strcpy(imux->items[i].label, texts[i]);
1053 if (spec->imux_pins[i])
1054 imux->num_items = i + 1;
1055 }
1056 spec->num_mux_defs = 1;
1057 spec->input_mux = imux;
1058 return true;
1059}
1060
1061/* check whether all auto-mic pins are valid; setup indices if OK */
1062static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1063{
1064 struct alc_spec *spec = codec->spec;
1065 const struct hda_input_mux *imux;
1066
1067 if (!spec->auto_mic)
1068 return false;
1069 if (spec->auto_mic_valid_imux)
1070 return true; /* already checked */
1071
1072 /* fill up imux indices */
1073 if (!alc_check_dyn_adc_switch(codec)) {
1074 spec->auto_mic = 0;
1075 return false;
1076 }
1077
1078 imux = spec->input_mux;
1079 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1080 spec->imux_pins, imux->num_items);
1081 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1082 spec->imux_pins, imux->num_items);
1083 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1084 spec->imux_pins, imux->num_items);
1085 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1086 spec->auto_mic = 0;
1087 return false; /* no corresponding imux */
1088 }
1089
1090 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1091 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001092 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001093 if (spec->dock_mic_pin)
1094 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1095 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001096 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001097
1098 spec->auto_mic_valid_imux = 1;
1099 spec->auto_mic = 1;
1100 return true;
1101}
1102
Takashi Iwai1d045db2011-07-07 18:23:21 +02001103/*
1104 * Check the availability of auto-mic switch;
1105 * Set up if really supported
1106 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001107static void alc_init_auto_mic(struct hda_codec *codec)
1108{
1109 struct alc_spec *spec = codec->spec;
1110 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001111 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001112 int i;
1113
Takashi Iwai21268962011-07-07 15:01:13 +02001114 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1115
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001116 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001117 for (i = 0; i < cfg->num_inputs; i++) {
1118 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001119 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001120 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001121 switch (snd_hda_get_input_pin_attr(defcfg)) {
1122 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001123 if (fixed)
1124 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001125 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1126 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001127 fixed = nid;
1128 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001129 case INPUT_PIN_ATTR_UNUSED:
1130 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001131 case INPUT_PIN_ATTR_DOCK:
1132 if (dock)
1133 return; /* already occupied */
1134 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1135 return; /* invalid type */
1136 dock = nid;
1137 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001138 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001139 if (ext)
1140 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001141 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1142 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001143 ext = nid;
1144 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 }
1146 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001147 if (!ext && dock) {
1148 ext = dock;
1149 dock = 0;
1150 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001151 if (!ext || !fixed)
1152 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001153 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001154 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001155 if (dock && !is_jack_detectable(codec, dock))
1156 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001157
1158 /* check imux indices */
1159 spec->ext_mic_pin = ext;
1160 spec->int_mic_pin = fixed;
1161 spec->dock_mic_pin = dock;
1162
1163 spec->auto_mic = 1;
1164 if (!alc_auto_mic_check_imux(codec))
1165 return;
1166
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001167 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1168 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001169 spec->unsol_event = alc_sku_unsol_event;
1170}
1171
Takashi Iwai1d045db2011-07-07 18:23:21 +02001172/* check the availabilities of auto-mute and auto-mic switches */
1173static void alc_auto_check_switches(struct hda_codec *codec)
1174{
David Henningsson42cf0d02011-09-20 12:04:56 +02001175 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001176 alc_init_auto_mic(codec);
1177}
1178
1179/*
1180 * Realtek SSID verification
1181 */
1182
David Henningsson90622912010-10-14 14:50:18 +02001183/* Could be any non-zero and even value. When used as fixup, tells
1184 * the driver to ignore any present sku defines.
1185 */
1186#define ALC_FIXUP_SKU_IGNORE (2)
1187
Kailang Yangda00c242010-03-19 11:23:45 +01001188static int alc_auto_parse_customize_define(struct hda_codec *codec)
1189{
1190 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001191 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001192 struct alc_spec *spec = codec->spec;
1193
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001194 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1195
David Henningsson90622912010-10-14 14:50:18 +02001196 if (spec->cdefine.fixup) {
1197 ass = spec->cdefine.sku_cfg;
1198 if (ass == ALC_FIXUP_SKU_IGNORE)
1199 return -1;
1200 goto do_sku;
1201 }
1202
Kailang Yangda00c242010-03-19 11:23:45 +01001203 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001204 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001205 goto do_sku;
1206
1207 nid = 0x1d;
1208 if (codec->vendor_id == 0x10ec0260)
1209 nid = 0x17;
1210 ass = snd_hda_codec_get_pincfg(codec, nid);
1211
1212 if (!(ass & 1)) {
1213 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1214 codec->chip_name, ass);
1215 return -1;
1216 }
1217
1218 /* check sum */
1219 tmp = 0;
1220 for (i = 1; i < 16; i++) {
1221 if ((ass >> i) & 1)
1222 tmp++;
1223 }
1224 if (((ass >> 16) & 0xf) != tmp)
1225 return -1;
1226
1227 spec->cdefine.port_connectivity = ass >> 30;
1228 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1229 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1230 spec->cdefine.customization = ass >> 8;
1231do_sku:
1232 spec->cdefine.sku_cfg = ass;
1233 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1234 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1235 spec->cdefine.swap = (ass & 0x2) >> 1;
1236 spec->cdefine.override = ass & 0x1;
1237
1238 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1239 nid, spec->cdefine.sku_cfg);
1240 snd_printd("SKU: port_connectivity=0x%x\n",
1241 spec->cdefine.port_connectivity);
1242 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1243 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1244 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1245 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1246 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1247 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1248 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1249
1250 return 0;
1251}
1252
Takashi Iwai1d045db2011-07-07 18:23:21 +02001253/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001254static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1255{
Takashi Iwai21268962011-07-07 15:01:13 +02001256 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001257}
1258
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001259/* check subsystem ID and set up device-specific initialization;
1260 * return 1 if initialized, 0 if invalid SSID
1261 */
1262/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1263 * 31 ~ 16 : Manufacture ID
1264 * 15 ~ 8 : SKU ID
1265 * 7 ~ 0 : Assembly ID
1266 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1267 */
1268static int alc_subsystem_id(struct hda_codec *codec,
1269 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001270 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001271{
1272 unsigned int ass, tmp, i;
1273 unsigned nid;
1274 struct alc_spec *spec = codec->spec;
1275
David Henningsson90622912010-10-14 14:50:18 +02001276 if (spec->cdefine.fixup) {
1277 ass = spec->cdefine.sku_cfg;
1278 if (ass == ALC_FIXUP_SKU_IGNORE)
1279 return 0;
1280 goto do_sku;
1281 }
1282
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001283 ass = codec->subsystem_id & 0xffff;
1284 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1285 goto do_sku;
1286
1287 /* invalid SSID, check the special NID pin defcfg instead */
1288 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001289 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001290 * 29~21 : reserve
1291 * 20 : PCBEEP input
1292 * 19~16 : Check sum (15:1)
1293 * 15~1 : Custom
1294 * 0 : override
1295 */
1296 nid = 0x1d;
1297 if (codec->vendor_id == 0x10ec0260)
1298 nid = 0x17;
1299 ass = snd_hda_codec_get_pincfg(codec, nid);
1300 snd_printd("realtek: No valid SSID, "
1301 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001302 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001303 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001304 return 0;
1305 if ((ass >> 30) != 1) /* no physical connection */
1306 return 0;
1307
1308 /* check sum */
1309 tmp = 0;
1310 for (i = 1; i < 16; i++) {
1311 if ((ass >> i) & 1)
1312 tmp++;
1313 }
1314 if (((ass >> 16) & 0xf) != tmp)
1315 return 0;
1316do_sku:
1317 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1318 ass & 0xffff, codec->vendor_id);
1319 /*
1320 * 0 : override
1321 * 1 : Swap Jack
1322 * 2 : 0 --> Desktop, 1 --> Laptop
1323 * 3~5 : External Amplifier control
1324 * 7~6 : Reserved
1325 */
1326 tmp = (ass & 0x38) >> 3; /* external Amp control */
1327 switch (tmp) {
1328 case 1:
1329 spec->init_amp = ALC_INIT_GPIO1;
1330 break;
1331 case 3:
1332 spec->init_amp = ALC_INIT_GPIO2;
1333 break;
1334 case 7:
1335 spec->init_amp = ALC_INIT_GPIO3;
1336 break;
1337 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001338 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001339 spec->init_amp = ALC_INIT_DEFAULT;
1340 break;
1341 }
1342
1343 /* is laptop or Desktop and enable the function "Mute internal speaker
1344 * when the external headphone out jack is plugged"
1345 */
1346 if (!(ass & 0x8000))
1347 return 1;
1348 /*
1349 * 10~8 : Jack location
1350 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1351 * 14~13: Resvered
1352 * 15 : 1 --> enable the function "Mute internal speaker
1353 * when the external headphone out jack is plugged"
1354 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001355 if (!spec->autocfg.hp_pins[0] &&
1356 !(spec->autocfg.line_out_pins[0] &&
1357 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001358 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001359 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1360 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001361 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001362 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001363 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001364 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001365 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001366 else if (tmp == 3)
1367 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001368 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001369 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001370 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1371 spec->autocfg.line_outs))
1372 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001373 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001374 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001375 return 1;
1376}
Kailang Yangea1fb292008-08-26 12:58:38 +02001377
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001378/* Check the validity of ALC subsystem-id
1379 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1380static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001381{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001382 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001383 struct alc_spec *spec = codec->spec;
1384 snd_printd("realtek: "
1385 "Enable default setup for auto mode as fallback\n");
1386 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001387 }
Takashi Iwai21268962011-07-07 15:01:13 +02001388}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001389
Takashi Iwai41e41f12005-06-08 14:48:49 +02001390/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001391 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001392 */
1393
1394struct alc_pincfg {
1395 hda_nid_t nid;
1396 u32 val;
1397};
1398
Todd Broche1eb5f12010-12-06 11:19:51 -08001399struct alc_model_fixup {
1400 const int id;
1401 const char *name;
1402};
1403
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001404struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001405 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001406 bool chained;
1407 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001408 union {
1409 unsigned int sku;
1410 const struct alc_pincfg *pins;
1411 const struct hda_verb *verbs;
1412 void (*func)(struct hda_codec *codec,
1413 const struct alc_fixup *fix,
1414 int action);
1415 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001416};
1417
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001418enum {
1419 ALC_FIXUP_INVALID,
1420 ALC_FIXUP_SKU,
1421 ALC_FIXUP_PINS,
1422 ALC_FIXUP_VERBS,
1423 ALC_FIXUP_FUNC,
1424};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001425
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001426enum {
1427 ALC_FIXUP_ACT_PRE_PROBE,
1428 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001429 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001430};
1431
1432static void alc_apply_fixup(struct hda_codec *codec, int action)
1433{
1434 struct alc_spec *spec = codec->spec;
1435 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001436#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001437 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001438#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001439 int depth = 0;
1440
1441 if (!spec->fixup_list)
1442 return;
1443
1444 while (id >= 0) {
1445 const struct alc_fixup *fix = spec->fixup_list + id;
1446 const struct alc_pincfg *cfg;
1447
1448 switch (fix->type) {
1449 case ALC_FIXUP_SKU:
1450 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1451 break;;
1452 snd_printdd(KERN_INFO "hda_codec: %s: "
1453 "Apply sku override for %s\n",
1454 codec->chip_name, modelname);
1455 spec->cdefine.sku_cfg = fix->v.sku;
1456 spec->cdefine.fixup = 1;
1457 break;
1458 case ALC_FIXUP_PINS:
1459 cfg = fix->v.pins;
1460 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1461 break;
1462 snd_printdd(KERN_INFO "hda_codec: %s: "
1463 "Apply pincfg for %s\n",
1464 codec->chip_name, modelname);
1465 for (; cfg->nid; cfg++)
1466 snd_hda_codec_set_pincfg(codec, cfg->nid,
1467 cfg->val);
1468 break;
1469 case ALC_FIXUP_VERBS:
1470 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1471 break;
1472 snd_printdd(KERN_INFO "hda_codec: %s: "
1473 "Apply fix-verbs for %s\n",
1474 codec->chip_name, modelname);
1475 add_verb(codec->spec, fix->v.verbs);
1476 break;
1477 case ALC_FIXUP_FUNC:
1478 if (!fix->v.func)
1479 break;
1480 snd_printdd(KERN_INFO "hda_codec: %s: "
1481 "Apply fix-func for %s\n",
1482 codec->chip_name, modelname);
1483 fix->v.func(codec, fix, action);
1484 break;
1485 default:
1486 snd_printk(KERN_ERR "hda_codec: %s: "
1487 "Invalid fixup type %d\n",
1488 codec->chip_name, fix->type);
1489 break;
1490 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001491 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001492 break;
1493 if (++depth > 10)
1494 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001495 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001496 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001497}
1498
Todd Broche1eb5f12010-12-06 11:19:51 -08001499static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001500 const struct alc_model_fixup *models,
1501 const struct snd_pci_quirk *quirk,
1502 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001503{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001504 struct alc_spec *spec = codec->spec;
1505 int id = -1;
1506 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001507
Todd Broche1eb5f12010-12-06 11:19:51 -08001508 if (codec->modelname && models) {
1509 while (models->name) {
1510 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001511 id = models->id;
1512 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001513 break;
1514 }
1515 models++;
1516 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001517 }
1518 if (id < 0) {
1519 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1520 if (quirk) {
1521 id = quirk->value;
1522#ifdef CONFIG_SND_DEBUG_VERBOSE
1523 name = quirk->name;
1524#endif
1525 }
1526 }
1527
1528 spec->fixup_id = id;
1529 if (id >= 0) {
1530 spec->fixup_list = fixlist;
1531 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001532 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001533}
1534
Takashi Iwai1d045db2011-07-07 18:23:21 +02001535/*
1536 * COEF access helper functions
1537 */
Kailang Yang274693f2009-12-03 10:07:50 +01001538static int alc_read_coef_idx(struct hda_codec *codec,
1539 unsigned int coef_idx)
1540{
1541 unsigned int val;
1542 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1543 coef_idx);
1544 val = snd_hda_codec_read(codec, 0x20, 0,
1545 AC_VERB_GET_PROC_COEF, 0);
1546 return val;
1547}
1548
Kailang Yang977ddd62010-09-15 10:02:29 +02001549static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1550 unsigned int coef_val)
1551{
1552 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1553 coef_idx);
1554 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1555 coef_val);
1556}
1557
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001558/* a special bypass for COEF 0; read the cached value at the second time */
1559static unsigned int alc_get_coef0(struct hda_codec *codec)
1560{
1561 struct alc_spec *spec = codec->spec;
1562 if (!spec->coef0)
1563 spec->coef0 = alc_read_coef_idx(codec, 0);
1564 return spec->coef0;
1565}
1566
Takashi Iwai1d045db2011-07-07 18:23:21 +02001567/*
1568 * Digital I/O handling
1569 */
1570
Takashi Iwai757899a2010-07-30 10:48:14 +02001571/* set right pin controls for digital I/O */
1572static void alc_auto_init_digital(struct hda_codec *codec)
1573{
1574 struct alc_spec *spec = codec->spec;
1575 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001576 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001577
1578 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1579 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001580 if (!pin)
1581 continue;
1582 snd_hda_codec_write(codec, pin, 0,
1583 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1584 if (!i)
1585 dac = spec->multiout.dig_out_nid;
1586 else
1587 dac = spec->slave_dig_outs[i - 1];
1588 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1589 continue;
1590 snd_hda_codec_write(codec, dac, 0,
1591 AC_VERB_SET_AMP_GAIN_MUTE,
1592 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001593 }
1594 pin = spec->autocfg.dig_in_pin;
1595 if (pin)
1596 snd_hda_codec_write(codec, pin, 0,
1597 AC_VERB_SET_PIN_WIDGET_CONTROL,
1598 PIN_IN);
1599}
1600
1601/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1602static void alc_auto_parse_digital(struct hda_codec *codec)
1603{
1604 struct alc_spec *spec = codec->spec;
1605 int i, err;
1606 hda_nid_t dig_nid;
1607
1608 /* support multiple SPDIFs; the secondary is set up as a slave */
1609 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001610 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001611 err = snd_hda_get_connections(codec,
1612 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001613 conn, ARRAY_SIZE(conn));
Takashi Iwai757899a2010-07-30 10:48:14 +02001614 if (err < 0)
1615 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001616 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai757899a2010-07-30 10:48:14 +02001617 if (!i) {
1618 spec->multiout.dig_out_nid = dig_nid;
1619 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1620 } else {
1621 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1622 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1623 break;
1624 spec->slave_dig_outs[i - 1] = dig_nid;
1625 }
1626 }
1627
1628 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001629 dig_nid = codec->start_nid;
1630 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1631 unsigned int wcaps = get_wcaps(codec, dig_nid);
1632 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1633 continue;
1634 if (!(wcaps & AC_WCAP_DIGITAL))
1635 continue;
1636 if (!(wcaps & AC_WCAP_CONN_LIST))
1637 continue;
1638 err = get_connection_index(codec, dig_nid,
1639 spec->autocfg.dig_in_pin);
1640 if (err >= 0) {
1641 spec->dig_in_nid = dig_nid;
1642 break;
1643 }
1644 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001645 }
1646}
1647
Takashi Iwaif95474e2007-07-10 00:47:43 +02001648/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001649 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001650 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001651static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1652 struct snd_ctl_elem_info *uinfo)
1653{
1654 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1655 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001656 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001657 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001658
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001659 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001660 if (spec->vol_in_capsrc)
1661 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1662 else
1663 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1664 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001665 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001666 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001667 return err;
1668}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001670static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1671 unsigned int size, unsigned int __user *tlv)
1672{
1673 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1674 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001675 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001676 int err;
1677
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001678 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001679 if (spec->vol_in_capsrc)
1680 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1681 else
1682 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1683 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001684 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001685 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001686 return err;
1687}
1688
1689typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1690 struct snd_ctl_elem_value *ucontrol);
1691
1692static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1693 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001694 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001695{
1696 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1697 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001698 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001699
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001700 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001701 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001702 for (i = 0; i < spec->num_adc_nids; i++) {
1703 kcontrol->private_value =
1704 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1705 3, 0, HDA_INPUT);
1706 err = func(kcontrol, ucontrol);
1707 if (err < 0)
1708 goto error;
1709 }
1710 } else {
1711 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001712 if (spec->vol_in_capsrc)
1713 kcontrol->private_value =
1714 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1715 3, 0, HDA_OUTPUT);
1716 else
1717 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001718 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1719 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001720 err = func(kcontrol, ucontrol);
1721 }
1722 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001723 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001724 return err;
1725}
1726
1727static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1728 struct snd_ctl_elem_value *ucontrol)
1729{
1730 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001731 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001732}
1733
1734static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1735 struct snd_ctl_elem_value *ucontrol)
1736{
1737 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001738 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001739}
1740
1741/* capture mixer elements */
1742#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1743
1744static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1745 struct snd_ctl_elem_value *ucontrol)
1746{
1747 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001748 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001749}
1750
1751static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1752 struct snd_ctl_elem_value *ucontrol)
1753{
1754 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001755 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001756}
1757
Takashi Iwaia23b6882009-03-23 15:21:36 +01001758#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001759 { \
1760 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1761 .name = "Capture Switch", \
1762 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1763 .count = num, \
1764 .info = alc_cap_sw_info, \
1765 .get = alc_cap_sw_get, \
1766 .put = alc_cap_sw_put, \
1767 }, \
1768 { \
1769 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1770 .name = "Capture Volume", \
1771 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1772 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1773 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1774 .count = num, \
1775 .info = alc_cap_vol_info, \
1776 .get = alc_cap_vol_get, \
1777 .put = alc_cap_vol_put, \
1778 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001779 }
1780
1781#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001782 { \
1783 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1784 /* .name = "Capture Source", */ \
1785 .name = "Input Source", \
1786 .count = num, \
1787 .info = alc_mux_enum_info, \
1788 .get = alc_mux_enum_get, \
1789 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001790 }
1791
1792#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001793static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001794 _DEFINE_CAPMIX(num), \
1795 _DEFINE_CAPSRC(num), \
1796 { } /* end */ \
1797}
1798
1799#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001800static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001801 _DEFINE_CAPMIX(num), \
1802 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001803}
1804
1805/* up to three ADCs */
1806DEFINE_CAPMIX(1);
1807DEFINE_CAPMIX(2);
1808DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001809DEFINE_CAPMIX_NOSRC(1);
1810DEFINE_CAPMIX_NOSRC(2);
1811DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001812
1813/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001814 * virtual master controls
1815 */
1816
1817/*
1818 * slave controls for virtual master
1819 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001820static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001821 "Front Playback Volume",
1822 "Surround Playback Volume",
1823 "Center Playback Volume",
1824 "LFE Playback Volume",
1825 "Side Playback Volume",
1826 "Headphone Playback Volume",
1827 "Speaker Playback Volume",
1828 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001829 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001830 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001831 NULL,
1832};
1833
Takashi Iwaiea734962011-01-17 11:29:34 +01001834static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001835 "Front Playback Switch",
1836 "Surround Playback Switch",
1837 "Center Playback Switch",
1838 "LFE Playback Switch",
1839 "Side Playback Switch",
1840 "Headphone Playback Switch",
1841 "Speaker Playback Switch",
1842 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001843 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001844 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001845 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001846 NULL,
1847};
1848
1849/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001850 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001852
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001853#define NID_MAPPING (-1)
1854
1855#define SUBDEV_SPEAKER_ (0 << 6)
1856#define SUBDEV_HP_ (1 << 6)
1857#define SUBDEV_LINE_ (2 << 6)
1858#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1859#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1860#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1861
Takashi Iwai603c4012008-07-30 15:01:44 +02001862static void alc_free_kctls(struct hda_codec *codec);
1863
Takashi Iwai67d634c2009-11-16 15:35:59 +01001864#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001865/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001866static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001867 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001868 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001869 { } /* end */
1870};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001871#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001872
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873static int alc_build_controls(struct hda_codec *codec)
1874{
1875 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001876 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001877 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001878 int i, j, err;
1879 unsigned int u;
1880 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881
1882 for (i = 0; i < spec->num_mixers; i++) {
1883 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1884 if (err < 0)
1885 return err;
1886 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001887 if (spec->cap_mixer) {
1888 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1889 if (err < 0)
1890 return err;
1891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001893 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001894 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001895 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 if (err < 0)
1897 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001898 if (!spec->no_analog) {
1899 err = snd_hda_create_spdif_share_sw(codec,
1900 &spec->multiout);
1901 if (err < 0)
1902 return err;
1903 spec->multiout.share_spdif = 1;
1904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 }
1906 if (spec->dig_in_nid) {
1907 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1908 if (err < 0)
1909 return err;
1910 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001911
Takashi Iwai67d634c2009-11-16 15:35:59 +01001912#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001913 /* create beep controls if needed */
1914 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001915 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001916 for (knew = alc_beep_mixer; knew->name; knew++) {
1917 struct snd_kcontrol *kctl;
1918 kctl = snd_ctl_new1(knew, codec);
1919 if (!kctl)
1920 return -ENOMEM;
1921 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001922 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001923 if (err < 0)
1924 return err;
1925 }
1926 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001927#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001928
Takashi Iwai2134ea42008-01-10 16:53:55 +01001929 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001930 if (!spec->no_analog &&
1931 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001932 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001933 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001934 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001935 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001936 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001937 if (err < 0)
1938 return err;
1939 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001940 if (!spec->no_analog &&
1941 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001942 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1943 NULL, alc_slave_sws);
1944 if (err < 0)
1945 return err;
1946 }
1947
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001948 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001949 if (spec->capsrc_nids || spec->adc_nids) {
1950 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1951 if (!kctl)
1952 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1953 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02001954 const hda_nid_t *nids = spec->capsrc_nids;
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001955 if (!nids)
1956 nids = spec->adc_nids;
1957 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1958 if (err < 0)
1959 return err;
1960 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001961 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001962 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001963 const char *kname = kctl ? kctl->id.name : NULL;
1964 for (knew = spec->cap_mixer; knew->name; knew++) {
1965 if (kname && strcmp(knew->name, kname) == 0)
1966 continue;
1967 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1968 for (i = 0; kctl && i < kctl->count; i++) {
1969 err = snd_hda_add_nid(codec, kctl, i,
1970 spec->adc_nids[i]);
1971 if (err < 0)
1972 return err;
1973 }
1974 }
1975 }
1976
1977 /* other nid->control mapping */
1978 for (i = 0; i < spec->num_mixers; i++) {
1979 for (knew = spec->mixers[i]; knew->name; knew++) {
1980 if (knew->iface != NID_MAPPING)
1981 continue;
1982 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1983 if (kctl == NULL)
1984 continue;
1985 u = knew->subdevice;
1986 for (j = 0; j < 4; j++, u >>= 8) {
1987 nid = u & 0x3f;
1988 if (nid == 0)
1989 continue;
1990 switch (u & 0xc0) {
1991 case SUBDEV_SPEAKER_:
1992 nid = spec->autocfg.speaker_pins[nid];
1993 break;
1994 case SUBDEV_LINE_:
1995 nid = spec->autocfg.line_out_pins[nid];
1996 break;
1997 case SUBDEV_HP_:
1998 nid = spec->autocfg.hp_pins[nid];
1999 break;
2000 default:
2001 continue;
2002 }
2003 err = snd_hda_add_nid(codec, kctl, 0, nid);
2004 if (err < 0)
2005 return err;
2006 }
2007 u = knew->private_value;
2008 for (j = 0; j < 4; j++, u >>= 8) {
2009 nid = u & 0xff;
2010 if (nid == 0)
2011 continue;
2012 err = snd_hda_add_nid(codec, kctl, 0, nid);
2013 if (err < 0)
2014 return err;
2015 }
2016 }
2017 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002018
2019 alc_free_kctls(codec); /* no longer needed */
2020
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 return 0;
2022}
2023
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002024
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002026 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002027 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002028
Takashi Iwai584c0c42011-03-10 12:51:11 +01002029static void alc_init_special_input_src(struct hda_codec *codec);
2030
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031static int alc_init(struct hda_codec *codec)
2032{
2033 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002034 unsigned int i;
2035
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002036 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002037 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002038
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002039 for (i = 0; i < spec->num_init_verbs; i++)
2040 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002041 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002042
2043 if (spec->init_hook)
2044 spec->init_hook(codec);
2045
Takashi Iwai58701122011-01-13 15:41:45 +01002046 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2047
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002048 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 return 0;
2050}
2051
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002052static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2053{
2054 struct alc_spec *spec = codec->spec;
2055
2056 if (spec->unsol_event)
2057 spec->unsol_event(codec, res);
2058}
2059
Takashi Iwaicb53c622007-08-10 17:21:45 +02002060#ifdef CONFIG_SND_HDA_POWER_SAVE
2061static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2062{
2063 struct alc_spec *spec = codec->spec;
2064 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2065}
2066#endif
2067
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068/*
2069 * Analog playback callbacks
2070 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002071static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002073 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074{
2075 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002076 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2077 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078}
2079
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002080static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 struct hda_codec *codec,
2082 unsigned int stream_tag,
2083 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002084 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
2086 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002087 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2088 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089}
2090
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002091static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002093 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094{
2095 struct alc_spec *spec = codec->spec;
2096 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2097}
2098
2099/*
2100 * Digital out
2101 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002102static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002104 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105{
2106 struct alc_spec *spec = codec->spec;
2107 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2108}
2109
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002110static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002111 struct hda_codec *codec,
2112 unsigned int stream_tag,
2113 unsigned int format,
2114 struct snd_pcm_substream *substream)
2115{
2116 struct alc_spec *spec = codec->spec;
2117 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2118 stream_tag, format, substream);
2119}
2120
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002121static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002122 struct hda_codec *codec,
2123 struct snd_pcm_substream *substream)
2124{
2125 struct alc_spec *spec = codec->spec;
2126 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2127}
2128
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002129static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002131 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
2133 struct alc_spec *spec = codec->spec;
2134 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2135}
2136
2137/*
2138 * Analog capture
2139 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002140static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 struct hda_codec *codec,
2142 unsigned int stream_tag,
2143 unsigned int format,
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
Takashi Iwai63300792008-01-24 15:31:36 +01002148 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 stream_tag, 0, format);
2150 return 0;
2151}
2152
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002153static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002155 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
2157 struct alc_spec *spec = codec->spec;
2158
Takashi Iwai888afa12008-03-18 09:57:50 +01002159 snd_hda_codec_cleanup_stream(codec,
2160 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 return 0;
2162}
2163
Takashi Iwai840b64c2010-07-13 22:49:01 +02002164/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002165static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002166 struct hda_codec *codec,
2167 unsigned int stream_tag,
2168 unsigned int format,
2169 struct snd_pcm_substream *substream)
2170{
2171 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002172 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002173 spec->cur_adc_stream_tag = stream_tag;
2174 spec->cur_adc_format = format;
2175 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2176 return 0;
2177}
2178
Takashi Iwai21268962011-07-07 15:01:13 +02002179static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002180 struct hda_codec *codec,
2181 struct snd_pcm_substream *substream)
2182{
2183 struct alc_spec *spec = codec->spec;
2184 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2185 spec->cur_adc = 0;
2186 return 0;
2187}
2188
Takashi Iwai21268962011-07-07 15:01:13 +02002189static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002190 .substreams = 1,
2191 .channels_min = 2,
2192 .channels_max = 2,
2193 .nid = 0, /* fill later */
2194 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002195 .prepare = dyn_adc_capture_pcm_prepare,
2196 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002197 },
2198};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
2200/*
2201 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002202static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 .substreams = 1,
2204 .channels_min = 2,
2205 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002206 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002208 .open = alc_playback_pcm_open,
2209 .prepare = alc_playback_pcm_prepare,
2210 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 },
2212};
2213
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002214static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002215 .substreams = 1,
2216 .channels_min = 2,
2217 .channels_max = 2,
2218 /* NID is set in alc_build_pcms */
2219};
2220
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002221static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002222 .substreams = 1,
2223 .channels_min = 2,
2224 .channels_max = 2,
2225 /* NID is set in alc_build_pcms */
2226};
2227
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002228static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002229 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 .channels_min = 2,
2231 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002232 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002234 .prepare = alc_alt_capture_pcm_prepare,
2235 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 },
2237};
2238
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002239static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 .substreams = 1,
2241 .channels_min = 2,
2242 .channels_max = 2,
2243 /* NID is set in alc_build_pcms */
2244 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002245 .open = alc_dig_playback_pcm_open,
2246 .close = alc_dig_playback_pcm_close,
2247 .prepare = alc_dig_playback_pcm_prepare,
2248 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 },
2250};
2251
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002252static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 .substreams = 1,
2254 .channels_min = 2,
2255 .channels_max = 2,
2256 /* NID is set in alc_build_pcms */
2257};
2258
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002259/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002260static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002261 .substreams = 0,
2262 .channels_min = 0,
2263 .channels_max = 0,
2264};
2265
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266static int alc_build_pcms(struct hda_codec *codec)
2267{
2268 struct alc_spec *spec = codec->spec;
2269 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002270 const struct hda_pcm_stream *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 int i;
2272
2273 codec->num_pcms = 1;
2274 codec->pcm_info = info;
2275
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002276 if (spec->no_analog)
2277 goto skip_analog;
2278
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002279 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2280 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002282
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002283 if (spec->multiout.dac_nids > 0) {
2284 p = spec->stream_analog_playback;
2285 if (!p)
2286 p = &alc_pcm_analog_playback;
2287 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002288 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2289 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002290 if (spec->adc_nids) {
2291 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002292 if (!p) {
2293 if (spec->dyn_adc_switch)
2294 p = &dyn_adc_pcm_analog_capture;
2295 else
2296 p = &alc_pcm_analog_capture;
2297 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002298 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002299 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301
Takashi Iwai4a471b72005-12-07 13:56:29 +01002302 if (spec->channel_mode) {
2303 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2304 for (i = 0; i < spec->num_channel_mode; i++) {
2305 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2306 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2307 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 }
2309 }
2310
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002311 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002312 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002314 snprintf(spec->stream_name_digital,
2315 sizeof(spec->stream_name_digital),
2316 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002317 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002318 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002319 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002320 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002321 if (spec->dig_out_type)
2322 info->pcm_type = spec->dig_out_type;
2323 else
2324 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002325 if (spec->multiout.dig_out_nid) {
2326 p = spec->stream_digital_playback;
2327 if (!p)
2328 p = &alc_pcm_digital_playback;
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2331 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002332 if (spec->dig_in_nid) {
2333 p = spec->stream_digital_capture;
2334 if (!p)
2335 p = &alc_pcm_digital_capture;
2336 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2338 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002339 /* FIXME: do we need this for all Realtek codec models? */
2340 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002341 }
2342
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002343 if (spec->no_analog)
2344 return 0;
2345
Takashi Iwaie08a0072006-09-07 17:52:14 +02002346 /* If the use of more than one ADC is requested for the current
2347 * model, configure a second analog capture-only PCM.
2348 */
2349 /* Additional Analaog capture for index #2 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002350 if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002351 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002352 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002353 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002354 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002355 p = spec->stream_analog_alt_playback;
2356 if (!p)
2357 p = &alc_pcm_analog_alt_playback;
2358 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002359 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2360 spec->alt_dac_nid;
2361 } else {
2362 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2363 alc_pcm_null_stream;
2364 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2365 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002366 if (spec->num_adc_nids > 1) {
2367 p = spec->stream_analog_alt_capture;
2368 if (!p)
2369 p = &alc_pcm_analog_alt_capture;
2370 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002371 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2372 spec->adc_nids[1];
2373 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2374 spec->num_adc_nids - 1;
2375 } else {
2376 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2377 alc_pcm_null_stream;
2378 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002379 }
2380 }
2381
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 return 0;
2383}
2384
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002385static inline void alc_shutup(struct hda_codec *codec)
2386{
Takashi Iwai1c716152011-04-07 10:37:16 +02002387 struct alc_spec *spec = codec->spec;
2388
2389 if (spec && spec->shutup)
2390 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002391 snd_hda_shutup_pins(codec);
2392}
2393
Takashi Iwai603c4012008-07-30 15:01:44 +02002394static void alc_free_kctls(struct hda_codec *codec)
2395{
2396 struct alc_spec *spec = codec->spec;
2397
2398 if (spec->kctls.list) {
2399 struct snd_kcontrol_new *kctl = spec->kctls.list;
2400 int i;
2401 for (i = 0; i < spec->kctls.used; i++)
2402 kfree(kctl[i].name);
2403 }
2404 snd_array_free(&spec->kctls);
2405}
2406
Takashi Iwai23c09b02011-08-19 09:05:35 +02002407static void alc_free_bind_ctls(struct hda_codec *codec)
2408{
2409 struct alc_spec *spec = codec->spec;
2410 if (spec->bind_ctls.list) {
2411 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2412 int i;
2413 for (i = 0; i < spec->bind_ctls.used; i++)
2414 kfree(ctl[i]);
2415 }
2416 snd_array_free(&spec->bind_ctls);
2417}
2418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419static void alc_free(struct hda_codec *codec)
2420{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002421 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002422
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002423 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002424 return;
2425
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002426 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002427 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002428 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002429 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002430 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002431 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432}
2433
Hector Martinf5de24b2009-12-20 22:51:31 +01002434#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002435static void alc_power_eapd(struct hda_codec *codec)
2436{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002437 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002438}
2439
Hector Martinf5de24b2009-12-20 22:51:31 +01002440static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2441{
2442 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002443 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002444 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002445 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002446 return 0;
2447}
2448#endif
2449
Takashi Iwai2a439522011-07-26 09:52:50 +02002450#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002451static int alc_resume(struct hda_codec *codec)
2452{
Takashi Iwai1c716152011-04-07 10:37:16 +02002453 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002454 codec->patch_ops.init(codec);
2455 snd_hda_codec_resume_amp(codec);
2456 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002457 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002458 return 0;
2459}
Takashi Iwaie044c392008-10-27 16:56:24 +01002460#endif
2461
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462/*
2463 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002464static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 .build_controls = alc_build_controls,
2466 .build_pcms = alc_build_pcms,
2467 .init = alc_init,
2468 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002469 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002470#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002471 .resume = alc_resume,
2472#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002473#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002474 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002475 .check_power_status = alc_check_power_status,
2476#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002477 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478};
2479
Kailang Yangc027ddc2010-03-19 11:33:06 +01002480/* replace the codec chip_name with the given string */
2481static int alc_codec_rename(struct hda_codec *codec, const char *name)
2482{
2483 kfree(codec->chip_name);
2484 codec->chip_name = kstrdup(name, GFP_KERNEL);
2485 if (!codec->chip_name) {
2486 alc_free(codec);
2487 return -ENOMEM;
2488 }
2489 return 0;
2490}
2491
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002492/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002493 * Rename codecs appropriately from COEF value
2494 */
2495struct alc_codec_rename_table {
2496 unsigned int vendor_id;
2497 unsigned short coef_mask;
2498 unsigned short coef_bits;
2499 const char *name;
2500};
2501
2502static struct alc_codec_rename_table rename_tbl[] = {
2503 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2504 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2505 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2506 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2507 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2508 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2509 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2510 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2511 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2512 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2513 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2514 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2515 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2516 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2517 { } /* terminator */
2518};
2519
2520static int alc_codec_rename_from_preset(struct hda_codec *codec)
2521{
2522 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002523
2524 for (p = rename_tbl; p->vendor_id; p++) {
2525 if (p->vendor_id != codec->vendor_id)
2526 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002527 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002528 return alc_codec_rename(codec, p->name);
2529 }
2530 return 0;
2531}
2532
2533/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002534 * Automatic parse of I/O pins from the BIOS configuration
2535 */
2536
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002537enum {
2538 ALC_CTL_WIDGET_VOL,
2539 ALC_CTL_WIDGET_MUTE,
2540 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002541 ALC_CTL_BIND_VOL,
2542 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002543};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002544static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002545 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2546 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002547 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002548 HDA_BIND_VOL(NULL, 0),
2549 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002550};
2551
2552/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002553static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002554 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002555{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002556 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002557
Takashi Iwaice764ab2011-04-27 16:35:23 +02002558 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002559 if (!knew)
2560 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002561 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002562 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002563 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002564 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002565 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002566 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002567 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002568 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002569 return 0;
2570}
2571
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002572static int add_control_with_pfx(struct alc_spec *spec, int type,
2573 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002574 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002575{
2576 char name[32];
2577 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002578 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002579}
2580
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002581#define add_pb_vol_ctrl(spec, type, pfx, val) \
2582 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2583#define add_pb_sw_ctrl(spec, type, pfx, val) \
2584 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2585#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2586 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2587#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2588 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002589
Takashi Iwai23c09b02011-08-19 09:05:35 +02002590static const char * const channel_name[4] = {
2591 "Front", "Surround", "CLFE", "Side"
2592};
2593
Takashi Iwai6843ca12011-06-24 11:03:58 +02002594static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2595 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002596{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002597 struct auto_pin_cfg *cfg = &spec->autocfg;
2598
Takashi Iwai6843ca12011-06-24 11:03:58 +02002599 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002600 if (cfg->line_outs == 1 && !spec->multi_ios &&
2601 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002602 return "Master";
2603
2604 switch (cfg->line_out_type) {
2605 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002606 if (cfg->line_outs == 1)
2607 return "Speaker";
2608 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002609 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002610 /* for multi-io case, only the primary out */
2611 if (ch && spec->multi_ios)
2612 break;
2613 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002614 return "Headphone";
2615 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002616 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002617 return "PCM";
2618 break;
2619 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002620 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2621 return "PCM";
2622
2623 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002624}
2625
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002626/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002627static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002628 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002629 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002630{
Kailang Yangdf694da2005-12-05 19:42:22 +01002631 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002632
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002633 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002634 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2635 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002636 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002637 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002638 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2639 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002640 return err;
2641 return 0;
2642}
2643
Takashi Iwai05f5f472009-08-25 13:10:18 +02002644static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002645{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002646 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2647 return (pincap & AC_PINCAP_IN) != 0;
2648}
2649
Takashi Iwai1d045db2011-07-07 18:23:21 +02002650/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002651static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002652{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002653 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002654 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002655 hda_nid_t *adc_nids = spec->private_adc_nids;
2656 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2657 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2658 bool indep_capsrc = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002659 int i, nums = 0;
2660
2661 nid = codec->start_nid;
2662 for (i = 0; i < codec->num_nodes; i++, nid++) {
2663 hda_nid_t src;
2664 const hda_nid_t *list;
2665 unsigned int caps = get_wcaps(codec, nid);
2666 int type = get_wcaps_type(caps);
2667
2668 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2669 continue;
2670 adc_nids[nums] = nid;
2671 cap_nids[nums] = nid;
2672 src = nid;
2673 for (;;) {
2674 int n;
2675 type = get_wcaps_type(get_wcaps(codec, src));
2676 if (type == AC_WID_PIN)
2677 break;
2678 if (type == AC_WID_AUD_SEL) {
2679 cap_nids[nums] = src;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002680 indep_capsrc = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002681 break;
2682 }
2683 n = snd_hda_get_conn_list(codec, src, &list);
2684 if (n > 1) {
2685 cap_nids[nums] = src;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002686 indep_capsrc = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002687 break;
2688 } else if (n != 1)
2689 break;
2690 src = *list;
2691 }
2692 if (++nums >= max_nums)
2693 break;
2694 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002695 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002696 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002697 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002698 return nums;
2699}
2700
Takashi Iwai05f5f472009-08-25 13:10:18 +02002701/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002702static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002703{
2704 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002705 const struct auto_pin_cfg *cfg = &spec->autocfg;
2706 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002707 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002708 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002709 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002710 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002711
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002712 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002713 if (num_adcs < 0)
2714 return 0;
2715
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002716 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002717 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002718 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002719
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002720 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002721 if (!alc_is_input_pin(codec, pin))
2722 continue;
2723
David Henningsson5322bf22011-01-05 11:03:56 +01002724 label = hda_get_autocfg_input_label(codec, cfg, i);
2725 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002726 type_idx++;
2727 else
2728 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002729 prev_label = label;
2730
Takashi Iwai05f5f472009-08-25 13:10:18 +02002731 if (mixer) {
2732 idx = get_connection_index(codec, mixer, pin);
2733 if (idx >= 0) {
2734 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002735 label, type_idx,
2736 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002737 if (err < 0)
2738 return err;
2739 }
2740 }
2741
Takashi Iwaib7821702011-07-06 15:12:46 +02002742 for (c = 0; c < num_adcs; c++) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002743 hda_nid_t cap = spec->capsrc_nids ?
2744 spec->capsrc_nids[c] : spec->adc_nids[c];
2745 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002746 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002747 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002748 snd_hda_add_imux_item(imux, label, idx, NULL);
2749 break;
2750 }
2751 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002752 }
Takashi Iwai21268962011-07-07 15:01:13 +02002753
2754 spec->num_mux_defs = 1;
2755 spec->input_mux = imux;
2756
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002757 return 0;
2758}
2759
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002760static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2761 unsigned int pin_type)
2762{
2763 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2764 pin_type);
2765 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002766 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2767 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002768 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002769}
2770
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002771static int get_pin_type(int line_out_type)
2772{
2773 if (line_out_type == AUTO_PIN_HP_OUT)
2774 return PIN_HP;
2775 else
2776 return PIN_OUT;
2777}
2778
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002779static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002780{
2781 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002782 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002783 int i;
2784
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002785 for (i = 0; i < cfg->num_inputs; i++) {
2786 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002787 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002788 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002789 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002790 snd_hda_codec_write(codec, nid, 0,
2791 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002792 AMP_OUT_MUTE);
2793 }
2794 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002795
2796 /* mute all loopback inputs */
2797 if (spec->mixer_nid) {
2798 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2799 for (i = 0; i < nums; i++)
2800 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2801 AC_VERB_SET_AMP_GAIN_MUTE,
2802 AMP_IN_MUTE(i));
2803 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002804}
2805
Takashi Iwai7085ec12009-10-02 09:03:58 +02002806/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002807static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002808{
Takashi Iwai604401a2011-04-27 15:14:23 +02002809 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002810 int i, num;
2811
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002812 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2813 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002814 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2815 for (i = 0; i < num; i++) {
2816 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2817 return list[i];
2818 }
2819 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002820}
2821
Takashi Iwai604401a2011-04-27 15:14:23 +02002822/* go down to the selector widget before the mixer */
2823static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2824{
2825 hda_nid_t srcs[5];
2826 int num = snd_hda_get_connections(codec, pin, srcs,
2827 ARRAY_SIZE(srcs));
2828 if (num != 1 ||
2829 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2830 return pin;
2831 return srcs[0];
2832}
2833
Takashi Iwai7085ec12009-10-02 09:03:58 +02002834/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002835static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002836 hda_nid_t dac)
2837{
David Henningssoncc1c4522010-11-24 14:17:47 +01002838 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002839 int i, num;
2840
Takashi Iwai604401a2011-04-27 15:14:23 +02002841 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002842 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2843 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002844 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002845 return mix[i];
2846 }
2847 return 0;
2848}
2849
Takashi Iwaice764ab2011-04-27 16:35:23 +02002850/* select the connection from pin to DAC if needed */
2851static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2852 hda_nid_t dac)
2853{
2854 hda_nid_t mix[5];
2855 int i, num;
2856
2857 pin = alc_go_down_to_selector(codec, pin);
2858 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2859 if (num < 2)
2860 return 0;
2861 for (i = 0; i < num; i++) {
2862 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2863 snd_hda_codec_update_cache(codec, pin, 0,
2864 AC_VERB_SET_CONNECT_SEL, i);
2865 return 0;
2866 }
2867 }
2868 return 0;
2869}
2870
Takashi Iwai7085ec12009-10-02 09:03:58 +02002871/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002872static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002873{
2874 struct alc_spec *spec = codec->spec;
2875 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002876 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002877
Takashi Iwai604401a2011-04-27 15:14:23 +02002878 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002879 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002880 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002881 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002882 if (!nid)
2883 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002884 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2885 spec->multiout.num_dacs))
2886 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002887 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2888 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2889 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002890 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2891 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2892 continue;
2893 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002894 }
2895 return 0;
2896}
2897
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002898static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2899{
2900 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2901 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2902 return alc_auto_look_for_dac(codec, pin);
2903 return 0;
2904}
2905
Takashi Iwaic2674682011-08-24 17:57:44 +02002906static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2907 const hda_nid_t *pins, hda_nid_t *dacs)
2908{
2909 int i;
2910
2911 if (num_outs && !dacs[0]) {
2912 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2913 if (!dacs[0])
2914 return 0;
2915 }
2916
2917 for (i = 1; i < num_outs; i++)
2918 dacs[i] = get_dac_if_single(codec, pins[i]);
2919 for (i = 1; i < num_outs; i++) {
2920 if (!dacs[i])
2921 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2922 }
2923 return 0;
2924}
2925
2926static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2927 unsigned int location);
2928
Takashi Iwai7085ec12009-10-02 09:03:58 +02002929/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02002930static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002931{
2932 struct alc_spec *spec = codec->spec;
Takashi Iwaicb053a82011-06-27 11:32:07 +02002933 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai350434e2011-06-30 21:29:12 +02002934 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002935 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002936
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002937 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002938 /* set num_dacs once to full for alc_auto_look_for_dac() */
2939 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02002940 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002941 spec->multiout.extra_out_nid[0] = 0;
2942 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2943 spec->multiout.dac_nids = spec->private_dac_nids;
2944
2945 /* fill hard-wired DACs first */
2946 if (!redone) {
2947 for (i = 0; i < cfg->line_outs; i++)
2948 spec->private_dac_nids[i] =
2949 get_dac_if_single(codec, cfg->line_out_pins[i]);
2950 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02002951 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002952 get_dac_if_single(codec, cfg->hp_pins[0]);
2953 if (cfg->speaker_outs)
2954 spec->multiout.extra_out_nid[0] =
2955 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002956 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002957
2958 for (i = 0; i < cfg->line_outs; i++) {
2959 hda_nid_t pin = cfg->line_out_pins[i];
2960 if (spec->private_dac_nids[i])
2961 continue;
2962 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2963 if (!spec->private_dac_nids[i] && !redone) {
2964 /* if we can't find primary DACs, re-probe without
2965 * checking the hard-wired DACs
2966 */
2967 redone = true;
2968 goto again;
2969 }
2970 }
2971
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002972 /* re-count num_dacs and squash invalid entries */
2973 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002974 for (i = 0; i < cfg->line_outs; i++) {
2975 if (spec->private_dac_nids[i])
2976 spec->multiout.num_dacs++;
2977 else
2978 memmove(spec->private_dac_nids + i,
2979 spec->private_dac_nids + i + 1,
2980 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2981 }
2982
Takashi Iwaic2674682011-08-24 17:57:44 +02002983 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
2984 /* try to fill multi-io first */
2985 unsigned int location, defcfg;
2986 int num_pins;
Takashi Iwaibb8bf4d2011-07-06 13:07:54 +02002987
Takashi Iwaic2674682011-08-24 17:57:44 +02002988 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
2989 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002990
Takashi Iwaic2674682011-08-24 17:57:44 +02002991 num_pins = alc_auto_fill_multi_ios(codec, location);
2992 if (num_pins > 0) {
2993 spec->multi_ios = num_pins;
2994 spec->ext_channel_count = 2;
2995 spec->multiout.num_dacs = num_pins + 1;
2996 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002997 }
Takashi Iwaic2674682011-08-24 17:57:44 +02002998
2999 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3000 spec->multiout.hp_out_nid);
3001 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
3002 spec->multiout.extra_out_nid);
3003
Takashi Iwai23c09b02011-08-19 09:05:35 +02003004 return 0;
3005}
3006
Takashi Iwai343a04b2011-07-06 14:28:39 +02003007static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003008 const char *pfx, int cidx,
3009 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003010{
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003011 if (!nid)
3012 return 0;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003013 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
3014 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003015}
3016
Takashi Iwai343a04b2011-07-06 14:28:39 +02003017#define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
3018 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai97aaab72011-07-06 14:02:55 +02003019
3020/* create a mute-switch for the given mixer widget;
3021 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3022 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003023static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003024 const char *pfx, int cidx,
3025 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003026{
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003027 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003028 int type;
3029 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003030 if (!nid)
3031 return 0;
3032 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3033 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3034 type = ALC_CTL_WIDGET_MUTE;
3035 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3036 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003037 type = ALC_CTL_WIDGET_MUTE;
3038 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3039 } else {
3040 type = ALC_CTL_BIND_MUTE;
3041 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3042 }
3043 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003044}
3045
Takashi Iwai343a04b2011-07-06 14:28:39 +02003046#define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
3047 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003048
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003049static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3050 hda_nid_t pin, hda_nid_t dac)
3051{
3052 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3053 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3054 return pin;
3055 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3056 return mix;
3057 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3058 return dac;
3059 return 0;
3060}
3061
3062static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3063 hda_nid_t pin, hda_nid_t dac)
3064{
3065 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3066 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3067 return dac;
3068 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3069 return mix;
3070 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3071 return pin;
3072 return 0;
3073}
3074
Takashi Iwai7085ec12009-10-02 09:03:58 +02003075/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003076static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003077 const struct auto_pin_cfg *cfg)
3078{
3079 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003080 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003081
Takashi Iwaice764ab2011-04-27 16:35:23 +02003082 noutputs = cfg->line_outs;
3083 if (spec->multi_ios > 0)
3084 noutputs += spec->multi_ios;
3085
3086 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003087 const char *name;
3088 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003089 hda_nid_t dac, pin;
3090 hda_nid_t sw, vol;
3091
3092 dac = spec->multiout.dac_nids[i];
3093 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003094 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003095 if (i >= cfg->line_outs)
3096 pin = spec->multi_io[i - 1].pin;
3097 else
3098 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003099
3100 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3101 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003102 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003103 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003104 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003105 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003106 if (err < 0)
3107 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003108 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003109 if (err < 0)
3110 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003111 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003112 if (err < 0)
3113 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003114 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003115 if (err < 0)
3116 return err;
3117 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003118 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003119 if (err < 0)
3120 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003121 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003122 if (err < 0)
3123 return err;
3124 }
3125 }
3126 return 0;
3127}
3128
Takashi Iwai343a04b2011-07-06 14:28:39 +02003129static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai23c09b02011-08-19 09:05:35 +02003130 hda_nid_t dac, const char *pfx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003131{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003132 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003133 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003134 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003135
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003136 if (!dac) {
Takashi Iwai7085ec12009-10-02 09:03:58 +02003137 /* the corresponding DAC is already occupied */
3138 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3139 return 0; /* no way */
3140 /* create a switch only */
Takashi Iwai0afe5f82009-10-02 09:20:00 +02003141 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003142 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3143 }
3144
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003145 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3146 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3147 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003148 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003149 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003150 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003151 if (err < 0)
3152 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003153 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003154}
3155
Takashi Iwai23c09b02011-08-19 09:05:35 +02003156static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3157 unsigned int nums,
3158 struct hda_ctl_ops *ops)
3159{
3160 struct alc_spec *spec = codec->spec;
3161 struct hda_bind_ctls **ctlp, *ctl;
3162 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3163 ctlp = snd_array_new(&spec->bind_ctls);
3164 if (!ctlp)
3165 return NULL;
3166 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3167 *ctlp = ctl;
3168 if (ctl)
3169 ctl->ops = ops;
3170 return ctl;
3171}
3172
3173/* add playback controls for speaker and HP outputs */
3174static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3175 const hda_nid_t *pins,
3176 const hda_nid_t *dacs,
3177 const char *pfx)
3178{
3179 struct alc_spec *spec = codec->spec;
3180 struct hda_bind_ctls *ctl;
3181 char name[32];
3182 int i, n, err;
3183
3184 if (!num_pins || !pins[0])
3185 return 0;
3186
3187 if (num_pins == 1)
3188 return alc_auto_create_extra_out(codec, *pins, *dacs, pfx);
3189
3190 if (dacs[num_pins - 1]) {
3191 /* OK, we have a multi-output system with individual volumes */
3192 for (i = 0; i < num_pins; i++) {
3193 snprintf(name, sizeof(name), "%s %s",
3194 pfx, channel_name[i]);
3195 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3196 name);
3197 if (err < 0)
3198 return err;
3199 }
3200 return 0;
3201 }
3202
3203 /* Let's create a bind-controls */
3204 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3205 if (!ctl)
3206 return -ENOMEM;
3207 n = 0;
3208 for (i = 0; i < num_pins; i++) {
3209 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3210 ctl->values[n++] =
3211 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3212 }
3213 if (n) {
3214 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3215 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3216 if (err < 0)
3217 return err;
3218 }
3219
3220 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3221 if (!ctl)
3222 return -ENOMEM;
3223 n = 0;
3224 for (i = 0; i < num_pins; i++) {
3225 hda_nid_t vol;
3226 if (!pins[i] || !dacs[i])
3227 continue;
3228 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3229 if (vol)
3230 ctl->values[n++] =
3231 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3232 }
3233 if (n) {
3234 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3235 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3236 if (err < 0)
3237 return err;
3238 }
3239 return 0;
3240}
3241
Takashi Iwai343a04b2011-07-06 14:28:39 +02003242static int alc_auto_create_hp_out(struct hda_codec *codec)
3243{
3244 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003245 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3246 spec->autocfg.hp_pins,
3247 spec->multiout.hp_out_nid,
3248 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003249}
3250
3251static int alc_auto_create_speaker_out(struct hda_codec *codec)
3252{
3253 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003254 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3255 spec->autocfg.speaker_pins,
3256 spec->multiout.extra_out_nid,
3257 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003258}
3259
Takashi Iwai343a04b2011-07-06 14:28:39 +02003260static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003261 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003262 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003263{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003264 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003265 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003266 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003267
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003268 alc_set_pin_output(codec, pin, pin_type);
3269 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003270 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003271 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003272 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003273 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003274 mix = srcs[i];
3275 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003276 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003277 if (!mix)
3278 return;
3279
3280 /* need the manual connection? */
3281 if (num > 1)
3282 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3283 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003284 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3285 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003286 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003287 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003288 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003289 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003290 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003291 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3292 if (nid)
3293 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3294 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003295}
3296
Takashi Iwai343a04b2011-07-06 14:28:39 +02003297static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003298{
3299 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003300 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003301 int i;
3302
3303 for (i = 0; i <= HDA_SIDE; i++) {
3304 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3305 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003306 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003307 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003308 }
3309}
3310
Takashi Iwai343a04b2011-07-06 14:28:39 +02003311static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003312{
3313 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003314 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003315 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003316
David Henningsson636030e2011-10-12 19:26:03 +02003317 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwaie23832a2011-08-23 18:16:56 +02003318 pin = spec->autocfg.hp_pins[i];
3319 if (!pin)
3320 break;
3321 dac = spec->multiout.hp_out_nid[i];
3322 if (!dac) {
3323 if (i > 0 && spec->multiout.hp_out_nid[0])
3324 dac = spec->multiout.hp_out_nid[0];
3325 else
3326 dac = spec->multiout.dac_nids[0];
3327 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003328 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3329 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003330 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3331 pin = spec->autocfg.speaker_pins[i];
3332 if (!pin)
3333 break;
3334 dac = spec->multiout.extra_out_nid[i];
3335 if (!dac) {
3336 if (i > 0 && spec->multiout.extra_out_nid[0])
3337 dac = spec->multiout.extra_out_nid[0];
3338 else
3339 dac = spec->multiout.dac_nids[0];
3340 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003341 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3342 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003343}
3344
Takashi Iwaice764ab2011-04-27 16:35:23 +02003345/*
3346 * multi-io helper
3347 */
3348static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3349 unsigned int location)
3350{
3351 struct alc_spec *spec = codec->spec;
3352 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003353 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwaice764ab2011-04-27 16:35:23 +02003354 int type, i, num_pins = 0;
3355
3356 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3357 for (i = 0; i < cfg->num_inputs; i++) {
3358 hda_nid_t nid = cfg->inputs[i].pin;
3359 hda_nid_t dac;
3360 unsigned int defcfg, caps;
3361 if (cfg->inputs[i].type != type)
3362 continue;
3363 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3364 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3365 continue;
3366 if (location && get_defcfg_location(defcfg) != location)
3367 continue;
3368 caps = snd_hda_query_pin_caps(codec, nid);
3369 if (!(caps & AC_PINCAP_OUT))
3370 continue;
3371 dac = alc_auto_look_for_dac(codec, nid);
3372 if (!dac)
3373 continue;
3374 spec->multi_io[num_pins].pin = nid;
3375 spec->multi_io[num_pins].dac = dac;
3376 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003377 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003378 }
3379 }
3380 spec->multiout.num_dacs = 1;
Takashi Iwaic2674682011-08-24 17:57:44 +02003381 if (num_pins < 2) {
3382 /* clear up again */
3383 memset(spec->private_dac_nids, 0,
3384 sizeof(spec->private_dac_nids));
3385 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003386 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003387 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003388 return num_pins;
3389}
3390
3391static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3392 struct snd_ctl_elem_info *uinfo)
3393{
3394 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3395 struct alc_spec *spec = codec->spec;
3396
3397 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3398 uinfo->count = 1;
3399 uinfo->value.enumerated.items = spec->multi_ios + 1;
3400 if (uinfo->value.enumerated.item > spec->multi_ios)
3401 uinfo->value.enumerated.item = spec->multi_ios;
3402 sprintf(uinfo->value.enumerated.name, "%dch",
3403 (uinfo->value.enumerated.item + 1) * 2);
3404 return 0;
3405}
3406
3407static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3408 struct snd_ctl_elem_value *ucontrol)
3409{
3410 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3411 struct alc_spec *spec = codec->spec;
3412 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3413 return 0;
3414}
3415
3416static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3417{
3418 struct alc_spec *spec = codec->spec;
3419 hda_nid_t nid = spec->multi_io[idx].pin;
3420
3421 if (!spec->multi_io[idx].ctl_in)
3422 spec->multi_io[idx].ctl_in =
3423 snd_hda_codec_read(codec, nid, 0,
3424 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3425 if (output) {
3426 snd_hda_codec_update_cache(codec, nid, 0,
3427 AC_VERB_SET_PIN_WIDGET_CONTROL,
3428 PIN_OUT);
3429 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3430 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3431 HDA_AMP_MUTE, 0);
3432 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3433 } else {
3434 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3435 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3436 HDA_AMP_MUTE, HDA_AMP_MUTE);
3437 snd_hda_codec_update_cache(codec, nid, 0,
3438 AC_VERB_SET_PIN_WIDGET_CONTROL,
3439 spec->multi_io[idx].ctl_in);
3440 }
3441 return 0;
3442}
3443
3444static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3445 struct snd_ctl_elem_value *ucontrol)
3446{
3447 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3448 struct alc_spec *spec = codec->spec;
3449 int i, ch;
3450
3451 ch = ucontrol->value.enumerated.item[0];
3452 if (ch < 0 || ch > spec->multi_ios)
3453 return -EINVAL;
3454 if (ch == (spec->ext_channel_count - 1) / 2)
3455 return 0;
3456 spec->ext_channel_count = (ch + 1) * 2;
3457 for (i = 0; i < spec->multi_ios; i++)
3458 alc_set_multi_io(codec, i, i < ch);
3459 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003460 if (spec->need_dac_fix && !spec->const_channel_count)
3461 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003462 return 1;
3463}
3464
Takashi Iwaia9111322011-05-02 11:30:18 +02003465static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003466 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3467 .name = "Channel Mode",
3468 .info = alc_auto_ch_mode_info,
3469 .get = alc_auto_ch_mode_get,
3470 .put = alc_auto_ch_mode_put,
3471};
3472
Takashi Iwai23c09b02011-08-19 09:05:35 +02003473static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003474{
3475 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003476
Takashi Iwaic2674682011-08-24 17:57:44 +02003477 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003478 struct snd_kcontrol_new *knew;
3479
3480 knew = alc_kcontrol_new(spec);
3481 if (!knew)
3482 return -ENOMEM;
3483 *knew = alc_auto_channel_mode_enum;
3484 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3485 if (!knew->name)
3486 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003487 }
3488 return 0;
3489}
3490
Takashi Iwai1d045db2011-07-07 18:23:21 +02003491/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3492 * active input pins
3493 */
3494static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3495{
3496 struct alc_spec *spec = codec->spec;
3497 const struct hda_input_mux *imux;
3498 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3499 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3500 int i, n, nums;
3501
3502 imux = spec->input_mux;
3503 if (!imux)
3504 return;
3505 if (spec->dyn_adc_switch)
3506 return;
3507
3508 nums = 0;
3509 for (n = 0; n < spec->num_adc_nids; n++) {
3510 hda_nid_t cap = spec->private_capsrc_nids[n];
3511 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3512 for (i = 0; i < imux->num_items; i++) {
3513 hda_nid_t pin = spec->imux_pins[i];
3514 if (pin) {
3515 if (get_connection_index(codec, cap, pin) < 0)
3516 break;
3517 } else if (num_conns <= imux->items[i].index)
3518 break;
3519 }
3520 if (i >= imux->num_items) {
3521 adc_nids[nums] = spec->private_adc_nids[n];
3522 capsrc_nids[nums++] = cap;
3523 }
3524 }
3525 if (!nums) {
3526 /* check whether ADC-switch is possible */
3527 if (!alc_check_dyn_adc_switch(codec)) {
3528 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3529 " using fallback 0x%x\n",
3530 codec->chip_name, spec->private_adc_nids[0]);
3531 spec->num_adc_nids = 1;
3532 spec->auto_mic = 0;
3533 return;
3534 }
3535 } else if (nums != spec->num_adc_nids) {
3536 memcpy(spec->private_adc_nids, adc_nids,
3537 nums * sizeof(hda_nid_t));
3538 memcpy(spec->private_capsrc_nids, capsrc_nids,
3539 nums * sizeof(hda_nid_t));
3540 spec->num_adc_nids = nums;
3541 }
3542
3543 if (spec->auto_mic)
3544 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3545 else if (spec->input_mux->num_items == 1)
3546 spec->num_adc_nids = 1; /* reduce to a single ADC */
3547}
3548
3549/*
3550 * initialize ADC paths
3551 */
3552static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3553{
3554 struct alc_spec *spec = codec->spec;
3555 hda_nid_t nid;
3556
3557 nid = spec->adc_nids[adc_idx];
3558 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003559 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003560 snd_hda_codec_write(codec, nid, 0,
3561 AC_VERB_SET_AMP_GAIN_MUTE,
3562 AMP_IN_MUTE(0));
3563 return;
3564 }
3565 if (!spec->capsrc_nids)
3566 return;
3567 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003568 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003569 snd_hda_codec_write(codec, nid, 0,
3570 AC_VERB_SET_AMP_GAIN_MUTE,
3571 AMP_OUT_MUTE);
3572}
3573
3574static void alc_auto_init_input_src(struct hda_codec *codec)
3575{
3576 struct alc_spec *spec = codec->spec;
3577 int c, nums;
3578
3579 for (c = 0; c < spec->num_adc_nids; c++)
3580 alc_auto_init_adc(codec, c);
3581 if (spec->dyn_adc_switch)
3582 nums = 1;
3583 else
3584 nums = spec->num_adc_nids;
3585 for (c = 0; c < nums; c++)
3586 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3587}
3588
3589/* add mic boosts if needed */
3590static int alc_auto_add_mic_boost(struct hda_codec *codec)
3591{
3592 struct alc_spec *spec = codec->spec;
3593 struct auto_pin_cfg *cfg = &spec->autocfg;
3594 int i, err;
3595 int type_idx = 0;
3596 hda_nid_t nid;
3597 const char *prev_label = NULL;
3598
3599 for (i = 0; i < cfg->num_inputs; i++) {
3600 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3601 break;
3602 nid = cfg->inputs[i].pin;
3603 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3604 const char *label;
3605 char boost_label[32];
3606
3607 label = hda_get_autocfg_input_label(codec, cfg, i);
3608 if (prev_label && !strcmp(label, prev_label))
3609 type_idx++;
3610 else
3611 type_idx = 0;
3612 prev_label = label;
3613
3614 snprintf(boost_label, sizeof(boost_label),
3615 "%s Boost Volume", label);
3616 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3617 boost_label, type_idx,
3618 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3619 if (err < 0)
3620 return err;
3621 }
3622 }
3623 return 0;
3624}
3625
3626/* select or unmute the given capsrc route */
3627static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3628 int idx)
3629{
3630 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3631 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3632 HDA_AMP_MUTE, 0);
3633 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3634 snd_hda_codec_write_cache(codec, cap, 0,
3635 AC_VERB_SET_CONNECT_SEL, idx);
3636 }
3637}
3638
3639/* set the default connection to that pin */
3640static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3641{
3642 struct alc_spec *spec = codec->spec;
3643 int i;
3644
3645 if (!pin)
3646 return 0;
3647 for (i = 0; i < spec->num_adc_nids; i++) {
3648 hda_nid_t cap = spec->capsrc_nids ?
3649 spec->capsrc_nids[i] : spec->adc_nids[i];
3650 int idx;
3651
3652 idx = get_connection_index(codec, cap, pin);
3653 if (idx < 0)
3654 continue;
3655 select_or_unmute_capsrc(codec, cap, idx);
3656 return i; /* return the found index */
3657 }
3658 return -1; /* not found */
3659}
3660
3661/* initialize some special cases for input sources */
3662static void alc_init_special_input_src(struct hda_codec *codec)
3663{
3664 struct alc_spec *spec = codec->spec;
3665 int i;
3666
3667 for (i = 0; i < spec->autocfg.num_inputs; i++)
3668 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3669}
3670
3671/* assign appropriate capture mixers */
3672static void set_capture_mixer(struct hda_codec *codec)
3673{
3674 struct alc_spec *spec = codec->spec;
3675 static const struct snd_kcontrol_new *caps[2][3] = {
3676 { alc_capture_mixer_nosrc1,
3677 alc_capture_mixer_nosrc2,
3678 alc_capture_mixer_nosrc3 },
3679 { alc_capture_mixer1,
3680 alc_capture_mixer2,
3681 alc_capture_mixer3 },
3682 };
3683
3684 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003685 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003686 if (!spec->capsrc_nids)
3687 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003688 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003689 return; /* no volume in capsrc, too */
3690 spec->vol_in_capsrc = 1;
3691 }
3692
3693 if (spec->num_adc_nids > 0) {
3694 int mux = 0;
3695 int num_adcs = 0;
3696
3697 if (spec->input_mux && spec->input_mux->num_items > 1)
3698 mux = 1;
3699 if (spec->auto_mic) {
3700 num_adcs = 1;
3701 mux = 0;
3702 } else if (spec->dyn_adc_switch)
3703 num_adcs = 1;
3704 if (!num_adcs) {
3705 if (spec->num_adc_nids > 3)
3706 spec->num_adc_nids = 3;
3707 else if (!spec->num_adc_nids)
3708 return;
3709 num_adcs = spec->num_adc_nids;
3710 }
3711 spec->cap_mixer = caps[mux][num_adcs - 1];
3712 }
3713}
3714
3715/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003716 * standard auto-parser initializations
3717 */
3718static void alc_auto_init_std(struct hda_codec *codec)
3719{
3720 struct alc_spec *spec = codec->spec;
3721 alc_auto_init_multi_out(codec);
3722 alc_auto_init_extra_out(codec);
3723 alc_auto_init_analog_input(codec);
3724 alc_auto_init_input_src(codec);
3725 alc_auto_init_digital(codec);
3726 if (spec->unsol_event)
3727 alc_inithook(codec);
3728}
3729
3730/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003731 * Digital-beep handlers
3732 */
3733#ifdef CONFIG_SND_HDA_INPUT_BEEP
3734#define set_beep_amp(spec, nid, idx, dir) \
3735 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3736
3737static const struct snd_pci_quirk beep_white_list[] = {
3738 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3739 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3740 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3741 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3742 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3743 {}
3744};
3745
3746static inline int has_cdefine_beep(struct hda_codec *codec)
3747{
3748 struct alc_spec *spec = codec->spec;
3749 const struct snd_pci_quirk *q;
3750 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3751 if (q)
3752 return q->value;
3753 return spec->cdefine.enable_pcbeep;
3754}
3755#else
3756#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3757#define has_cdefine_beep(codec) 0
3758#endif
3759
3760/* parse the BIOS configuration and set up the alc_spec */
3761/* return 1 if successful, 0 if the proper config is not found,
3762 * or a negative error code
3763 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003764static int alc_parse_auto_config(struct hda_codec *codec,
3765 const hda_nid_t *ignore_nids,
3766 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003767{
3768 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003769 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003770 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003771
Takashi Iwai53c334a2011-08-23 18:27:14 +02003772 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3773 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003774 if (err < 0)
3775 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003776 if (!cfg->line_outs) {
3777 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003778 spec->multiout.max_channels = 2;
3779 spec->no_analog = 1;
3780 goto dig_only;
3781 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003782 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003783 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003784
Takashi Iwai06503672011-10-06 08:27:19 +02003785 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3786 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003787 /* use HP as primary out */
3788 cfg->speaker_outs = cfg->line_outs;
3789 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3790 sizeof(cfg->speaker_pins));
3791 cfg->line_outs = cfg->hp_outs;
3792 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3793 cfg->hp_outs = 0;
3794 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3795 cfg->line_out_type = AUTO_PIN_HP_OUT;
3796 }
3797
Takashi Iwai1d045db2011-07-07 18:23:21 +02003798 err = alc_auto_fill_dac_nids(codec);
3799 if (err < 0)
3800 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003801 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003802 if (err < 0)
3803 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003804 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003805 if (err < 0)
3806 return err;
3807 err = alc_auto_create_hp_out(codec);
3808 if (err < 0)
3809 return err;
3810 err = alc_auto_create_speaker_out(codec);
3811 if (err < 0)
3812 return err;
3813 err = alc_auto_create_input_ctls(codec);
3814 if (err < 0)
3815 return err;
3816
3817 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3818
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003819 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02003820 alc_auto_parse_digital(codec);
3821
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003822 if (!spec->no_analog)
3823 alc_remove_invalid_adc_nids(codec);
3824
3825 if (ssid_nids)
3826 alc_ssid_check(codec, ssid_nids);
3827
3828 if (!spec->no_analog) {
3829 alc_auto_check_switches(codec);
3830 err = alc_auto_add_mic_boost(codec);
3831 if (err < 0)
3832 return err;
3833 }
3834
Takashi Iwai1d045db2011-07-07 18:23:21 +02003835 if (spec->kctls.list)
3836 add_mixer(spec, spec->kctls.list);
3837
Takashi Iwai1d045db2011-07-07 18:23:21 +02003838 return 1;
3839}
3840
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003841static int alc880_parse_auto_config(struct hda_codec *codec)
3842{
3843 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3844 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3845 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3846}
3847
Takashi Iwai1d045db2011-07-07 18:23:21 +02003848#ifdef CONFIG_SND_HDA_POWER_SAVE
3849static const struct hda_amp_list alc880_loopbacks[] = {
3850 { 0x0b, HDA_INPUT, 0 },
3851 { 0x0b, HDA_INPUT, 1 },
3852 { 0x0b, HDA_INPUT, 2 },
3853 { 0x0b, HDA_INPUT, 3 },
3854 { 0x0b, HDA_INPUT, 4 },
3855 { } /* end */
3856};
3857#endif
3858
3859/*
3860 * board setups
3861 */
3862#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3863#define alc_board_config \
3864 snd_hda_check_board_config
3865#define alc_board_codec_sid_config \
3866 snd_hda_check_board_codec_sid_config
3867#include "alc_quirks.c"
3868#else
3869#define alc_board_config(codec, nums, models, tbl) -1
3870#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3871#define setup_preset(codec, x) /* NOP */
3872#endif
3873
3874/*
3875 * OK, here we have finally the patch for ALC880
3876 */
3877#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3878#include "alc880_quirks.c"
3879#endif
3880
3881static int patch_alc880(struct hda_codec *codec)
3882{
3883 struct alc_spec *spec;
3884 int board_config;
3885 int err;
3886
3887 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3888 if (spec == NULL)
3889 return -ENOMEM;
3890
3891 codec->spec = spec;
3892
3893 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003894 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003895
3896 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3897 alc880_models, alc880_cfg_tbl);
3898 if (board_config < 0) {
3899 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3900 codec->chip_name);
3901 board_config = ALC_MODEL_AUTO;
3902 }
3903
3904 if (board_config == ALC_MODEL_AUTO) {
3905 /* automatic parse from the BIOS config */
3906 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02003907 if (err < 0)
3908 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003909#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3910 else if (!err) {
3911 printk(KERN_INFO
3912 "hda_codec: Cannot set up configuration "
3913 "from BIOS. Using 3-stack mode...\n");
3914 board_config = ALC880_3ST;
3915 }
3916#endif
3917 }
3918
Takashi Iwai1d045db2011-07-07 18:23:21 +02003919 if (board_config != ALC_MODEL_AUTO)
3920 setup_preset(codec, &alc880_presets[board_config]);
3921
Takashi Iwai60a6a842011-07-27 14:01:24 +02003922 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003923 alc_auto_fill_adc_caps(codec);
3924 alc_rebuild_imux_for_auto_mic(codec);
3925 alc_remove_invalid_adc_nids(codec);
3926 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003927
3928 if (!spec->no_analog && !spec->cap_mixer)
3929 set_capture_mixer(codec);
3930
3931 if (!spec->no_analog) {
3932 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02003933 if (err < 0)
3934 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003935 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3936 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003937
3938 spec->vmaster_nid = 0x0c;
3939
3940 codec->patch_ops = alc_patch_ops;
3941 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02003942 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003943#ifdef CONFIG_SND_HDA_POWER_SAVE
3944 if (!spec->loopback.amplist)
3945 spec->loopback.amplist = alc880_loopbacks;
3946#endif
3947
3948 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02003949
3950 error:
3951 alc_free(codec);
3952 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003953}
3954
3955
3956/*
3957 * ALC260 support
3958 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02003959static int alc260_parse_auto_config(struct hda_codec *codec)
3960{
Takashi Iwai1d045db2011-07-07 18:23:21 +02003961 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003962 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
3963 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003964}
3965
Takashi Iwai1d045db2011-07-07 18:23:21 +02003966#ifdef CONFIG_SND_HDA_POWER_SAVE
3967static const struct hda_amp_list alc260_loopbacks[] = {
3968 { 0x07, HDA_INPUT, 0 },
3969 { 0x07, HDA_INPUT, 1 },
3970 { 0x07, HDA_INPUT, 2 },
3971 { 0x07, HDA_INPUT, 3 },
3972 { 0x07, HDA_INPUT, 4 },
3973 { } /* end */
3974};
3975#endif
3976
3977/*
3978 * Pin config fixes
3979 */
3980enum {
3981 PINFIX_HP_DC5750,
3982};
3983
3984static const struct alc_fixup alc260_fixups[] = {
3985 [PINFIX_HP_DC5750] = {
3986 .type = ALC_FIXUP_PINS,
3987 .v.pins = (const struct alc_pincfg[]) {
3988 { 0x11, 0x90130110 }, /* speaker */
3989 { }
3990 }
3991 },
3992};
3993
3994static const struct snd_pci_quirk alc260_fixup_tbl[] = {
3995 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
3996 {}
3997};
3998
3999/*
4000 */
4001#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4002#include "alc260_quirks.c"
4003#endif
4004
4005static int patch_alc260(struct hda_codec *codec)
4006{
4007 struct alc_spec *spec;
4008 int err, board_config;
4009
4010 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4011 if (spec == NULL)
4012 return -ENOMEM;
4013
4014 codec->spec = spec;
4015
4016 spec->mixer_nid = 0x07;
4017
4018 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4019 alc260_models, alc260_cfg_tbl);
4020 if (board_config < 0) {
4021 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4022 codec->chip_name);
4023 board_config = ALC_MODEL_AUTO;
4024 }
4025
4026 if (board_config == ALC_MODEL_AUTO) {
4027 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4028 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4029 }
4030
4031 if (board_config == ALC_MODEL_AUTO) {
4032 /* automatic parse from the BIOS config */
4033 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004034 if (err < 0)
4035 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004036#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4037 else if (!err) {
4038 printk(KERN_INFO
4039 "hda_codec: Cannot set up configuration "
4040 "from BIOS. Using base mode...\n");
4041 board_config = ALC260_BASIC;
4042 }
4043#endif
4044 }
4045
Takashi Iwai1d045db2011-07-07 18:23:21 +02004046 if (board_config != ALC_MODEL_AUTO)
4047 setup_preset(codec, &alc260_presets[board_config]);
4048
Takashi Iwai60a6a842011-07-27 14:01:24 +02004049 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004050 alc_auto_fill_adc_caps(codec);
4051 alc_rebuild_imux_for_auto_mic(codec);
4052 alc_remove_invalid_adc_nids(codec);
4053 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004054
4055 if (!spec->no_analog && !spec->cap_mixer)
4056 set_capture_mixer(codec);
4057
4058 if (!spec->no_analog) {
4059 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004060 if (err < 0)
4061 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004062 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4063 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004064
4065 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4066
4067 spec->vmaster_nid = 0x08;
4068
4069 codec->patch_ops = alc_patch_ops;
4070 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004071 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004072 spec->shutup = alc_eapd_shutup;
4073#ifdef CONFIG_SND_HDA_POWER_SAVE
4074 if (!spec->loopback.amplist)
4075 spec->loopback.amplist = alc260_loopbacks;
4076#endif
4077
4078 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004079
4080 error:
4081 alc_free(codec);
4082 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004083}
4084
4085
4086/*
4087 * ALC882/883/885/888/889 support
4088 *
4089 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4090 * configuration. Each pin widget can choose any input DACs and a mixer.
4091 * Each ADC is connected from a mixer of all inputs. This makes possible
4092 * 6-channel independent captures.
4093 *
4094 * In addition, an independent DAC for the multi-playback (not used in this
4095 * driver yet).
4096 */
4097#ifdef CONFIG_SND_HDA_POWER_SAVE
4098#define alc882_loopbacks alc880_loopbacks
4099#endif
4100
4101/*
4102 * Pin config fixes
4103 */
4104enum {
4105 PINFIX_ABIT_AW9D_MAX,
4106 PINFIX_LENOVO_Y530,
4107 PINFIX_PB_M5210,
4108 PINFIX_ACER_ASPIRE_7736,
4109};
4110
4111static const struct alc_fixup alc882_fixups[] = {
4112 [PINFIX_ABIT_AW9D_MAX] = {
4113 .type = ALC_FIXUP_PINS,
4114 .v.pins = (const struct alc_pincfg[]) {
4115 { 0x15, 0x01080104 }, /* side */
4116 { 0x16, 0x01011012 }, /* rear */
4117 { 0x17, 0x01016011 }, /* clfe */
4118 { }
4119 }
4120 },
4121 [PINFIX_LENOVO_Y530] = {
4122 .type = ALC_FIXUP_PINS,
4123 .v.pins = (const struct alc_pincfg[]) {
4124 { 0x15, 0x99130112 }, /* rear int speakers */
4125 { 0x16, 0x99130111 }, /* subwoofer */
4126 { }
4127 }
4128 },
4129 [PINFIX_PB_M5210] = {
4130 .type = ALC_FIXUP_VERBS,
4131 .v.verbs = (const struct hda_verb[]) {
4132 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4133 {}
4134 }
4135 },
4136 [PINFIX_ACER_ASPIRE_7736] = {
4137 .type = ALC_FIXUP_SKU,
4138 .v.sku = ALC_FIXUP_SKU_IGNORE,
4139 },
4140};
4141
4142static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4143 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4144 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4145 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4146 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4147 {}
4148};
4149
4150/*
4151 * BIOS auto configuration
4152 */
4153/* almost identical with ALC880 parser... */
4154static int alc882_parse_auto_config(struct hda_codec *codec)
4155{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004156 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004157 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4158 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004159}
4160
Takashi Iwai1d045db2011-07-07 18:23:21 +02004161/*
4162 */
4163#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4164#include "alc882_quirks.c"
4165#endif
4166
4167static int patch_alc882(struct hda_codec *codec)
4168{
4169 struct alc_spec *spec;
4170 int err, board_config;
4171
4172 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4173 if (spec == NULL)
4174 return -ENOMEM;
4175
4176 codec->spec = spec;
4177
4178 spec->mixer_nid = 0x0b;
4179
4180 switch (codec->vendor_id) {
4181 case 0x10ec0882:
4182 case 0x10ec0885:
4183 break;
4184 default:
4185 /* ALC883 and variants */
4186 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4187 break;
4188 }
4189
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004190 err = alc_codec_rename_from_preset(codec);
4191 if (err < 0)
4192 goto error;
4193
Takashi Iwai1d045db2011-07-07 18:23:21 +02004194 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4195 alc882_models, alc882_cfg_tbl);
4196
4197 if (board_config < 0)
4198 board_config = alc_board_codec_sid_config(codec,
4199 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4200
4201 if (board_config < 0) {
4202 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4203 codec->chip_name);
4204 board_config = ALC_MODEL_AUTO;
4205 }
4206
4207 if (board_config == ALC_MODEL_AUTO) {
4208 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4209 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4210 }
4211
4212 alc_auto_parse_customize_define(codec);
4213
4214 if (board_config == ALC_MODEL_AUTO) {
4215 /* automatic parse from the BIOS config */
4216 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004217 if (err < 0)
4218 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004219#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4220 else if (!err) {
4221 printk(KERN_INFO
4222 "hda_codec: Cannot set up configuration "
4223 "from BIOS. Using base mode...\n");
4224 board_config = ALC882_3ST_DIG;
4225 }
4226#endif
4227 }
4228
Takashi Iwai1d045db2011-07-07 18:23:21 +02004229 if (board_config != ALC_MODEL_AUTO)
4230 setup_preset(codec, &alc882_presets[board_config]);
4231
Takashi Iwai60a6a842011-07-27 14:01:24 +02004232 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004233 alc_auto_fill_adc_caps(codec);
4234 alc_rebuild_imux_for_auto_mic(codec);
4235 alc_remove_invalid_adc_nids(codec);
4236 }
4237
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004238 if (!spec->no_analog && !spec->cap_mixer)
4239 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004240
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004241 if (!spec->no_analog && has_cdefine_beep(codec)) {
4242 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004243 if (err < 0)
4244 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004245 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004246 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004247
4248 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4249
4250 spec->vmaster_nid = 0x0c;
4251
4252 codec->patch_ops = alc_patch_ops;
4253 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004254 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004255
4256 alc_init_jacks(codec);
4257#ifdef CONFIG_SND_HDA_POWER_SAVE
4258 if (!spec->loopback.amplist)
4259 spec->loopback.amplist = alc882_loopbacks;
4260#endif
4261
4262 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004263
4264 error:
4265 alc_free(codec);
4266 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004267}
4268
4269
4270/*
4271 * ALC262 support
4272 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004273static int alc262_parse_auto_config(struct hda_codec *codec)
4274{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004275 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004276 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4277 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004278}
4279
4280/*
4281 * Pin config fixes
4282 */
4283enum {
4284 PINFIX_FSC_H270,
4285 PINFIX_HP_Z200,
4286};
4287
4288static const struct alc_fixup alc262_fixups[] = {
4289 [PINFIX_FSC_H270] = {
4290 .type = ALC_FIXUP_PINS,
4291 .v.pins = (const struct alc_pincfg[]) {
4292 { 0x14, 0x99130110 }, /* speaker */
4293 { 0x15, 0x0221142f }, /* front HP */
4294 { 0x1b, 0x0121141f }, /* rear HP */
4295 { }
4296 }
4297 },
4298 [PINFIX_HP_Z200] = {
4299 .type = ALC_FIXUP_PINS,
4300 .v.pins = (const struct alc_pincfg[]) {
4301 { 0x16, 0x99130120 }, /* internal speaker */
4302 { }
4303 }
4304 },
4305};
4306
4307static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4308 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4309 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4310 {}
4311};
4312
4313
4314#ifdef CONFIG_SND_HDA_POWER_SAVE
4315#define alc262_loopbacks alc880_loopbacks
4316#endif
4317
Takashi Iwai1d045db2011-07-07 18:23:21 +02004318/*
4319 */
4320#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4321#include "alc262_quirks.c"
4322#endif
4323
4324static int patch_alc262(struct hda_codec *codec)
4325{
4326 struct alc_spec *spec;
4327 int board_config;
4328 int err;
4329
4330 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4331 if (spec == NULL)
4332 return -ENOMEM;
4333
4334 codec->spec = spec;
4335
4336 spec->mixer_nid = 0x0b;
4337
4338#if 0
4339 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4340 * under-run
4341 */
4342 {
4343 int tmp;
4344 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4345 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4346 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4347 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4348 }
4349#endif
4350 alc_auto_parse_customize_define(codec);
4351
4352 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4353
4354 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4355 alc262_models, alc262_cfg_tbl);
4356
4357 if (board_config < 0) {
4358 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4359 codec->chip_name);
4360 board_config = ALC_MODEL_AUTO;
4361 }
4362
4363 if (board_config == ALC_MODEL_AUTO) {
4364 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4365 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4366 }
4367
4368 if (board_config == ALC_MODEL_AUTO) {
4369 /* automatic parse from the BIOS config */
4370 err = alc262_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004371 if (err < 0)
4372 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004373#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4374 else if (!err) {
4375 printk(KERN_INFO
4376 "hda_codec: Cannot set up configuration "
4377 "from BIOS. Using base mode...\n");
4378 board_config = ALC262_BASIC;
4379 }
4380#endif
4381 }
4382
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004383 if (board_config != ALC_MODEL_AUTO)
4384 setup_preset(codec, &alc262_presets[board_config]);
4385
Takashi Iwai60a6a842011-07-27 14:01:24 +02004386 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004387 alc_auto_fill_adc_caps(codec);
4388 alc_rebuild_imux_for_auto_mic(codec);
4389 alc_remove_invalid_adc_nids(codec);
4390 }
4391
4392 if (!spec->no_analog && !spec->cap_mixer)
4393 set_capture_mixer(codec);
4394
Takashi Iwai1d045db2011-07-07 18:23:21 +02004395 if (!spec->no_analog && has_cdefine_beep(codec)) {
4396 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004397 if (err < 0)
4398 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004399 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004400 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004401
4402 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4403
4404 spec->vmaster_nid = 0x0c;
4405
4406 codec->patch_ops = alc_patch_ops;
4407 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004408 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004409 spec->shutup = alc_eapd_shutup;
4410
4411 alc_init_jacks(codec);
4412#ifdef CONFIG_SND_HDA_POWER_SAVE
4413 if (!spec->loopback.amplist)
4414 spec->loopback.amplist = alc262_loopbacks;
4415#endif
4416
4417 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004418
4419 error:
4420 alc_free(codec);
4421 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004422}
4423
4424/*
4425 * ALC268
4426 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004427/* bind Beep switches of both NID 0x0f and 0x10 */
4428static const struct hda_bind_ctls alc268_bind_beep_sw = {
4429 .ops = &snd_hda_bind_sw,
4430 .values = {
4431 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4432 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4433 0
4434 },
4435};
4436
4437static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4438 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4439 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4440 { }
4441};
4442
4443/* set PCBEEP vol = 0, mute connections */
4444static const struct hda_verb alc268_beep_init_verbs[] = {
4445 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4446 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4447 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4448 { }
4449};
4450
4451/*
4452 * BIOS auto configuration
4453 */
4454static int alc268_parse_auto_config(struct hda_codec *codec)
4455{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004456 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004457 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004458 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4459 if (err > 0) {
4460 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4461 add_mixer(spec, alc268_beep_mixer);
4462 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004463 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004464 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004465 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004466}
4467
Takashi Iwai1d045db2011-07-07 18:23:21 +02004468/*
4469 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004470static int patch_alc268(struct hda_codec *codec)
4471{
4472 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004473 int i, has_beep, err;
4474
4475 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4476 if (spec == NULL)
4477 return -ENOMEM;
4478
4479 codec->spec = spec;
4480
4481 /* ALC268 has no aa-loopback mixer */
4482
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004483 /* automatic parse from the BIOS config */
4484 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004485 if (err < 0)
4486 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004487
Takashi Iwai1d045db2011-07-07 18:23:21 +02004488 has_beep = 0;
4489 for (i = 0; i < spec->num_mixers; i++) {
4490 if (spec->mixers[i] == alc268_beep_mixer) {
4491 has_beep = 1;
4492 break;
4493 }
4494 }
4495
4496 if (has_beep) {
4497 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004498 if (err < 0)
4499 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004500 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4501 /* override the amp caps for beep generator */
4502 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4503 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4504 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4505 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4506 (0 << AC_AMPCAP_MUTE_SHIFT));
4507 }
4508
Takashi Iwai60a6a842011-07-27 14:01:24 +02004509 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004510 alc_auto_fill_adc_caps(codec);
4511 alc_rebuild_imux_for_auto_mic(codec);
4512 alc_remove_invalid_adc_nids(codec);
4513 }
4514
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004515 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004516 set_capture_mixer(codec);
4517
4518 spec->vmaster_nid = 0x02;
4519
4520 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004521 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004522 spec->shutup = alc_eapd_shutup;
4523
4524 alc_init_jacks(codec);
4525
4526 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004527
4528 error:
4529 alc_free(codec);
4530 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004531}
4532
4533/*
4534 * ALC269
4535 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004536#ifdef CONFIG_SND_HDA_POWER_SAVE
4537#define alc269_loopbacks alc880_loopbacks
4538#endif
4539
4540static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4541 .substreams = 1,
4542 .channels_min = 2,
4543 .channels_max = 8,
4544 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4545 /* NID is set in alc_build_pcms */
4546 .ops = {
4547 .open = alc_playback_pcm_open,
4548 .prepare = alc_playback_pcm_prepare,
4549 .cleanup = alc_playback_pcm_cleanup
4550 },
4551};
4552
4553static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4554 .substreams = 1,
4555 .channels_min = 2,
4556 .channels_max = 2,
4557 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4558 /* NID is set in alc_build_pcms */
4559};
4560
4561#ifdef CONFIG_SND_HDA_POWER_SAVE
4562static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4563{
4564 switch (codec->subsystem_id) {
4565 case 0x103c1586:
4566 return 1;
4567 }
4568 return 0;
4569}
4570
4571static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4572{
4573 /* update mute-LED according to the speaker mute state */
4574 if (nid == 0x01 || nid == 0x14) {
4575 int pinval;
4576 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4577 HDA_AMP_MUTE)
4578 pinval = 0x24;
4579 else
4580 pinval = 0x20;
4581 /* mic2 vref pin is used for mute LED control */
4582 snd_hda_codec_update_cache(codec, 0x19, 0,
4583 AC_VERB_SET_PIN_WIDGET_CONTROL,
4584 pinval);
4585 }
4586 return alc_check_power_status(codec, nid);
4587}
4588#endif /* CONFIG_SND_HDA_POWER_SAVE */
4589
4590/* different alc269-variants */
4591enum {
4592 ALC269_TYPE_ALC269VA,
4593 ALC269_TYPE_ALC269VB,
4594 ALC269_TYPE_ALC269VC,
4595};
4596
4597/*
4598 * BIOS auto configuration
4599 */
4600static int alc269_parse_auto_config(struct hda_codec *codec)
4601{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004602 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004603 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4604 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4605 struct alc_spec *spec = codec->spec;
4606 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4607 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004608
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004609 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004610}
4611
Takashi Iwai1d045db2011-07-07 18:23:21 +02004612static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4613{
4614 int val = alc_read_coef_idx(codec, 0x04);
4615 if (power_up)
4616 val |= 1 << 11;
4617 else
4618 val &= ~(1 << 11);
4619 alc_write_coef_idx(codec, 0x04, val);
4620}
4621
4622static void alc269_shutup(struct hda_codec *codec)
4623{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004624 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004625 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004626 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004627 alc269_toggle_power_output(codec, 0);
4628 msleep(150);
4629 }
4630}
4631
Takashi Iwai2a439522011-07-26 09:52:50 +02004632#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02004633static int alc269_resume(struct hda_codec *codec)
4634{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004635 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004636 alc269_toggle_power_output(codec, 0);
4637 msleep(150);
4638 }
4639
4640 codec->patch_ops.init(codec);
4641
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004642 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004643 alc269_toggle_power_output(codec, 1);
4644 msleep(200);
4645 }
4646
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004647 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004648 alc269_toggle_power_output(codec, 1);
4649
4650 snd_hda_codec_resume_amp(codec);
4651 snd_hda_codec_resume_cache(codec);
4652 hda_call_check_power_status(codec, 0x01);
4653 return 0;
4654}
Takashi Iwai2a439522011-07-26 09:52:50 +02004655#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004656
4657static void alc269_fixup_hweq(struct hda_codec *codec,
4658 const struct alc_fixup *fix, int action)
4659{
4660 int coef;
4661
4662 if (action != ALC_FIXUP_ACT_INIT)
4663 return;
4664 coef = alc_read_coef_idx(codec, 0x1e);
4665 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4666}
4667
4668static void alc271_fixup_dmic(struct hda_codec *codec,
4669 const struct alc_fixup *fix, int action)
4670{
4671 static const struct hda_verb verbs[] = {
4672 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4673 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4674 {}
4675 };
4676 unsigned int cfg;
4677
4678 if (strcmp(codec->chip_name, "ALC271X"))
4679 return;
4680 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4681 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4682 snd_hda_sequence_write(codec, verbs);
4683}
4684
Takashi Iwai017f2a12011-07-09 14:42:25 +02004685static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4686 const struct alc_fixup *fix, int action)
4687{
4688 struct alc_spec *spec = codec->spec;
4689
4690 if (action != ALC_FIXUP_ACT_PROBE)
4691 return;
4692
4693 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4694 * fix the sample rate of analog I/O to 44.1kHz
4695 */
4696 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4697 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4698}
4699
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004700static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4701 const struct alc_fixup *fix, int action)
4702{
4703 int coef;
4704
4705 if (action != ALC_FIXUP_ACT_INIT)
4706 return;
4707 /* The digital-mic unit sends PDM (differential signal) instead of
4708 * the standard PCM, thus you can't record a valid mono stream as is.
4709 * Below is a workaround specific to ALC269 to control the dmic
4710 * signal source as mono.
4711 */
4712 coef = alc_read_coef_idx(codec, 0x07);
4713 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4714}
4715
Takashi Iwai24519912011-08-16 15:08:49 +02004716static void alc269_quanta_automute(struct hda_codec *codec)
4717{
David Henningsson42cf0d02011-09-20 12:04:56 +02004718 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02004719
4720 snd_hda_codec_write(codec, 0x20, 0,
4721 AC_VERB_SET_COEF_INDEX, 0x0c);
4722 snd_hda_codec_write(codec, 0x20, 0,
4723 AC_VERB_SET_PROC_COEF, 0x680);
4724
4725 snd_hda_codec_write(codec, 0x20, 0,
4726 AC_VERB_SET_COEF_INDEX, 0x0c);
4727 snd_hda_codec_write(codec, 0x20, 0,
4728 AC_VERB_SET_PROC_COEF, 0x480);
4729}
4730
4731static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4732 const struct alc_fixup *fix, int action)
4733{
4734 struct alc_spec *spec = codec->spec;
4735 if (action != ALC_FIXUP_ACT_PROBE)
4736 return;
4737 spec->automute_hook = alc269_quanta_automute;
4738}
4739
Takashi Iwai1d045db2011-07-07 18:23:21 +02004740enum {
4741 ALC269_FIXUP_SONY_VAIO,
4742 ALC275_FIXUP_SONY_VAIO_GPIO2,
4743 ALC269_FIXUP_DELL_M101Z,
4744 ALC269_FIXUP_SKU_IGNORE,
4745 ALC269_FIXUP_ASUS_G73JW,
4746 ALC269_FIXUP_LENOVO_EAPD,
4747 ALC275_FIXUP_SONY_HWEQ,
4748 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02004749 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004750 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02004751 ALC269_FIXUP_QUANTA_MUTE,
4752 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02004753 ALC269_FIXUP_AMIC,
4754 ALC269_FIXUP_DMIC,
4755 ALC269VB_FIXUP_AMIC,
4756 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004757};
4758
4759static const struct alc_fixup alc269_fixups[] = {
4760 [ALC269_FIXUP_SONY_VAIO] = {
4761 .type = ALC_FIXUP_VERBS,
4762 .v.verbs = (const struct hda_verb[]) {
4763 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4764 {}
4765 }
4766 },
4767 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4768 .type = ALC_FIXUP_VERBS,
4769 .v.verbs = (const struct hda_verb[]) {
4770 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4771 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4772 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4773 { }
4774 },
4775 .chained = true,
4776 .chain_id = ALC269_FIXUP_SONY_VAIO
4777 },
4778 [ALC269_FIXUP_DELL_M101Z] = {
4779 .type = ALC_FIXUP_VERBS,
4780 .v.verbs = (const struct hda_verb[]) {
4781 /* Enables internal speaker */
4782 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4783 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4784 {}
4785 }
4786 },
4787 [ALC269_FIXUP_SKU_IGNORE] = {
4788 .type = ALC_FIXUP_SKU,
4789 .v.sku = ALC_FIXUP_SKU_IGNORE,
4790 },
4791 [ALC269_FIXUP_ASUS_G73JW] = {
4792 .type = ALC_FIXUP_PINS,
4793 .v.pins = (const struct alc_pincfg[]) {
4794 { 0x17, 0x99130111 }, /* subwoofer */
4795 { }
4796 }
4797 },
4798 [ALC269_FIXUP_LENOVO_EAPD] = {
4799 .type = ALC_FIXUP_VERBS,
4800 .v.verbs = (const struct hda_verb[]) {
4801 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4802 {}
4803 }
4804 },
4805 [ALC275_FIXUP_SONY_HWEQ] = {
4806 .type = ALC_FIXUP_FUNC,
4807 .v.func = alc269_fixup_hweq,
4808 .chained = true,
4809 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4810 },
4811 [ALC271_FIXUP_DMIC] = {
4812 .type = ALC_FIXUP_FUNC,
4813 .v.func = alc271_fixup_dmic,
4814 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02004815 [ALC269_FIXUP_PCM_44K] = {
4816 .type = ALC_FIXUP_FUNC,
4817 .v.func = alc269_fixup_pcm_44k,
4818 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004819 [ALC269_FIXUP_STEREO_DMIC] = {
4820 .type = ALC_FIXUP_FUNC,
4821 .v.func = alc269_fixup_stereo_dmic,
4822 },
Takashi Iwai24519912011-08-16 15:08:49 +02004823 [ALC269_FIXUP_QUANTA_MUTE] = {
4824 .type = ALC_FIXUP_FUNC,
4825 .v.func = alc269_fixup_quanta_mute,
4826 },
4827 [ALC269_FIXUP_LIFEBOOK] = {
4828 .type = ALC_FIXUP_PINS,
4829 .v.pins = (const struct alc_pincfg[]) {
4830 { 0x1a, 0x2101103f }, /* dock line-out */
4831 { 0x1b, 0x23a11040 }, /* dock mic-in */
4832 { }
4833 },
4834 .chained = true,
4835 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4836 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02004837 [ALC269_FIXUP_AMIC] = {
4838 .type = ALC_FIXUP_PINS,
4839 .v.pins = (const struct alc_pincfg[]) {
4840 { 0x14, 0x99130110 }, /* speaker */
4841 { 0x15, 0x0121401f }, /* HP out */
4842 { 0x18, 0x01a19c20 }, /* mic */
4843 { 0x19, 0x99a3092f }, /* int-mic */
4844 { }
4845 },
4846 },
4847 [ALC269_FIXUP_DMIC] = {
4848 .type = ALC_FIXUP_PINS,
4849 .v.pins = (const struct alc_pincfg[]) {
4850 { 0x12, 0x99a3092f }, /* int-mic */
4851 { 0x14, 0x99130110 }, /* speaker */
4852 { 0x15, 0x0121401f }, /* HP out */
4853 { 0x18, 0x01a19c20 }, /* mic */
4854 { }
4855 },
4856 },
4857 [ALC269VB_FIXUP_AMIC] = {
4858 .type = ALC_FIXUP_PINS,
4859 .v.pins = (const struct alc_pincfg[]) {
4860 { 0x14, 0x99130110 }, /* speaker */
4861 { 0x18, 0x01a19c20 }, /* mic */
4862 { 0x19, 0x99a3092f }, /* int-mic */
4863 { 0x21, 0x0121401f }, /* HP out */
4864 { }
4865 },
4866 },
4867 [ALC269_FIXUP_DMIC] = {
4868 .type = ALC_FIXUP_PINS,
4869 .v.pins = (const struct alc_pincfg[]) {
4870 { 0x12, 0x99a3092f }, /* int-mic */
4871 { 0x14, 0x99130110 }, /* speaker */
4872 { 0x18, 0x01a19c20 }, /* mic */
4873 { 0x21, 0x0121401f }, /* HP out */
4874 { }
4875 },
4876 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004877};
4878
4879static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02004880 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004881 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4882 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4883 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4884 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4885 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004886 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4887 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4888 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4889 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4890 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4891 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02004892 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004893 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4894 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4895 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4896 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4897 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02004898 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02004899 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004900 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02004901
4902#if 1
4903 /* Below is a quirk table taken from the old code.
4904 * Basically the device should work as is without the fixup table.
4905 * If BIOS doesn't give a proper info, enable the corresponding
4906 * fixup entry.
4907 */
4908 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4909 ALC269_FIXUP_AMIC),
4910 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
4911 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
4912 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
4913 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
4914 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
4915 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
4916 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
4917 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
4918 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
4919 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
4920 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
4921 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
4922 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
4923 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
4924 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
4925 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
4926 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
4927 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
4928 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
4929 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
4930 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
4931 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
4932 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
4933 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
4934 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
4935 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
4936 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
4937 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
4938 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
4939 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
4940 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
4941 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
4942 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
4943 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
4944 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
4945 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
4946 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
4947 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
4948 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
4949 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
4950#endif
4951 {}
4952};
4953
4954static const struct alc_model_fixup alc269_fixup_models[] = {
4955 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
4956 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02004957 {}
4958};
4959
4960
4961static int alc269_fill_coef(struct hda_codec *codec)
4962{
4963 int val;
4964
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004965 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004966 alc_write_coef_idx(codec, 0xf, 0x960b);
4967 alc_write_coef_idx(codec, 0xe, 0x8817);
4968 }
4969
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004970 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004971 alc_write_coef_idx(codec, 0xf, 0x960b);
4972 alc_write_coef_idx(codec, 0xe, 0x8814);
4973 }
4974
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004975 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004976 val = alc_read_coef_idx(codec, 0x04);
4977 /* Power up output pin */
4978 alc_write_coef_idx(codec, 0x04, val | (1<<11));
4979 }
4980
Takashi Iwai1bb7e432011-10-17 16:50:59 +02004981 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004982 val = alc_read_coef_idx(codec, 0xd);
4983 if ((val & 0x0c00) >> 10 != 0x1) {
4984 /* Capless ramp up clock control */
4985 alc_write_coef_idx(codec, 0xd, val | (1<<10));
4986 }
4987 val = alc_read_coef_idx(codec, 0x17);
4988 if ((val & 0x01c0) >> 6 != 0x4) {
4989 /* Class D power on reset */
4990 alc_write_coef_idx(codec, 0x17, val | (1<<7));
4991 }
4992 }
4993
4994 val = alc_read_coef_idx(codec, 0xd); /* Class D */
4995 alc_write_coef_idx(codec, 0xd, val | (1<<14));
4996
4997 val = alc_read_coef_idx(codec, 0x4); /* HP */
4998 alc_write_coef_idx(codec, 0x4, val | (1<<11));
4999
5000 return 0;
5001}
5002
5003/*
5004 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005005static int patch_alc269(struct hda_codec *codec)
5006{
5007 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005008 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005009
5010 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5011 if (spec == NULL)
5012 return -ENOMEM;
5013
5014 codec->spec = spec;
5015
5016 spec->mixer_nid = 0x0b;
5017
5018 alc_auto_parse_customize_define(codec);
5019
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005020 err = alc_codec_rename_from_preset(codec);
5021 if (err < 0)
5022 goto error;
5023
Takashi Iwai1d045db2011-07-07 18:23:21 +02005024 if (codec->vendor_id == 0x10ec0269) {
5025 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005026 switch (alc_get_coef0(codec) & 0x00f0) {
5027 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005028 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005029 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005030 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005031 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005032 break;
5033 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005034 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5035 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005036 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005037 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005038 break;
5039 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005040 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005041 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005042 if (err < 0)
5043 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005044 alc269_fill_coef(codec);
5045 }
5046
Takashi Iwaia4297b52011-08-23 18:40:12 +02005047 alc_pick_fixup(codec, alc269_fixup_models,
5048 alc269_fixup_tbl, alc269_fixups);
5049 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005050
Takashi Iwaia4297b52011-08-23 18:40:12 +02005051 /* automatic parse from the BIOS config */
5052 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005053 if (err < 0)
5054 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005055
Takashi Iwai60a6a842011-07-27 14:01:24 +02005056 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005057 alc_auto_fill_adc_caps(codec);
5058 alc_rebuild_imux_for_auto_mic(codec);
5059 alc_remove_invalid_adc_nids(codec);
5060 }
5061
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005062 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005063 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005064
5065 if (!spec->no_analog && has_cdefine_beep(codec)) {
5066 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005067 if (err < 0)
5068 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005069 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005070 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005071
5072 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5073
5074 spec->vmaster_nid = 0x02;
5075
5076 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005077#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005078 codec->patch_ops.resume = alc269_resume;
5079#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005080 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081 spec->shutup = alc269_shutup;
5082
5083 alc_init_jacks(codec);
5084#ifdef CONFIG_SND_HDA_POWER_SAVE
5085 if (!spec->loopback.amplist)
5086 spec->loopback.amplist = alc269_loopbacks;
5087 if (alc269_mic2_for_mute_led(codec))
5088 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5089#endif
5090
5091 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005092
5093 error:
5094 alc_free(codec);
5095 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005096}
5097
5098/*
5099 * ALC861
5100 */
5101
Takashi Iwai1d045db2011-07-07 18:23:21 +02005102static int alc861_parse_auto_config(struct hda_codec *codec)
5103{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005104 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005105 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5106 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005107}
5108
Takashi Iwai1d045db2011-07-07 18:23:21 +02005109#ifdef CONFIG_SND_HDA_POWER_SAVE
5110static const struct hda_amp_list alc861_loopbacks[] = {
5111 { 0x15, HDA_INPUT, 0 },
5112 { 0x15, HDA_INPUT, 1 },
5113 { 0x15, HDA_INPUT, 2 },
5114 { 0x15, HDA_INPUT, 3 },
5115 { } /* end */
5116};
5117#endif
5118
5119
5120/* Pin config fixes */
5121enum {
5122 PINFIX_FSC_AMILO_PI1505,
5123};
5124
5125static const struct alc_fixup alc861_fixups[] = {
5126 [PINFIX_FSC_AMILO_PI1505] = {
5127 .type = ALC_FIXUP_PINS,
5128 .v.pins = (const struct alc_pincfg[]) {
5129 { 0x0b, 0x0221101f }, /* HP */
5130 { 0x0f, 0x90170310 }, /* speaker */
5131 { }
5132 }
5133 },
5134};
5135
5136static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5137 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5138 {}
5139};
5140
5141/*
5142 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005143static int patch_alc861(struct hda_codec *codec)
5144{
5145 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005146 int err;
5147
5148 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5149 if (spec == NULL)
5150 return -ENOMEM;
5151
5152 codec->spec = spec;
5153
5154 spec->mixer_nid = 0x15;
5155
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005156 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5157 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005158
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005159 /* automatic parse from the BIOS config */
5160 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005161 if (err < 0)
5162 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005163
Takashi Iwai60a6a842011-07-27 14:01:24 +02005164 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005165 alc_auto_fill_adc_caps(codec);
5166 alc_rebuild_imux_for_auto_mic(codec);
5167 alc_remove_invalid_adc_nids(codec);
5168 }
5169
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005170 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005171 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005172
5173 if (!spec->no_analog) {
5174 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005175 if (err < 0)
5176 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005177 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5178 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005179
5180 spec->vmaster_nid = 0x03;
5181
5182 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5183
5184 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005185 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005186#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005187 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005188 if (!spec->loopback.amplist)
5189 spec->loopback.amplist = alc861_loopbacks;
5190#endif
5191
5192 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005193
5194 error:
5195 alc_free(codec);
5196 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005197}
5198
5199/*
5200 * ALC861-VD support
5201 *
5202 * Based on ALC882
5203 *
5204 * In addition, an independent DAC
5205 */
5206#ifdef CONFIG_SND_HDA_POWER_SAVE
5207#define alc861vd_loopbacks alc880_loopbacks
5208#endif
5209
Takashi Iwai1d045db2011-07-07 18:23:21 +02005210static int alc861vd_parse_auto_config(struct hda_codec *codec)
5211{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005212 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005213 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5214 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005215}
5216
Takashi Iwai1d045db2011-07-07 18:23:21 +02005217enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005218 ALC660VD_FIX_ASUS_GPIO1,
5219 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005220};
5221
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005222/* exclude VREF80 */
5223static void alc861vd_fixup_dallas(struct hda_codec *codec,
5224 const struct alc_fixup *fix, int action)
5225{
5226 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5227 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5228 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5229 }
5230}
5231
Takashi Iwai1d045db2011-07-07 18:23:21 +02005232static const struct alc_fixup alc861vd_fixups[] = {
5233 [ALC660VD_FIX_ASUS_GPIO1] = {
5234 .type = ALC_FIXUP_VERBS,
5235 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005236 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005237 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5238 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5239 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5240 { }
5241 }
5242 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005243 [ALC861VD_FIX_DALLAS] = {
5244 .type = ALC_FIXUP_FUNC,
5245 .v.func = alc861vd_fixup_dallas,
5246 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005247};
5248
5249static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005250 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005251 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005252 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005253 {}
5254};
5255
5256static const struct hda_verb alc660vd_eapd_verbs[] = {
5257 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5258 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5259 { }
5260};
5261
5262/*
5263 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005264static int patch_alc861vd(struct hda_codec *codec)
5265{
5266 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005267 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005268
5269 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5270 if (spec == NULL)
5271 return -ENOMEM;
5272
5273 codec->spec = spec;
5274
5275 spec->mixer_nid = 0x0b;
5276
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005277 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5278 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005279
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005280 /* automatic parse from the BIOS config */
5281 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005282 if (err < 0)
5283 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005284
Takashi Iwai1d045db2011-07-07 18:23:21 +02005285 if (codec->vendor_id == 0x10ec0660) {
5286 /* always turn on EAPD */
5287 add_verb(spec, alc660vd_eapd_verbs);
5288 }
5289
Takashi Iwai60a6a842011-07-27 14:01:24 +02005290 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005291 alc_auto_fill_adc_caps(codec);
5292 alc_rebuild_imux_for_auto_mic(codec);
5293 alc_remove_invalid_adc_nids(codec);
5294 }
5295
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005296 if (!spec->no_analog && !spec->cap_mixer)
5297 set_capture_mixer(codec);
5298
5299 if (!spec->no_analog) {
5300 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005301 if (err < 0)
5302 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005303 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5304 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005305
5306 spec->vmaster_nid = 0x02;
5307
5308 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5309
5310 codec->patch_ops = alc_patch_ops;
5311
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005312 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005313 spec->shutup = alc_eapd_shutup;
5314#ifdef CONFIG_SND_HDA_POWER_SAVE
5315 if (!spec->loopback.amplist)
5316 spec->loopback.amplist = alc861vd_loopbacks;
5317#endif
5318
5319 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005320
5321 error:
5322 alc_free(codec);
5323 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005324}
5325
5326/*
5327 * ALC662 support
5328 *
5329 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5330 * configuration. Each pin widget can choose any input DACs and a mixer.
5331 * Each ADC is connected from a mixer of all inputs. This makes possible
5332 * 6-channel independent captures.
5333 *
5334 * In addition, an independent DAC for the multi-playback (not used in this
5335 * driver yet).
5336 */
5337#ifdef CONFIG_SND_HDA_POWER_SAVE
5338#define alc662_loopbacks alc880_loopbacks
5339#endif
5340
5341/*
5342 * BIOS auto configuration
5343 */
5344
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005345static int alc662_parse_auto_config(struct hda_codec *codec)
5346{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005347 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005348 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5349 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5350 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005351
Kailang Yang6227cdc2010-02-25 08:36:52 +01005352 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5353 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005354 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005355 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005356 ssids = alc662_ssids;
5357 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005358}
5359
Todd Broch6be79482010-12-07 16:51:05 -08005360static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005361 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005362{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005363 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005364 return;
Todd Broch6be79482010-12-07 16:51:05 -08005365 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5366 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5367 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5368 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5369 (0 << AC_AMPCAP_MUTE_SHIFT)))
5370 printk(KERN_WARNING
5371 "hda_codec: failed to override amp caps for NID 0x2\n");
5372}
5373
David Henningsson6cb3b702010-09-09 08:51:44 +02005374enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005375 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005376 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005377 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005378 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005379 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005380 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005381 ALC662_FIXUP_ASUS_MODE1,
5382 ALC662_FIXUP_ASUS_MODE2,
5383 ALC662_FIXUP_ASUS_MODE3,
5384 ALC662_FIXUP_ASUS_MODE4,
5385 ALC662_FIXUP_ASUS_MODE5,
5386 ALC662_FIXUP_ASUS_MODE6,
5387 ALC662_FIXUP_ASUS_MODE7,
5388 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005389};
5390
5391static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005392 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005393 .type = ALC_FIXUP_PINS,
5394 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005395 { 0x15, 0x99130112 }, /* subwoofer */
5396 { }
5397 }
5398 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005399 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005400 .type = ALC_FIXUP_PINS,
5401 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005402 { 0x17, 0x99130112 }, /* subwoofer */
5403 { }
5404 }
5405 },
Todd Broch6be79482010-12-07 16:51:05 -08005406 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005407 .type = ALC_FIXUP_FUNC,
5408 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005409 },
5410 [ALC662_FIXUP_CZC_P10T] = {
5411 .type = ALC_FIXUP_VERBS,
5412 .v.verbs = (const struct hda_verb[]) {
5413 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5414 {}
5415 }
5416 },
David Henningsson94024cd2011-04-29 14:10:55 +02005417 [ALC662_FIXUP_SKU_IGNORE] = {
5418 .type = ALC_FIXUP_SKU,
5419 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005420 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005421 [ALC662_FIXUP_HP_RP5800] = {
5422 .type = ALC_FIXUP_PINS,
5423 .v.pins = (const struct alc_pincfg[]) {
5424 { 0x14, 0x0221201f }, /* HP out */
5425 { }
5426 },
5427 .chained = true,
5428 .chain_id = ALC662_FIXUP_SKU_IGNORE
5429 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005430 [ALC662_FIXUP_ASUS_MODE1] = {
5431 .type = ALC_FIXUP_PINS,
5432 .v.pins = (const struct alc_pincfg[]) {
5433 { 0x14, 0x99130110 }, /* speaker */
5434 { 0x18, 0x01a19c20 }, /* mic */
5435 { 0x19, 0x99a3092f }, /* int-mic */
5436 { 0x21, 0x0121401f }, /* HP out */
5437 { }
5438 },
5439 .chained = true,
5440 .chain_id = ALC662_FIXUP_SKU_IGNORE
5441 },
5442 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005443 .type = ALC_FIXUP_PINS,
5444 .v.pins = (const struct alc_pincfg[]) {
5445 { 0x14, 0x99130110 }, /* speaker */
5446 { 0x18, 0x01a19820 }, /* mic */
5447 { 0x19, 0x99a3092f }, /* int-mic */
5448 { 0x1b, 0x0121401f }, /* HP out */
5449 { }
5450 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005451 .chained = true,
5452 .chain_id = ALC662_FIXUP_SKU_IGNORE
5453 },
5454 [ALC662_FIXUP_ASUS_MODE3] = {
5455 .type = ALC_FIXUP_PINS,
5456 .v.pins = (const struct alc_pincfg[]) {
5457 { 0x14, 0x99130110 }, /* speaker */
5458 { 0x15, 0x0121441f }, /* HP */
5459 { 0x18, 0x01a19840 }, /* mic */
5460 { 0x19, 0x99a3094f }, /* int-mic */
5461 { 0x21, 0x01211420 }, /* HP2 */
5462 { }
5463 },
5464 .chained = true,
5465 .chain_id = ALC662_FIXUP_SKU_IGNORE
5466 },
5467 [ALC662_FIXUP_ASUS_MODE4] = {
5468 .type = ALC_FIXUP_PINS,
5469 .v.pins = (const struct alc_pincfg[]) {
5470 { 0x14, 0x99130110 }, /* speaker */
5471 { 0x16, 0x99130111 }, /* speaker */
5472 { 0x18, 0x01a19840 }, /* mic */
5473 { 0x19, 0x99a3094f }, /* int-mic */
5474 { 0x21, 0x0121441f }, /* HP */
5475 { }
5476 },
5477 .chained = true,
5478 .chain_id = ALC662_FIXUP_SKU_IGNORE
5479 },
5480 [ALC662_FIXUP_ASUS_MODE5] = {
5481 .type = ALC_FIXUP_PINS,
5482 .v.pins = (const struct alc_pincfg[]) {
5483 { 0x14, 0x99130110 }, /* speaker */
5484 { 0x15, 0x0121441f }, /* HP */
5485 { 0x16, 0x99130111 }, /* speaker */
5486 { 0x18, 0x01a19840 }, /* mic */
5487 { 0x19, 0x99a3094f }, /* int-mic */
5488 { }
5489 },
5490 .chained = true,
5491 .chain_id = ALC662_FIXUP_SKU_IGNORE
5492 },
5493 [ALC662_FIXUP_ASUS_MODE6] = {
5494 .type = ALC_FIXUP_PINS,
5495 .v.pins = (const struct alc_pincfg[]) {
5496 { 0x14, 0x99130110 }, /* speaker */
5497 { 0x15, 0x01211420 }, /* HP2 */
5498 { 0x18, 0x01a19840 }, /* mic */
5499 { 0x19, 0x99a3094f }, /* int-mic */
5500 { 0x1b, 0x0121441f }, /* HP */
5501 { }
5502 },
5503 .chained = true,
5504 .chain_id = ALC662_FIXUP_SKU_IGNORE
5505 },
5506 [ALC662_FIXUP_ASUS_MODE7] = {
5507 .type = ALC_FIXUP_PINS,
5508 .v.pins = (const struct alc_pincfg[]) {
5509 { 0x14, 0x99130110 }, /* speaker */
5510 { 0x17, 0x99130111 }, /* speaker */
5511 { 0x18, 0x01a19840 }, /* mic */
5512 { 0x19, 0x99a3094f }, /* int-mic */
5513 { 0x1b, 0x01214020 }, /* HP */
5514 { 0x21, 0x0121401f }, /* HP */
5515 { }
5516 },
5517 .chained = true,
5518 .chain_id = ALC662_FIXUP_SKU_IGNORE
5519 },
5520 [ALC662_FIXUP_ASUS_MODE8] = {
5521 .type = ALC_FIXUP_PINS,
5522 .v.pins = (const struct alc_pincfg[]) {
5523 { 0x14, 0x99130110 }, /* speaker */
5524 { 0x12, 0x99a30970 }, /* int-mic */
5525 { 0x15, 0x01214020 }, /* HP */
5526 { 0x17, 0x99130111 }, /* speaker */
5527 { 0x18, 0x01a19840 }, /* mic */
5528 { 0x21, 0x0121401f }, /* HP */
5529 { }
5530 },
5531 .chained = true,
5532 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005533 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005534};
5535
Takashi Iwaia9111322011-05-02 11:30:18 +02005536static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02005537 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01005538 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02005539 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04005540 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005541 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005542 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05005543 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06005544 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02005545 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01005546 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005547
5548#if 0
5549 /* Below is a quirk table taken from the old code.
5550 * Basically the device should work as is without the fixup table.
5551 * If BIOS doesn't give a proper info, enable the corresponding
5552 * fixup entry.
5553 */
5554 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5555 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5556 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5557 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5558 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5559 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5560 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5561 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5562 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5563 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5564 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5565 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5566 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5567 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5568 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5569 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5570 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5571 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5572 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5573 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5574 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5575 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5576 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5577 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5578 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5579 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5580 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5581 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5582 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5583 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5584 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5585 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5586 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5587 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5588 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5589 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5590 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5591 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5592 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5593 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5594 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5595 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5596 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5597 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5598 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5599 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5600 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5601 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5602 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5603 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5604#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02005605 {}
5606};
5607
Todd Broch6be79482010-12-07 16:51:05 -08005608static const struct alc_model_fixup alc662_fixup_models[] = {
5609 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02005610 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5611 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5612 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5613 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5614 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5615 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5616 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5617 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08005618 {}
5619};
David Henningsson6cb3b702010-09-09 08:51:44 +02005620
5621
Takashi Iwai1d045db2011-07-07 18:23:21 +02005622/*
5623 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005624static int patch_alc662(struct hda_codec *codec)
5625{
5626 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005627 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005628
5629 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5630 if (!spec)
5631 return -ENOMEM;
5632
5633 codec->spec = spec;
5634
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005635 spec->mixer_nid = 0x0b;
5636
Takashi Iwai53c334a2011-08-23 18:27:14 +02005637 /* handle multiple HPs as is */
5638 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5639
Kailang Yangda00c242010-03-19 11:23:45 +01005640 alc_auto_parse_customize_define(codec);
5641
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02005642 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5643
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005644 err = alc_codec_rename_from_preset(codec);
5645 if (err < 0)
5646 goto error;
5647
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005648 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005649 codec->bus->pci->subsystem_vendor == 0x1025 &&
5650 spec->cdefine.platform_type == 1) {
5651 if (alc_codec_rename(codec, "ALC272X") < 0)
5652 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005653 }
Kailang Yang274693f2009-12-03 10:07:50 +01005654
Takashi Iwaib9c51062011-08-24 18:08:07 +02005655 alc_pick_fixup(codec, alc662_fixup_models,
5656 alc662_fixup_tbl, alc662_fixups);
5657 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5658 /* automatic parse from the BIOS config */
5659 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005660 if (err < 0)
5661 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005662
Takashi Iwai60a6a842011-07-27 14:01:24 +02005663 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005664 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02005665 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005666 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02005667 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005668
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005669 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02005670 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01005671
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005672 if (!spec->no_analog && has_cdefine_beep(codec)) {
5673 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005674 if (err < 0)
5675 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01005676 switch (codec->vendor_id) {
5677 case 0x10ec0662:
5678 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5679 break;
5680 case 0x10ec0272:
5681 case 0x10ec0663:
5682 case 0x10ec0665:
5683 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5684 break;
5685 case 0x10ec0273:
5686 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5687 break;
5688 }
Kailang Yangcec27c82010-02-04 14:18:18 +01005689 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01005690 spec->vmaster_nid = 0x02;
5691
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005692 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5693
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005694 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02005695 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02005696 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02005697
Kailang Yangbf1b0222010-10-21 08:49:56 +02005698 alc_init_jacks(codec);
5699
Takashi Iwaicb53c622007-08-10 17:21:45 +02005700#ifdef CONFIG_SND_HDA_POWER_SAVE
5701 if (!spec->loopback.amplist)
5702 spec->loopback.amplist = alc662_loopbacks;
5703#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005704
5705 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005706
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005707 error:
5708 alc_free(codec);
5709 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02005710}
5711
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005712/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005713 * ALC680 support
5714 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005715
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005716static int alc680_parse_auto_config(struct hda_codec *codec)
5717{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005718 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005719}
5720
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005721/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005722 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005723static int patch_alc680(struct hda_codec *codec)
5724{
5725 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005726 int err;
5727
5728 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5729 if (spec == NULL)
5730 return -ENOMEM;
5731
5732 codec->spec = spec;
5733
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005734 /* ALC680 has no aa-loopback mixer */
5735
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005736 /* automatic parse from the BIOS config */
5737 err = alc680_parse_auto_config(codec);
5738 if (err < 0) {
5739 alc_free(codec);
5740 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005741 }
5742
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005743 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005744 set_capture_mixer(codec);
5745
5746 spec->vmaster_nid = 0x02;
5747
5748 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005749 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005750
5751 return 0;
5752}
5753
5754/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755 * patch entries
5756 */
Takashi Iwaia9111322011-05-02 11:30:18 +02005757static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02005758 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005760 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005761 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02005762 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005763 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005764 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02005765 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005766 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02005767 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005768 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005769 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005770 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5771 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5772 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005773 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02005774 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005775 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5776 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02005777 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01005778 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01005779 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005780 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005781 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005782 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02005783 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02005784 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02005785 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02005786 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02005787 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005788 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005789 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02005790 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02005791 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005792 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02005793 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01005794 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005795 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005796 {} /* terminator */
5797};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005798
5799MODULE_ALIAS("snd-hda-codec-id:10ec*");
5800
5801MODULE_LICENSE("GPL");
5802MODULE_DESCRIPTION("Realtek HD-audio codec");
5803
5804static struct hda_codec_preset_list realtek_list = {
5805 .preset = snd_hda_preset_realtek,
5806 .owner = THIS_MODULE,
5807};
5808
5809static int __init patch_realtek_init(void)
5810{
5811 return snd_hda_add_codec_preset(&realtek_list);
5812}
5813
5814static void __exit patch_realtek_exit(void)
5815{
5816 snd_hda_delete_codec_preset(&realtek_list);
5817}
5818
5819module_init(patch_realtek_init)
5820module_exit(patch_realtek_exit)