blob: de63619decdb1e2f1f29e80b2aadac0bd04e3e65 [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 */
Takashi Iwai834be882006-03-01 14:16:17 +0100165 unsigned int 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 */
Takashi Iwaid922b512011-04-28 12:18:53 +0200170 unsigned int automute:1; /* HP automute enabled */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200171 unsigned int detect_line:1; /* Line-out detection enabled */
172 unsigned int automute_lines:1; /* automute line-out as well */
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200173 unsigned int automute_hp_lo:1; /* both HP and LO available */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200174
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100175 /* other flags */
176 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200177 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100178 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200179 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200180 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwaid922b512011-04-28 12:18:53 +0200181
182 /* auto-mute control */
183 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200184 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200185
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200186 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200187 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100188
Takashi Iwai2134ea42008-01-10 16:53:55 +0100189 /* for virtual master */
190 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200191#ifdef CONFIG_SND_HDA_POWER_SAVE
192 struct hda_loopback_check loopback;
193#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200194
195 /* for PLL fix */
196 hda_nid_t pll_nid;
197 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100198
199 /* fix-up list */
200 int fixup_id;
201 const struct alc_fixup *fixup_list;
202 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200203
204 /* multi-io */
205 int multi_ios;
206 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200207
208 /* bind volumes */
209 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100210};
211
Takashi Iwai1d045db2011-07-07 18:23:21 +0200212#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
Takashi Iwai44c02402011-07-08 15:14:19 +0200214static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
215 int dir, unsigned int bits)
216{
217 if (!nid)
218 return false;
219 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
220 if (query_amp_caps(codec, nid, dir) & bits)
221 return true;
222 return false;
223}
224
225#define nid_has_mute(codec, nid, dir) \
226 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
227#define nid_has_volume(codec, nid, dir) \
228 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
229
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230/*
231 * input MUX handling
232 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200233static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
234 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235{
236 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
237 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200238 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
239 if (mux_idx >= spec->num_mux_defs)
240 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100241 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
242 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200243 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200246static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
247 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
249 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
250 struct alc_spec *spec = codec->spec;
251 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
252
253 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
254 return 0;
255}
256
Takashi Iwai21268962011-07-07 15:01:13 +0200257static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
Takashi Iwai21268962011-07-07 15:01:13 +0200259 struct alc_spec *spec = codec->spec;
260 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
261
262 if (spec->cur_adc && spec->cur_adc != new_adc) {
263 /* stream is running, let's swap the current ADC */
264 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
265 spec->cur_adc = new_adc;
266 snd_hda_codec_setup_stream(codec, new_adc,
267 spec->cur_adc_stream_tag, 0,
268 spec->cur_adc_format);
269 return true;
270 }
271 return false;
272}
273
274/* select the given imux item; either unmute exclusively or select the route */
275static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
276 unsigned int idx, bool force)
277{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100279 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100280 unsigned int mux_idx;
Takashi Iwai21268962011-07-07 15:01:13 +0200281 int i, type;
282 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283
Takashi Iwaicd896c32008-11-18 12:36:33 +0100284 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
285 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100286 if (!imux->num_items && mux_idx > 0)
287 imux = &spec->input_mux[0];
Takashi Iwaicd896c32008-11-18 12:36:33 +0100288
Takashi Iwai21268962011-07-07 15:01:13 +0200289 if (idx >= imux->num_items)
290 idx = imux->num_items - 1;
291 if (spec->cur_mux[adc_idx] == idx && !force)
292 return 0;
293 spec->cur_mux[adc_idx] = idx;
294
295 if (spec->dyn_adc_switch) {
296 alc_dyn_adc_pcm_resetup(codec, idx);
297 adc_idx = spec->dyn_adc_idx[idx];
298 }
299
300 nid = spec->capsrc_nids ?
301 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
302
303 /* no selection? */
304 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
305 return 1;
306
Takashi Iwaia22d5432009-07-27 12:54:26 +0200307 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200308 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100309 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100310 for (i = 0; i < imux->num_items; i++) {
311 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
312 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
313 imux->items[i].index,
314 HDA_AMP_MUTE, v);
315 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100316 } else {
317 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200318 snd_hda_codec_write_cache(codec, nid, 0,
319 AC_VERB_SET_CONNECT_SEL,
320 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100321 }
Takashi Iwai21268962011-07-07 15:01:13 +0200322 return 1;
323}
324
325static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
326 struct snd_ctl_elem_value *ucontrol)
327{
328 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
329 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
330 return alc_mux_select(codec, adc_idx,
331 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100332}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100335 * set up the input pin config (depending on the given auto-pin type)
336 */
337static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
338 int auto_pin_type)
339{
340 unsigned int val = PIN_IN;
341
Takashi Iwai86e29592010-09-09 14:50:17 +0200342 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100343 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200344 unsigned int oldval;
345 oldval = snd_hda_codec_read(codec, nid, 0,
346 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100347 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100348 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200349 /* if the default pin setup is vref50, we give it priority */
350 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100351 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200352 else if (pincap & AC_PINCAP_VREF_50)
353 val = PIN_VREF50;
354 else if (pincap & AC_PINCAP_VREF_100)
355 val = PIN_VREF100;
356 else if (pincap & AC_PINCAP_VREF_GRD)
357 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100358 }
359 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
360}
361
362/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200363 * Append the given mixer and verb elements for the later use
364 * The mixer array is referred in build_controls(), and init_verbs are
365 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100366 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200367static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100368{
369 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
370 return;
371 spec->mixers[spec->num_mixers++] = mix;
372}
373
374static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
375{
376 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
377 return;
378 spec->init_verbs[spec->num_init_verbs++] = verb;
379}
380
381/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200382 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100383 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200384/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200385static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200386 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
387 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
388 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
389 { }
390};
391
Takashi Iwaia9111322011-05-02 11:30:18 +0200392static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200393 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
394 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
395 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
396 { }
397};
398
Takashi Iwaia9111322011-05-02 11:30:18 +0200399static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200400 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
401 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
402 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
403 { }
404};
405
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200406/*
407 * Fix hardware PLL issue
408 * On some codecs, the analog PLL gating control must be off while
409 * the default value is 1.
410 */
411static void alc_fix_pll(struct hda_codec *codec)
412{
413 struct alc_spec *spec = codec->spec;
414 unsigned int val;
415
416 if (!spec->pll_nid)
417 return;
418 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
419 spec->pll_coef_idx);
420 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
421 AC_VERB_GET_PROC_COEF, 0);
422 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
423 spec->pll_coef_idx);
424 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
425 val & ~(1 << spec->pll_coef_bit));
426}
427
428static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
429 unsigned int coef_idx, unsigned int coef_bit)
430{
431 struct alc_spec *spec = codec->spec;
432 spec->pll_nid = nid;
433 spec->pll_coef_idx = coef_idx;
434 spec->pll_coef_bit = coef_bit;
435 alc_fix_pll(codec);
436}
437
Takashi Iwai1d045db2011-07-07 18:23:21 +0200438/*
439 * Jack-reporting via input-jack layer
440 */
441
442/* initialization of jacks; currently checks only a few known pins */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200443static int alc_init_jacks(struct hda_codec *codec)
444{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100445#ifdef CONFIG_SND_HDA_INPUT_JACK
Kailang Yang9ad0e492010-09-14 23:22:00 +0200446 struct alc_spec *spec = codec->spec;
447 int err;
448 unsigned int hp_nid = spec->autocfg.hp_pins[0];
Takashi Iwai21268962011-07-07 15:01:13 +0200449 unsigned int mic_nid = spec->ext_mic_pin;
450 unsigned int dock_nid = spec->dock_mic_pin;
Kailang Yang9ad0e492010-09-14 23:22:00 +0200451
Takashi Iwai265a0242010-09-21 11:26:21 +0200452 if (hp_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100453 err = snd_hda_input_jack_add(codec, hp_nid,
454 SND_JACK_HEADPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200455 if (err < 0)
456 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100457 snd_hda_input_jack_report(codec, hp_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200458 }
Kailang Yang9ad0e492010-09-14 23:22:00 +0200459
Takashi Iwai265a0242010-09-21 11:26:21 +0200460 if (mic_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100461 err = snd_hda_input_jack_add(codec, mic_nid,
462 SND_JACK_MICROPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200463 if (err < 0)
464 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100465 snd_hda_input_jack_report(codec, mic_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200466 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200467 if (dock_nid) {
468 err = snd_hda_input_jack_add(codec, dock_nid,
469 SND_JACK_MICROPHONE, NULL);
470 if (err < 0)
471 return err;
472 snd_hda_input_jack_report(codec, dock_nid);
473 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100474#endif /* CONFIG_SND_HDA_INPUT_JACK */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200475 return 0;
476}
Kailang Yang9ad0e492010-09-14 23:22:00 +0200477
Takashi Iwai1d045db2011-07-07 18:23:21 +0200478/*
479 * Jack detections for HP auto-mute and mic-switch
480 */
481
482/* check each pin in the given array; returns true if any of them is plugged */
483static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200484{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200485 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200486
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200487 for (i = 0; i < num_pins; i++) {
488 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200489 if (!nid)
490 break;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100491 snd_hda_input_jack_report(codec, nid);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200492 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200493 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200494 return present;
495}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200496
Takashi Iwai1d045db2011-07-07 18:23:21 +0200497/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200498static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200499 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200500{
501 struct alc_spec *spec = codec->spec;
502 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200503 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200504 int i;
505
506 for (i = 0; i < num_pins; i++) {
507 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200508 if (!nid)
509 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200510 switch (spec->automute_mode) {
511 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200512 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200513 AC_VERB_SET_PIN_WIDGET_CONTROL,
514 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200515 break;
516 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200517 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200518 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200519 break;
520 case ALC_AUTOMUTE_MIXER:
521 nid = spec->automute_mixer_nid[i];
522 if (!nid)
523 break;
524 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200525 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200526 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200527 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200528 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200529 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200530 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200531}
532
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200533/* Toggle internal speakers muting */
534static void update_speakers(struct hda_codec *codec)
535{
536 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200537 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200538
Takashi Iwaic0a20262011-06-10 15:28:15 +0200539 /* Control HP pins/amps depending on master_mute state;
540 * in general, HP pins/amps control should be enabled in all cases,
541 * but currently set only for master_mute, just to be safe
542 */
543 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
544 spec->autocfg.hp_pins, spec->master_mute, true);
545
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200546 if (!spec->automute)
547 on = 0;
548 else
549 on = spec->jack_present | spec->line_jack_present;
550 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200551 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200552 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200553
554 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 /* if LO is a copy of either HP or Speaker, don't need to handle it */
556 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
557 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558 return;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200559 if (!spec->automute_lines || !spec->automute)
560 on = 0;
561 else
562 on = spec->jack_present;
563 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200564 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200566}
567
Takashi Iwai24519912011-08-16 15:08:49 +0200568static void call_update_speakers(struct hda_codec *codec)
569{
570 struct alc_spec *spec = codec->spec;
571 if (spec->automute_hook)
572 spec->automute_hook(codec);
573 else
574 update_speakers(codec);
575}
576
Takashi Iwai1d045db2011-07-07 18:23:21 +0200577/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200578static void alc_hp_automute(struct hda_codec *codec)
579{
580 struct alc_spec *spec = codec->spec;
581
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582 spec->jack_present =
583 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
584 spec->autocfg.hp_pins);
Takashi Iwai3c715a92011-08-23 12:41:09 +0200585 if (!spec->automute)
586 return;
Takashi Iwai24519912011-08-16 15:08:49 +0200587 call_update_speakers(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588}
589
Takashi Iwai1d045db2011-07-07 18:23:21 +0200590/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591static void alc_line_automute(struct hda_codec *codec)
592{
593 struct alc_spec *spec = codec->spec;
594
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200595 spec->line_jack_present =
596 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
597 spec->autocfg.line_out_pins);
Takashi Iwai3c715a92011-08-23 12:41:09 +0200598 if (!spec->automute || !spec->detect_line)
599 return;
Takashi Iwai24519912011-08-16 15:08:49 +0200600 call_update_speakers(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200601}
602
Takashi Iwai8d087c72011-06-28 12:45:47 +0200603#define get_connection_index(codec, mux, nid) \
604 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200605
Takashi Iwai1d045db2011-07-07 18:23:21 +0200606/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200607static void alc_mic_automute(struct hda_codec *codec)
608{
609 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200610 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200611
Takashi Iwai21268962011-07-07 15:01:13 +0200612 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200613 return;
614 if (snd_BUG_ON(!spec->adc_nids))
615 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200616 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200617 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200618
Takashi Iwai21268962011-07-07 15:01:13 +0200619 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
620 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
621 else if (spec->dock_mic_idx >= 0 &&
622 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
623 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
624 else
625 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Takashi Iwai6c819492009-08-10 18:47:44 +0200626
Takashi Iwai21268962011-07-07 15:01:13 +0200627 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
628 if (spec->dock_mic_idx >= 0)
629 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200630}
631
Kailang Yangc9b58002007-10-16 14:30:01 +0200632/* unsolicited event for HP jack sensing */
633static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
634{
635 if (codec->vendor_id == 0x10ec0880)
636 res >>= 28;
637 else
638 res >>= 26;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200639 switch (res) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200640 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200641 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200642 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200643 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200644 alc_line_automute(codec);
645 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200646 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200647 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200648 break;
649 }
Kailang Yang7fb0d782008-10-15 11:12:35 +0200650}
651
Takashi Iwai1d045db2011-07-07 18:23:21 +0200652/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200653static void alc_inithook(struct hda_codec *codec)
654{
Takashi Iwaid922b512011-04-28 12:18:53 +0200655 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200656 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200657 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200658}
659
Kailang Yangf9423e72008-05-27 12:32:25 +0200660/* additional initialization for ALC888 variants */
661static void alc888_coef_init(struct hda_codec *codec)
662{
663 unsigned int tmp;
664
665 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
666 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
667 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100668 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200669 /* alc888S-VC */
670 snd_hda_codec_read(codec, 0x20, 0,
671 AC_VERB_SET_PROC_COEF, 0x830);
672 else
673 /* alc888-VB */
674 snd_hda_codec_read(codec, 0x20, 0,
675 AC_VERB_SET_PROC_COEF, 0x3030);
676}
677
Takashi Iwai1d045db2011-07-07 18:23:21 +0200678/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200679static void alc889_coef_init(struct hda_codec *codec)
680{
681 unsigned int tmp;
682
683 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
684 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
685 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
686 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
687}
688
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100689/* turn on/off EAPD control (only if available) */
690static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
691{
692 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
693 return;
694 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
695 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
696 on ? 2 : 0);
697}
698
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200699/* turn on/off EAPD controls of the codec */
700static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
701{
702 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200703 static hda_nid_t pins[] = {
704 0x0f, 0x10, 0x14, 0x15, 0
705 };
706 hda_nid_t *p;
707 for (p = pins; *p; p++)
708 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200709}
710
Takashi Iwai1c716152011-04-07 10:37:16 +0200711/* generic shutup callback;
712 * just turning off EPAD and a little pause for avoiding pop-noise
713 */
714static void alc_eapd_shutup(struct hda_codec *codec)
715{
716 alc_auto_setup_eapd(codec, false);
717 msleep(200);
718}
719
Takashi Iwai1d045db2011-07-07 18:23:21 +0200720/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200721static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200722{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200723 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200724
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200725 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200726 switch (type) {
727 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200728 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
729 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200730 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200731 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
732 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200733 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200734 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
735 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200736 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200737 switch (codec->vendor_id) {
738 case 0x10ec0260:
739 snd_hda_codec_write(codec, 0x1a, 0,
740 AC_VERB_SET_COEF_INDEX, 7);
741 tmp = snd_hda_codec_read(codec, 0x1a, 0,
742 AC_VERB_GET_PROC_COEF, 0);
743 snd_hda_codec_write(codec, 0x1a, 0,
744 AC_VERB_SET_COEF_INDEX, 7);
745 snd_hda_codec_write(codec, 0x1a, 0,
746 AC_VERB_SET_PROC_COEF,
747 tmp | 0x2010);
748 break;
749 case 0x10ec0262:
750 case 0x10ec0880:
751 case 0x10ec0882:
752 case 0x10ec0883:
753 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100754 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100755 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200756 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200757 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200758 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200759 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200760 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100761#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200762 case 0x10ec0267:
763 case 0x10ec0268:
764 snd_hda_codec_write(codec, 0x20, 0,
765 AC_VERB_SET_COEF_INDEX, 7);
766 tmp = snd_hda_codec_read(codec, 0x20, 0,
767 AC_VERB_GET_PROC_COEF, 0);
768 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200769 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200770 snd_hda_codec_write(codec, 0x20, 0,
771 AC_VERB_SET_PROC_COEF,
772 tmp | 0x3000);
773 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100774#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200775 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200776 break;
777 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200778}
Kailang Yangea1fb292008-08-26 12:58:38 +0200779
Takashi Iwai1d045db2011-07-07 18:23:21 +0200780/*
781 * Auto-Mute mode mixer enum support
782 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200783static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
784 struct snd_ctl_elem_info *uinfo)
785{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200786 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
787 struct alc_spec *spec = codec->spec;
788 static const char * const texts2[] = {
789 "Disabled", "Enabled"
790 };
791 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200792 "Disabled", "Speaker Only", "Line-Out+Speaker"
793 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200794 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200795
796 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
797 uinfo->count = 1;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200798 if (spec->automute_hp_lo) {
799 uinfo->value.enumerated.items = 3;
800 texts = texts3;
801 } else {
802 uinfo->value.enumerated.items = 2;
803 texts = texts2;
804 }
805 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
806 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200807 strcpy(uinfo->value.enumerated.name,
808 texts[uinfo->value.enumerated.item]);
809 return 0;
810}
811
812static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
813 struct snd_ctl_elem_value *ucontrol)
814{
815 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
816 struct alc_spec *spec = codec->spec;
817 unsigned int val;
818 if (!spec->automute)
819 val = 0;
820 else if (!spec->automute_lines)
821 val = 1;
822 else
823 val = 2;
824 ucontrol->value.enumerated.item[0] = val;
825 return 0;
826}
827
828static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
829 struct snd_ctl_elem_value *ucontrol)
830{
831 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
832 struct alc_spec *spec = codec->spec;
833
834 switch (ucontrol->value.enumerated.item[0]) {
835 case 0:
836 if (!spec->automute)
837 return 0;
838 spec->automute = 0;
839 break;
840 case 1:
841 if (spec->automute && !spec->automute_lines)
842 return 0;
843 spec->automute = 1;
844 spec->automute_lines = 0;
845 break;
846 case 2:
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200847 if (!spec->automute_hp_lo)
848 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200849 if (spec->automute && spec->automute_lines)
850 return 0;
851 spec->automute = 1;
852 spec->automute_lines = 1;
853 break;
854 default:
855 return -EINVAL;
856 }
Takashi Iwai24519912011-08-16 15:08:49 +0200857 call_update_speakers(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200858 return 1;
859}
860
Takashi Iwaia9111322011-05-02 11:30:18 +0200861static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200862 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
863 .name = "Auto-Mute Mode",
864 .info = alc_automute_mode_info,
865 .get = alc_automute_mode_get,
866 .put = alc_automute_mode_put,
867};
868
Takashi Iwai1d045db2011-07-07 18:23:21 +0200869static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
870{
871 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
872 return snd_array_new(&spec->kctls);
873}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200874
875static int alc_add_automute_mode_enum(struct hda_codec *codec)
876{
877 struct alc_spec *spec = codec->spec;
878 struct snd_kcontrol_new *knew;
879
880 knew = alc_kcontrol_new(spec);
881 if (!knew)
882 return -ENOMEM;
883 *knew = alc_automute_mode_enum;
884 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
885 if (!knew->name)
886 return -ENOMEM;
887 return 0;
888}
889
Takashi Iwai1d045db2011-07-07 18:23:21 +0200890/*
891 * Check the availability of HP/line-out auto-mute;
892 * Set up appropriately if really supported
893 */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200894static void alc_init_auto_hp(struct hda_codec *codec)
895{
896 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200897 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200898 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200899 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200900
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200901 if (cfg->hp_pins[0])
902 present++;
903 if (cfg->line_out_pins[0])
904 present++;
905 if (cfg->speaker_pins[0])
906 present++;
907 if (present < 2) /* need two different output types */
908 return;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200909 if (present == 3)
910 spec->automute_hp_lo = 1; /* both HP and LO automute */
Kailang Yangc9b58002007-10-16 14:30:01 +0200911
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200912 if (!cfg->speaker_pins[0] &&
913 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200914 memcpy(cfg->speaker_pins, cfg->line_out_pins,
915 sizeof(cfg->speaker_pins));
916 cfg->speaker_outs = cfg->line_outs;
917 }
918
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200919 if (!cfg->hp_pins[0] &&
920 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200921 memcpy(cfg->hp_pins, cfg->line_out_pins,
922 sizeof(cfg->hp_pins));
923 cfg->hp_outs = cfg->line_outs;
924 }
925
926 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200927 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200928 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200929 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200930 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200931 nid);
932 snd_hda_codec_write_cache(codec, nid, 0,
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200933 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +0200934 AC_USRSP_EN | ALC_HP_EVENT);
Takashi Iwaid922b512011-04-28 12:18:53 +0200935 spec->automute = 1;
936 spec->automute_mode = ALC_AUTOMUTE_PIN;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200937 }
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200938 if (spec->automute && cfg->line_out_pins[0] &&
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200939 cfg->speaker_pins[0] &&
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200940 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
941 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
942 for (i = 0; i < cfg->line_outs; i++) {
943 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200944 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200945 continue;
946 snd_printdd("realtek: Enable Line-Out auto-muting "
947 "on NID 0x%x\n", nid);
948 snd_hda_codec_write_cache(codec, nid, 0,
949 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +0200950 AC_USRSP_EN | ALC_FRONT_EVENT);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200951 spec->detect_line = 1;
952 }
Takashi Iwai52d3cb82011-05-17 10:04:08 +0200953 spec->automute_lines = spec->detect_line;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200954 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200955
956 if (spec->automute) {
957 /* create a control for automute mode */
958 alc_add_automute_mode_enum(codec);
959 spec->unsol_event = alc_sku_unsol_event;
960 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200961}
962
Takashi Iwai1d045db2011-07-07 18:23:21 +0200963/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200964static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
965{
966 int i;
967 for (i = 0; i < nums; i++)
968 if (list[i] == nid)
969 return i;
970 return -1;
971}
972
Takashi Iwai1d045db2011-07-07 18:23:21 +0200973/* check whether dynamic ADC-switching is available */
974static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
975{
976 struct alc_spec *spec = codec->spec;
977 struct hda_input_mux *imux = &spec->private_imux[0];
978 int i, n, idx;
979 hda_nid_t cap, pin;
980
981 if (imux != spec->input_mux) /* no dynamic imux? */
982 return false;
983
984 for (n = 0; n < spec->num_adc_nids; n++) {
985 cap = spec->private_capsrc_nids[n];
986 for (i = 0; i < imux->num_items; i++) {
987 pin = spec->imux_pins[i];
988 if (!pin)
989 return false;
990 if (get_connection_index(codec, cap, pin) < 0)
991 break;
992 }
993 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +0200994 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +0200995 }
996
997 for (i = 0; i < imux->num_items; i++) {
998 pin = spec->imux_pins[i];
999 for (n = 0; n < spec->num_adc_nids; n++) {
1000 cap = spec->private_capsrc_nids[n];
1001 idx = get_connection_index(codec, cap, pin);
1002 if (idx >= 0) {
1003 imux->items[i].index = idx;
1004 spec->dyn_adc_idx[i] = n;
1005 break;
1006 }
1007 }
1008 }
1009
1010 snd_printdd("realtek: enabling ADC switching\n");
1011 spec->dyn_adc_switch = 1;
1012 return true;
1013}
Takashi Iwai21268962011-07-07 15:01:13 +02001014
1015/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1016static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1017{
1018 struct alc_spec *spec = codec->spec;
1019 struct hda_input_mux *imux;
1020 static char * const texts[3] = {
1021 "Mic", "Internal Mic", "Dock Mic"
1022 };
1023 int i;
1024
1025 if (!spec->auto_mic)
1026 return false;
1027 imux = &spec->private_imux[0];
1028 if (spec->input_mux == imux)
1029 return true;
1030 spec->imux_pins[0] = spec->ext_mic_pin;
1031 spec->imux_pins[1] = spec->int_mic_pin;
1032 spec->imux_pins[2] = spec->dock_mic_pin;
1033 for (i = 0; i < 3; i++) {
1034 strcpy(imux->items[i].label, texts[i]);
1035 if (spec->imux_pins[i])
1036 imux->num_items = i + 1;
1037 }
1038 spec->num_mux_defs = 1;
1039 spec->input_mux = imux;
1040 return true;
1041}
1042
1043/* check whether all auto-mic pins are valid; setup indices if OK */
1044static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1045{
1046 struct alc_spec *spec = codec->spec;
1047 const struct hda_input_mux *imux;
1048
1049 if (!spec->auto_mic)
1050 return false;
1051 if (spec->auto_mic_valid_imux)
1052 return true; /* already checked */
1053
1054 /* fill up imux indices */
1055 if (!alc_check_dyn_adc_switch(codec)) {
1056 spec->auto_mic = 0;
1057 return false;
1058 }
1059
1060 imux = spec->input_mux;
1061 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1062 spec->imux_pins, imux->num_items);
1063 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1064 spec->imux_pins, imux->num_items);
1065 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1066 spec->imux_pins, imux->num_items);
1067 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1068 spec->auto_mic = 0;
1069 return false; /* no corresponding imux */
1070 }
1071
1072 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1073 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001074 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001075 if (spec->dock_mic_pin)
1076 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1077 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001078 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001079
1080 spec->auto_mic_valid_imux = 1;
1081 spec->auto_mic = 1;
1082 return true;
1083}
1084
Takashi Iwai1d045db2011-07-07 18:23:21 +02001085/*
1086 * Check the availability of auto-mic switch;
1087 * Set up if really supported
1088 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001089static void alc_init_auto_mic(struct hda_codec *codec)
1090{
1091 struct alc_spec *spec = codec->spec;
1092 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001093 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001094 int i;
1095
Takashi Iwai21268962011-07-07 15:01:13 +02001096 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1097
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001098 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001099 for (i = 0; i < cfg->num_inputs; i++) {
1100 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001101 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001102 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001103 switch (snd_hda_get_input_pin_attr(defcfg)) {
1104 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001105 if (fixed)
1106 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001107 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1108 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001109 fixed = nid;
1110 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001111 case INPUT_PIN_ATTR_UNUSED:
1112 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001113 case INPUT_PIN_ATTR_DOCK:
1114 if (dock)
1115 return; /* already occupied */
1116 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1117 return; /* invalid type */
1118 dock = nid;
1119 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001120 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001121 if (ext)
1122 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001123 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1124 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001125 ext = nid;
1126 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001127 }
1128 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001129 if (!ext && dock) {
1130 ext = dock;
1131 dock = 0;
1132 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001133 if (!ext || !fixed)
1134 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001135 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001136 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001137 if (dock && !is_jack_detectable(codec, dock))
1138 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001139
1140 /* check imux indices */
1141 spec->ext_mic_pin = ext;
1142 spec->int_mic_pin = fixed;
1143 spec->dock_mic_pin = dock;
1144
1145 spec->auto_mic = 1;
1146 if (!alc_auto_mic_check_imux(codec))
1147 return;
1148
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001149 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1150 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001151 spec->unsol_event = alc_sku_unsol_event;
1152}
1153
Takashi Iwai1d045db2011-07-07 18:23:21 +02001154/* check the availabilities of auto-mute and auto-mic switches */
1155static void alc_auto_check_switches(struct hda_codec *codec)
1156{
1157 alc_init_auto_hp(codec);
1158 alc_init_auto_mic(codec);
1159}
1160
1161/*
1162 * Realtek SSID verification
1163 */
1164
David Henningsson90622912010-10-14 14:50:18 +02001165/* Could be any non-zero and even value. When used as fixup, tells
1166 * the driver to ignore any present sku defines.
1167 */
1168#define ALC_FIXUP_SKU_IGNORE (2)
1169
Kailang Yangda00c242010-03-19 11:23:45 +01001170static int alc_auto_parse_customize_define(struct hda_codec *codec)
1171{
1172 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001173 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001174 struct alc_spec *spec = codec->spec;
1175
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001176 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1177
David Henningsson90622912010-10-14 14:50:18 +02001178 if (spec->cdefine.fixup) {
1179 ass = spec->cdefine.sku_cfg;
1180 if (ass == ALC_FIXUP_SKU_IGNORE)
1181 return -1;
1182 goto do_sku;
1183 }
1184
Kailang Yangda00c242010-03-19 11:23:45 +01001185 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001186 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001187 goto do_sku;
1188
1189 nid = 0x1d;
1190 if (codec->vendor_id == 0x10ec0260)
1191 nid = 0x17;
1192 ass = snd_hda_codec_get_pincfg(codec, nid);
1193
1194 if (!(ass & 1)) {
1195 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1196 codec->chip_name, ass);
1197 return -1;
1198 }
1199
1200 /* check sum */
1201 tmp = 0;
1202 for (i = 1; i < 16; i++) {
1203 if ((ass >> i) & 1)
1204 tmp++;
1205 }
1206 if (((ass >> 16) & 0xf) != tmp)
1207 return -1;
1208
1209 spec->cdefine.port_connectivity = ass >> 30;
1210 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1211 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1212 spec->cdefine.customization = ass >> 8;
1213do_sku:
1214 spec->cdefine.sku_cfg = ass;
1215 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1216 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1217 spec->cdefine.swap = (ass & 0x2) >> 1;
1218 spec->cdefine.override = ass & 0x1;
1219
1220 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1221 nid, spec->cdefine.sku_cfg);
1222 snd_printd("SKU: port_connectivity=0x%x\n",
1223 spec->cdefine.port_connectivity);
1224 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1225 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1226 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1227 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1228 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1229 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1230 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1231
1232 return 0;
1233}
1234
Takashi Iwai1d045db2011-07-07 18:23:21 +02001235/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001236static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1237{
Takashi Iwai21268962011-07-07 15:01:13 +02001238 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001239}
1240
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001241/* check subsystem ID and set up device-specific initialization;
1242 * return 1 if initialized, 0 if invalid SSID
1243 */
1244/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1245 * 31 ~ 16 : Manufacture ID
1246 * 15 ~ 8 : SKU ID
1247 * 7 ~ 0 : Assembly ID
1248 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1249 */
1250static int alc_subsystem_id(struct hda_codec *codec,
1251 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001252 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001253{
1254 unsigned int ass, tmp, i;
1255 unsigned nid;
1256 struct alc_spec *spec = codec->spec;
1257
David Henningsson90622912010-10-14 14:50:18 +02001258 if (spec->cdefine.fixup) {
1259 ass = spec->cdefine.sku_cfg;
1260 if (ass == ALC_FIXUP_SKU_IGNORE)
1261 return 0;
1262 goto do_sku;
1263 }
1264
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001265 ass = codec->subsystem_id & 0xffff;
1266 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1267 goto do_sku;
1268
1269 /* invalid SSID, check the special NID pin defcfg instead */
1270 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001271 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001272 * 29~21 : reserve
1273 * 20 : PCBEEP input
1274 * 19~16 : Check sum (15:1)
1275 * 15~1 : Custom
1276 * 0 : override
1277 */
1278 nid = 0x1d;
1279 if (codec->vendor_id == 0x10ec0260)
1280 nid = 0x17;
1281 ass = snd_hda_codec_get_pincfg(codec, nid);
1282 snd_printd("realtek: No valid SSID, "
1283 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001284 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001285 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001286 return 0;
1287 if ((ass >> 30) != 1) /* no physical connection */
1288 return 0;
1289
1290 /* check sum */
1291 tmp = 0;
1292 for (i = 1; i < 16; i++) {
1293 if ((ass >> i) & 1)
1294 tmp++;
1295 }
1296 if (((ass >> 16) & 0xf) != tmp)
1297 return 0;
1298do_sku:
1299 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1300 ass & 0xffff, codec->vendor_id);
1301 /*
1302 * 0 : override
1303 * 1 : Swap Jack
1304 * 2 : 0 --> Desktop, 1 --> Laptop
1305 * 3~5 : External Amplifier control
1306 * 7~6 : Reserved
1307 */
1308 tmp = (ass & 0x38) >> 3; /* external Amp control */
1309 switch (tmp) {
1310 case 1:
1311 spec->init_amp = ALC_INIT_GPIO1;
1312 break;
1313 case 3:
1314 spec->init_amp = ALC_INIT_GPIO2;
1315 break;
1316 case 7:
1317 spec->init_amp = ALC_INIT_GPIO3;
1318 break;
1319 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001320 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001321 spec->init_amp = ALC_INIT_DEFAULT;
1322 break;
1323 }
1324
1325 /* is laptop or Desktop and enable the function "Mute internal speaker
1326 * when the external headphone out jack is plugged"
1327 */
1328 if (!(ass & 0x8000))
1329 return 1;
1330 /*
1331 * 10~8 : Jack location
1332 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1333 * 14~13: Resvered
1334 * 15 : 1 --> enable the function "Mute internal speaker
1335 * when the external headphone out jack is plugged"
1336 */
Kailang Yangc9b58002007-10-16 14:30:01 +02001337 if (!spec->autocfg.hp_pins[0]) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001338 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001339 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1340 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001341 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001342 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001343 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001344 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001345 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001346 else if (tmp == 3)
1347 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001348 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001349 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001350 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1351 spec->autocfg.line_outs))
1352 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001353 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001354 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001355 return 1;
1356}
Kailang Yangea1fb292008-08-26 12:58:38 +02001357
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001358/* Check the validity of ALC subsystem-id
1359 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1360static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001361{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001362 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001363 struct alc_spec *spec = codec->spec;
1364 snd_printd("realtek: "
1365 "Enable default setup for auto mode as fallback\n");
1366 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001367 }
Takashi Iwai21268962011-07-07 15:01:13 +02001368}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001369
Takashi Iwai41e41f12005-06-08 14:48:49 +02001370/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001371 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001372 */
1373
1374struct alc_pincfg {
1375 hda_nid_t nid;
1376 u32 val;
1377};
1378
Todd Broche1eb5f12010-12-06 11:19:51 -08001379struct alc_model_fixup {
1380 const int id;
1381 const char *name;
1382};
1383
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001384struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001385 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001386 bool chained;
1387 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001388 union {
1389 unsigned int sku;
1390 const struct alc_pincfg *pins;
1391 const struct hda_verb *verbs;
1392 void (*func)(struct hda_codec *codec,
1393 const struct alc_fixup *fix,
1394 int action);
1395 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001396};
1397
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001398enum {
1399 ALC_FIXUP_INVALID,
1400 ALC_FIXUP_SKU,
1401 ALC_FIXUP_PINS,
1402 ALC_FIXUP_VERBS,
1403 ALC_FIXUP_FUNC,
1404};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001405
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001406enum {
1407 ALC_FIXUP_ACT_PRE_PROBE,
1408 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001409 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001410};
1411
1412static void alc_apply_fixup(struct hda_codec *codec, int action)
1413{
1414 struct alc_spec *spec = codec->spec;
1415 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001416#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001417 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001418#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001419 int depth = 0;
1420
1421 if (!spec->fixup_list)
1422 return;
1423
1424 while (id >= 0) {
1425 const struct alc_fixup *fix = spec->fixup_list + id;
1426 const struct alc_pincfg *cfg;
1427
1428 switch (fix->type) {
1429 case ALC_FIXUP_SKU:
1430 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1431 break;;
1432 snd_printdd(KERN_INFO "hda_codec: %s: "
1433 "Apply sku override for %s\n",
1434 codec->chip_name, modelname);
1435 spec->cdefine.sku_cfg = fix->v.sku;
1436 spec->cdefine.fixup = 1;
1437 break;
1438 case ALC_FIXUP_PINS:
1439 cfg = fix->v.pins;
1440 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1441 break;
1442 snd_printdd(KERN_INFO "hda_codec: %s: "
1443 "Apply pincfg for %s\n",
1444 codec->chip_name, modelname);
1445 for (; cfg->nid; cfg++)
1446 snd_hda_codec_set_pincfg(codec, cfg->nid,
1447 cfg->val);
1448 break;
1449 case ALC_FIXUP_VERBS:
1450 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1451 break;
1452 snd_printdd(KERN_INFO "hda_codec: %s: "
1453 "Apply fix-verbs for %s\n",
1454 codec->chip_name, modelname);
1455 add_verb(codec->spec, fix->v.verbs);
1456 break;
1457 case ALC_FIXUP_FUNC:
1458 if (!fix->v.func)
1459 break;
1460 snd_printdd(KERN_INFO "hda_codec: %s: "
1461 "Apply fix-func for %s\n",
1462 codec->chip_name, modelname);
1463 fix->v.func(codec, fix, action);
1464 break;
1465 default:
1466 snd_printk(KERN_ERR "hda_codec: %s: "
1467 "Invalid fixup type %d\n",
1468 codec->chip_name, fix->type);
1469 break;
1470 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001471 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001472 break;
1473 if (++depth > 10)
1474 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001475 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001476 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001477}
1478
Todd Broche1eb5f12010-12-06 11:19:51 -08001479static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001480 const struct alc_model_fixup *models,
1481 const struct snd_pci_quirk *quirk,
1482 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001483{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001484 struct alc_spec *spec = codec->spec;
1485 int id = -1;
1486 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001487
Todd Broche1eb5f12010-12-06 11:19:51 -08001488 if (codec->modelname && models) {
1489 while (models->name) {
1490 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001491 id = models->id;
1492 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001493 break;
1494 }
1495 models++;
1496 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001497 }
1498 if (id < 0) {
1499 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1500 if (quirk) {
1501 id = quirk->value;
1502#ifdef CONFIG_SND_DEBUG_VERBOSE
1503 name = quirk->name;
1504#endif
1505 }
1506 }
1507
1508 spec->fixup_id = id;
1509 if (id >= 0) {
1510 spec->fixup_list = fixlist;
1511 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001512 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001513}
1514
Takashi Iwai1d045db2011-07-07 18:23:21 +02001515/*
1516 * COEF access helper functions
1517 */
Kailang Yang274693f2009-12-03 10:07:50 +01001518static int alc_read_coef_idx(struct hda_codec *codec,
1519 unsigned int coef_idx)
1520{
1521 unsigned int val;
1522 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1523 coef_idx);
1524 val = snd_hda_codec_read(codec, 0x20, 0,
1525 AC_VERB_GET_PROC_COEF, 0);
1526 return val;
1527}
1528
Kailang Yang977ddd62010-09-15 10:02:29 +02001529static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1530 unsigned int coef_val)
1531{
1532 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1533 coef_idx);
1534 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1535 coef_val);
1536}
1537
Takashi Iwai1d045db2011-07-07 18:23:21 +02001538/*
1539 * Digital I/O handling
1540 */
1541
Takashi Iwai757899a2010-07-30 10:48:14 +02001542/* set right pin controls for digital I/O */
1543static void alc_auto_init_digital(struct hda_codec *codec)
1544{
1545 struct alc_spec *spec = codec->spec;
1546 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001547 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001548
1549 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1550 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001551 if (!pin)
1552 continue;
1553 snd_hda_codec_write(codec, pin, 0,
1554 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1555 if (!i)
1556 dac = spec->multiout.dig_out_nid;
1557 else
1558 dac = spec->slave_dig_outs[i - 1];
1559 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1560 continue;
1561 snd_hda_codec_write(codec, dac, 0,
1562 AC_VERB_SET_AMP_GAIN_MUTE,
1563 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001564 }
1565 pin = spec->autocfg.dig_in_pin;
1566 if (pin)
1567 snd_hda_codec_write(codec, pin, 0,
1568 AC_VERB_SET_PIN_WIDGET_CONTROL,
1569 PIN_IN);
1570}
1571
1572/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1573static void alc_auto_parse_digital(struct hda_codec *codec)
1574{
1575 struct alc_spec *spec = codec->spec;
1576 int i, err;
1577 hda_nid_t dig_nid;
1578
1579 /* support multiple SPDIFs; the secondary is set up as a slave */
1580 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001581 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001582 err = snd_hda_get_connections(codec,
1583 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001584 conn, ARRAY_SIZE(conn));
Takashi Iwai757899a2010-07-30 10:48:14 +02001585 if (err < 0)
1586 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001587 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai757899a2010-07-30 10:48:14 +02001588 if (!i) {
1589 spec->multiout.dig_out_nid = dig_nid;
1590 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1591 } else {
1592 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1593 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1594 break;
1595 spec->slave_dig_outs[i - 1] = dig_nid;
1596 }
1597 }
1598
1599 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001600 dig_nid = codec->start_nid;
1601 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1602 unsigned int wcaps = get_wcaps(codec, dig_nid);
1603 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1604 continue;
1605 if (!(wcaps & AC_WCAP_DIGITAL))
1606 continue;
1607 if (!(wcaps & AC_WCAP_CONN_LIST))
1608 continue;
1609 err = get_connection_index(codec, dig_nid,
1610 spec->autocfg.dig_in_pin);
1611 if (err >= 0) {
1612 spec->dig_in_nid = dig_nid;
1613 break;
1614 }
1615 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001616 }
1617}
1618
Takashi Iwaif95474e2007-07-10 00:47:43 +02001619/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001620 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001621 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001622static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1623 struct snd_ctl_elem_info *uinfo)
1624{
1625 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1626 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001627 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001628 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001629
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001630 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001631 if (spec->vol_in_capsrc)
1632 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1633 else
1634 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1635 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001636 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001637 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001638 return err;
1639}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001641static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1642 unsigned int size, unsigned int __user *tlv)
1643{
1644 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1645 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001646 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001647 int err;
1648
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001649 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001650 if (spec->vol_in_capsrc)
1651 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1652 else
1653 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1654 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001655 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001656 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001657 return err;
1658}
1659
1660typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1661 struct snd_ctl_elem_value *ucontrol);
1662
1663static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1664 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001665 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001666{
1667 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1668 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001669 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001670
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001671 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001672 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001673 for (i = 0; i < spec->num_adc_nids; i++) {
1674 kcontrol->private_value =
1675 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1676 3, 0, HDA_INPUT);
1677 err = func(kcontrol, ucontrol);
1678 if (err < 0)
1679 goto error;
1680 }
1681 } else {
1682 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001683 if (spec->vol_in_capsrc)
1684 kcontrol->private_value =
1685 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1686 3, 0, HDA_OUTPUT);
1687 else
1688 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001689 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1690 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001691 err = func(kcontrol, ucontrol);
1692 }
1693 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001694 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001695 return err;
1696}
1697
1698static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1699 struct snd_ctl_elem_value *ucontrol)
1700{
1701 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001702 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001703}
1704
1705static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1706 struct snd_ctl_elem_value *ucontrol)
1707{
1708 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001709 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001710}
1711
1712/* capture mixer elements */
1713#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1714
1715static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1716 struct snd_ctl_elem_value *ucontrol)
1717{
1718 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001719 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001720}
1721
1722static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1723 struct snd_ctl_elem_value *ucontrol)
1724{
1725 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001726 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001727}
1728
Takashi Iwaia23b6882009-03-23 15:21:36 +01001729#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001730 { \
1731 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1732 .name = "Capture Switch", \
1733 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1734 .count = num, \
1735 .info = alc_cap_sw_info, \
1736 .get = alc_cap_sw_get, \
1737 .put = alc_cap_sw_put, \
1738 }, \
1739 { \
1740 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1741 .name = "Capture Volume", \
1742 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1743 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1744 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1745 .count = num, \
1746 .info = alc_cap_vol_info, \
1747 .get = alc_cap_vol_get, \
1748 .put = alc_cap_vol_put, \
1749 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001750 }
1751
1752#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001753 { \
1754 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1755 /* .name = "Capture Source", */ \
1756 .name = "Input Source", \
1757 .count = num, \
1758 .info = alc_mux_enum_info, \
1759 .get = alc_mux_enum_get, \
1760 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001761 }
1762
1763#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001764static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001765 _DEFINE_CAPMIX(num), \
1766 _DEFINE_CAPSRC(num), \
1767 { } /* end */ \
1768}
1769
1770#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001771static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001772 _DEFINE_CAPMIX(num), \
1773 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001774}
1775
1776/* up to three ADCs */
1777DEFINE_CAPMIX(1);
1778DEFINE_CAPMIX(2);
1779DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001780DEFINE_CAPMIX_NOSRC(1);
1781DEFINE_CAPMIX_NOSRC(2);
1782DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001783
1784/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001785 * virtual master controls
1786 */
1787
1788/*
1789 * slave controls for virtual master
1790 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001791static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001792 "Front Playback Volume",
1793 "Surround Playback Volume",
1794 "Center Playback Volume",
1795 "LFE Playback Volume",
1796 "Side Playback Volume",
1797 "Headphone Playback Volume",
1798 "Speaker Playback Volume",
1799 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001800 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001801 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001802 NULL,
1803};
1804
Takashi Iwaiea734962011-01-17 11:29:34 +01001805static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001806 "Front Playback Switch",
1807 "Surround Playback Switch",
1808 "Center Playback Switch",
1809 "LFE Playback Switch",
1810 "Side Playback Switch",
1811 "Headphone Playback Switch",
1812 "Speaker Playback Switch",
1813 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001814 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001815 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001816 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001817 NULL,
1818};
1819
1820/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001821 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001823
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001824#define NID_MAPPING (-1)
1825
1826#define SUBDEV_SPEAKER_ (0 << 6)
1827#define SUBDEV_HP_ (1 << 6)
1828#define SUBDEV_LINE_ (2 << 6)
1829#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1830#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1831#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1832
Takashi Iwai603c4012008-07-30 15:01:44 +02001833static void alc_free_kctls(struct hda_codec *codec);
1834
Takashi Iwai67d634c2009-11-16 15:35:59 +01001835#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001836/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001837static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001838 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001839 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001840 { } /* end */
1841};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001842#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001843
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844static int alc_build_controls(struct hda_codec *codec)
1845{
1846 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001847 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001848 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001849 int i, j, err;
1850 unsigned int u;
1851 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
1853 for (i = 0; i < spec->num_mixers; i++) {
1854 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1855 if (err < 0)
1856 return err;
1857 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001858 if (spec->cap_mixer) {
1859 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1860 if (err < 0)
1861 return err;
1862 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001864 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001865 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001866 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 if (err < 0)
1868 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001869 if (!spec->no_analog) {
1870 err = snd_hda_create_spdif_share_sw(codec,
1871 &spec->multiout);
1872 if (err < 0)
1873 return err;
1874 spec->multiout.share_spdif = 1;
1875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 }
1877 if (spec->dig_in_nid) {
1878 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1879 if (err < 0)
1880 return err;
1881 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001882
Takashi Iwai67d634c2009-11-16 15:35:59 +01001883#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001884 /* create beep controls if needed */
1885 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001886 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001887 for (knew = alc_beep_mixer; knew->name; knew++) {
1888 struct snd_kcontrol *kctl;
1889 kctl = snd_ctl_new1(knew, codec);
1890 if (!kctl)
1891 return -ENOMEM;
1892 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001893 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001894 if (err < 0)
1895 return err;
1896 }
1897 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001898#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001899
Takashi Iwai2134ea42008-01-10 16:53:55 +01001900 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001901 if (!spec->no_analog &&
1902 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001903 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001904 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001905 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001906 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001907 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001908 if (err < 0)
1909 return err;
1910 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001911 if (!spec->no_analog &&
1912 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001913 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1914 NULL, alc_slave_sws);
1915 if (err < 0)
1916 return err;
1917 }
1918
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001919 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001920 if (spec->capsrc_nids || spec->adc_nids) {
1921 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1922 if (!kctl)
1923 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1924 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02001925 const hda_nid_t *nids = spec->capsrc_nids;
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001926 if (!nids)
1927 nids = spec->adc_nids;
1928 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1929 if (err < 0)
1930 return err;
1931 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001932 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001933 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001934 const char *kname = kctl ? kctl->id.name : NULL;
1935 for (knew = spec->cap_mixer; knew->name; knew++) {
1936 if (kname && strcmp(knew->name, kname) == 0)
1937 continue;
1938 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1939 for (i = 0; kctl && i < kctl->count; i++) {
1940 err = snd_hda_add_nid(codec, kctl, i,
1941 spec->adc_nids[i]);
1942 if (err < 0)
1943 return err;
1944 }
1945 }
1946 }
1947
1948 /* other nid->control mapping */
1949 for (i = 0; i < spec->num_mixers; i++) {
1950 for (knew = spec->mixers[i]; knew->name; knew++) {
1951 if (knew->iface != NID_MAPPING)
1952 continue;
1953 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1954 if (kctl == NULL)
1955 continue;
1956 u = knew->subdevice;
1957 for (j = 0; j < 4; j++, u >>= 8) {
1958 nid = u & 0x3f;
1959 if (nid == 0)
1960 continue;
1961 switch (u & 0xc0) {
1962 case SUBDEV_SPEAKER_:
1963 nid = spec->autocfg.speaker_pins[nid];
1964 break;
1965 case SUBDEV_LINE_:
1966 nid = spec->autocfg.line_out_pins[nid];
1967 break;
1968 case SUBDEV_HP_:
1969 nid = spec->autocfg.hp_pins[nid];
1970 break;
1971 default:
1972 continue;
1973 }
1974 err = snd_hda_add_nid(codec, kctl, 0, nid);
1975 if (err < 0)
1976 return err;
1977 }
1978 u = knew->private_value;
1979 for (j = 0; j < 4; j++, u >>= 8) {
1980 nid = u & 0xff;
1981 if (nid == 0)
1982 continue;
1983 err = snd_hda_add_nid(codec, kctl, 0, nid);
1984 if (err < 0)
1985 return err;
1986 }
1987 }
1988 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001989
1990 alc_free_kctls(codec); /* no longer needed */
1991
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 return 0;
1993}
1994
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001995
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001997 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001998 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001999
Takashi Iwai584c0c42011-03-10 12:51:11 +01002000static void alc_init_special_input_src(struct hda_codec *codec);
2001
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002static int alc_init(struct hda_codec *codec)
2003{
2004 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002005 unsigned int i;
2006
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002007 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002008 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002009
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002010 for (i = 0; i < spec->num_init_verbs; i++)
2011 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002012 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002013
2014 if (spec->init_hook)
2015 spec->init_hook(codec);
2016
Takashi Iwai58701122011-01-13 15:41:45 +01002017 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2018
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002019 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 return 0;
2021}
2022
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002023static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2024{
2025 struct alc_spec *spec = codec->spec;
2026
2027 if (spec->unsol_event)
2028 spec->unsol_event(codec, res);
2029}
2030
Takashi Iwaicb53c622007-08-10 17:21:45 +02002031#ifdef CONFIG_SND_HDA_POWER_SAVE
2032static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2033{
2034 struct alc_spec *spec = codec->spec;
2035 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2036}
2037#endif
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039/*
2040 * Analog playback callbacks
2041 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002042static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002044 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045{
2046 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002047 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2048 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049}
2050
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002051static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 struct hda_codec *codec,
2053 unsigned int stream_tag,
2054 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002055 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056{
2057 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002058 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2059 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060}
2061
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002062static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002064 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065{
2066 struct alc_spec *spec = codec->spec;
2067 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2068}
2069
2070/*
2071 * Digital out
2072 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002073static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002075 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076{
2077 struct alc_spec *spec = codec->spec;
2078 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2079}
2080
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002081static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002082 struct hda_codec *codec,
2083 unsigned int stream_tag,
2084 unsigned int format,
2085 struct snd_pcm_substream *substream)
2086{
2087 struct alc_spec *spec = codec->spec;
2088 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2089 stream_tag, format, substream);
2090}
2091
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002092static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002093 struct hda_codec *codec,
2094 struct snd_pcm_substream *substream)
2095{
2096 struct alc_spec *spec = codec->spec;
2097 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2098}
2099
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002100static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002102 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103{
2104 struct alc_spec *spec = codec->spec;
2105 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2106}
2107
2108/*
2109 * Analog capture
2110 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002111static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 struct hda_codec *codec,
2113 unsigned int stream_tag,
2114 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002115 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116{
2117 struct alc_spec *spec = codec->spec;
2118
Takashi Iwai63300792008-01-24 15:31:36 +01002119 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120 stream_tag, 0, format);
2121 return 0;
2122}
2123
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002124static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002126 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127{
2128 struct alc_spec *spec = codec->spec;
2129
Takashi Iwai888afa12008-03-18 09:57:50 +01002130 snd_hda_codec_cleanup_stream(codec,
2131 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 return 0;
2133}
2134
Takashi Iwai840b64c2010-07-13 22:49:01 +02002135/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002136static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002137 struct hda_codec *codec,
2138 unsigned int stream_tag,
2139 unsigned int format,
2140 struct snd_pcm_substream *substream)
2141{
2142 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002143 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002144 spec->cur_adc_stream_tag = stream_tag;
2145 spec->cur_adc_format = format;
2146 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2147 return 0;
2148}
2149
Takashi Iwai21268962011-07-07 15:01:13 +02002150static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002151 struct hda_codec *codec,
2152 struct snd_pcm_substream *substream)
2153{
2154 struct alc_spec *spec = codec->spec;
2155 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2156 spec->cur_adc = 0;
2157 return 0;
2158}
2159
Takashi Iwai21268962011-07-07 15:01:13 +02002160static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002161 .substreams = 1,
2162 .channels_min = 2,
2163 .channels_max = 2,
2164 .nid = 0, /* fill later */
2165 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002166 .prepare = dyn_adc_capture_pcm_prepare,
2167 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002168 },
2169};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170
2171/*
2172 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002173static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 .substreams = 1,
2175 .channels_min = 2,
2176 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002177 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002179 .open = alc_playback_pcm_open,
2180 .prepare = alc_playback_pcm_prepare,
2181 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 },
2183};
2184
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002185static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002186 .substreams = 1,
2187 .channels_min = 2,
2188 .channels_max = 2,
2189 /* NID is set in alc_build_pcms */
2190};
2191
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002192static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002193 .substreams = 1,
2194 .channels_min = 2,
2195 .channels_max = 2,
2196 /* NID is set in alc_build_pcms */
2197};
2198
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002199static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002200 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 .channels_min = 2,
2202 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002203 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002205 .prepare = alc_alt_capture_pcm_prepare,
2206 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 },
2208};
2209
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002210static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 .substreams = 1,
2212 .channels_min = 2,
2213 .channels_max = 2,
2214 /* NID is set in alc_build_pcms */
2215 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002216 .open = alc_dig_playback_pcm_open,
2217 .close = alc_dig_playback_pcm_close,
2218 .prepare = alc_dig_playback_pcm_prepare,
2219 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 },
2221};
2222
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002223static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 .substreams = 1,
2225 .channels_min = 2,
2226 .channels_max = 2,
2227 /* NID is set in alc_build_pcms */
2228};
2229
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002230/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002231static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002232 .substreams = 0,
2233 .channels_min = 0,
2234 .channels_max = 0,
2235};
2236
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237static int alc_build_pcms(struct hda_codec *codec)
2238{
2239 struct alc_spec *spec = codec->spec;
2240 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002241 const struct hda_pcm_stream *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 int i;
2243
2244 codec->num_pcms = 1;
2245 codec->pcm_info = info;
2246
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002247 if (spec->no_analog)
2248 goto skip_analog;
2249
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002250 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2251 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002253
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002254 if (spec->multiout.dac_nids > 0) {
2255 p = spec->stream_analog_playback;
2256 if (!p)
2257 p = &alc_pcm_analog_playback;
2258 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002259 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2260 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002261 if (spec->adc_nids) {
2262 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002263 if (!p) {
2264 if (spec->dyn_adc_switch)
2265 p = &dyn_adc_pcm_analog_capture;
2266 else
2267 p = &alc_pcm_analog_capture;
2268 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002269 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002270 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2271 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272
Takashi Iwai4a471b72005-12-07 13:56:29 +01002273 if (spec->channel_mode) {
2274 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2275 for (i = 0; i < spec->num_channel_mode; i++) {
2276 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2277 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2278 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 }
2280 }
2281
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002282 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002283 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002285 snprintf(spec->stream_name_digital,
2286 sizeof(spec->stream_name_digital),
2287 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002288 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002289 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002290 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002292 if (spec->dig_out_type)
2293 info->pcm_type = spec->dig_out_type;
2294 else
2295 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002296 if (spec->multiout.dig_out_nid) {
2297 p = spec->stream_digital_playback;
2298 if (!p)
2299 p = &alc_pcm_digital_playback;
2300 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2302 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002303 if (spec->dig_in_nid) {
2304 p = spec->stream_digital_capture;
2305 if (!p)
2306 p = &alc_pcm_digital_capture;
2307 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2309 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002310 /* FIXME: do we need this for all Realtek codec models? */
2311 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 }
2313
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002314 if (spec->no_analog)
2315 return 0;
2316
Takashi Iwaie08a0072006-09-07 17:52:14 +02002317 /* If the use of more than one ADC is requested for the current
2318 * model, configure a second analog capture-only PCM.
2319 */
2320 /* Additional Analaog capture for index #2 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002321 if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002322 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002323 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002324 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002325 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002326 p = spec->stream_analog_alt_playback;
2327 if (!p)
2328 p = &alc_pcm_analog_alt_playback;
2329 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002330 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2331 spec->alt_dac_nid;
2332 } else {
2333 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2334 alc_pcm_null_stream;
2335 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2336 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002337 if (spec->num_adc_nids > 1) {
2338 p = spec->stream_analog_alt_capture;
2339 if (!p)
2340 p = &alc_pcm_analog_alt_capture;
2341 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002342 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2343 spec->adc_nids[1];
2344 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2345 spec->num_adc_nids - 1;
2346 } else {
2347 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2348 alc_pcm_null_stream;
2349 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002350 }
2351 }
2352
Linus Torvalds1da177e2005-04-16 15:20:36 -07002353 return 0;
2354}
2355
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002356static inline void alc_shutup(struct hda_codec *codec)
2357{
Takashi Iwai1c716152011-04-07 10:37:16 +02002358 struct alc_spec *spec = codec->spec;
2359
2360 if (spec && spec->shutup)
2361 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002362 snd_hda_shutup_pins(codec);
2363}
2364
Takashi Iwai603c4012008-07-30 15:01:44 +02002365static void alc_free_kctls(struct hda_codec *codec)
2366{
2367 struct alc_spec *spec = codec->spec;
2368
2369 if (spec->kctls.list) {
2370 struct snd_kcontrol_new *kctl = spec->kctls.list;
2371 int i;
2372 for (i = 0; i < spec->kctls.used; i++)
2373 kfree(kctl[i].name);
2374 }
2375 snd_array_free(&spec->kctls);
2376}
2377
Takashi Iwai23c09b02011-08-19 09:05:35 +02002378static void alc_free_bind_ctls(struct hda_codec *codec)
2379{
2380 struct alc_spec *spec = codec->spec;
2381 if (spec->bind_ctls.list) {
2382 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2383 int i;
2384 for (i = 0; i < spec->bind_ctls.used; i++)
2385 kfree(ctl[i]);
2386 }
2387 snd_array_free(&spec->bind_ctls);
2388}
2389
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390static void alc_free(struct hda_codec *codec)
2391{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002392 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002393
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002394 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002395 return;
2396
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002397 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002398 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002399 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002400 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002401 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002402 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403}
2404
Hector Martinf5de24b2009-12-20 22:51:31 +01002405#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002406static void alc_power_eapd(struct hda_codec *codec)
2407{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002408 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002409}
2410
Hector Martinf5de24b2009-12-20 22:51:31 +01002411static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2412{
2413 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002414 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002415 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002416 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002417 return 0;
2418}
2419#endif
2420
Takashi Iwai2a439522011-07-26 09:52:50 +02002421#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002422static int alc_resume(struct hda_codec *codec)
2423{
Takashi Iwai1c716152011-04-07 10:37:16 +02002424 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002425 codec->patch_ops.init(codec);
2426 snd_hda_codec_resume_amp(codec);
2427 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002428 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002429 return 0;
2430}
Takashi Iwaie044c392008-10-27 16:56:24 +01002431#endif
2432
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433/*
2434 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002435static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 .build_controls = alc_build_controls,
2437 .build_pcms = alc_build_pcms,
2438 .init = alc_init,
2439 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002440 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002441#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002442 .resume = alc_resume,
2443#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002444#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002445 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002446 .check_power_status = alc_check_power_status,
2447#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002448 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449};
2450
Kailang Yangc027ddc2010-03-19 11:33:06 +01002451/* replace the codec chip_name with the given string */
2452static int alc_codec_rename(struct hda_codec *codec, const char *name)
2453{
2454 kfree(codec->chip_name);
2455 codec->chip_name = kstrdup(name, GFP_KERNEL);
2456 if (!codec->chip_name) {
2457 alc_free(codec);
2458 return -ENOMEM;
2459 }
2460 return 0;
2461}
2462
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002463/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002464 * Automatic parse of I/O pins from the BIOS configuration
2465 */
2466
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002467enum {
2468 ALC_CTL_WIDGET_VOL,
2469 ALC_CTL_WIDGET_MUTE,
2470 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002471 ALC_CTL_BIND_VOL,
2472 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002473};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002474static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002475 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2476 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002477 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002478 HDA_BIND_VOL(NULL, 0),
2479 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002480};
2481
2482/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002483static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002484 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002485{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002486 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002487
Takashi Iwaice764ab2011-04-27 16:35:23 +02002488 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002489 if (!knew)
2490 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002491 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002492 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002493 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002494 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002495 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002496 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002497 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002498 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002499 return 0;
2500}
2501
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002502static int add_control_with_pfx(struct alc_spec *spec, int type,
2503 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002504 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002505{
2506 char name[32];
2507 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002508 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002509}
2510
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002511#define add_pb_vol_ctrl(spec, type, pfx, val) \
2512 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2513#define add_pb_sw_ctrl(spec, type, pfx, val) \
2514 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2515#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2516 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2517#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2518 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002519
Takashi Iwai23c09b02011-08-19 09:05:35 +02002520static const char * const channel_name[4] = {
2521 "Front", "Surround", "CLFE", "Side"
2522};
2523
Takashi Iwai6843ca12011-06-24 11:03:58 +02002524static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2525 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002526{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002527 struct auto_pin_cfg *cfg = &spec->autocfg;
2528
Takashi Iwai6843ca12011-06-24 11:03:58 +02002529 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002530 if (cfg->line_outs == 1 && !spec->multi_ios &&
2531 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002532 return "Master";
2533
2534 switch (cfg->line_out_type) {
2535 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002536 if (cfg->line_outs == 1)
2537 return "Speaker";
2538 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002539 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002540 /* for multi-io case, only the primary out */
2541 if (ch && spec->multi_ios)
2542 break;
2543 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002544 return "Headphone";
2545 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002546 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002547 return "PCM";
2548 break;
2549 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002550 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2551 return "PCM";
2552
2553 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002554}
2555
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002556/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002557static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002558 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002559 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002560{
Kailang Yangdf694da2005-12-05 19:42:22 +01002561 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002562
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002563 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002564 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2565 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002566 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002567 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002568 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2569 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002570 return err;
2571 return 0;
2572}
2573
Takashi Iwai05f5f472009-08-25 13:10:18 +02002574static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002575{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002576 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2577 return (pincap & AC_PINCAP_IN) != 0;
2578}
2579
Takashi Iwai1d045db2011-07-07 18:23:21 +02002580/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002581static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002582{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002583 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002584 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002585 hda_nid_t *adc_nids = spec->private_adc_nids;
2586 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2587 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2588 bool indep_capsrc = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002589 int i, nums = 0;
2590
2591 nid = codec->start_nid;
2592 for (i = 0; i < codec->num_nodes; i++, nid++) {
2593 hda_nid_t src;
2594 const hda_nid_t *list;
2595 unsigned int caps = get_wcaps(codec, nid);
2596 int type = get_wcaps_type(caps);
2597
2598 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2599 continue;
2600 adc_nids[nums] = nid;
2601 cap_nids[nums] = nid;
2602 src = nid;
2603 for (;;) {
2604 int n;
2605 type = get_wcaps_type(get_wcaps(codec, src));
2606 if (type == AC_WID_PIN)
2607 break;
2608 if (type == AC_WID_AUD_SEL) {
2609 cap_nids[nums] = src;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002610 indep_capsrc = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002611 break;
2612 }
2613 n = snd_hda_get_conn_list(codec, src, &list);
2614 if (n > 1) {
2615 cap_nids[nums] = src;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002616 indep_capsrc = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002617 break;
2618 } else if (n != 1)
2619 break;
2620 src = *list;
2621 }
2622 if (++nums >= max_nums)
2623 break;
2624 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002625 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002626 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002627 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002628 return nums;
2629}
2630
Takashi Iwai05f5f472009-08-25 13:10:18 +02002631/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002632static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002633{
2634 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002635 const struct auto_pin_cfg *cfg = &spec->autocfg;
2636 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002637 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002638 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002639 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002640 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002641
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002642 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002643 if (num_adcs < 0)
2644 return 0;
2645
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002646 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002647 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002648 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002649
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002650 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002651 if (!alc_is_input_pin(codec, pin))
2652 continue;
2653
David Henningsson5322bf22011-01-05 11:03:56 +01002654 label = hda_get_autocfg_input_label(codec, cfg, i);
2655 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002656 type_idx++;
2657 else
2658 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002659 prev_label = label;
2660
Takashi Iwai05f5f472009-08-25 13:10:18 +02002661 if (mixer) {
2662 idx = get_connection_index(codec, mixer, pin);
2663 if (idx >= 0) {
2664 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002665 label, type_idx,
2666 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002667 if (err < 0)
2668 return err;
2669 }
2670 }
2671
Takashi Iwaib7821702011-07-06 15:12:46 +02002672 for (c = 0; c < num_adcs; c++) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002673 hda_nid_t cap = spec->capsrc_nids ?
2674 spec->capsrc_nids[c] : spec->adc_nids[c];
2675 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002676 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002677 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002678 snd_hda_add_imux_item(imux, label, idx, NULL);
2679 break;
2680 }
2681 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002682 }
Takashi Iwai21268962011-07-07 15:01:13 +02002683
2684 spec->num_mux_defs = 1;
2685 spec->input_mux = imux;
2686
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002687 return 0;
2688}
2689
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002690static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2691 unsigned int pin_type)
2692{
2693 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2694 pin_type);
2695 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002696 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2697 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002698 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002699}
2700
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002701static int get_pin_type(int line_out_type)
2702{
2703 if (line_out_type == AUTO_PIN_HP_OUT)
2704 return PIN_HP;
2705 else
2706 return PIN_OUT;
2707}
2708
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002709static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002710{
2711 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002712 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002713 int i;
2714
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002715 for (i = 0; i < cfg->num_inputs; i++) {
2716 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002717 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002718 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002719 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002720 snd_hda_codec_write(codec, nid, 0,
2721 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002722 AMP_OUT_MUTE);
2723 }
2724 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002725
2726 /* mute all loopback inputs */
2727 if (spec->mixer_nid) {
2728 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2729 for (i = 0; i < nums; i++)
2730 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2731 AC_VERB_SET_AMP_GAIN_MUTE,
2732 AMP_IN_MUTE(i));
2733 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002734}
2735
Takashi Iwai7085ec12009-10-02 09:03:58 +02002736/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002737static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002738{
Takashi Iwai604401a2011-04-27 15:14:23 +02002739 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002740 int i, num;
2741
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002742 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2743 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002744 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2745 for (i = 0; i < num; i++) {
2746 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2747 return list[i];
2748 }
2749 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002750}
2751
Takashi Iwai604401a2011-04-27 15:14:23 +02002752/* go down to the selector widget before the mixer */
2753static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2754{
2755 hda_nid_t srcs[5];
2756 int num = snd_hda_get_connections(codec, pin, srcs,
2757 ARRAY_SIZE(srcs));
2758 if (num != 1 ||
2759 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2760 return pin;
2761 return srcs[0];
2762}
2763
Takashi Iwai7085ec12009-10-02 09:03:58 +02002764/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002765static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002766 hda_nid_t dac)
2767{
David Henningssoncc1c4522010-11-24 14:17:47 +01002768 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002769 int i, num;
2770
Takashi Iwai604401a2011-04-27 15:14:23 +02002771 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002772 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2773 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002774 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002775 return mix[i];
2776 }
2777 return 0;
2778}
2779
Takashi Iwaice764ab2011-04-27 16:35:23 +02002780/* select the connection from pin to DAC if needed */
2781static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2782 hda_nid_t dac)
2783{
2784 hda_nid_t mix[5];
2785 int i, num;
2786
2787 pin = alc_go_down_to_selector(codec, pin);
2788 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2789 if (num < 2)
2790 return 0;
2791 for (i = 0; i < num; i++) {
2792 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2793 snd_hda_codec_update_cache(codec, pin, 0,
2794 AC_VERB_SET_CONNECT_SEL, i);
2795 return 0;
2796 }
2797 }
2798 return 0;
2799}
2800
Takashi Iwai7085ec12009-10-02 09:03:58 +02002801/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002802static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002803{
2804 struct alc_spec *spec = codec->spec;
2805 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002806 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002807
Takashi Iwai604401a2011-04-27 15:14:23 +02002808 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002809 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002810 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002811 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002812 if (!nid)
2813 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002814 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2815 spec->multiout.num_dacs))
2816 continue;
Takashi Iwaie23832a2011-08-23 18:16:56 +02002817 if (spec->multiout.hp_out_nid[0] == nid)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002818 continue;
2819 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2820 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2821 continue;
2822 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002823 }
2824 return 0;
2825}
2826
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002827static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2828{
2829 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2830 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2831 return alc_auto_look_for_dac(codec, pin);
2832 return 0;
2833}
2834
Takashi Iwai7085ec12009-10-02 09:03:58 +02002835/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02002836static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002837{
2838 struct alc_spec *spec = codec->spec;
Takashi Iwaicb053a82011-06-27 11:32:07 +02002839 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai350434e2011-06-30 21:29:12 +02002840 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002841 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002842
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002843 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002844 /* set num_dacs once to full for alc_auto_look_for_dac() */
2845 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02002846 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002847 spec->multiout.extra_out_nid[0] = 0;
2848 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2849 spec->multiout.dac_nids = spec->private_dac_nids;
2850
2851 /* fill hard-wired DACs first */
2852 if (!redone) {
2853 for (i = 0; i < cfg->line_outs; i++)
2854 spec->private_dac_nids[i] =
2855 get_dac_if_single(codec, cfg->line_out_pins[i]);
2856 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02002857 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002858 get_dac_if_single(codec, cfg->hp_pins[0]);
2859 if (cfg->speaker_outs)
2860 spec->multiout.extra_out_nid[0] =
2861 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002862 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002863
2864 for (i = 0; i < cfg->line_outs; i++) {
2865 hda_nid_t pin = cfg->line_out_pins[i];
2866 if (spec->private_dac_nids[i])
2867 continue;
2868 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2869 if (!spec->private_dac_nids[i] && !redone) {
2870 /* if we can't find primary DACs, re-probe without
2871 * checking the hard-wired DACs
2872 */
2873 redone = true;
2874 goto again;
2875 }
2876 }
2877
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002878 /* re-count num_dacs and squash invalid entries */
2879 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002880 for (i = 0; i < cfg->line_outs; i++) {
2881 if (spec->private_dac_nids[i])
2882 spec->multiout.num_dacs++;
2883 else
2884 memmove(spec->private_dac_nids + i,
2885 spec->private_dac_nids + i + 1,
2886 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2887 }
2888
Takashi Iwaie23832a2011-08-23 18:16:56 +02002889 if (cfg->hp_outs && !spec->multiout.hp_out_nid[0])
2890 spec->multiout.hp_out_nid[0] =
Takashi Iwaibb8bf4d2011-07-06 13:07:54 +02002891 alc_auto_look_for_dac(codec, cfg->hp_pins[0]);
2892 if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0])
2893 spec->multiout.extra_out_nid[0] =
2894 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2895
Takashi Iwai7085ec12009-10-02 09:03:58 +02002896 return 0;
2897}
2898
Takashi Iwai23c09b02011-08-19 09:05:35 +02002899/* fill in the dac_nids table for surround speakers, etc */
2900static int alc_auto_fill_extra_dacs(struct hda_codec *codec)
2901{
2902 struct alc_spec *spec = codec->spec;
2903 const struct auto_pin_cfg *cfg = &spec->autocfg;
2904 int i;
2905
2906 if (cfg->speaker_outs < 2 || !spec->multiout.extra_out_nid[0])
2907 return 0;
2908
2909 for (i = 1; i < cfg->speaker_outs; i++)
2910 spec->multiout.extra_out_nid[i] =
2911 get_dac_if_single(codec, cfg->speaker_pins[i]);
2912 for (i = 1; i < cfg->speaker_outs; i++) {
2913 if (spec->multiout.extra_out_nid[i])
2914 continue;
2915 spec->multiout.extra_out_nid[i] =
2916 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2917 }
2918 return 0;
2919}
2920
Takashi Iwai343a04b2011-07-06 14:28:39 +02002921static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02002922 const char *pfx, int cidx,
2923 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02002924{
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002925 if (!nid)
2926 return 0;
Takashi Iwai97aaab72011-07-06 14:02:55 +02002927 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
2928 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002929}
2930
Takashi Iwai343a04b2011-07-06 14:28:39 +02002931#define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2932 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai97aaab72011-07-06 14:02:55 +02002933
2934/* create a mute-switch for the given mixer widget;
2935 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2936 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02002937static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02002938 const char *pfx, int cidx,
2939 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002940{
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002941 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02002942 int type;
2943 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002944 if (!nid)
2945 return 0;
2946 wid_type = get_wcaps_type(get_wcaps(codec, nid));
2947 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
2948 type = ALC_CTL_WIDGET_MUTE;
2949 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
2950 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02002951 type = ALC_CTL_WIDGET_MUTE;
2952 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
2953 } else {
2954 type = ALC_CTL_BIND_MUTE;
2955 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
2956 }
2957 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002958}
2959
Takashi Iwai343a04b2011-07-06 14:28:39 +02002960#define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2961 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002962
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002963static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
2964 hda_nid_t pin, hda_nid_t dac)
2965{
2966 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2967 if (nid_has_mute(codec, pin, HDA_OUTPUT))
2968 return pin;
2969 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
2970 return mix;
2971 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
2972 return dac;
2973 return 0;
2974}
2975
2976static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
2977 hda_nid_t pin, hda_nid_t dac)
2978{
2979 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2980 if (nid_has_volume(codec, dac, HDA_OUTPUT))
2981 return dac;
2982 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
2983 return mix;
2984 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
2985 return pin;
2986 return 0;
2987}
2988
Takashi Iwai7085ec12009-10-02 09:03:58 +02002989/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02002990static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002991 const struct auto_pin_cfg *cfg)
2992{
2993 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002994 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02002995
Takashi Iwaice764ab2011-04-27 16:35:23 +02002996 noutputs = cfg->line_outs;
2997 if (spec->multi_ios > 0)
2998 noutputs += spec->multi_ios;
2999
3000 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003001 const char *name;
3002 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003003 hda_nid_t dac, pin;
3004 hda_nid_t sw, vol;
3005
3006 dac = spec->multiout.dac_nids[i];
3007 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003008 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003009 if (i >= cfg->line_outs)
3010 pin = spec->multi_io[i - 1].pin;
3011 else
3012 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003013
3014 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3015 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003016 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003017 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003018 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003019 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003020 if (err < 0)
3021 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003022 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003023 if (err < 0)
3024 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003025 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003026 if (err < 0)
3027 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003028 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003029 if (err < 0)
3030 return err;
3031 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003032 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003033 if (err < 0)
3034 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003035 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003036 if (err < 0)
3037 return err;
3038 }
3039 }
3040 return 0;
3041}
3042
Takashi Iwai343a04b2011-07-06 14:28:39 +02003043static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai23c09b02011-08-19 09:05:35 +02003044 hda_nid_t dac, const char *pfx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003045{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003046 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003047 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003048 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003049
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003050 if (!dac) {
Takashi Iwai7085ec12009-10-02 09:03:58 +02003051 /* the corresponding DAC is already occupied */
3052 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3053 return 0; /* no way */
3054 /* create a switch only */
Takashi Iwai0afe5f82009-10-02 09:20:00 +02003055 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003056 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3057 }
3058
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003059 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3060 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3061 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003062 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003063 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003064 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003065 if (err < 0)
3066 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003067 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003068}
3069
Takashi Iwai23c09b02011-08-19 09:05:35 +02003070static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3071 unsigned int nums,
3072 struct hda_ctl_ops *ops)
3073{
3074 struct alc_spec *spec = codec->spec;
3075 struct hda_bind_ctls **ctlp, *ctl;
3076 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3077 ctlp = snd_array_new(&spec->bind_ctls);
3078 if (!ctlp)
3079 return NULL;
3080 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3081 *ctlp = ctl;
3082 if (ctl)
3083 ctl->ops = ops;
3084 return ctl;
3085}
3086
3087/* add playback controls for speaker and HP outputs */
3088static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3089 const hda_nid_t *pins,
3090 const hda_nid_t *dacs,
3091 const char *pfx)
3092{
3093 struct alc_spec *spec = codec->spec;
3094 struct hda_bind_ctls *ctl;
3095 char name[32];
3096 int i, n, err;
3097
3098 if (!num_pins || !pins[0])
3099 return 0;
3100
3101 if (num_pins == 1)
3102 return alc_auto_create_extra_out(codec, *pins, *dacs, pfx);
3103
3104 if (dacs[num_pins - 1]) {
3105 /* OK, we have a multi-output system with individual volumes */
3106 for (i = 0; i < num_pins; i++) {
3107 snprintf(name, sizeof(name), "%s %s",
3108 pfx, channel_name[i]);
3109 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3110 name);
3111 if (err < 0)
3112 return err;
3113 }
3114 return 0;
3115 }
3116
3117 /* Let's create a bind-controls */
3118 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3119 if (!ctl)
3120 return -ENOMEM;
3121 n = 0;
3122 for (i = 0; i < num_pins; i++) {
3123 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3124 ctl->values[n++] =
3125 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3126 }
3127 if (n) {
3128 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3129 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3130 if (err < 0)
3131 return err;
3132 }
3133
3134 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3135 if (!ctl)
3136 return -ENOMEM;
3137 n = 0;
3138 for (i = 0; i < num_pins; i++) {
3139 hda_nid_t vol;
3140 if (!pins[i] || !dacs[i])
3141 continue;
3142 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3143 if (vol)
3144 ctl->values[n++] =
3145 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3146 }
3147 if (n) {
3148 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3149 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3150 if (err < 0)
3151 return err;
3152 }
3153 return 0;
3154}
3155
Takashi Iwai343a04b2011-07-06 14:28:39 +02003156static int alc_auto_create_hp_out(struct hda_codec *codec)
3157{
3158 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003159 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3160 spec->autocfg.hp_pins,
3161 spec->multiout.hp_out_nid,
3162 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003163}
3164
3165static int alc_auto_create_speaker_out(struct hda_codec *codec)
3166{
3167 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003168 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3169 spec->autocfg.speaker_pins,
3170 spec->multiout.extra_out_nid,
3171 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003172}
3173
Takashi Iwai343a04b2011-07-06 14:28:39 +02003174static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003175 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003176 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003177{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003178 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003179 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003180 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003181
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003182 alc_set_pin_output(codec, pin, pin_type);
3183 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003184 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003185 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003186 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003187 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003188 mix = srcs[i];
3189 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003190 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003191 if (!mix)
3192 return;
3193
3194 /* need the manual connection? */
3195 if (num > 1)
3196 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3197 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003198 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3199 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003200 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003201 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003202 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003203 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003204 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003205 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3206 if (nid)
3207 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3208 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003209}
3210
Takashi Iwai343a04b2011-07-06 14:28:39 +02003211static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003212{
3213 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003214 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003215 int i;
3216
3217 for (i = 0; i <= HDA_SIDE; i++) {
3218 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3219 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003220 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003221 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003222 }
3223}
3224
Takashi Iwai343a04b2011-07-06 14:28:39 +02003225static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003226{
3227 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003228 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003229 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003230
Takashi Iwaie23832a2011-08-23 18:16:56 +02003231 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3232 pin = spec->autocfg.hp_pins[i];
3233 if (!pin)
3234 break;
3235 dac = spec->multiout.hp_out_nid[i];
3236 if (!dac) {
3237 if (i > 0 && spec->multiout.hp_out_nid[0])
3238 dac = spec->multiout.hp_out_nid[0];
3239 else
3240 dac = spec->multiout.dac_nids[0];
3241 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003242 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3243 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003244 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3245 pin = spec->autocfg.speaker_pins[i];
3246 if (!pin)
3247 break;
3248 dac = spec->multiout.extra_out_nid[i];
3249 if (!dac) {
3250 if (i > 0 && spec->multiout.extra_out_nid[0])
3251 dac = spec->multiout.extra_out_nid[0];
3252 else
3253 dac = spec->multiout.dac_nids[0];
3254 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003255 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3256 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003257}
3258
Takashi Iwaice764ab2011-04-27 16:35:23 +02003259/*
3260 * multi-io helper
3261 */
3262static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3263 unsigned int location)
3264{
3265 struct alc_spec *spec = codec->spec;
3266 struct auto_pin_cfg *cfg = &spec->autocfg;
3267 int type, i, num_pins = 0;
3268
3269 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3270 for (i = 0; i < cfg->num_inputs; i++) {
3271 hda_nid_t nid = cfg->inputs[i].pin;
3272 hda_nid_t dac;
3273 unsigned int defcfg, caps;
3274 if (cfg->inputs[i].type != type)
3275 continue;
3276 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3277 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3278 continue;
3279 if (location && get_defcfg_location(defcfg) != location)
3280 continue;
3281 caps = snd_hda_query_pin_caps(codec, nid);
3282 if (!(caps & AC_PINCAP_OUT))
3283 continue;
3284 dac = alc_auto_look_for_dac(codec, nid);
3285 if (!dac)
3286 continue;
3287 spec->multi_io[num_pins].pin = nid;
3288 spec->multi_io[num_pins].dac = dac;
3289 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003290 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003291 }
3292 }
3293 spec->multiout.num_dacs = 1;
3294 if (num_pins < 2)
3295 return 0;
3296 return num_pins;
3297}
3298
3299static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3300 struct snd_ctl_elem_info *uinfo)
3301{
3302 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3303 struct alc_spec *spec = codec->spec;
3304
3305 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3306 uinfo->count = 1;
3307 uinfo->value.enumerated.items = spec->multi_ios + 1;
3308 if (uinfo->value.enumerated.item > spec->multi_ios)
3309 uinfo->value.enumerated.item = spec->multi_ios;
3310 sprintf(uinfo->value.enumerated.name, "%dch",
3311 (uinfo->value.enumerated.item + 1) * 2);
3312 return 0;
3313}
3314
3315static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3316 struct snd_ctl_elem_value *ucontrol)
3317{
3318 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3319 struct alc_spec *spec = codec->spec;
3320 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3321 return 0;
3322}
3323
3324static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3325{
3326 struct alc_spec *spec = codec->spec;
3327 hda_nid_t nid = spec->multi_io[idx].pin;
3328
3329 if (!spec->multi_io[idx].ctl_in)
3330 spec->multi_io[idx].ctl_in =
3331 snd_hda_codec_read(codec, nid, 0,
3332 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3333 if (output) {
3334 snd_hda_codec_update_cache(codec, nid, 0,
3335 AC_VERB_SET_PIN_WIDGET_CONTROL,
3336 PIN_OUT);
3337 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3338 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3339 HDA_AMP_MUTE, 0);
3340 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3341 } else {
3342 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3343 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3344 HDA_AMP_MUTE, HDA_AMP_MUTE);
3345 snd_hda_codec_update_cache(codec, nid, 0,
3346 AC_VERB_SET_PIN_WIDGET_CONTROL,
3347 spec->multi_io[idx].ctl_in);
3348 }
3349 return 0;
3350}
3351
3352static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3353 struct snd_ctl_elem_value *ucontrol)
3354{
3355 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3356 struct alc_spec *spec = codec->spec;
3357 int i, ch;
3358
3359 ch = ucontrol->value.enumerated.item[0];
3360 if (ch < 0 || ch > spec->multi_ios)
3361 return -EINVAL;
3362 if (ch == (spec->ext_channel_count - 1) / 2)
3363 return 0;
3364 spec->ext_channel_count = (ch + 1) * 2;
3365 for (i = 0; i < spec->multi_ios; i++)
3366 alc_set_multi_io(codec, i, i < ch);
3367 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003368 if (spec->need_dac_fix && !spec->const_channel_count)
3369 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003370 return 1;
3371}
3372
Takashi Iwaia9111322011-05-02 11:30:18 +02003373static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003374 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3375 .name = "Channel Mode",
3376 .info = alc_auto_ch_mode_info,
3377 .get = alc_auto_ch_mode_get,
3378 .put = alc_auto_ch_mode_put,
3379};
3380
Takashi Iwai23c09b02011-08-19 09:05:35 +02003381static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003382{
3383 struct alc_spec *spec = codec->spec;
3384 struct auto_pin_cfg *cfg = &spec->autocfg;
3385 unsigned int location, defcfg;
3386 int num_pins;
3387
3388 if (cfg->line_outs != 1 ||
Takashi Iwai3fccdfd2011-06-24 10:35:05 +02003389 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003390 return 0;
3391
3392 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3393 location = get_defcfg_location(defcfg);
3394
3395 num_pins = alc_auto_fill_multi_ios(codec, location);
3396 if (num_pins > 0) {
3397 struct snd_kcontrol_new *knew;
3398
3399 knew = alc_kcontrol_new(spec);
3400 if (!knew)
3401 return -ENOMEM;
3402 *knew = alc_auto_channel_mode_enum;
3403 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3404 if (!knew->name)
3405 return -ENOMEM;
3406
3407 spec->multi_ios = num_pins;
3408 spec->ext_channel_count = 2;
3409 spec->multiout.num_dacs = num_pins + 1;
3410 }
3411 return 0;
3412}
3413
Takashi Iwai1d045db2011-07-07 18:23:21 +02003414/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3415 * active input pins
3416 */
3417static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3418{
3419 struct alc_spec *spec = codec->spec;
3420 const struct hda_input_mux *imux;
3421 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3422 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3423 int i, n, nums;
3424
3425 imux = spec->input_mux;
3426 if (!imux)
3427 return;
3428 if (spec->dyn_adc_switch)
3429 return;
3430
3431 nums = 0;
3432 for (n = 0; n < spec->num_adc_nids; n++) {
3433 hda_nid_t cap = spec->private_capsrc_nids[n];
3434 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3435 for (i = 0; i < imux->num_items; i++) {
3436 hda_nid_t pin = spec->imux_pins[i];
3437 if (pin) {
3438 if (get_connection_index(codec, cap, pin) < 0)
3439 break;
3440 } else if (num_conns <= imux->items[i].index)
3441 break;
3442 }
3443 if (i >= imux->num_items) {
3444 adc_nids[nums] = spec->private_adc_nids[n];
3445 capsrc_nids[nums++] = cap;
3446 }
3447 }
3448 if (!nums) {
3449 /* check whether ADC-switch is possible */
3450 if (!alc_check_dyn_adc_switch(codec)) {
3451 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3452 " using fallback 0x%x\n",
3453 codec->chip_name, spec->private_adc_nids[0]);
3454 spec->num_adc_nids = 1;
3455 spec->auto_mic = 0;
3456 return;
3457 }
3458 } else if (nums != spec->num_adc_nids) {
3459 memcpy(spec->private_adc_nids, adc_nids,
3460 nums * sizeof(hda_nid_t));
3461 memcpy(spec->private_capsrc_nids, capsrc_nids,
3462 nums * sizeof(hda_nid_t));
3463 spec->num_adc_nids = nums;
3464 }
3465
3466 if (spec->auto_mic)
3467 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3468 else if (spec->input_mux->num_items == 1)
3469 spec->num_adc_nids = 1; /* reduce to a single ADC */
3470}
3471
3472/*
3473 * initialize ADC paths
3474 */
3475static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3476{
3477 struct alc_spec *spec = codec->spec;
3478 hda_nid_t nid;
3479
3480 nid = spec->adc_nids[adc_idx];
3481 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003482 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003483 snd_hda_codec_write(codec, nid, 0,
3484 AC_VERB_SET_AMP_GAIN_MUTE,
3485 AMP_IN_MUTE(0));
3486 return;
3487 }
3488 if (!spec->capsrc_nids)
3489 return;
3490 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003491 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003492 snd_hda_codec_write(codec, nid, 0,
3493 AC_VERB_SET_AMP_GAIN_MUTE,
3494 AMP_OUT_MUTE);
3495}
3496
3497static void alc_auto_init_input_src(struct hda_codec *codec)
3498{
3499 struct alc_spec *spec = codec->spec;
3500 int c, nums;
3501
3502 for (c = 0; c < spec->num_adc_nids; c++)
3503 alc_auto_init_adc(codec, c);
3504 if (spec->dyn_adc_switch)
3505 nums = 1;
3506 else
3507 nums = spec->num_adc_nids;
3508 for (c = 0; c < nums; c++)
3509 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3510}
3511
3512/* add mic boosts if needed */
3513static int alc_auto_add_mic_boost(struct hda_codec *codec)
3514{
3515 struct alc_spec *spec = codec->spec;
3516 struct auto_pin_cfg *cfg = &spec->autocfg;
3517 int i, err;
3518 int type_idx = 0;
3519 hda_nid_t nid;
3520 const char *prev_label = NULL;
3521
3522 for (i = 0; i < cfg->num_inputs; i++) {
3523 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3524 break;
3525 nid = cfg->inputs[i].pin;
3526 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3527 const char *label;
3528 char boost_label[32];
3529
3530 label = hda_get_autocfg_input_label(codec, cfg, i);
3531 if (prev_label && !strcmp(label, prev_label))
3532 type_idx++;
3533 else
3534 type_idx = 0;
3535 prev_label = label;
3536
3537 snprintf(boost_label, sizeof(boost_label),
3538 "%s Boost Volume", label);
3539 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3540 boost_label, type_idx,
3541 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3542 if (err < 0)
3543 return err;
3544 }
3545 }
3546 return 0;
3547}
3548
3549/* select or unmute the given capsrc route */
3550static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3551 int idx)
3552{
3553 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3554 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3555 HDA_AMP_MUTE, 0);
3556 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3557 snd_hda_codec_write_cache(codec, cap, 0,
3558 AC_VERB_SET_CONNECT_SEL, idx);
3559 }
3560}
3561
3562/* set the default connection to that pin */
3563static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3564{
3565 struct alc_spec *spec = codec->spec;
3566 int i;
3567
3568 if (!pin)
3569 return 0;
3570 for (i = 0; i < spec->num_adc_nids; i++) {
3571 hda_nid_t cap = spec->capsrc_nids ?
3572 spec->capsrc_nids[i] : spec->adc_nids[i];
3573 int idx;
3574
3575 idx = get_connection_index(codec, cap, pin);
3576 if (idx < 0)
3577 continue;
3578 select_or_unmute_capsrc(codec, cap, idx);
3579 return i; /* return the found index */
3580 }
3581 return -1; /* not found */
3582}
3583
3584/* initialize some special cases for input sources */
3585static void alc_init_special_input_src(struct hda_codec *codec)
3586{
3587 struct alc_spec *spec = codec->spec;
3588 int i;
3589
3590 for (i = 0; i < spec->autocfg.num_inputs; i++)
3591 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3592}
3593
3594/* assign appropriate capture mixers */
3595static void set_capture_mixer(struct hda_codec *codec)
3596{
3597 struct alc_spec *spec = codec->spec;
3598 static const struct snd_kcontrol_new *caps[2][3] = {
3599 { alc_capture_mixer_nosrc1,
3600 alc_capture_mixer_nosrc2,
3601 alc_capture_mixer_nosrc3 },
3602 { alc_capture_mixer1,
3603 alc_capture_mixer2,
3604 alc_capture_mixer3 },
3605 };
3606
3607 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003608 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003609 if (!spec->capsrc_nids)
3610 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003611 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003612 return; /* no volume in capsrc, too */
3613 spec->vol_in_capsrc = 1;
3614 }
3615
3616 if (spec->num_adc_nids > 0) {
3617 int mux = 0;
3618 int num_adcs = 0;
3619
3620 if (spec->input_mux && spec->input_mux->num_items > 1)
3621 mux = 1;
3622 if (spec->auto_mic) {
3623 num_adcs = 1;
3624 mux = 0;
3625 } else if (spec->dyn_adc_switch)
3626 num_adcs = 1;
3627 if (!num_adcs) {
3628 if (spec->num_adc_nids > 3)
3629 spec->num_adc_nids = 3;
3630 else if (!spec->num_adc_nids)
3631 return;
3632 num_adcs = spec->num_adc_nids;
3633 }
3634 spec->cap_mixer = caps[mux][num_adcs - 1];
3635 }
3636}
3637
3638/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003639 * standard auto-parser initializations
3640 */
3641static void alc_auto_init_std(struct hda_codec *codec)
3642{
3643 struct alc_spec *spec = codec->spec;
3644 alc_auto_init_multi_out(codec);
3645 alc_auto_init_extra_out(codec);
3646 alc_auto_init_analog_input(codec);
3647 alc_auto_init_input_src(codec);
3648 alc_auto_init_digital(codec);
3649 if (spec->unsol_event)
3650 alc_inithook(codec);
3651}
3652
3653/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003654 * Digital-beep handlers
3655 */
3656#ifdef CONFIG_SND_HDA_INPUT_BEEP
3657#define set_beep_amp(spec, nid, idx, dir) \
3658 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3659
3660static const struct snd_pci_quirk beep_white_list[] = {
3661 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3662 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3663 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3664 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3665 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3666 {}
3667};
3668
3669static inline int has_cdefine_beep(struct hda_codec *codec)
3670{
3671 struct alc_spec *spec = codec->spec;
3672 const struct snd_pci_quirk *q;
3673 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3674 if (q)
3675 return q->value;
3676 return spec->cdefine.enable_pcbeep;
3677}
3678#else
3679#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3680#define has_cdefine_beep(codec) 0
3681#endif
3682
3683/* parse the BIOS configuration and set up the alc_spec */
3684/* return 1 if successful, 0 if the proper config is not found,
3685 * or a negative error code
3686 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003687static int alc_parse_auto_config(struct hda_codec *codec,
3688 const hda_nid_t *ignore_nids,
3689 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003690{
3691 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003692 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003693 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003694
Takashi Iwai53c334a2011-08-23 18:27:14 +02003695 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3696 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003697 if (err < 0)
3698 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003699 if (!cfg->line_outs) {
3700 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003701 spec->multiout.max_channels = 2;
3702 spec->no_analog = 1;
3703 goto dig_only;
3704 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003705 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003706 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003707
Takashi Iwaie23832a2011-08-23 18:16:56 +02003708 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs > 0) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003709 /* use HP as primary out */
3710 cfg->speaker_outs = cfg->line_outs;
3711 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3712 sizeof(cfg->speaker_pins));
3713 cfg->line_outs = cfg->hp_outs;
3714 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3715 cfg->hp_outs = 0;
3716 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3717 cfg->line_out_type = AUTO_PIN_HP_OUT;
3718 }
3719
Takashi Iwai1d045db2011-07-07 18:23:21 +02003720 err = alc_auto_fill_dac_nids(codec);
3721 if (err < 0)
3722 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003723 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003724 if (err < 0)
3725 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003726 err = alc_auto_fill_extra_dacs(codec);
3727 if (err < 0)
3728 return err;
3729 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003730 if (err < 0)
3731 return err;
3732 err = alc_auto_create_hp_out(codec);
3733 if (err < 0)
3734 return err;
3735 err = alc_auto_create_speaker_out(codec);
3736 if (err < 0)
3737 return err;
3738 err = alc_auto_create_input_ctls(codec);
3739 if (err < 0)
3740 return err;
3741
3742 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3743
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003744 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02003745 alc_auto_parse_digital(codec);
3746
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003747 if (!spec->no_analog)
3748 alc_remove_invalid_adc_nids(codec);
3749
3750 if (ssid_nids)
3751 alc_ssid_check(codec, ssid_nids);
3752
3753 if (!spec->no_analog) {
3754 alc_auto_check_switches(codec);
3755 err = alc_auto_add_mic_boost(codec);
3756 if (err < 0)
3757 return err;
3758 }
3759
Takashi Iwai1d045db2011-07-07 18:23:21 +02003760 if (spec->kctls.list)
3761 add_mixer(spec, spec->kctls.list);
3762
Takashi Iwai1d045db2011-07-07 18:23:21 +02003763 return 1;
3764}
3765
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003766static int alc880_parse_auto_config(struct hda_codec *codec)
3767{
3768 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3769 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3770 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3771}
3772
Takashi Iwai1d045db2011-07-07 18:23:21 +02003773#ifdef CONFIG_SND_HDA_POWER_SAVE
3774static const struct hda_amp_list alc880_loopbacks[] = {
3775 { 0x0b, HDA_INPUT, 0 },
3776 { 0x0b, HDA_INPUT, 1 },
3777 { 0x0b, HDA_INPUT, 2 },
3778 { 0x0b, HDA_INPUT, 3 },
3779 { 0x0b, HDA_INPUT, 4 },
3780 { } /* end */
3781};
3782#endif
3783
3784/*
3785 * board setups
3786 */
3787#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3788#define alc_board_config \
3789 snd_hda_check_board_config
3790#define alc_board_codec_sid_config \
3791 snd_hda_check_board_codec_sid_config
3792#include "alc_quirks.c"
3793#else
3794#define alc_board_config(codec, nums, models, tbl) -1
3795#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3796#define setup_preset(codec, x) /* NOP */
3797#endif
3798
3799/*
3800 * OK, here we have finally the patch for ALC880
3801 */
3802#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3803#include "alc880_quirks.c"
3804#endif
3805
3806static int patch_alc880(struct hda_codec *codec)
3807{
3808 struct alc_spec *spec;
3809 int board_config;
3810 int err;
3811
3812 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3813 if (spec == NULL)
3814 return -ENOMEM;
3815
3816 codec->spec = spec;
3817
3818 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003819 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003820
3821 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3822 alc880_models, alc880_cfg_tbl);
3823 if (board_config < 0) {
3824 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3825 codec->chip_name);
3826 board_config = ALC_MODEL_AUTO;
3827 }
3828
3829 if (board_config == ALC_MODEL_AUTO) {
3830 /* automatic parse from the BIOS config */
3831 err = alc880_parse_auto_config(codec);
3832 if (err < 0) {
3833 alc_free(codec);
3834 return err;
3835 }
3836#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3837 else if (!err) {
3838 printk(KERN_INFO
3839 "hda_codec: Cannot set up configuration "
3840 "from BIOS. Using 3-stack mode...\n");
3841 board_config = ALC880_3ST;
3842 }
3843#endif
3844 }
3845
Takashi Iwai1d045db2011-07-07 18:23:21 +02003846 if (board_config != ALC_MODEL_AUTO)
3847 setup_preset(codec, &alc880_presets[board_config]);
3848
Takashi Iwai60a6a842011-07-27 14:01:24 +02003849 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003850 alc_auto_fill_adc_caps(codec);
3851 alc_rebuild_imux_for_auto_mic(codec);
3852 alc_remove_invalid_adc_nids(codec);
3853 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003854
3855 if (!spec->no_analog && !spec->cap_mixer)
3856 set_capture_mixer(codec);
3857
3858 if (!spec->no_analog) {
3859 err = snd_hda_attach_beep_device(codec, 0x1);
3860 if (err < 0) {
3861 alc_free(codec);
3862 return err;
3863 }
3864 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3865 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003866
3867 spec->vmaster_nid = 0x0c;
3868
3869 codec->patch_ops = alc_patch_ops;
3870 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02003871 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003872#ifdef CONFIG_SND_HDA_POWER_SAVE
3873 if (!spec->loopback.amplist)
3874 spec->loopback.amplist = alc880_loopbacks;
3875#endif
3876
3877 return 0;
3878}
3879
3880
3881/*
3882 * ALC260 support
3883 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02003884static int alc260_parse_auto_config(struct hda_codec *codec)
3885{
Takashi Iwai1d045db2011-07-07 18:23:21 +02003886 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003887 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
3888 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003889}
3890
Takashi Iwai1d045db2011-07-07 18:23:21 +02003891#ifdef CONFIG_SND_HDA_POWER_SAVE
3892static const struct hda_amp_list alc260_loopbacks[] = {
3893 { 0x07, HDA_INPUT, 0 },
3894 { 0x07, HDA_INPUT, 1 },
3895 { 0x07, HDA_INPUT, 2 },
3896 { 0x07, HDA_INPUT, 3 },
3897 { 0x07, HDA_INPUT, 4 },
3898 { } /* end */
3899};
3900#endif
3901
3902/*
3903 * Pin config fixes
3904 */
3905enum {
3906 PINFIX_HP_DC5750,
3907};
3908
3909static const struct alc_fixup alc260_fixups[] = {
3910 [PINFIX_HP_DC5750] = {
3911 .type = ALC_FIXUP_PINS,
3912 .v.pins = (const struct alc_pincfg[]) {
3913 { 0x11, 0x90130110 }, /* speaker */
3914 { }
3915 }
3916 },
3917};
3918
3919static const struct snd_pci_quirk alc260_fixup_tbl[] = {
3920 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
3921 {}
3922};
3923
3924/*
3925 */
3926#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3927#include "alc260_quirks.c"
3928#endif
3929
3930static int patch_alc260(struct hda_codec *codec)
3931{
3932 struct alc_spec *spec;
3933 int err, board_config;
3934
3935 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3936 if (spec == NULL)
3937 return -ENOMEM;
3938
3939 codec->spec = spec;
3940
3941 spec->mixer_nid = 0x07;
3942
3943 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
3944 alc260_models, alc260_cfg_tbl);
3945 if (board_config < 0) {
3946 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3947 codec->chip_name);
3948 board_config = ALC_MODEL_AUTO;
3949 }
3950
3951 if (board_config == ALC_MODEL_AUTO) {
3952 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
3953 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
3954 }
3955
3956 if (board_config == ALC_MODEL_AUTO) {
3957 /* automatic parse from the BIOS config */
3958 err = alc260_parse_auto_config(codec);
3959 if (err < 0) {
3960 alc_free(codec);
3961 return err;
3962 }
3963#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3964 else if (!err) {
3965 printk(KERN_INFO
3966 "hda_codec: Cannot set up configuration "
3967 "from BIOS. Using base mode...\n");
3968 board_config = ALC260_BASIC;
3969 }
3970#endif
3971 }
3972
Takashi Iwai1d045db2011-07-07 18:23:21 +02003973 if (board_config != ALC_MODEL_AUTO)
3974 setup_preset(codec, &alc260_presets[board_config]);
3975
Takashi Iwai60a6a842011-07-27 14:01:24 +02003976 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003977 alc_auto_fill_adc_caps(codec);
3978 alc_rebuild_imux_for_auto_mic(codec);
3979 alc_remove_invalid_adc_nids(codec);
3980 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003981
3982 if (!spec->no_analog && !spec->cap_mixer)
3983 set_capture_mixer(codec);
3984
3985 if (!spec->no_analog) {
3986 err = snd_hda_attach_beep_device(codec, 0x1);
3987 if (err < 0) {
3988 alc_free(codec);
3989 return err;
3990 }
3991 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
3992 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003993
3994 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
3995
3996 spec->vmaster_nid = 0x08;
3997
3998 codec->patch_ops = alc_patch_ops;
3999 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004000 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004001 spec->shutup = alc_eapd_shutup;
4002#ifdef CONFIG_SND_HDA_POWER_SAVE
4003 if (!spec->loopback.amplist)
4004 spec->loopback.amplist = alc260_loopbacks;
4005#endif
4006
4007 return 0;
4008}
4009
4010
4011/*
4012 * ALC882/883/885/888/889 support
4013 *
4014 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4015 * configuration. Each pin widget can choose any input DACs and a mixer.
4016 * Each ADC is connected from a mixer of all inputs. This makes possible
4017 * 6-channel independent captures.
4018 *
4019 * In addition, an independent DAC for the multi-playback (not used in this
4020 * driver yet).
4021 */
4022#ifdef CONFIG_SND_HDA_POWER_SAVE
4023#define alc882_loopbacks alc880_loopbacks
4024#endif
4025
4026/*
4027 * Pin config fixes
4028 */
4029enum {
4030 PINFIX_ABIT_AW9D_MAX,
4031 PINFIX_LENOVO_Y530,
4032 PINFIX_PB_M5210,
4033 PINFIX_ACER_ASPIRE_7736,
4034};
4035
4036static const struct alc_fixup alc882_fixups[] = {
4037 [PINFIX_ABIT_AW9D_MAX] = {
4038 .type = ALC_FIXUP_PINS,
4039 .v.pins = (const struct alc_pincfg[]) {
4040 { 0x15, 0x01080104 }, /* side */
4041 { 0x16, 0x01011012 }, /* rear */
4042 { 0x17, 0x01016011 }, /* clfe */
4043 { }
4044 }
4045 },
4046 [PINFIX_LENOVO_Y530] = {
4047 .type = ALC_FIXUP_PINS,
4048 .v.pins = (const struct alc_pincfg[]) {
4049 { 0x15, 0x99130112 }, /* rear int speakers */
4050 { 0x16, 0x99130111 }, /* subwoofer */
4051 { }
4052 }
4053 },
4054 [PINFIX_PB_M5210] = {
4055 .type = ALC_FIXUP_VERBS,
4056 .v.verbs = (const struct hda_verb[]) {
4057 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4058 {}
4059 }
4060 },
4061 [PINFIX_ACER_ASPIRE_7736] = {
4062 .type = ALC_FIXUP_SKU,
4063 .v.sku = ALC_FIXUP_SKU_IGNORE,
4064 },
4065};
4066
4067static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4068 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4069 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4070 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4071 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4072 {}
4073};
4074
4075/*
4076 * BIOS auto configuration
4077 */
4078/* almost identical with ALC880 parser... */
4079static int alc882_parse_auto_config(struct hda_codec *codec)
4080{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004081 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004082 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4083 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004084}
4085
Takashi Iwai1d045db2011-07-07 18:23:21 +02004086/*
4087 */
4088#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4089#include "alc882_quirks.c"
4090#endif
4091
4092static int patch_alc882(struct hda_codec *codec)
4093{
4094 struct alc_spec *spec;
4095 int err, board_config;
4096
4097 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4098 if (spec == NULL)
4099 return -ENOMEM;
4100
4101 codec->spec = spec;
4102
4103 spec->mixer_nid = 0x0b;
4104
4105 switch (codec->vendor_id) {
4106 case 0x10ec0882:
4107 case 0x10ec0885:
4108 break;
4109 default:
4110 /* ALC883 and variants */
4111 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4112 break;
4113 }
4114
4115 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4116 alc882_models, alc882_cfg_tbl);
4117
4118 if (board_config < 0)
4119 board_config = alc_board_codec_sid_config(codec,
4120 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4121
4122 if (board_config < 0) {
4123 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4124 codec->chip_name);
4125 board_config = ALC_MODEL_AUTO;
4126 }
4127
4128 if (board_config == ALC_MODEL_AUTO) {
4129 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4130 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4131 }
4132
4133 alc_auto_parse_customize_define(codec);
4134
4135 if (board_config == ALC_MODEL_AUTO) {
4136 /* automatic parse from the BIOS config */
4137 err = alc882_parse_auto_config(codec);
4138 if (err < 0) {
4139 alc_free(codec);
4140 return err;
4141 }
4142#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4143 else if (!err) {
4144 printk(KERN_INFO
4145 "hda_codec: Cannot set up configuration "
4146 "from BIOS. Using base mode...\n");
4147 board_config = ALC882_3ST_DIG;
4148 }
4149#endif
4150 }
4151
Takashi Iwai1d045db2011-07-07 18:23:21 +02004152 if (board_config != ALC_MODEL_AUTO)
4153 setup_preset(codec, &alc882_presets[board_config]);
4154
Takashi Iwai60a6a842011-07-27 14:01:24 +02004155 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004156 alc_auto_fill_adc_caps(codec);
4157 alc_rebuild_imux_for_auto_mic(codec);
4158 alc_remove_invalid_adc_nids(codec);
4159 }
4160
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004161 if (!spec->no_analog && !spec->cap_mixer)
4162 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004163
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004164 if (!spec->no_analog && has_cdefine_beep(codec)) {
4165 err = snd_hda_attach_beep_device(codec, 0x1);
4166 if (err < 0) {
4167 alc_free(codec);
4168 return err;
4169 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004170 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004171 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004172
4173 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4174
4175 spec->vmaster_nid = 0x0c;
4176
4177 codec->patch_ops = alc_patch_ops;
4178 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004179 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004180
4181 alc_init_jacks(codec);
4182#ifdef CONFIG_SND_HDA_POWER_SAVE
4183 if (!spec->loopback.amplist)
4184 spec->loopback.amplist = alc882_loopbacks;
4185#endif
4186
4187 return 0;
4188}
4189
4190
4191/*
4192 * ALC262 support
4193 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004194static int alc262_parse_auto_config(struct hda_codec *codec)
4195{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004196 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004197 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4198 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004199}
4200
4201/*
4202 * Pin config fixes
4203 */
4204enum {
4205 PINFIX_FSC_H270,
4206 PINFIX_HP_Z200,
4207};
4208
4209static const struct alc_fixup alc262_fixups[] = {
4210 [PINFIX_FSC_H270] = {
4211 .type = ALC_FIXUP_PINS,
4212 .v.pins = (const struct alc_pincfg[]) {
4213 { 0x14, 0x99130110 }, /* speaker */
4214 { 0x15, 0x0221142f }, /* front HP */
4215 { 0x1b, 0x0121141f }, /* rear HP */
4216 { }
4217 }
4218 },
4219 [PINFIX_HP_Z200] = {
4220 .type = ALC_FIXUP_PINS,
4221 .v.pins = (const struct alc_pincfg[]) {
4222 { 0x16, 0x99130120 }, /* internal speaker */
4223 { }
4224 }
4225 },
4226};
4227
4228static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4229 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4230 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4231 {}
4232};
4233
4234
4235#ifdef CONFIG_SND_HDA_POWER_SAVE
4236#define alc262_loopbacks alc880_loopbacks
4237#endif
4238
Takashi Iwai1d045db2011-07-07 18:23:21 +02004239/*
4240 */
4241#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4242#include "alc262_quirks.c"
4243#endif
4244
4245static int patch_alc262(struct hda_codec *codec)
4246{
4247 struct alc_spec *spec;
4248 int board_config;
4249 int err;
4250
4251 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4252 if (spec == NULL)
4253 return -ENOMEM;
4254
4255 codec->spec = spec;
4256
4257 spec->mixer_nid = 0x0b;
4258
4259#if 0
4260 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4261 * under-run
4262 */
4263 {
4264 int tmp;
4265 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4266 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4267 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4268 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4269 }
4270#endif
4271 alc_auto_parse_customize_define(codec);
4272
4273 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4274
4275 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4276 alc262_models, alc262_cfg_tbl);
4277
4278 if (board_config < 0) {
4279 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4280 codec->chip_name);
4281 board_config = ALC_MODEL_AUTO;
4282 }
4283
4284 if (board_config == ALC_MODEL_AUTO) {
4285 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4286 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4287 }
4288
4289 if (board_config == ALC_MODEL_AUTO) {
4290 /* automatic parse from the BIOS config */
4291 err = alc262_parse_auto_config(codec);
4292 if (err < 0) {
4293 alc_free(codec);
4294 return err;
4295 }
4296#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4297 else if (!err) {
4298 printk(KERN_INFO
4299 "hda_codec: Cannot set up configuration "
4300 "from BIOS. Using base mode...\n");
4301 board_config = ALC262_BASIC;
4302 }
4303#endif
4304 }
4305
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004306 if (board_config != ALC_MODEL_AUTO)
4307 setup_preset(codec, &alc262_presets[board_config]);
4308
Takashi Iwai60a6a842011-07-27 14:01:24 +02004309 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004310 alc_auto_fill_adc_caps(codec);
4311 alc_rebuild_imux_for_auto_mic(codec);
4312 alc_remove_invalid_adc_nids(codec);
4313 }
4314
4315 if (!spec->no_analog && !spec->cap_mixer)
4316 set_capture_mixer(codec);
4317
Takashi Iwai1d045db2011-07-07 18:23:21 +02004318 if (!spec->no_analog && has_cdefine_beep(codec)) {
4319 err = snd_hda_attach_beep_device(codec, 0x1);
4320 if (err < 0) {
4321 alc_free(codec);
4322 return err;
4323 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004324 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004325 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004326
4327 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4328
4329 spec->vmaster_nid = 0x0c;
4330
4331 codec->patch_ops = alc_patch_ops;
4332 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004333 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004334 spec->shutup = alc_eapd_shutup;
4335
4336 alc_init_jacks(codec);
4337#ifdef CONFIG_SND_HDA_POWER_SAVE
4338 if (!spec->loopback.amplist)
4339 spec->loopback.amplist = alc262_loopbacks;
4340#endif
4341
4342 return 0;
4343}
4344
4345/*
4346 * ALC268
4347 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004348/* bind Beep switches of both NID 0x0f and 0x10 */
4349static const struct hda_bind_ctls alc268_bind_beep_sw = {
4350 .ops = &snd_hda_bind_sw,
4351 .values = {
4352 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4353 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4354 0
4355 },
4356};
4357
4358static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4359 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4360 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4361 { }
4362};
4363
4364/* set PCBEEP vol = 0, mute connections */
4365static const struct hda_verb alc268_beep_init_verbs[] = {
4366 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4367 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4368 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4369 { }
4370};
4371
4372/*
4373 * BIOS auto configuration
4374 */
4375static int alc268_parse_auto_config(struct hda_codec *codec)
4376{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004377 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004378 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004379 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4380 if (err > 0) {
4381 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4382 add_mixer(spec, alc268_beep_mixer);
4383 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004384 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004386 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004387}
4388
Takashi Iwai1d045db2011-07-07 18:23:21 +02004389/*
4390 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004391static int patch_alc268(struct hda_codec *codec)
4392{
4393 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004394 int i, has_beep, err;
4395
4396 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4397 if (spec == NULL)
4398 return -ENOMEM;
4399
4400 codec->spec = spec;
4401
4402 /* ALC268 has no aa-loopback mixer */
4403
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004404 /* automatic parse from the BIOS config */
4405 err = alc268_parse_auto_config(codec);
4406 if (err < 0) {
4407 alc_free(codec);
4408 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004409 }
4410
Takashi Iwai1d045db2011-07-07 18:23:21 +02004411 has_beep = 0;
4412 for (i = 0; i < spec->num_mixers; i++) {
4413 if (spec->mixers[i] == alc268_beep_mixer) {
4414 has_beep = 1;
4415 break;
4416 }
4417 }
4418
4419 if (has_beep) {
4420 err = snd_hda_attach_beep_device(codec, 0x1);
4421 if (err < 0) {
4422 alc_free(codec);
4423 return err;
4424 }
4425 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4426 /* override the amp caps for beep generator */
4427 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4428 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4429 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4430 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4431 (0 << AC_AMPCAP_MUTE_SHIFT));
4432 }
4433
Takashi Iwai60a6a842011-07-27 14:01:24 +02004434 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004435 alc_auto_fill_adc_caps(codec);
4436 alc_rebuild_imux_for_auto_mic(codec);
4437 alc_remove_invalid_adc_nids(codec);
4438 }
4439
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004440 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004441 set_capture_mixer(codec);
4442
4443 spec->vmaster_nid = 0x02;
4444
4445 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004446 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004447 spec->shutup = alc_eapd_shutup;
4448
4449 alc_init_jacks(codec);
4450
4451 return 0;
4452}
4453
4454/*
4455 * ALC269
4456 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004457#ifdef CONFIG_SND_HDA_POWER_SAVE
4458#define alc269_loopbacks alc880_loopbacks
4459#endif
4460
4461static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4462 .substreams = 1,
4463 .channels_min = 2,
4464 .channels_max = 8,
4465 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4466 /* NID is set in alc_build_pcms */
4467 .ops = {
4468 .open = alc_playback_pcm_open,
4469 .prepare = alc_playback_pcm_prepare,
4470 .cleanup = alc_playback_pcm_cleanup
4471 },
4472};
4473
4474static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4475 .substreams = 1,
4476 .channels_min = 2,
4477 .channels_max = 2,
4478 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4479 /* NID is set in alc_build_pcms */
4480};
4481
4482#ifdef CONFIG_SND_HDA_POWER_SAVE
4483static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4484{
4485 switch (codec->subsystem_id) {
4486 case 0x103c1586:
4487 return 1;
4488 }
4489 return 0;
4490}
4491
4492static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4493{
4494 /* update mute-LED according to the speaker mute state */
4495 if (nid == 0x01 || nid == 0x14) {
4496 int pinval;
4497 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4498 HDA_AMP_MUTE)
4499 pinval = 0x24;
4500 else
4501 pinval = 0x20;
4502 /* mic2 vref pin is used for mute LED control */
4503 snd_hda_codec_update_cache(codec, 0x19, 0,
4504 AC_VERB_SET_PIN_WIDGET_CONTROL,
4505 pinval);
4506 }
4507 return alc_check_power_status(codec, nid);
4508}
4509#endif /* CONFIG_SND_HDA_POWER_SAVE */
4510
4511/* different alc269-variants */
4512enum {
4513 ALC269_TYPE_ALC269VA,
4514 ALC269_TYPE_ALC269VB,
4515 ALC269_TYPE_ALC269VC,
4516};
4517
4518/*
4519 * BIOS auto configuration
4520 */
4521static int alc269_parse_auto_config(struct hda_codec *codec)
4522{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004523 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004524 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4525 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4526 struct alc_spec *spec = codec->spec;
4527 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4528 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004529
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004530 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004531}
4532
Takashi Iwai1d045db2011-07-07 18:23:21 +02004533static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4534{
4535 int val = alc_read_coef_idx(codec, 0x04);
4536 if (power_up)
4537 val |= 1 << 11;
4538 else
4539 val &= ~(1 << 11);
4540 alc_write_coef_idx(codec, 0x04, val);
4541}
4542
4543static void alc269_shutup(struct hda_codec *codec)
4544{
4545 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
4546 alc269_toggle_power_output(codec, 0);
4547 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4548 alc269_toggle_power_output(codec, 0);
4549 msleep(150);
4550 }
4551}
4552
Takashi Iwai2a439522011-07-26 09:52:50 +02004553#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02004554static int alc269_resume(struct hda_codec *codec)
4555{
4556 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4557 alc269_toggle_power_output(codec, 0);
4558 msleep(150);
4559 }
4560
4561 codec->patch_ops.init(codec);
4562
4563 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4564 alc269_toggle_power_output(codec, 1);
4565 msleep(200);
4566 }
4567
4568 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
4569 alc269_toggle_power_output(codec, 1);
4570
4571 snd_hda_codec_resume_amp(codec);
4572 snd_hda_codec_resume_cache(codec);
4573 hda_call_check_power_status(codec, 0x01);
4574 return 0;
4575}
Takashi Iwai2a439522011-07-26 09:52:50 +02004576#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004577
4578static void alc269_fixup_hweq(struct hda_codec *codec,
4579 const struct alc_fixup *fix, int action)
4580{
4581 int coef;
4582
4583 if (action != ALC_FIXUP_ACT_INIT)
4584 return;
4585 coef = alc_read_coef_idx(codec, 0x1e);
4586 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4587}
4588
4589static void alc271_fixup_dmic(struct hda_codec *codec,
4590 const struct alc_fixup *fix, int action)
4591{
4592 static const struct hda_verb verbs[] = {
4593 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4594 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4595 {}
4596 };
4597 unsigned int cfg;
4598
4599 if (strcmp(codec->chip_name, "ALC271X"))
4600 return;
4601 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4602 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4603 snd_hda_sequence_write(codec, verbs);
4604}
4605
Takashi Iwai017f2a12011-07-09 14:42:25 +02004606static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4607 const struct alc_fixup *fix, int action)
4608{
4609 struct alc_spec *spec = codec->spec;
4610
4611 if (action != ALC_FIXUP_ACT_PROBE)
4612 return;
4613
4614 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4615 * fix the sample rate of analog I/O to 44.1kHz
4616 */
4617 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4618 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4619}
4620
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004621static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4622 const struct alc_fixup *fix, int action)
4623{
4624 int coef;
4625
4626 if (action != ALC_FIXUP_ACT_INIT)
4627 return;
4628 /* The digital-mic unit sends PDM (differential signal) instead of
4629 * the standard PCM, thus you can't record a valid mono stream as is.
4630 * Below is a workaround specific to ALC269 to control the dmic
4631 * signal source as mono.
4632 */
4633 coef = alc_read_coef_idx(codec, 0x07);
4634 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4635}
4636
Takashi Iwai24519912011-08-16 15:08:49 +02004637static void alc269_quanta_automute(struct hda_codec *codec)
4638{
4639 update_speakers(codec);
4640
4641 snd_hda_codec_write(codec, 0x20, 0,
4642 AC_VERB_SET_COEF_INDEX, 0x0c);
4643 snd_hda_codec_write(codec, 0x20, 0,
4644 AC_VERB_SET_PROC_COEF, 0x680);
4645
4646 snd_hda_codec_write(codec, 0x20, 0,
4647 AC_VERB_SET_COEF_INDEX, 0x0c);
4648 snd_hda_codec_write(codec, 0x20, 0,
4649 AC_VERB_SET_PROC_COEF, 0x480);
4650}
4651
4652static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4653 const struct alc_fixup *fix, int action)
4654{
4655 struct alc_spec *spec = codec->spec;
4656 if (action != ALC_FIXUP_ACT_PROBE)
4657 return;
4658 spec->automute_hook = alc269_quanta_automute;
4659}
4660
Takashi Iwai1d045db2011-07-07 18:23:21 +02004661enum {
4662 ALC269_FIXUP_SONY_VAIO,
4663 ALC275_FIXUP_SONY_VAIO_GPIO2,
4664 ALC269_FIXUP_DELL_M101Z,
4665 ALC269_FIXUP_SKU_IGNORE,
4666 ALC269_FIXUP_ASUS_G73JW,
4667 ALC269_FIXUP_LENOVO_EAPD,
4668 ALC275_FIXUP_SONY_HWEQ,
4669 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02004670 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004671 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02004672 ALC269_FIXUP_QUANTA_MUTE,
4673 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02004674 ALC269_FIXUP_AMIC,
4675 ALC269_FIXUP_DMIC,
4676 ALC269VB_FIXUP_AMIC,
4677 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004678};
4679
4680static const struct alc_fixup alc269_fixups[] = {
4681 [ALC269_FIXUP_SONY_VAIO] = {
4682 .type = ALC_FIXUP_VERBS,
4683 .v.verbs = (const struct hda_verb[]) {
4684 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4685 {}
4686 }
4687 },
4688 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4689 .type = ALC_FIXUP_VERBS,
4690 .v.verbs = (const struct hda_verb[]) {
4691 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4692 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4693 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4694 { }
4695 },
4696 .chained = true,
4697 .chain_id = ALC269_FIXUP_SONY_VAIO
4698 },
4699 [ALC269_FIXUP_DELL_M101Z] = {
4700 .type = ALC_FIXUP_VERBS,
4701 .v.verbs = (const struct hda_verb[]) {
4702 /* Enables internal speaker */
4703 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4704 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4705 {}
4706 }
4707 },
4708 [ALC269_FIXUP_SKU_IGNORE] = {
4709 .type = ALC_FIXUP_SKU,
4710 .v.sku = ALC_FIXUP_SKU_IGNORE,
4711 },
4712 [ALC269_FIXUP_ASUS_G73JW] = {
4713 .type = ALC_FIXUP_PINS,
4714 .v.pins = (const struct alc_pincfg[]) {
4715 { 0x17, 0x99130111 }, /* subwoofer */
4716 { }
4717 }
4718 },
4719 [ALC269_FIXUP_LENOVO_EAPD] = {
4720 .type = ALC_FIXUP_VERBS,
4721 .v.verbs = (const struct hda_verb[]) {
4722 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4723 {}
4724 }
4725 },
4726 [ALC275_FIXUP_SONY_HWEQ] = {
4727 .type = ALC_FIXUP_FUNC,
4728 .v.func = alc269_fixup_hweq,
4729 .chained = true,
4730 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4731 },
4732 [ALC271_FIXUP_DMIC] = {
4733 .type = ALC_FIXUP_FUNC,
4734 .v.func = alc271_fixup_dmic,
4735 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02004736 [ALC269_FIXUP_PCM_44K] = {
4737 .type = ALC_FIXUP_FUNC,
4738 .v.func = alc269_fixup_pcm_44k,
4739 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004740 [ALC269_FIXUP_STEREO_DMIC] = {
4741 .type = ALC_FIXUP_FUNC,
4742 .v.func = alc269_fixup_stereo_dmic,
4743 },
Takashi Iwai24519912011-08-16 15:08:49 +02004744 [ALC269_FIXUP_QUANTA_MUTE] = {
4745 .type = ALC_FIXUP_FUNC,
4746 .v.func = alc269_fixup_quanta_mute,
4747 },
4748 [ALC269_FIXUP_LIFEBOOK] = {
4749 .type = ALC_FIXUP_PINS,
4750 .v.pins = (const struct alc_pincfg[]) {
4751 { 0x1a, 0x2101103f }, /* dock line-out */
4752 { 0x1b, 0x23a11040 }, /* dock mic-in */
4753 { }
4754 },
4755 .chained = true,
4756 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4757 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02004758 [ALC269_FIXUP_AMIC] = {
4759 .type = ALC_FIXUP_PINS,
4760 .v.pins = (const struct alc_pincfg[]) {
4761 { 0x14, 0x99130110 }, /* speaker */
4762 { 0x15, 0x0121401f }, /* HP out */
4763 { 0x18, 0x01a19c20 }, /* mic */
4764 { 0x19, 0x99a3092f }, /* int-mic */
4765 { }
4766 },
4767 },
4768 [ALC269_FIXUP_DMIC] = {
4769 .type = ALC_FIXUP_PINS,
4770 .v.pins = (const struct alc_pincfg[]) {
4771 { 0x12, 0x99a3092f }, /* int-mic */
4772 { 0x14, 0x99130110 }, /* speaker */
4773 { 0x15, 0x0121401f }, /* HP out */
4774 { 0x18, 0x01a19c20 }, /* mic */
4775 { }
4776 },
4777 },
4778 [ALC269VB_FIXUP_AMIC] = {
4779 .type = ALC_FIXUP_PINS,
4780 .v.pins = (const struct alc_pincfg[]) {
4781 { 0x14, 0x99130110 }, /* speaker */
4782 { 0x18, 0x01a19c20 }, /* mic */
4783 { 0x19, 0x99a3092f }, /* int-mic */
4784 { 0x21, 0x0121401f }, /* HP out */
4785 { }
4786 },
4787 },
4788 [ALC269_FIXUP_DMIC] = {
4789 .type = ALC_FIXUP_PINS,
4790 .v.pins = (const struct alc_pincfg[]) {
4791 { 0x12, 0x99a3092f }, /* int-mic */
4792 { 0x14, 0x99130110 }, /* speaker */
4793 { 0x18, 0x01a19c20 }, /* mic */
4794 { 0x21, 0x0121401f }, /* HP out */
4795 { }
4796 },
4797 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004798};
4799
4800static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02004801 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004802 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4803 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4804 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4805 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4806 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004807 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4808 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4809 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4810 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4811 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4812 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02004813 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004814 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4815 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4816 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4817 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4818 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02004819 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02004820 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004821 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02004822
4823#if 1
4824 /* Below is a quirk table taken from the old code.
4825 * Basically the device should work as is without the fixup table.
4826 * If BIOS doesn't give a proper info, enable the corresponding
4827 * fixup entry.
4828 */
4829 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4830 ALC269_FIXUP_AMIC),
4831 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
4832 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
4833 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
4834 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
4835 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
4836 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
4837 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
4838 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
4839 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
4840 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
4841 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
4842 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
4843 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
4844 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
4845 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
4846 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
4847 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
4848 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
4849 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
4850 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
4851 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
4852 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
4853 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
4854 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
4855 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
4856 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
4857 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
4858 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
4859 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
4860 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
4861 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
4862 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
4863 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
4864 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
4865 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
4866 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
4867 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
4868 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
4869 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
4870 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
4871#endif
4872 {}
4873};
4874
4875static const struct alc_model_fixup alc269_fixup_models[] = {
4876 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
4877 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02004878 {}
4879};
4880
4881
4882static int alc269_fill_coef(struct hda_codec *codec)
4883{
4884 int val;
4885
4886 if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
4887 alc_write_coef_idx(codec, 0xf, 0x960b);
4888 alc_write_coef_idx(codec, 0xe, 0x8817);
4889 }
4890
4891 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
4892 alc_write_coef_idx(codec, 0xf, 0x960b);
4893 alc_write_coef_idx(codec, 0xe, 0x8814);
4894 }
4895
4896 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4897 val = alc_read_coef_idx(codec, 0x04);
4898 /* Power up output pin */
4899 alc_write_coef_idx(codec, 0x04, val | (1<<11));
4900 }
4901
4902 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4903 val = alc_read_coef_idx(codec, 0xd);
4904 if ((val & 0x0c00) >> 10 != 0x1) {
4905 /* Capless ramp up clock control */
4906 alc_write_coef_idx(codec, 0xd, val | (1<<10));
4907 }
4908 val = alc_read_coef_idx(codec, 0x17);
4909 if ((val & 0x01c0) >> 6 != 0x4) {
4910 /* Class D power on reset */
4911 alc_write_coef_idx(codec, 0x17, val | (1<<7));
4912 }
4913 }
4914
4915 val = alc_read_coef_idx(codec, 0xd); /* Class D */
4916 alc_write_coef_idx(codec, 0xd, val | (1<<14));
4917
4918 val = alc_read_coef_idx(codec, 0x4); /* HP */
4919 alc_write_coef_idx(codec, 0x4, val | (1<<11));
4920
4921 return 0;
4922}
4923
4924/*
4925 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004926static int patch_alc269(struct hda_codec *codec)
4927{
4928 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004929 int err;
4930
4931 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4932 if (spec == NULL)
4933 return -ENOMEM;
4934
4935 codec->spec = spec;
4936
4937 spec->mixer_nid = 0x0b;
4938
4939 alc_auto_parse_customize_define(codec);
4940
4941 if (codec->vendor_id == 0x10ec0269) {
Takashi Iwaia4297b52011-08-23 18:40:12 +02004942 unsigned int coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004943 spec->codec_variant = ALC269_TYPE_ALC269VA;
4944 coef = alc_read_coef_idx(codec, 0);
4945 if ((coef & 0x00f0) == 0x0010) {
4946 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
4947 spec->cdefine.platform_type == 1) {
4948 alc_codec_rename(codec, "ALC271X");
4949 } else if ((coef & 0xf000) == 0x2000) {
4950 alc_codec_rename(codec, "ALC259");
4951 } else if ((coef & 0xf000) == 0x3000) {
4952 alc_codec_rename(codec, "ALC258");
4953 } else if ((coef & 0xfff0) == 0x3010) {
4954 alc_codec_rename(codec, "ALC277");
4955 } else {
4956 alc_codec_rename(codec, "ALC269VB");
4957 }
4958 spec->codec_variant = ALC269_TYPE_ALC269VB;
4959 } else if ((coef & 0x00f0) == 0x0020) {
4960 if (coef == 0xa023)
4961 alc_codec_rename(codec, "ALC259");
4962 else if (coef == 0x6023)
4963 alc_codec_rename(codec, "ALC281X");
4964 else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
4965 codec->bus->pci->subsystem_device == 0x21f3)
4966 alc_codec_rename(codec, "ALC3202");
4967 else
4968 alc_codec_rename(codec, "ALC269VC");
4969 spec->codec_variant = ALC269_TYPE_ALC269VC;
4970 } else
4971 alc_fix_pll_init(codec, 0x20, 0x04, 15);
4972 alc269_fill_coef(codec);
4973 }
4974
Takashi Iwaia4297b52011-08-23 18:40:12 +02004975 alc_pick_fixup(codec, alc269_fixup_models,
4976 alc269_fixup_tbl, alc269_fixups);
4977 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004978
Takashi Iwaia4297b52011-08-23 18:40:12 +02004979 /* automatic parse from the BIOS config */
4980 err = alc269_parse_auto_config(codec);
4981 if (err < 0) {
4982 alc_free(codec);
4983 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004984 }
4985
Takashi Iwai60a6a842011-07-27 14:01:24 +02004986 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004987 alc_auto_fill_adc_caps(codec);
4988 alc_rebuild_imux_for_auto_mic(codec);
4989 alc_remove_invalid_adc_nids(codec);
4990 }
4991
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004992 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004994
4995 if (!spec->no_analog && has_cdefine_beep(codec)) {
4996 err = snd_hda_attach_beep_device(codec, 0x1);
4997 if (err < 0) {
4998 alc_free(codec);
4999 return err;
5000 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005001 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005002 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005003
5004 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5005
5006 spec->vmaster_nid = 0x02;
5007
5008 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005009#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005010 codec->patch_ops.resume = alc269_resume;
5011#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005012 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005013 spec->shutup = alc269_shutup;
5014
5015 alc_init_jacks(codec);
5016#ifdef CONFIG_SND_HDA_POWER_SAVE
5017 if (!spec->loopback.amplist)
5018 spec->loopback.amplist = alc269_loopbacks;
5019 if (alc269_mic2_for_mute_led(codec))
5020 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5021#endif
5022
5023 return 0;
5024}
5025
5026/*
5027 * ALC861
5028 */
5029
Takashi Iwai1d045db2011-07-07 18:23:21 +02005030static int alc861_parse_auto_config(struct hda_codec *codec)
5031{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005032 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005033 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5034 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005035}
5036
Takashi Iwai1d045db2011-07-07 18:23:21 +02005037#ifdef CONFIG_SND_HDA_POWER_SAVE
5038static const struct hda_amp_list alc861_loopbacks[] = {
5039 { 0x15, HDA_INPUT, 0 },
5040 { 0x15, HDA_INPUT, 1 },
5041 { 0x15, HDA_INPUT, 2 },
5042 { 0x15, HDA_INPUT, 3 },
5043 { } /* end */
5044};
5045#endif
5046
5047
5048/* Pin config fixes */
5049enum {
5050 PINFIX_FSC_AMILO_PI1505,
5051};
5052
5053static const struct alc_fixup alc861_fixups[] = {
5054 [PINFIX_FSC_AMILO_PI1505] = {
5055 .type = ALC_FIXUP_PINS,
5056 .v.pins = (const struct alc_pincfg[]) {
5057 { 0x0b, 0x0221101f }, /* HP */
5058 { 0x0f, 0x90170310 }, /* speaker */
5059 { }
5060 }
5061 },
5062};
5063
5064static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5065 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5066 {}
5067};
5068
5069/*
5070 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005071static int patch_alc861(struct hda_codec *codec)
5072{
5073 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005074 int err;
5075
5076 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5077 if (spec == NULL)
5078 return -ENOMEM;
5079
5080 codec->spec = spec;
5081
5082 spec->mixer_nid = 0x15;
5083
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005084 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5085 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005086
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005087 /* automatic parse from the BIOS config */
5088 err = alc861_parse_auto_config(codec);
5089 if (err < 0) {
5090 alc_free(codec);
5091 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005092 }
5093
Takashi Iwai60a6a842011-07-27 14:01:24 +02005094 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005095 alc_auto_fill_adc_caps(codec);
5096 alc_rebuild_imux_for_auto_mic(codec);
5097 alc_remove_invalid_adc_nids(codec);
5098 }
5099
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005100 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005101 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005102
5103 if (!spec->no_analog) {
5104 err = snd_hda_attach_beep_device(codec, 0x23);
5105 if (err < 0) {
5106 alc_free(codec);
5107 return err;
5108 }
5109 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5110 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005111
5112 spec->vmaster_nid = 0x03;
5113
5114 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5115
5116 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005117 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005118#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005119 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005120 if (!spec->loopback.amplist)
5121 spec->loopback.amplist = alc861_loopbacks;
5122#endif
5123
5124 return 0;
5125}
5126
5127/*
5128 * ALC861-VD support
5129 *
5130 * Based on ALC882
5131 *
5132 * In addition, an independent DAC
5133 */
5134#ifdef CONFIG_SND_HDA_POWER_SAVE
5135#define alc861vd_loopbacks alc880_loopbacks
5136#endif
5137
Takashi Iwai1d045db2011-07-07 18:23:21 +02005138static int alc861vd_parse_auto_config(struct hda_codec *codec)
5139{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005140 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005141 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5142 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005143}
5144
Takashi Iwai1d045db2011-07-07 18:23:21 +02005145enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005146 ALC660VD_FIX_ASUS_GPIO1,
5147 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005148};
5149
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005150/* exclude VREF80 */
5151static void alc861vd_fixup_dallas(struct hda_codec *codec,
5152 const struct alc_fixup *fix, int action)
5153{
5154 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5155 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5156 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5157 }
5158}
5159
Takashi Iwai1d045db2011-07-07 18:23:21 +02005160static const struct alc_fixup alc861vd_fixups[] = {
5161 [ALC660VD_FIX_ASUS_GPIO1] = {
5162 .type = ALC_FIXUP_VERBS,
5163 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005164 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005165 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5166 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5167 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5168 { }
5169 }
5170 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005171 [ALC861VD_FIX_DALLAS] = {
5172 .type = ALC_FIXUP_FUNC,
5173 .v.func = alc861vd_fixup_dallas,
5174 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005175};
5176
5177static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005178 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005179 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005180 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005181 {}
5182};
5183
5184static const struct hda_verb alc660vd_eapd_verbs[] = {
5185 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5186 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5187 { }
5188};
5189
5190/*
5191 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005192static int patch_alc861vd(struct hda_codec *codec)
5193{
5194 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005195 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005196
5197 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5198 if (spec == NULL)
5199 return -ENOMEM;
5200
5201 codec->spec = spec;
5202
5203 spec->mixer_nid = 0x0b;
5204
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005205 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5206 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005207
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005208 /* automatic parse from the BIOS config */
5209 err = alc861vd_parse_auto_config(codec);
5210 if (err < 0) {
5211 alc_free(codec);
5212 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005213 }
5214
Takashi Iwai1d045db2011-07-07 18:23:21 +02005215 if (codec->vendor_id == 0x10ec0660) {
5216 /* always turn on EAPD */
5217 add_verb(spec, alc660vd_eapd_verbs);
5218 }
5219
Takashi Iwai60a6a842011-07-27 14:01:24 +02005220 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005221 alc_auto_fill_adc_caps(codec);
5222 alc_rebuild_imux_for_auto_mic(codec);
5223 alc_remove_invalid_adc_nids(codec);
5224 }
5225
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005226 if (!spec->no_analog && !spec->cap_mixer)
5227 set_capture_mixer(codec);
5228
5229 if (!spec->no_analog) {
5230 err = snd_hda_attach_beep_device(codec, 0x23);
5231 if (err < 0) {
5232 alc_free(codec);
5233 return err;
5234 }
5235 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5236 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005237
5238 spec->vmaster_nid = 0x02;
5239
5240 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5241
5242 codec->patch_ops = alc_patch_ops;
5243
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005244 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005245 spec->shutup = alc_eapd_shutup;
5246#ifdef CONFIG_SND_HDA_POWER_SAVE
5247 if (!spec->loopback.amplist)
5248 spec->loopback.amplist = alc861vd_loopbacks;
5249#endif
5250
5251 return 0;
5252}
5253
5254/*
5255 * ALC662 support
5256 *
5257 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5258 * configuration. Each pin widget can choose any input DACs and a mixer.
5259 * Each ADC is connected from a mixer of all inputs. This makes possible
5260 * 6-channel independent captures.
5261 *
5262 * In addition, an independent DAC for the multi-playback (not used in this
5263 * driver yet).
5264 */
5265#ifdef CONFIG_SND_HDA_POWER_SAVE
5266#define alc662_loopbacks alc880_loopbacks
5267#endif
5268
5269/*
5270 * BIOS auto configuration
5271 */
5272
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005273static int alc662_parse_auto_config(struct hda_codec *codec)
5274{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005275 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005276 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5277 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5278 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005279
Kailang Yang6227cdc2010-02-25 08:36:52 +01005280 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5281 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005282 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005283 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005284 ssids = alc662_ssids;
5285 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005286}
5287
Todd Broch6be79482010-12-07 16:51:05 -08005288static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005289 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005290{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005291 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005292 return;
Todd Broch6be79482010-12-07 16:51:05 -08005293 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5294 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5295 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5296 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5297 (0 << AC_AMPCAP_MUTE_SHIFT)))
5298 printk(KERN_WARNING
5299 "hda_codec: failed to override amp caps for NID 0x2\n");
5300}
5301
David Henningsson6cb3b702010-09-09 08:51:44 +02005302enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005303 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005304 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005305 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005306 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005307 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005308 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005309 ALC662_FIXUP_ASUS_MODE1,
5310 ALC662_FIXUP_ASUS_MODE2,
5311 ALC662_FIXUP_ASUS_MODE3,
5312 ALC662_FIXUP_ASUS_MODE4,
5313 ALC662_FIXUP_ASUS_MODE5,
5314 ALC662_FIXUP_ASUS_MODE6,
5315 ALC662_FIXUP_ASUS_MODE7,
5316 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005317};
5318
5319static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005320 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005321 .type = ALC_FIXUP_PINS,
5322 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005323 { 0x15, 0x99130112 }, /* subwoofer */
5324 { }
5325 }
5326 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005327 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005328 .type = ALC_FIXUP_PINS,
5329 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005330 { 0x17, 0x99130112 }, /* subwoofer */
5331 { }
5332 }
5333 },
Todd Broch6be79482010-12-07 16:51:05 -08005334 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005335 .type = ALC_FIXUP_FUNC,
5336 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005337 },
5338 [ALC662_FIXUP_CZC_P10T] = {
5339 .type = ALC_FIXUP_VERBS,
5340 .v.verbs = (const struct hda_verb[]) {
5341 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5342 {}
5343 }
5344 },
David Henningsson94024cd2011-04-29 14:10:55 +02005345 [ALC662_FIXUP_SKU_IGNORE] = {
5346 .type = ALC_FIXUP_SKU,
5347 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005348 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005349 [ALC662_FIXUP_HP_RP5800] = {
5350 .type = ALC_FIXUP_PINS,
5351 .v.pins = (const struct alc_pincfg[]) {
5352 { 0x14, 0x0221201f }, /* HP out */
5353 { }
5354 },
5355 .chained = true,
5356 .chain_id = ALC662_FIXUP_SKU_IGNORE
5357 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005358 [ALC662_FIXUP_ASUS_MODE1] = {
5359 .type = ALC_FIXUP_PINS,
5360 .v.pins = (const struct alc_pincfg[]) {
5361 { 0x14, 0x99130110 }, /* speaker */
5362 { 0x18, 0x01a19c20 }, /* mic */
5363 { 0x19, 0x99a3092f }, /* int-mic */
5364 { 0x21, 0x0121401f }, /* HP out */
5365 { }
5366 },
5367 .chained = true,
5368 .chain_id = ALC662_FIXUP_SKU_IGNORE
5369 },
5370 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005371 .type = ALC_FIXUP_PINS,
5372 .v.pins = (const struct alc_pincfg[]) {
5373 { 0x14, 0x99130110 }, /* speaker */
5374 { 0x18, 0x01a19820 }, /* mic */
5375 { 0x19, 0x99a3092f }, /* int-mic */
5376 { 0x1b, 0x0121401f }, /* HP out */
5377 { }
5378 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005379 .chained = true,
5380 .chain_id = ALC662_FIXUP_SKU_IGNORE
5381 },
5382 [ALC662_FIXUP_ASUS_MODE3] = {
5383 .type = ALC_FIXUP_PINS,
5384 .v.pins = (const struct alc_pincfg[]) {
5385 { 0x14, 0x99130110 }, /* speaker */
5386 { 0x15, 0x0121441f }, /* HP */
5387 { 0x18, 0x01a19840 }, /* mic */
5388 { 0x19, 0x99a3094f }, /* int-mic */
5389 { 0x21, 0x01211420 }, /* HP2 */
5390 { }
5391 },
5392 .chained = true,
5393 .chain_id = ALC662_FIXUP_SKU_IGNORE
5394 },
5395 [ALC662_FIXUP_ASUS_MODE4] = {
5396 .type = ALC_FIXUP_PINS,
5397 .v.pins = (const struct alc_pincfg[]) {
5398 { 0x14, 0x99130110 }, /* speaker */
5399 { 0x16, 0x99130111 }, /* speaker */
5400 { 0x18, 0x01a19840 }, /* mic */
5401 { 0x19, 0x99a3094f }, /* int-mic */
5402 { 0x21, 0x0121441f }, /* HP */
5403 { }
5404 },
5405 .chained = true,
5406 .chain_id = ALC662_FIXUP_SKU_IGNORE
5407 },
5408 [ALC662_FIXUP_ASUS_MODE5] = {
5409 .type = ALC_FIXUP_PINS,
5410 .v.pins = (const struct alc_pincfg[]) {
5411 { 0x14, 0x99130110 }, /* speaker */
5412 { 0x15, 0x0121441f }, /* HP */
5413 { 0x16, 0x99130111 }, /* speaker */
5414 { 0x18, 0x01a19840 }, /* mic */
5415 { 0x19, 0x99a3094f }, /* int-mic */
5416 { }
5417 },
5418 .chained = true,
5419 .chain_id = ALC662_FIXUP_SKU_IGNORE
5420 },
5421 [ALC662_FIXUP_ASUS_MODE6] = {
5422 .type = ALC_FIXUP_PINS,
5423 .v.pins = (const struct alc_pincfg[]) {
5424 { 0x14, 0x99130110 }, /* speaker */
5425 { 0x15, 0x01211420 }, /* HP2 */
5426 { 0x18, 0x01a19840 }, /* mic */
5427 { 0x19, 0x99a3094f }, /* int-mic */
5428 { 0x1b, 0x0121441f }, /* HP */
5429 { }
5430 },
5431 .chained = true,
5432 .chain_id = ALC662_FIXUP_SKU_IGNORE
5433 },
5434 [ALC662_FIXUP_ASUS_MODE7] = {
5435 .type = ALC_FIXUP_PINS,
5436 .v.pins = (const struct alc_pincfg[]) {
5437 { 0x14, 0x99130110 }, /* speaker */
5438 { 0x17, 0x99130111 }, /* speaker */
5439 { 0x18, 0x01a19840 }, /* mic */
5440 { 0x19, 0x99a3094f }, /* int-mic */
5441 { 0x1b, 0x01214020 }, /* HP */
5442 { 0x21, 0x0121401f }, /* HP */
5443 { }
5444 },
5445 .chained = true,
5446 .chain_id = ALC662_FIXUP_SKU_IGNORE
5447 },
5448 [ALC662_FIXUP_ASUS_MODE8] = {
5449 .type = ALC_FIXUP_PINS,
5450 .v.pins = (const struct alc_pincfg[]) {
5451 { 0x14, 0x99130110 }, /* speaker */
5452 { 0x12, 0x99a30970 }, /* int-mic */
5453 { 0x15, 0x01214020 }, /* HP */
5454 { 0x17, 0x99130111 }, /* speaker */
5455 { 0x18, 0x01a19840 }, /* mic */
5456 { 0x21, 0x0121401f }, /* HP */
5457 { }
5458 },
5459 .chained = true,
5460 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005461 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005462};
5463
Takashi Iwaia9111322011-05-02 11:30:18 +02005464static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02005465 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01005466 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02005467 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04005468 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005469 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005470 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05005471 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06005472 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02005473 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01005474 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005475
5476#if 0
5477 /* Below is a quirk table taken from the old code.
5478 * Basically the device should work as is without the fixup table.
5479 * If BIOS doesn't give a proper info, enable the corresponding
5480 * fixup entry.
5481 */
5482 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5483 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5484 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5485 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5486 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5487 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5488 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5489 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5490 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5491 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5492 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5493 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5494 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5495 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5496 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5497 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5498 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5499 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5500 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5501 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5502 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5503 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5504 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5505 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5506 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5507 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5508 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5509 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5510 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5511 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5512 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5513 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5514 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5515 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5516 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5517 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5518 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5519 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5520 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5521 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5522 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5523 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5524 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5525 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5526 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5527 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5528 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5529 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5530 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5531 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5532#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02005533 {}
5534};
5535
Todd Broch6be79482010-12-07 16:51:05 -08005536static const struct alc_model_fixup alc662_fixup_models[] = {
5537 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02005538 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5539 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5540 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5541 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5542 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5543 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5544 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5545 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08005546 {}
5547};
David Henningsson6cb3b702010-09-09 08:51:44 +02005548
5549
Takashi Iwai1d045db2011-07-07 18:23:21 +02005550/*
5551 */
5552#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5553#include "alc662_quirks.c"
5554#endif
5555
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005556static int patch_alc662(struct hda_codec *codec)
5557{
5558 struct alc_spec *spec;
5559 int err, board_config;
Kailang Yang693194f2010-10-21 08:51:48 +02005560 int coef;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005561
5562 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5563 if (!spec)
5564 return -ENOMEM;
5565
5566 codec->spec = spec;
5567
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005568 spec->mixer_nid = 0x0b;
5569
Takashi Iwai53c334a2011-08-23 18:27:14 +02005570 /* handle multiple HPs as is */
5571 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5572
Kailang Yangda00c242010-03-19 11:23:45 +01005573 alc_auto_parse_customize_define(codec);
5574
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02005575 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5576
Kailang Yang693194f2010-10-21 08:51:48 +02005577 coef = alc_read_coef_idx(codec, 0);
5578 if (coef == 0x8020 || coef == 0x8011)
Kailang Yangc027ddc2010-03-19 11:33:06 +01005579 alc_codec_rename(codec, "ALC661");
Kailang Yang693194f2010-10-21 08:51:48 +02005580 else if (coef & (1 << 14) &&
5581 codec->bus->pci->subsystem_vendor == 0x1025 &&
5582 spec->cdefine.platform_type == 1)
Kailang Yangc027ddc2010-03-19 11:33:06 +01005583 alc_codec_rename(codec, "ALC272X");
Kailang Yang693194f2010-10-21 08:51:48 +02005584 else if (coef == 0x4011)
5585 alc_codec_rename(codec, "ALC656");
Kailang Yang274693f2009-12-03 10:07:50 +01005586
Takashi Iwai1d045db2011-07-07 18:23:21 +02005587 board_config = alc_board_config(codec, ALC662_MODEL_LAST,
5588 alc662_models, alc662_cfg_tbl);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005589 if (board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005590 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5591 codec->chip_name);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005592 board_config = ALC_MODEL_AUTO;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005593 }
5594
Takashi Iwai1d045db2011-07-07 18:23:21 +02005595 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005596 alc_pick_fixup(codec, alc662_fixup_models,
5597 alc662_fixup_tbl, alc662_fixups);
5598 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005599 /* automatic parse from the BIOS config */
5600 err = alc662_parse_auto_config(codec);
5601 if (err < 0) {
5602 alc_free(codec);
5603 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604 }
5605#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5606 else if (!err) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005607 printk(KERN_INFO
5608 "hda_codec: Cannot set up configuration "
5609 "from BIOS. Using base mode...\n");
5610 board_config = ALC662_3ST_2ch_DIG;
5611 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005612#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005613 }
5614
Takashi Iwai1d045db2011-07-07 18:23:21 +02005615 if (board_config != ALC_MODEL_AUTO)
Takashi Iwaie9c364c2009-08-11 17:16:13 +02005616 setup_preset(codec, &alc662_presets[board_config]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005617
Takashi Iwai60a6a842011-07-27 14:01:24 +02005618 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005619 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02005620 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005621 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02005622 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005623
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005624 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02005625 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01005626
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005627 if (!spec->no_analog && has_cdefine_beep(codec)) {
5628 err = snd_hda_attach_beep_device(codec, 0x1);
5629 if (err < 0) {
5630 alc_free(codec);
5631 return err;
5632 }
Kailang Yangda00c242010-03-19 11:23:45 +01005633 switch (codec->vendor_id) {
5634 case 0x10ec0662:
5635 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5636 break;
5637 case 0x10ec0272:
5638 case 0x10ec0663:
5639 case 0x10ec0665:
5640 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5641 break;
5642 case 0x10ec0273:
5643 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5644 break;
5645 }
Kailang Yangcec27c82010-02-04 14:18:18 +01005646 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01005647 spec->vmaster_nid = 0x02;
5648
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005649 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5650
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005651 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02005653 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02005654 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02005655
Kailang Yangbf1b0222010-10-21 08:49:56 +02005656 alc_init_jacks(codec);
5657
Takashi Iwaicb53c622007-08-10 17:21:45 +02005658#ifdef CONFIG_SND_HDA_POWER_SAVE
5659 if (!spec->loopback.amplist)
5660 spec->loopback.amplist = alc662_loopbacks;
5661#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005662
5663 return 0;
5664}
5665
Kailang Yang274693f2009-12-03 10:07:50 +01005666static int patch_alc888(struct hda_codec *codec)
5667{
5668 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
5669 kfree(codec->chip_name);
Kailang Yang01e0f132010-11-22 10:59:36 +01005670 if (codec->vendor_id == 0x10ec0887)
5671 codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
5672 else
5673 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
Takashi Iwaiac2c92e2009-12-03 10:14:10 +01005674 if (!codec->chip_name) {
5675 alc_free(codec);
Kailang Yang274693f2009-12-03 10:07:50 +01005676 return -ENOMEM;
Takashi Iwaiac2c92e2009-12-03 10:14:10 +01005677 }
5678 return patch_alc662(codec);
Kailang Yang274693f2009-12-03 10:07:50 +01005679 }
Takashi Iwaiac2c92e2009-12-03 10:14:10 +01005680 return patch_alc882(codec);
Kailang Yang274693f2009-12-03 10:07:50 +01005681}
5682
Kailang Yangb478b992011-05-18 11:51:15 +02005683static int patch_alc899(struct hda_codec *codec)
5684{
5685 if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
5686 kfree(codec->chip_name);
5687 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
5688 }
5689 return patch_alc882(codec);
5690}
5691
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005692/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005693 * ALC680 support
5694 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005695
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005696static int alc680_parse_auto_config(struct hda_codec *codec)
5697{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005698 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005699}
5700
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005701/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005702 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005703static int patch_alc680(struct hda_codec *codec)
5704{
5705 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005706 int err;
5707
5708 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5709 if (spec == NULL)
5710 return -ENOMEM;
5711
5712 codec->spec = spec;
5713
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005714 /* ALC680 has no aa-loopback mixer */
5715
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005716 /* automatic parse from the BIOS config */
5717 err = alc680_parse_auto_config(codec);
5718 if (err < 0) {
5719 alc_free(codec);
5720 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005721 }
5722
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005723 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005724 set_capture_mixer(codec);
5725
5726 spec->vmaster_nid = 0x02;
5727
5728 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005729 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005730
5731 return 0;
5732}
5733
5734/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005735 * patch entries
5736 */
Takashi Iwaia9111322011-05-02 11:30:18 +02005737static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02005738 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005739 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005740 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005741 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02005742 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005743 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005744 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02005745 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005746 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02005747 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005748 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005749 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005750 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5751 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5752 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005753 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02005754 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005755 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5756 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02005757 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01005758 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01005759 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005760 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005761 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005762 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02005763 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02005764 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02005765 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02005766 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02005767 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005768 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Kailang Yang01e0f132010-11-22 10:59:36 +01005769 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
Kailang Yang44426082008-10-15 11:18:05 +02005770 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02005771 .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01005772 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
Takashi Iwai49535502009-06-30 15:28:30 +02005773 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01005774 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Kailang Yangb478b992011-05-18 11:51:15 +02005775 { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776 {} /* terminator */
5777};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005778
5779MODULE_ALIAS("snd-hda-codec-id:10ec*");
5780
5781MODULE_LICENSE("GPL");
5782MODULE_DESCRIPTION("Realtek HD-audio codec");
5783
5784static struct hda_codec_preset_list realtek_list = {
5785 .preset = snd_hda_preset_realtek,
5786 .owner = THIS_MODULE,
5787};
5788
5789static int __init patch_realtek_init(void)
5790{
5791 return snd_hda_add_codec_preset(&realtek_list);
5792}
5793
5794static void __exit patch_realtek_exit(void)
5795{
5796 snd_hda_delete_codec_preset(&realtek_list);
5797}
5798
5799module_init(patch_realtek_init)
5800module_exit(patch_realtek_exit)