blob: c23bd3b43c9c0bc0226a1b7e20ebc7425b7ad495 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e482006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
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 Iwai4953550a2009-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 Iwai1c7161532011-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 Iwaid922b512011-04-28 12:18:53 +0200180
181 /* auto-mute control */
182 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200183 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200184
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200185 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200186 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100187
Takashi Iwai2134ea42008-01-10 16:53:55 +0100188 /* for virtual master */
189 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200190#ifdef CONFIG_SND_HDA_POWER_SAVE
191 struct hda_loopback_check loopback;
192#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200193
194 /* for PLL fix */
195 hda_nid_t pll_nid;
196 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100197
198 /* fix-up list */
199 int fixup_id;
200 const struct alc_fixup *fixup_list;
201 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200202
203 /* multi-io */
204 int multi_ios;
205 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200206
207 /* bind volumes */
208 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100209};
210
Takashi Iwai1d045db2011-07-07 18:23:21 +0200211#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Takashi Iwai44c02402011-07-08 15:14:19 +0200213static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
214 int dir, unsigned int bits)
215{
216 if (!nid)
217 return false;
218 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
219 if (query_amp_caps(codec, nid, dir) & bits)
220 return true;
221 return false;
222}
223
224#define nid_has_mute(codec, nid, dir) \
225 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
226#define nid_has_volume(codec, nid, dir) \
227 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229/*
230 * input MUX handling
231 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200232static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
233 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234{
235 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
236 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200237 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
238 if (mux_idx >= spec->num_mux_defs)
239 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100240 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
241 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200242 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243}
244
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200245static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct alc_spec *spec = codec->spec;
250 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
251
252 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
253 return 0;
254}
255
Takashi Iwai21268962011-07-07 15:01:13 +0200256static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
Takashi Iwai21268962011-07-07 15:01:13 +0200258 struct alc_spec *spec = codec->spec;
259 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
260
261 if (spec->cur_adc && spec->cur_adc != new_adc) {
262 /* stream is running, let's swap the current ADC */
263 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
264 spec->cur_adc = new_adc;
265 snd_hda_codec_setup_stream(codec, new_adc,
266 spec->cur_adc_stream_tag, 0,
267 spec->cur_adc_format);
268 return true;
269 }
270 return false;
271}
272
273/* select the given imux item; either unmute exclusively or select the route */
274static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
275 unsigned int idx, bool force)
276{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100278 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100279 unsigned int mux_idx;
Takashi Iwai21268962011-07-07 15:01:13 +0200280 int i, type;
281 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Takashi Iwaicd896c32008-11-18 12:36:33 +0100283 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
284 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100285 if (!imux->num_items && mux_idx > 0)
286 imux = &spec->input_mux[0];
Takashi Iwaicd896c32008-11-18 12:36:33 +0100287
Takashi Iwai21268962011-07-07 15:01:13 +0200288 if (idx >= imux->num_items)
289 idx = imux->num_items - 1;
290 if (spec->cur_mux[adc_idx] == idx && !force)
291 return 0;
292 spec->cur_mux[adc_idx] = idx;
293
294 if (spec->dyn_adc_switch) {
295 alc_dyn_adc_pcm_resetup(codec, idx);
296 adc_idx = spec->dyn_adc_idx[idx];
297 }
298
299 nid = spec->capsrc_nids ?
300 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
301
302 /* no selection? */
303 if (snd_hda_get_conn_list(codec, nid, NULL) <= 1)
304 return 1;
305
Takashi Iwaia22d5432009-07-27 12:54:26 +0200306 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200307 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100308 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100309 for (i = 0; i < imux->num_items; i++) {
310 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
311 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
312 imux->items[i].index,
313 HDA_AMP_MUTE, v);
314 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100315 } else {
316 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200317 snd_hda_codec_write_cache(codec, nid, 0,
318 AC_VERB_SET_CONNECT_SEL,
319 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100320 }
Takashi Iwai21268962011-07-07 15:01:13 +0200321 return 1;
322}
323
324static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
325 struct snd_ctl_elem_value *ucontrol)
326{
327 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
328 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
329 return alc_mux_select(codec, adc_idx,
330 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100331}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200332
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100334 * set up the input pin config (depending on the given auto-pin type)
335 */
336static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
337 int auto_pin_type)
338{
339 unsigned int val = PIN_IN;
340
Takashi Iwai86e29592010-09-09 14:50:17 +0200341 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100342 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200343 unsigned int oldval;
344 oldval = snd_hda_codec_read(codec, nid, 0,
345 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100346 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100347 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200348 /* if the default pin setup is vref50, we give it priority */
349 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100350 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200351 else if (pincap & AC_PINCAP_VREF_50)
352 val = PIN_VREF50;
353 else if (pincap & AC_PINCAP_VREF_100)
354 val = PIN_VREF100;
355 else if (pincap & AC_PINCAP_VREF_GRD)
356 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100357 }
358 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
359}
360
361/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200362 * Append the given mixer and verb elements for the later use
363 * The mixer array is referred in build_controls(), and init_verbs are
364 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100365 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200366static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100367{
368 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
369 return;
370 spec->mixers[spec->num_mixers++] = mix;
371}
372
373static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
374{
375 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
376 return;
377 spec->init_verbs[spec->num_init_verbs++] = verb;
378}
379
380/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200381 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100382 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200383/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200384static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200385 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
386 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
387 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
388 { }
389};
390
Takashi Iwaia9111322011-05-02 11:30:18 +0200391static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200392 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
393 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
394 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
395 { }
396};
397
Takashi Iwaia9111322011-05-02 11:30:18 +0200398static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200399 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
400 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
401 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
402 { }
403};
404
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200405/*
406 * Fix hardware PLL issue
407 * On some codecs, the analog PLL gating control must be off while
408 * the default value is 1.
409 */
410static void alc_fix_pll(struct hda_codec *codec)
411{
412 struct alc_spec *spec = codec->spec;
413 unsigned int val;
414
415 if (!spec->pll_nid)
416 return;
417 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
418 spec->pll_coef_idx);
419 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
420 AC_VERB_GET_PROC_COEF, 0);
421 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
422 spec->pll_coef_idx);
423 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
424 val & ~(1 << spec->pll_coef_bit));
425}
426
427static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
428 unsigned int coef_idx, unsigned int coef_bit)
429{
430 struct alc_spec *spec = codec->spec;
431 spec->pll_nid = nid;
432 spec->pll_coef_idx = coef_idx;
433 spec->pll_coef_bit = coef_bit;
434 alc_fix_pll(codec);
435}
436
Takashi Iwai1d045db2011-07-07 18:23:21 +0200437/*
438 * Jack-reporting via input-jack layer
439 */
440
441/* initialization of jacks; currently checks only a few known pins */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200442static int alc_init_jacks(struct hda_codec *codec)
443{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100444#ifdef CONFIG_SND_HDA_INPUT_JACK
Kailang Yang9ad0e492010-09-14 23:22:00 +0200445 struct alc_spec *spec = codec->spec;
446 int err;
447 unsigned int hp_nid = spec->autocfg.hp_pins[0];
Takashi Iwai21268962011-07-07 15:01:13 +0200448 unsigned int mic_nid = spec->ext_mic_pin;
449 unsigned int dock_nid = spec->dock_mic_pin;
Kailang Yang9ad0e492010-09-14 23:22:00 +0200450
Takashi Iwai265a0242010-09-21 11:26:21 +0200451 if (hp_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100452 err = snd_hda_input_jack_add(codec, hp_nid,
453 SND_JACK_HEADPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200454 if (err < 0)
455 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100456 snd_hda_input_jack_report(codec, hp_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200457 }
Kailang Yang9ad0e492010-09-14 23:22:00 +0200458
Takashi Iwai265a0242010-09-21 11:26:21 +0200459 if (mic_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100460 err = snd_hda_input_jack_add(codec, mic_nid,
461 SND_JACK_MICROPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200462 if (err < 0)
463 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100464 snd_hda_input_jack_report(codec, mic_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200465 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200466 if (dock_nid) {
467 err = snd_hda_input_jack_add(codec, dock_nid,
468 SND_JACK_MICROPHONE, NULL);
469 if (err < 0)
470 return err;
471 snd_hda_input_jack_report(codec, dock_nid);
472 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100473#endif /* CONFIG_SND_HDA_INPUT_JACK */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200474 return 0;
475}
Kailang Yang9ad0e492010-09-14 23:22:00 +0200476
Takashi Iwai1d045db2011-07-07 18:23:21 +0200477/*
478 * Jack detections for HP auto-mute and mic-switch
479 */
480
481/* check each pin in the given array; returns true if any of them is plugged */
482static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200483{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200484 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200485
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200486 for (i = 0; i < num_pins; i++) {
487 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200488 if (!nid)
489 break;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100490 snd_hda_input_jack_report(codec, nid);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200491 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200492 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200493 return present;
494}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200495
Takashi Iwai1d045db2011-07-07 18:23:21 +0200496/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200497static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200498 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200499{
500 struct alc_spec *spec = codec->spec;
501 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200502 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200503 int i;
504
505 for (i = 0; i < num_pins; i++) {
506 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200507 if (!nid)
508 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200509 switch (spec->automute_mode) {
510 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200511 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200512 AC_VERB_SET_PIN_WIDGET_CONTROL,
513 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200514 break;
515 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200516 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200518 break;
519 case ALC_AUTOMUTE_MIXER:
520 nid = spec->automute_mixer_nid[i];
521 if (!nid)
522 break;
523 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200524 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200525 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200527 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200528 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200529 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200530}
531
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532/* Toggle internal speakers muting */
533static void update_speakers(struct hda_codec *codec)
534{
535 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200536 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537
Takashi Iwaic0a20262011-06-10 15:28:15 +0200538 /* Control HP pins/amps depending on master_mute state;
539 * in general, HP pins/amps control should be enabled in all cases,
540 * but currently set only for master_mute, just to be safe
541 */
542 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
543 spec->autocfg.hp_pins, spec->master_mute, true);
544
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200545 if (!spec->automute)
546 on = 0;
547 else
548 on = spec->jack_present | spec->line_jack_present;
549 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200550 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200551 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200552
553 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200554 /* if LO is a copy of either HP or Speaker, don't need to handle it */
555 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
556 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200557 return;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200558 if (!spec->automute_lines || !spec->automute)
559 on = 0;
560 else
561 on = spec->jack_present;
562 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200563 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200564 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200565}
566
Takashi Iwai24519912011-08-16 15:08:49 +0200567static void call_update_speakers(struct hda_codec *codec)
568{
569 struct alc_spec *spec = codec->spec;
570 if (spec->automute_hook)
571 spec->automute_hook(codec);
572 else
573 update_speakers(codec);
574}
575
Takashi Iwai1d045db2011-07-07 18:23:21 +0200576/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577static void alc_hp_automute(struct hda_codec *codec)
578{
579 struct alc_spec *spec = codec->spec;
580
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200581 spec->jack_present =
582 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
583 spec->autocfg.hp_pins);
Takashi Iwai3c715a92011-08-23 12:41:09 +0200584 if (!spec->automute)
585 return;
Takashi Iwai24519912011-08-16 15:08:49 +0200586 call_update_speakers(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200587}
588
Takashi Iwai1d045db2011-07-07 18:23:21 +0200589/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590static void alc_line_automute(struct hda_codec *codec)
591{
592 struct alc_spec *spec = codec->spec;
593
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200594 spec->line_jack_present =
595 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
596 spec->autocfg.line_out_pins);
Takashi Iwai3c715a92011-08-23 12:41:09 +0200597 if (!spec->automute || !spec->detect_line)
598 return;
Takashi Iwai24519912011-08-16 15:08:49 +0200599 call_update_speakers(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200600}
601
Takashi Iwai8d087c72011-06-28 12:45:47 +0200602#define get_connection_index(codec, mux, nid) \
603 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200604
Takashi Iwai1d045db2011-07-07 18:23:21 +0200605/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200606static void alc_mic_automute(struct hda_codec *codec)
607{
608 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200609 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200610
Takashi Iwai21268962011-07-07 15:01:13 +0200611 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200612 return;
613 if (snd_BUG_ON(!spec->adc_nids))
614 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200615 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200616 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200617
Takashi Iwai21268962011-07-07 15:01:13 +0200618 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
619 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
620 else if (spec->dock_mic_idx >= 0 &&
621 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
622 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
623 else
624 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Takashi Iwai6c819492009-08-10 18:47:44 +0200625
Takashi Iwai21268962011-07-07 15:01:13 +0200626 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
627 if (spec->dock_mic_idx >= 0)
628 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200629}
630
Kailang Yangc9b58002007-10-16 14:30:01 +0200631/* unsolicited event for HP jack sensing */
632static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
633{
634 if (codec->vendor_id == 0x10ec0880)
635 res >>= 28;
636 else
637 res >>= 26;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200638 switch (res) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200639 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200640 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200641 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200642 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200643 alc_line_automute(codec);
644 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200645 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200646 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200647 break;
648 }
Kailang Yang7fb0d782008-10-15 11:12:35 +0200649}
650
Takashi Iwai1d045db2011-07-07 18:23:21 +0200651/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200652static void alc_inithook(struct hda_codec *codec)
653{
Takashi Iwaid922b512011-04-28 12:18:53 +0200654 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200655 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200656 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200657}
658
Kailang Yangf9423e72008-05-27 12:32:25 +0200659/* additional initialization for ALC888 variants */
660static void alc888_coef_init(struct hda_codec *codec)
661{
662 unsigned int tmp;
663
664 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
665 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
666 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100667 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200668 /* alc888S-VC */
669 snd_hda_codec_read(codec, 0x20, 0,
670 AC_VERB_SET_PROC_COEF, 0x830);
671 else
672 /* alc888-VB */
673 snd_hda_codec_read(codec, 0x20, 0,
674 AC_VERB_SET_PROC_COEF, 0x3030);
675}
676
Takashi Iwai1d045db2011-07-07 18:23:21 +0200677/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200678static void alc889_coef_init(struct hda_codec *codec)
679{
680 unsigned int tmp;
681
682 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
683 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
684 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
685 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
686}
687
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100688/* turn on/off EAPD control (only if available) */
689static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
690{
691 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
692 return;
693 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
694 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
695 on ? 2 : 0);
696}
697
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200698/* turn on/off EAPD controls of the codec */
699static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
700{
701 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200702 static hda_nid_t pins[] = {
703 0x0f, 0x10, 0x14, 0x15, 0
704 };
705 hda_nid_t *p;
706 for (p = pins; *p; p++)
707 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200708}
709
Takashi Iwai1c7161532011-04-07 10:37:16 +0200710/* generic shutup callback;
711 * just turning off EPAD and a little pause for avoiding pop-noise
712 */
713static void alc_eapd_shutup(struct hda_codec *codec)
714{
715 alc_auto_setup_eapd(codec, false);
716 msleep(200);
717}
718
Takashi Iwai1d045db2011-07-07 18:23:21 +0200719/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200720static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200721{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200722 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200723
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200724 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200725 switch (type) {
726 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200727 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
728 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200729 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200730 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
731 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200732 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200733 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
734 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200735 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200736 switch (codec->vendor_id) {
737 case 0x10ec0260:
738 snd_hda_codec_write(codec, 0x1a, 0,
739 AC_VERB_SET_COEF_INDEX, 7);
740 tmp = snd_hda_codec_read(codec, 0x1a, 0,
741 AC_VERB_GET_PROC_COEF, 0);
742 snd_hda_codec_write(codec, 0x1a, 0,
743 AC_VERB_SET_COEF_INDEX, 7);
744 snd_hda_codec_write(codec, 0x1a, 0,
745 AC_VERB_SET_PROC_COEF,
746 tmp | 0x2010);
747 break;
748 case 0x10ec0262:
749 case 0x10ec0880:
750 case 0x10ec0882:
751 case 0x10ec0883:
752 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100753 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100754 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200755 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200756 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200757 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200758 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200759 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100760#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200761 case 0x10ec0267:
762 case 0x10ec0268:
763 snd_hda_codec_write(codec, 0x20, 0,
764 AC_VERB_SET_COEF_INDEX, 7);
765 tmp = snd_hda_codec_read(codec, 0x20, 0,
766 AC_VERB_GET_PROC_COEF, 0);
767 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200768 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200769 snd_hda_codec_write(codec, 0x20, 0,
770 AC_VERB_SET_PROC_COEF,
771 tmp | 0x3000);
772 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100773#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200774 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200775 break;
776 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777}
Kailang Yangea1fb292008-08-26 12:58:38 +0200778
Takashi Iwai1d045db2011-07-07 18:23:21 +0200779/*
780 * Auto-Mute mode mixer enum support
781 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200782static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
783 struct snd_ctl_elem_info *uinfo)
784{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200785 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
786 struct alc_spec *spec = codec->spec;
787 static const char * const texts2[] = {
788 "Disabled", "Enabled"
789 };
790 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200791 "Disabled", "Speaker Only", "Line-Out+Speaker"
792 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200793 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200794
795 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
796 uinfo->count = 1;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200797 if (spec->automute_hp_lo) {
798 uinfo->value.enumerated.items = 3;
799 texts = texts3;
800 } else {
801 uinfo->value.enumerated.items = 2;
802 texts = texts2;
803 }
804 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
805 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200806 strcpy(uinfo->value.enumerated.name,
807 texts[uinfo->value.enumerated.item]);
808 return 0;
809}
810
811static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
812 struct snd_ctl_elem_value *ucontrol)
813{
814 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
815 struct alc_spec *spec = codec->spec;
816 unsigned int val;
817 if (!spec->automute)
818 val = 0;
819 else if (!spec->automute_lines)
820 val = 1;
821 else
822 val = 2;
823 ucontrol->value.enumerated.item[0] = val;
824 return 0;
825}
826
827static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_value *ucontrol)
829{
830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831 struct alc_spec *spec = codec->spec;
832
833 switch (ucontrol->value.enumerated.item[0]) {
834 case 0:
835 if (!spec->automute)
836 return 0;
837 spec->automute = 0;
838 break;
839 case 1:
840 if (spec->automute && !spec->automute_lines)
841 return 0;
842 spec->automute = 1;
843 spec->automute_lines = 0;
844 break;
845 case 2:
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200846 if (!spec->automute_hp_lo)
847 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200848 if (spec->automute && spec->automute_lines)
849 return 0;
850 spec->automute = 1;
851 spec->automute_lines = 1;
852 break;
853 default:
854 return -EINVAL;
855 }
Takashi Iwai24519912011-08-16 15:08:49 +0200856 call_update_speakers(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200857 return 1;
858}
859
Takashi Iwaia9111322011-05-02 11:30:18 +0200860static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200861 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
862 .name = "Auto-Mute Mode",
863 .info = alc_automute_mode_info,
864 .get = alc_automute_mode_get,
865 .put = alc_automute_mode_put,
866};
867
Takashi Iwai1d045db2011-07-07 18:23:21 +0200868static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
869{
870 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
871 return snd_array_new(&spec->kctls);
872}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200873
874static int alc_add_automute_mode_enum(struct hda_codec *codec)
875{
876 struct alc_spec *spec = codec->spec;
877 struct snd_kcontrol_new *knew;
878
879 knew = alc_kcontrol_new(spec);
880 if (!knew)
881 return -ENOMEM;
882 *knew = alc_automute_mode_enum;
883 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
884 if (!knew->name)
885 return -ENOMEM;
886 return 0;
887}
888
Takashi Iwai1d045db2011-07-07 18:23:21 +0200889/*
890 * Check the availability of HP/line-out auto-mute;
891 * Set up appropriately if really supported
892 */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200893static void alc_init_auto_hp(struct hda_codec *codec)
894{
895 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200896 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200897 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200898 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200899
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200900 if (cfg->hp_pins[0])
901 present++;
902 if (cfg->line_out_pins[0])
903 present++;
904 if (cfg->speaker_pins[0])
905 present++;
906 if (present < 2) /* need two different output types */
907 return;
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200908 if (present == 3)
909 spec->automute_hp_lo = 1; /* both HP and LO automute */
Kailang Yangc9b58002007-10-16 14:30:01 +0200910
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200911 if (!cfg->speaker_pins[0] &&
912 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200913 memcpy(cfg->speaker_pins, cfg->line_out_pins,
914 sizeof(cfg->speaker_pins));
915 cfg->speaker_outs = cfg->line_outs;
916 }
917
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200918 if (!cfg->hp_pins[0] &&
919 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200920 memcpy(cfg->hp_pins, cfg->line_out_pins,
921 sizeof(cfg->hp_pins));
922 cfg->hp_outs = cfg->line_outs;
923 }
924
925 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200926 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200927 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200928 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200929 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200930 nid);
931 snd_hda_codec_write_cache(codec, nid, 0,
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200932 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +0200933 AC_USRSP_EN | ALC_HP_EVENT);
Takashi Iwaid922b512011-04-28 12:18:53 +0200934 spec->automute = 1;
935 spec->automute_mode = ALC_AUTOMUTE_PIN;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200936 }
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200937 if (spec->automute && cfg->line_out_pins[0] &&
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200938 cfg->speaker_pins[0] &&
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200939 cfg->line_out_pins[0] != cfg->hp_pins[0] &&
940 cfg->line_out_pins[0] != cfg->speaker_pins[0]) {
941 for (i = 0; i < cfg->line_outs; i++) {
942 hda_nid_t nid = cfg->line_out_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200943 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200944 continue;
945 snd_printdd("realtek: Enable Line-Out auto-muting "
946 "on NID 0x%x\n", nid);
947 snd_hda_codec_write_cache(codec, nid, 0,
948 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +0200949 AC_USRSP_EN | ALC_FRONT_EVENT);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200950 spec->detect_line = 1;
951 }
Takashi Iwai52d3cb82011-05-17 10:04:08 +0200952 spec->automute_lines = spec->detect_line;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200953 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200954
955 if (spec->automute) {
956 /* create a control for automute mode */
957 alc_add_automute_mode_enum(codec);
958 spec->unsol_event = alc_sku_unsol_event;
959 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200960}
961
Takashi Iwai1d045db2011-07-07 18:23:21 +0200962/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +0200963static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
964{
965 int i;
966 for (i = 0; i < nums; i++)
967 if (list[i] == nid)
968 return i;
969 return -1;
970}
971
Takashi Iwai1d045db2011-07-07 18:23:21 +0200972/* check whether dynamic ADC-switching is available */
973static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
974{
975 struct alc_spec *spec = codec->spec;
976 struct hda_input_mux *imux = &spec->private_imux[0];
977 int i, n, idx;
978 hda_nid_t cap, pin;
979
980 if (imux != spec->input_mux) /* no dynamic imux? */
981 return false;
982
983 for (n = 0; n < spec->num_adc_nids; n++) {
984 cap = spec->private_capsrc_nids[n];
985 for (i = 0; i < imux->num_items; i++) {
986 pin = spec->imux_pins[i];
987 if (!pin)
988 return false;
989 if (get_connection_index(codec, cap, pin) < 0)
990 break;
991 }
992 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +0200993 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +0200994 }
995
996 for (i = 0; i < imux->num_items; i++) {
997 pin = spec->imux_pins[i];
998 for (n = 0; n < spec->num_adc_nids; n++) {
999 cap = spec->private_capsrc_nids[n];
1000 idx = get_connection_index(codec, cap, pin);
1001 if (idx >= 0) {
1002 imux->items[i].index = idx;
1003 spec->dyn_adc_idx[i] = n;
1004 break;
1005 }
1006 }
1007 }
1008
1009 snd_printdd("realtek: enabling ADC switching\n");
1010 spec->dyn_adc_switch = 1;
1011 return true;
1012}
Takashi Iwai21268962011-07-07 15:01:13 +02001013
1014/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1015static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1016{
1017 struct alc_spec *spec = codec->spec;
1018 struct hda_input_mux *imux;
1019 static char * const texts[3] = {
1020 "Mic", "Internal Mic", "Dock Mic"
1021 };
1022 int i;
1023
1024 if (!spec->auto_mic)
1025 return false;
1026 imux = &spec->private_imux[0];
1027 if (spec->input_mux == imux)
1028 return true;
1029 spec->imux_pins[0] = spec->ext_mic_pin;
1030 spec->imux_pins[1] = spec->int_mic_pin;
1031 spec->imux_pins[2] = spec->dock_mic_pin;
1032 for (i = 0; i < 3; i++) {
1033 strcpy(imux->items[i].label, texts[i]);
1034 if (spec->imux_pins[i])
1035 imux->num_items = i + 1;
1036 }
1037 spec->num_mux_defs = 1;
1038 spec->input_mux = imux;
1039 return true;
1040}
1041
1042/* check whether all auto-mic pins are valid; setup indices if OK */
1043static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1044{
1045 struct alc_spec *spec = codec->spec;
1046 const struct hda_input_mux *imux;
1047
1048 if (!spec->auto_mic)
1049 return false;
1050 if (spec->auto_mic_valid_imux)
1051 return true; /* already checked */
1052
1053 /* fill up imux indices */
1054 if (!alc_check_dyn_adc_switch(codec)) {
1055 spec->auto_mic = 0;
1056 return false;
1057 }
1058
1059 imux = spec->input_mux;
1060 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1061 spec->imux_pins, imux->num_items);
1062 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1063 spec->imux_pins, imux->num_items);
1064 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1065 spec->imux_pins, imux->num_items);
1066 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1067 spec->auto_mic = 0;
1068 return false; /* no corresponding imux */
1069 }
1070
1071 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1072 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001073 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001074 if (spec->dock_mic_pin)
1075 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1076 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001077 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001078
1079 spec->auto_mic_valid_imux = 1;
1080 spec->auto_mic = 1;
1081 return true;
1082}
1083
Takashi Iwai1d045db2011-07-07 18:23:21 +02001084/*
1085 * Check the availability of auto-mic switch;
1086 * Set up if really supported
1087 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001088static void alc_init_auto_mic(struct hda_codec *codec)
1089{
1090 struct alc_spec *spec = codec->spec;
1091 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001092 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001093 int i;
1094
Takashi Iwai21268962011-07-07 15:01:13 +02001095 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1096
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001097 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001098 for (i = 0; i < cfg->num_inputs; i++) {
1099 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001100 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001101 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001102 switch (snd_hda_get_input_pin_attr(defcfg)) {
1103 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001104 if (fixed)
1105 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001106 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1107 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001108 fixed = nid;
1109 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001110 case INPUT_PIN_ATTR_UNUSED:
1111 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001112 case INPUT_PIN_ATTR_DOCK:
1113 if (dock)
1114 return; /* already occupied */
1115 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1116 return; /* invalid type */
1117 dock = nid;
1118 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001119 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001120 if (ext)
1121 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001122 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1123 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001124 ext = nid;
1125 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001126 }
1127 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001128 if (!ext && dock) {
1129 ext = dock;
1130 dock = 0;
1131 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001132 if (!ext || !fixed)
1133 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001134 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001135 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001136 if (dock && !is_jack_detectable(codec, dock))
1137 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001138
1139 /* check imux indices */
1140 spec->ext_mic_pin = ext;
1141 spec->int_mic_pin = fixed;
1142 spec->dock_mic_pin = dock;
1143
1144 spec->auto_mic = 1;
1145 if (!alc_auto_mic_check_imux(codec))
1146 return;
1147
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001148 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1149 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001150 spec->unsol_event = alc_sku_unsol_event;
1151}
1152
Takashi Iwai1d045db2011-07-07 18:23:21 +02001153/* check the availabilities of auto-mute and auto-mic switches */
1154static void alc_auto_check_switches(struct hda_codec *codec)
1155{
1156 alc_init_auto_hp(codec);
1157 alc_init_auto_mic(codec);
1158}
1159
1160/*
1161 * Realtek SSID verification
1162 */
1163
David Henningsson90622912010-10-14 14:50:18 +02001164/* Could be any non-zero and even value. When used as fixup, tells
1165 * the driver to ignore any present sku defines.
1166 */
1167#define ALC_FIXUP_SKU_IGNORE (2)
1168
Kailang Yangda00c242010-03-19 11:23:45 +01001169static int alc_auto_parse_customize_define(struct hda_codec *codec)
1170{
1171 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001172 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001173 struct alc_spec *spec = codec->spec;
1174
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001175 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1176
David Henningsson90622912010-10-14 14:50:18 +02001177 if (spec->cdefine.fixup) {
1178 ass = spec->cdefine.sku_cfg;
1179 if (ass == ALC_FIXUP_SKU_IGNORE)
1180 return -1;
1181 goto do_sku;
1182 }
1183
Kailang Yangda00c242010-03-19 11:23:45 +01001184 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001185 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001186 goto do_sku;
1187
1188 nid = 0x1d;
1189 if (codec->vendor_id == 0x10ec0260)
1190 nid = 0x17;
1191 ass = snd_hda_codec_get_pincfg(codec, nid);
1192
1193 if (!(ass & 1)) {
1194 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1195 codec->chip_name, ass);
1196 return -1;
1197 }
1198
1199 /* check sum */
1200 tmp = 0;
1201 for (i = 1; i < 16; i++) {
1202 if ((ass >> i) & 1)
1203 tmp++;
1204 }
1205 if (((ass >> 16) & 0xf) != tmp)
1206 return -1;
1207
1208 spec->cdefine.port_connectivity = ass >> 30;
1209 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1210 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1211 spec->cdefine.customization = ass >> 8;
1212do_sku:
1213 spec->cdefine.sku_cfg = ass;
1214 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1215 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1216 spec->cdefine.swap = (ass & 0x2) >> 1;
1217 spec->cdefine.override = ass & 0x1;
1218
1219 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1220 nid, spec->cdefine.sku_cfg);
1221 snd_printd("SKU: port_connectivity=0x%x\n",
1222 spec->cdefine.port_connectivity);
1223 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1224 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1225 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1226 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1227 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1228 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1229 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1230
1231 return 0;
1232}
1233
Takashi Iwai1d045db2011-07-07 18:23:21 +02001234/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001235static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1236{
Takashi Iwai21268962011-07-07 15:01:13 +02001237 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001238}
1239
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001240/* check subsystem ID and set up device-specific initialization;
1241 * return 1 if initialized, 0 if invalid SSID
1242 */
1243/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1244 * 31 ~ 16 : Manufacture ID
1245 * 15 ~ 8 : SKU ID
1246 * 7 ~ 0 : Assembly ID
1247 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1248 */
1249static int alc_subsystem_id(struct hda_codec *codec,
1250 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001251 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001252{
1253 unsigned int ass, tmp, i;
1254 unsigned nid;
1255 struct alc_spec *spec = codec->spec;
1256
David Henningsson90622912010-10-14 14:50:18 +02001257 if (spec->cdefine.fixup) {
1258 ass = spec->cdefine.sku_cfg;
1259 if (ass == ALC_FIXUP_SKU_IGNORE)
1260 return 0;
1261 goto do_sku;
1262 }
1263
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001264 ass = codec->subsystem_id & 0xffff;
1265 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1266 goto do_sku;
1267
1268 /* invalid SSID, check the special NID pin defcfg instead */
1269 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001270 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001271 * 29~21 : reserve
1272 * 20 : PCBEEP input
1273 * 19~16 : Check sum (15:1)
1274 * 15~1 : Custom
1275 * 0 : override
1276 */
1277 nid = 0x1d;
1278 if (codec->vendor_id == 0x10ec0260)
1279 nid = 0x17;
1280 ass = snd_hda_codec_get_pincfg(codec, nid);
1281 snd_printd("realtek: No valid SSID, "
1282 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001283 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001284 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001285 return 0;
1286 if ((ass >> 30) != 1) /* no physical connection */
1287 return 0;
1288
1289 /* check sum */
1290 tmp = 0;
1291 for (i = 1; i < 16; i++) {
1292 if ((ass >> i) & 1)
1293 tmp++;
1294 }
1295 if (((ass >> 16) & 0xf) != tmp)
1296 return 0;
1297do_sku:
1298 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1299 ass & 0xffff, codec->vendor_id);
1300 /*
1301 * 0 : override
1302 * 1 : Swap Jack
1303 * 2 : 0 --> Desktop, 1 --> Laptop
1304 * 3~5 : External Amplifier control
1305 * 7~6 : Reserved
1306 */
1307 tmp = (ass & 0x38) >> 3; /* external Amp control */
1308 switch (tmp) {
1309 case 1:
1310 spec->init_amp = ALC_INIT_GPIO1;
1311 break;
1312 case 3:
1313 spec->init_amp = ALC_INIT_GPIO2;
1314 break;
1315 case 7:
1316 spec->init_amp = ALC_INIT_GPIO3;
1317 break;
1318 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001319 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001320 spec->init_amp = ALC_INIT_DEFAULT;
1321 break;
1322 }
1323
1324 /* is laptop or Desktop and enable the function "Mute internal speaker
1325 * when the external headphone out jack is plugged"
1326 */
1327 if (!(ass & 0x8000))
1328 return 1;
1329 /*
1330 * 10~8 : Jack location
1331 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1332 * 14~13: Resvered
1333 * 15 : 1 --> enable the function "Mute internal speaker
1334 * when the external headphone out jack is plugged"
1335 */
Kailang Yangc9b58002007-10-16 14:30:01 +02001336 if (!spec->autocfg.hp_pins[0]) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001337 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001338 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1339 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001340 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001341 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001342 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001343 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001344 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001345 else if (tmp == 3)
1346 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001347 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001348 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001349 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1350 spec->autocfg.line_outs))
1351 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001352 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001353 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001354 return 1;
1355}
Kailang Yangea1fb292008-08-26 12:58:38 +02001356
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001357/* Check the validity of ALC subsystem-id
1358 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1359static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001360{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001361 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001362 struct alc_spec *spec = codec->spec;
1363 snd_printd("realtek: "
1364 "Enable default setup for auto mode as fallback\n");
1365 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001366 }
Takashi Iwai21268962011-07-07 15:01:13 +02001367}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001368
Takashi Iwai41e41f12005-06-08 14:48:49 +02001369/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001370 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001371 */
1372
1373struct alc_pincfg {
1374 hda_nid_t nid;
1375 u32 val;
1376};
1377
Todd Broche1eb5f12010-12-06 11:19:51 -08001378struct alc_model_fixup {
1379 const int id;
1380 const char *name;
1381};
1382
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001383struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001384 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001385 bool chained;
1386 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001387 union {
1388 unsigned int sku;
1389 const struct alc_pincfg *pins;
1390 const struct hda_verb *verbs;
1391 void (*func)(struct hda_codec *codec,
1392 const struct alc_fixup *fix,
1393 int action);
1394 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001395};
1396
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001397enum {
1398 ALC_FIXUP_INVALID,
1399 ALC_FIXUP_SKU,
1400 ALC_FIXUP_PINS,
1401 ALC_FIXUP_VERBS,
1402 ALC_FIXUP_FUNC,
1403};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001404
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001405enum {
1406 ALC_FIXUP_ACT_PRE_PROBE,
1407 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001408 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001409};
1410
1411static void alc_apply_fixup(struct hda_codec *codec, int action)
1412{
1413 struct alc_spec *spec = codec->spec;
1414 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001415#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001416 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001417#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001418 int depth = 0;
1419
1420 if (!spec->fixup_list)
1421 return;
1422
1423 while (id >= 0) {
1424 const struct alc_fixup *fix = spec->fixup_list + id;
1425 const struct alc_pincfg *cfg;
1426
1427 switch (fix->type) {
1428 case ALC_FIXUP_SKU:
1429 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
1430 break;;
1431 snd_printdd(KERN_INFO "hda_codec: %s: "
1432 "Apply sku override for %s\n",
1433 codec->chip_name, modelname);
1434 spec->cdefine.sku_cfg = fix->v.sku;
1435 spec->cdefine.fixup = 1;
1436 break;
1437 case ALC_FIXUP_PINS:
1438 cfg = fix->v.pins;
1439 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1440 break;
1441 snd_printdd(KERN_INFO "hda_codec: %s: "
1442 "Apply pincfg for %s\n",
1443 codec->chip_name, modelname);
1444 for (; cfg->nid; cfg++)
1445 snd_hda_codec_set_pincfg(codec, cfg->nid,
1446 cfg->val);
1447 break;
1448 case ALC_FIXUP_VERBS:
1449 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1450 break;
1451 snd_printdd(KERN_INFO "hda_codec: %s: "
1452 "Apply fix-verbs for %s\n",
1453 codec->chip_name, modelname);
1454 add_verb(codec->spec, fix->v.verbs);
1455 break;
1456 case ALC_FIXUP_FUNC:
1457 if (!fix->v.func)
1458 break;
1459 snd_printdd(KERN_INFO "hda_codec: %s: "
1460 "Apply fix-func for %s\n",
1461 codec->chip_name, modelname);
1462 fix->v.func(codec, fix, action);
1463 break;
1464 default:
1465 snd_printk(KERN_ERR "hda_codec: %s: "
1466 "Invalid fixup type %d\n",
1467 codec->chip_name, fix->type);
1468 break;
1469 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001470 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001471 break;
1472 if (++depth > 10)
1473 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001474 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001475 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001476}
1477
Todd Broche1eb5f12010-12-06 11:19:51 -08001478static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001479 const struct alc_model_fixup *models,
1480 const struct snd_pci_quirk *quirk,
1481 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001482{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001483 struct alc_spec *spec = codec->spec;
1484 int id = -1;
1485 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001486
Todd Broche1eb5f12010-12-06 11:19:51 -08001487 if (codec->modelname && models) {
1488 while (models->name) {
1489 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001490 id = models->id;
1491 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001492 break;
1493 }
1494 models++;
1495 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001496 }
1497 if (id < 0) {
1498 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1499 if (quirk) {
1500 id = quirk->value;
1501#ifdef CONFIG_SND_DEBUG_VERBOSE
1502 name = quirk->name;
1503#endif
1504 }
1505 }
1506
1507 spec->fixup_id = id;
1508 if (id >= 0) {
1509 spec->fixup_list = fixlist;
1510 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001511 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001512}
1513
Takashi Iwai1d045db2011-07-07 18:23:21 +02001514/*
1515 * COEF access helper functions
1516 */
Kailang Yang274693f2009-12-03 10:07:50 +01001517static int alc_read_coef_idx(struct hda_codec *codec,
1518 unsigned int coef_idx)
1519{
1520 unsigned int val;
1521 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1522 coef_idx);
1523 val = snd_hda_codec_read(codec, 0x20, 0,
1524 AC_VERB_GET_PROC_COEF, 0);
1525 return val;
1526}
1527
Kailang Yang977ddd62010-09-15 10:02:29 +02001528static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1529 unsigned int coef_val)
1530{
1531 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1532 coef_idx);
1533 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1534 coef_val);
1535}
1536
Takashi Iwai1d045db2011-07-07 18:23:21 +02001537/*
1538 * Digital I/O handling
1539 */
1540
Takashi Iwai757899a2010-07-30 10:48:14 +02001541/* set right pin controls for digital I/O */
1542static void alc_auto_init_digital(struct hda_codec *codec)
1543{
1544 struct alc_spec *spec = codec->spec;
1545 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001546 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001547
1548 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1549 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001550 if (!pin)
1551 continue;
1552 snd_hda_codec_write(codec, pin, 0,
1553 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1554 if (!i)
1555 dac = spec->multiout.dig_out_nid;
1556 else
1557 dac = spec->slave_dig_outs[i - 1];
1558 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1559 continue;
1560 snd_hda_codec_write(codec, dac, 0,
1561 AC_VERB_SET_AMP_GAIN_MUTE,
1562 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001563 }
1564 pin = spec->autocfg.dig_in_pin;
1565 if (pin)
1566 snd_hda_codec_write(codec, pin, 0,
1567 AC_VERB_SET_PIN_WIDGET_CONTROL,
1568 PIN_IN);
1569}
1570
1571/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1572static void alc_auto_parse_digital(struct hda_codec *codec)
1573{
1574 struct alc_spec *spec = codec->spec;
1575 int i, err;
1576 hda_nid_t dig_nid;
1577
1578 /* support multiple SPDIFs; the secondary is set up as a slave */
1579 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001580 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001581 err = snd_hda_get_connections(codec,
1582 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001583 conn, ARRAY_SIZE(conn));
Takashi Iwai757899a2010-07-30 10:48:14 +02001584 if (err < 0)
1585 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001586 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai757899a2010-07-30 10:48:14 +02001587 if (!i) {
1588 spec->multiout.dig_out_nid = dig_nid;
1589 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1590 } else {
1591 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1592 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1593 break;
1594 spec->slave_dig_outs[i - 1] = dig_nid;
1595 }
1596 }
1597
1598 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001599 dig_nid = codec->start_nid;
1600 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1601 unsigned int wcaps = get_wcaps(codec, dig_nid);
1602 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1603 continue;
1604 if (!(wcaps & AC_WCAP_DIGITAL))
1605 continue;
1606 if (!(wcaps & AC_WCAP_CONN_LIST))
1607 continue;
1608 err = get_connection_index(codec, dig_nid,
1609 spec->autocfg.dig_in_pin);
1610 if (err >= 0) {
1611 spec->dig_in_nid = dig_nid;
1612 break;
1613 }
1614 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001615 }
1616}
1617
Takashi Iwaif95474e2007-07-10 00:47:43 +02001618/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001619 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001620 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001621static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1622 struct snd_ctl_elem_info *uinfo)
1623{
1624 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1625 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001626 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001627 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001628
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001629 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001630 if (spec->vol_in_capsrc)
1631 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1632 else
1633 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1634 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001635 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001636 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001637 return err;
1638}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001640static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1641 unsigned int size, unsigned int __user *tlv)
1642{
1643 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1644 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001645 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001646 int err;
1647
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001648 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001649 if (spec->vol_in_capsrc)
1650 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1651 else
1652 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1653 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001654 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001655 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001656 return err;
1657}
1658
1659typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1660 struct snd_ctl_elem_value *ucontrol);
1661
1662static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1663 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001664 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001665{
1666 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1667 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001668 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001669
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001670 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001671 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001672 for (i = 0; i < spec->num_adc_nids; i++) {
1673 kcontrol->private_value =
1674 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1675 3, 0, HDA_INPUT);
1676 err = func(kcontrol, ucontrol);
1677 if (err < 0)
1678 goto error;
1679 }
1680 } else {
1681 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001682 if (spec->vol_in_capsrc)
1683 kcontrol->private_value =
1684 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1685 3, 0, HDA_OUTPUT);
1686 else
1687 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001688 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1689 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001690 err = func(kcontrol, ucontrol);
1691 }
1692 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001693 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001694 return err;
1695}
1696
1697static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1698 struct snd_ctl_elem_value *ucontrol)
1699{
1700 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001701 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001702}
1703
1704static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1705 struct snd_ctl_elem_value *ucontrol)
1706{
1707 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001708 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001709}
1710
1711/* capture mixer elements */
1712#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1713
1714static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1715 struct snd_ctl_elem_value *ucontrol)
1716{
1717 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001718 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001719}
1720
1721static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1722 struct snd_ctl_elem_value *ucontrol)
1723{
1724 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001725 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001726}
1727
Takashi Iwaia23b6882009-03-23 15:21:36 +01001728#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001729 { \
1730 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1731 .name = "Capture Switch", \
1732 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1733 .count = num, \
1734 .info = alc_cap_sw_info, \
1735 .get = alc_cap_sw_get, \
1736 .put = alc_cap_sw_put, \
1737 }, \
1738 { \
1739 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1740 .name = "Capture Volume", \
1741 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1742 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1743 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1744 .count = num, \
1745 .info = alc_cap_vol_info, \
1746 .get = alc_cap_vol_get, \
1747 .put = alc_cap_vol_put, \
1748 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001749 }
1750
1751#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001752 { \
1753 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1754 /* .name = "Capture Source", */ \
1755 .name = "Input Source", \
1756 .count = num, \
1757 .info = alc_mux_enum_info, \
1758 .get = alc_mux_enum_get, \
1759 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001760 }
1761
1762#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001763static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001764 _DEFINE_CAPMIX(num), \
1765 _DEFINE_CAPSRC(num), \
1766 { } /* end */ \
1767}
1768
1769#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001770static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001771 _DEFINE_CAPMIX(num), \
1772 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001773}
1774
1775/* up to three ADCs */
1776DEFINE_CAPMIX(1);
1777DEFINE_CAPMIX(2);
1778DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001779DEFINE_CAPMIX_NOSRC(1);
1780DEFINE_CAPMIX_NOSRC(2);
1781DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001782
1783/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001784 * virtual master controls
1785 */
1786
1787/*
1788 * slave controls for virtual master
1789 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001790static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001791 "Front Playback Volume",
1792 "Surround Playback Volume",
1793 "Center Playback Volume",
1794 "LFE Playback Volume",
1795 "Side Playback Volume",
1796 "Headphone Playback Volume",
1797 "Speaker Playback Volume",
1798 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001799 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001800 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001801 NULL,
1802};
1803
Takashi Iwaiea734962011-01-17 11:29:34 +01001804static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001805 "Front Playback Switch",
1806 "Surround Playback Switch",
1807 "Center Playback Switch",
1808 "LFE Playback Switch",
1809 "Side Playback Switch",
1810 "Headphone Playback Switch",
1811 "Speaker Playback Switch",
1812 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001813 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001814 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001815 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001816 NULL,
1817};
1818
1819/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001820 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001822
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001823#define NID_MAPPING (-1)
1824
1825#define SUBDEV_SPEAKER_ (0 << 6)
1826#define SUBDEV_HP_ (1 << 6)
1827#define SUBDEV_LINE_ (2 << 6)
1828#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1829#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1830#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1831
Takashi Iwai603c4012008-07-30 15:01:44 +02001832static void alc_free_kctls(struct hda_codec *codec);
1833
Takashi Iwai67d634c2009-11-16 15:35:59 +01001834#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001835/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001836static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001837 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001838 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001839 { } /* end */
1840};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001841#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001842
Linus Torvalds1da177e2005-04-16 15:20:36 -07001843static int alc_build_controls(struct hda_codec *codec)
1844{
1845 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001846 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001847 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001848 int i, j, err;
1849 unsigned int u;
1850 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
1852 for (i = 0; i < spec->num_mixers; i++) {
1853 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1854 if (err < 0)
1855 return err;
1856 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001857 if (spec->cap_mixer) {
1858 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1859 if (err < 0)
1860 return err;
1861 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001863 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001864 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001865 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 if (err < 0)
1867 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001868 if (!spec->no_analog) {
1869 err = snd_hda_create_spdif_share_sw(codec,
1870 &spec->multiout);
1871 if (err < 0)
1872 return err;
1873 spec->multiout.share_spdif = 1;
1874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 }
1876 if (spec->dig_in_nid) {
1877 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1878 if (err < 0)
1879 return err;
1880 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001881
Takashi Iwai67d634c2009-11-16 15:35:59 +01001882#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001883 /* create beep controls if needed */
1884 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001885 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001886 for (knew = alc_beep_mixer; knew->name; knew++) {
1887 struct snd_kcontrol *kctl;
1888 kctl = snd_ctl_new1(knew, codec);
1889 if (!kctl)
1890 return -ENOMEM;
1891 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001892 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001893 if (err < 0)
1894 return err;
1895 }
1896 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001897#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001898
Takashi Iwai2134ea42008-01-10 16:53:55 +01001899 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001900 if (!spec->no_analog &&
1901 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001902 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001903 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001904 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001905 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001906 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001907 if (err < 0)
1908 return err;
1909 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001910 if (!spec->no_analog &&
1911 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001912 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1913 NULL, alc_slave_sws);
1914 if (err < 0)
1915 return err;
1916 }
1917
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001918 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001919 if (spec->capsrc_nids || spec->adc_nids) {
1920 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1921 if (!kctl)
1922 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1923 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02001924 const hda_nid_t *nids = spec->capsrc_nids;
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001925 if (!nids)
1926 nids = spec->adc_nids;
1927 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1928 if (err < 0)
1929 return err;
1930 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001931 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001932 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001933 const char *kname = kctl ? kctl->id.name : NULL;
1934 for (knew = spec->cap_mixer; knew->name; knew++) {
1935 if (kname && strcmp(knew->name, kname) == 0)
1936 continue;
1937 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1938 for (i = 0; kctl && i < kctl->count; i++) {
1939 err = snd_hda_add_nid(codec, kctl, i,
1940 spec->adc_nids[i]);
1941 if (err < 0)
1942 return err;
1943 }
1944 }
1945 }
1946
1947 /* other nid->control mapping */
1948 for (i = 0; i < spec->num_mixers; i++) {
1949 for (knew = spec->mixers[i]; knew->name; knew++) {
1950 if (knew->iface != NID_MAPPING)
1951 continue;
1952 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1953 if (kctl == NULL)
1954 continue;
1955 u = knew->subdevice;
1956 for (j = 0; j < 4; j++, u >>= 8) {
1957 nid = u & 0x3f;
1958 if (nid == 0)
1959 continue;
1960 switch (u & 0xc0) {
1961 case SUBDEV_SPEAKER_:
1962 nid = spec->autocfg.speaker_pins[nid];
1963 break;
1964 case SUBDEV_LINE_:
1965 nid = spec->autocfg.line_out_pins[nid];
1966 break;
1967 case SUBDEV_HP_:
1968 nid = spec->autocfg.hp_pins[nid];
1969 break;
1970 default:
1971 continue;
1972 }
1973 err = snd_hda_add_nid(codec, kctl, 0, nid);
1974 if (err < 0)
1975 return err;
1976 }
1977 u = knew->private_value;
1978 for (j = 0; j < 4; j++, u >>= 8) {
1979 nid = u & 0xff;
1980 if (nid == 0)
1981 continue;
1982 err = snd_hda_add_nid(codec, kctl, 0, nid);
1983 if (err < 0)
1984 return err;
1985 }
1986 }
1987 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001988
1989 alc_free_kctls(codec); /* no longer needed */
1990
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 return 0;
1992}
1993
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001994
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001996 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001997 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001998
Takashi Iwai584c0c42011-03-10 12:51:11 +01001999static void alc_init_special_input_src(struct hda_codec *codec);
2000
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001static int alc_init(struct hda_codec *codec)
2002{
2003 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002004 unsigned int i;
2005
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002006 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002007 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002008
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002009 for (i = 0; i < spec->num_init_verbs; i++)
2010 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002011 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002012
2013 if (spec->init_hook)
2014 spec->init_hook(codec);
2015
Takashi Iwai58701122011-01-13 15:41:45 +01002016 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2017
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002018 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 return 0;
2020}
2021
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002022static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2023{
2024 struct alc_spec *spec = codec->spec;
2025
2026 if (spec->unsol_event)
2027 spec->unsol_event(codec, res);
2028}
2029
Takashi Iwaicb53c622007-08-10 17:21:45 +02002030#ifdef CONFIG_SND_HDA_POWER_SAVE
2031static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2032{
2033 struct alc_spec *spec = codec->spec;
2034 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2035}
2036#endif
2037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038/*
2039 * Analog playback callbacks
2040 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002041static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002043 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044{
2045 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002046 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2047 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048}
2049
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002050static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 struct hda_codec *codec,
2052 unsigned int stream_tag,
2053 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002054 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055{
2056 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002057 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2058 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059}
2060
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002061static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002063 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064{
2065 struct alc_spec *spec = codec->spec;
2066 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2067}
2068
2069/*
2070 * Digital out
2071 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002072static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002074 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075{
2076 struct alc_spec *spec = codec->spec;
2077 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2078}
2079
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002080static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002081 struct hda_codec *codec,
2082 unsigned int stream_tag,
2083 unsigned int format,
2084 struct snd_pcm_substream *substream)
2085{
2086 struct alc_spec *spec = codec->spec;
2087 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2088 stream_tag, format, substream);
2089}
2090
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002091static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002092 struct hda_codec *codec,
2093 struct snd_pcm_substream *substream)
2094{
2095 struct alc_spec *spec = codec->spec;
2096 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2097}
2098
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002099static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002101 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102{
2103 struct alc_spec *spec = codec->spec;
2104 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2105}
2106
2107/*
2108 * Analog capture
2109 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002110static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 struct hda_codec *codec,
2112 unsigned int stream_tag,
2113 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002114 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115{
2116 struct alc_spec *spec = codec->spec;
2117
Takashi Iwai63300792008-01-24 15:31:36 +01002118 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 stream_tag, 0, format);
2120 return 0;
2121}
2122
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002123static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002125 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126{
2127 struct alc_spec *spec = codec->spec;
2128
Takashi Iwai888afa12008-03-18 09:57:50 +01002129 snd_hda_codec_cleanup_stream(codec,
2130 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 return 0;
2132}
2133
Takashi Iwai840b64c2010-07-13 22:49:01 +02002134/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002135static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002136 struct hda_codec *codec,
2137 unsigned int stream_tag,
2138 unsigned int format,
2139 struct snd_pcm_substream *substream)
2140{
2141 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002142 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002143 spec->cur_adc_stream_tag = stream_tag;
2144 spec->cur_adc_format = format;
2145 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2146 return 0;
2147}
2148
Takashi Iwai21268962011-07-07 15:01:13 +02002149static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002150 struct hda_codec *codec,
2151 struct snd_pcm_substream *substream)
2152{
2153 struct alc_spec *spec = codec->spec;
2154 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2155 spec->cur_adc = 0;
2156 return 0;
2157}
2158
Takashi Iwai21268962011-07-07 15:01:13 +02002159static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002160 .substreams = 1,
2161 .channels_min = 2,
2162 .channels_max = 2,
2163 .nid = 0, /* fill later */
2164 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002165 .prepare = dyn_adc_capture_pcm_prepare,
2166 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002167 },
2168};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170/*
2171 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002172static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 .substreams = 1,
2174 .channels_min = 2,
2175 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002176 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002178 .open = alc_playback_pcm_open,
2179 .prepare = alc_playback_pcm_prepare,
2180 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 },
2182};
2183
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002184static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002185 .substreams = 1,
2186 .channels_min = 2,
2187 .channels_max = 2,
2188 /* NID is set in alc_build_pcms */
2189};
2190
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002191static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002192 .substreams = 1,
2193 .channels_min = 2,
2194 .channels_max = 2,
2195 /* NID is set in alc_build_pcms */
2196};
2197
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002198static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002199 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 .channels_min = 2,
2201 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002202 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002204 .prepare = alc_alt_capture_pcm_prepare,
2205 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 },
2207};
2208
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002209static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 .substreams = 1,
2211 .channels_min = 2,
2212 .channels_max = 2,
2213 /* NID is set in alc_build_pcms */
2214 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002215 .open = alc_dig_playback_pcm_open,
2216 .close = alc_dig_playback_pcm_close,
2217 .prepare = alc_dig_playback_pcm_prepare,
2218 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 },
2220};
2221
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002222static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 .substreams = 1,
2224 .channels_min = 2,
2225 .channels_max = 2,
2226 /* NID is set in alc_build_pcms */
2227};
2228
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002229/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002230static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002231 .substreams = 0,
2232 .channels_min = 0,
2233 .channels_max = 0,
2234};
2235
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236static int alc_build_pcms(struct hda_codec *codec)
2237{
2238 struct alc_spec *spec = codec->spec;
2239 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002240 const struct hda_pcm_stream *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 int i;
2242
2243 codec->num_pcms = 1;
2244 codec->pcm_info = info;
2245
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002246 if (spec->no_analog)
2247 goto skip_analog;
2248
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002249 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2250 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002252
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002253 if (spec->multiout.dac_nids > 0) {
2254 p = spec->stream_analog_playback;
2255 if (!p)
2256 p = &alc_pcm_analog_playback;
2257 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002258 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2259 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002260 if (spec->adc_nids) {
2261 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002262 if (!p) {
2263 if (spec->dyn_adc_switch)
2264 p = &dyn_adc_pcm_analog_capture;
2265 else
2266 p = &alc_pcm_analog_capture;
2267 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002268 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002269 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2270 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
Takashi Iwai4a471b72005-12-07 13:56:29 +01002272 if (spec->channel_mode) {
2273 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2274 for (i = 0; i < spec->num_channel_mode; i++) {
2275 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2276 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 }
2279 }
2280
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002281 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002282 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002284 snprintf(spec->stream_name_digital,
2285 sizeof(spec->stream_name_digital),
2286 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002287 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002288 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002289 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002291 if (spec->dig_out_type)
2292 info->pcm_type = spec->dig_out_type;
2293 else
2294 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002295 if (spec->multiout.dig_out_nid) {
2296 p = spec->stream_digital_playback;
2297 if (!p)
2298 p = &alc_pcm_digital_playback;
2299 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2301 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002302 if (spec->dig_in_nid) {
2303 p = spec->stream_digital_capture;
2304 if (!p)
2305 p = &alc_pcm_digital_capture;
2306 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2308 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002309 /* FIXME: do we need this for all Realtek codec models? */
2310 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 }
2312
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002313 if (spec->no_analog)
2314 return 0;
2315
Takashi Iwaie08a0072006-09-07 17:52:14 +02002316 /* If the use of more than one ADC is requested for the current
2317 * model, configure a second analog capture-only PCM.
2318 */
2319 /* Additional Analaog capture for index #2 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002320 if (spec->alt_dac_nid || spec->num_adc_nids > 1) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002321 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002322 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002323 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002324 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002325 p = spec->stream_analog_alt_playback;
2326 if (!p)
2327 p = &alc_pcm_analog_alt_playback;
2328 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002329 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2330 spec->alt_dac_nid;
2331 } else {
2332 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2333 alc_pcm_null_stream;
2334 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2335 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002336 if (spec->num_adc_nids > 1) {
2337 p = spec->stream_analog_alt_capture;
2338 if (!p)
2339 p = &alc_pcm_analog_alt_capture;
2340 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002341 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2342 spec->adc_nids[1];
2343 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2344 spec->num_adc_nids - 1;
2345 } else {
2346 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2347 alc_pcm_null_stream;
2348 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002349 }
2350 }
2351
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 return 0;
2353}
2354
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002355static inline void alc_shutup(struct hda_codec *codec)
2356{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002357 struct alc_spec *spec = codec->spec;
2358
2359 if (spec && spec->shutup)
2360 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002361 snd_hda_shutup_pins(codec);
2362}
2363
Takashi Iwai603c4012008-07-30 15:01:44 +02002364static void alc_free_kctls(struct hda_codec *codec)
2365{
2366 struct alc_spec *spec = codec->spec;
2367
2368 if (spec->kctls.list) {
2369 struct snd_kcontrol_new *kctl = spec->kctls.list;
2370 int i;
2371 for (i = 0; i < spec->kctls.used; i++)
2372 kfree(kctl[i].name);
2373 }
2374 snd_array_free(&spec->kctls);
2375}
2376
Takashi Iwai23c09b02011-08-19 09:05:35 +02002377static void alc_free_bind_ctls(struct hda_codec *codec)
2378{
2379 struct alc_spec *spec = codec->spec;
2380 if (spec->bind_ctls.list) {
2381 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2382 int i;
2383 for (i = 0; i < spec->bind_ctls.used; i++)
2384 kfree(ctl[i]);
2385 }
2386 snd_array_free(&spec->bind_ctls);
2387}
2388
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389static void alc_free(struct hda_codec *codec)
2390{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002391 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002392
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002393 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002394 return;
2395
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002396 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002397 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002398 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002399 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002400 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002401 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402}
2403
Hector Martinf5de24b2009-12-20 22:51:31 +01002404#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002405static void alc_power_eapd(struct hda_codec *codec)
2406{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002407 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002408}
2409
Hector Martinf5de24b2009-12-20 22:51:31 +01002410static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2411{
2412 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002413 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002414 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002415 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002416 return 0;
2417}
2418#endif
2419
Takashi Iwai2a439522011-07-26 09:52:50 +02002420#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002421static int alc_resume(struct hda_codec *codec)
2422{
Takashi Iwai1c7161532011-04-07 10:37:16 +02002423 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002424 codec->patch_ops.init(codec);
2425 snd_hda_codec_resume_amp(codec);
2426 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002427 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002428 return 0;
2429}
Takashi Iwaie044c392008-10-27 16:56:24 +01002430#endif
2431
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432/*
2433 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002434static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 .build_controls = alc_build_controls,
2436 .build_pcms = alc_build_pcms,
2437 .init = alc_init,
2438 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002439 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002440#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002441 .resume = alc_resume,
2442#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002443#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002444 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002445 .check_power_status = alc_check_power_status,
2446#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002447 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448};
2449
Kailang Yangc027ddc2010-03-19 11:33:06 +01002450/* replace the codec chip_name with the given string */
2451static int alc_codec_rename(struct hda_codec *codec, const char *name)
2452{
2453 kfree(codec->chip_name);
2454 codec->chip_name = kstrdup(name, GFP_KERNEL);
2455 if (!codec->chip_name) {
2456 alc_free(codec);
2457 return -ENOMEM;
2458 }
2459 return 0;
2460}
2461
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002462/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002463 * Automatic parse of I/O pins from the BIOS configuration
2464 */
2465
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002466enum {
2467 ALC_CTL_WIDGET_VOL,
2468 ALC_CTL_WIDGET_MUTE,
2469 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002470 ALC_CTL_BIND_VOL,
2471 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002472};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002473static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002474 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2475 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002476 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002477 HDA_BIND_VOL(NULL, 0),
2478 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002479};
2480
2481/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002482static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002483 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002484{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002485 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002486
Takashi Iwaice764ab2011-04-27 16:35:23 +02002487 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002488 if (!knew)
2489 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002490 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002491 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002492 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002493 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002494 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002495 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002496 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002497 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002498 return 0;
2499}
2500
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002501static int add_control_with_pfx(struct alc_spec *spec, int type,
2502 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002503 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002504{
2505 char name[32];
2506 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002507 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002508}
2509
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002510#define add_pb_vol_ctrl(spec, type, pfx, val) \
2511 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2512#define add_pb_sw_ctrl(spec, type, pfx, val) \
2513 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2514#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2515 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2516#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2517 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002518
Takashi Iwai23c09b02011-08-19 09:05:35 +02002519static const char * const channel_name[4] = {
2520 "Front", "Surround", "CLFE", "Side"
2521};
2522
Takashi Iwai6843ca12011-06-24 11:03:58 +02002523static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2524 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002525{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002526 struct auto_pin_cfg *cfg = &spec->autocfg;
2527
Takashi Iwai6843ca12011-06-24 11:03:58 +02002528 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002529 if (cfg->line_outs == 1 && !spec->multi_ios &&
2530 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002531 return "Master";
2532
2533 switch (cfg->line_out_type) {
2534 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002535 if (cfg->line_outs == 1)
2536 return "Speaker";
2537 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002538 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002539 /* for multi-io case, only the primary out */
2540 if (ch && spec->multi_ios)
2541 break;
2542 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002543 return "Headphone";
2544 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002545 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002546 return "PCM";
2547 break;
2548 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002549 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2550 return "PCM";
2551
2552 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002553}
2554
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002555/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002556static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002557 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002558 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002559{
Kailang Yangdf694da2005-12-05 19:42:22 +01002560 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002561
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002562 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002563 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2564 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002565 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002566 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002567 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2568 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002569 return err;
2570 return 0;
2571}
2572
Takashi Iwai05f5f472009-08-25 13:10:18 +02002573static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002574{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002575 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2576 return (pincap & AC_PINCAP_IN) != 0;
2577}
2578
Takashi Iwai1d045db2011-07-07 18:23:21 +02002579/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002580static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002581{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002582 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002583 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002584 hda_nid_t *adc_nids = spec->private_adc_nids;
2585 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2586 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2587 bool indep_capsrc = false;
Takashi Iwaib7821702011-07-06 15:12:46 +02002588 int i, nums = 0;
2589
2590 nid = codec->start_nid;
2591 for (i = 0; i < codec->num_nodes; i++, nid++) {
2592 hda_nid_t src;
2593 const hda_nid_t *list;
2594 unsigned int caps = get_wcaps(codec, nid);
2595 int type = get_wcaps_type(caps);
2596
2597 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2598 continue;
2599 adc_nids[nums] = nid;
2600 cap_nids[nums] = nid;
2601 src = nid;
2602 for (;;) {
2603 int n;
2604 type = get_wcaps_type(get_wcaps(codec, src));
2605 if (type == AC_WID_PIN)
2606 break;
2607 if (type == AC_WID_AUD_SEL) {
2608 cap_nids[nums] = src;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002609 indep_capsrc = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002610 break;
2611 }
2612 n = snd_hda_get_conn_list(codec, src, &list);
2613 if (n > 1) {
2614 cap_nids[nums] = src;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002615 indep_capsrc = true;
Takashi Iwaib7821702011-07-06 15:12:46 +02002616 break;
2617 } else if (n != 1)
2618 break;
2619 src = *list;
2620 }
2621 if (++nums >= max_nums)
2622 break;
2623 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002624 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002625 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002626 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002627 return nums;
2628}
2629
Takashi Iwai05f5f472009-08-25 13:10:18 +02002630/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002631static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002632{
2633 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002634 const struct auto_pin_cfg *cfg = &spec->autocfg;
2635 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002636 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002637 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002638 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002639 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002640
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002641 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002642 if (num_adcs < 0)
2643 return 0;
2644
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002645 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002646 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002647 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002648
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002649 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002650 if (!alc_is_input_pin(codec, pin))
2651 continue;
2652
David Henningsson5322bf22011-01-05 11:03:56 +01002653 label = hda_get_autocfg_input_label(codec, cfg, i);
2654 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002655 type_idx++;
2656 else
2657 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002658 prev_label = label;
2659
Takashi Iwai05f5f472009-08-25 13:10:18 +02002660 if (mixer) {
2661 idx = get_connection_index(codec, mixer, pin);
2662 if (idx >= 0) {
2663 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002664 label, type_idx,
2665 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002666 if (err < 0)
2667 return err;
2668 }
2669 }
2670
Takashi Iwaib7821702011-07-06 15:12:46 +02002671 for (c = 0; c < num_adcs; c++) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002672 hda_nid_t cap = spec->capsrc_nids ?
2673 spec->capsrc_nids[c] : spec->adc_nids[c];
2674 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002675 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002676 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002677 snd_hda_add_imux_item(imux, label, idx, NULL);
2678 break;
2679 }
2680 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002681 }
Takashi Iwai21268962011-07-07 15:01:13 +02002682
2683 spec->num_mux_defs = 1;
2684 spec->input_mux = imux;
2685
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002686 return 0;
2687}
2688
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002689static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2690 unsigned int pin_type)
2691{
2692 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2693 pin_type);
2694 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002695 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2696 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002697 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002698}
2699
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002700static int get_pin_type(int line_out_type)
2701{
2702 if (line_out_type == AUTO_PIN_HP_OUT)
2703 return PIN_HP;
2704 else
2705 return PIN_OUT;
2706}
2707
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002708static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002709{
2710 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002711 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002712 int i;
2713
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002714 for (i = 0; i < cfg->num_inputs; i++) {
2715 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002716 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002717 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002718 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002719 snd_hda_codec_write(codec, nid, 0,
2720 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002721 AMP_OUT_MUTE);
2722 }
2723 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002724
2725 /* mute all loopback inputs */
2726 if (spec->mixer_nid) {
2727 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2728 for (i = 0; i < nums; i++)
2729 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2730 AC_VERB_SET_AMP_GAIN_MUTE,
2731 AMP_IN_MUTE(i));
2732 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002733}
2734
Takashi Iwai7085ec12009-10-02 09:03:58 +02002735/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002736static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002737{
Takashi Iwai604401a2011-04-27 15:14:23 +02002738 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002739 int i, num;
2740
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002741 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2742 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002743 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2744 for (i = 0; i < num; i++) {
2745 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2746 return list[i];
2747 }
2748 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002749}
2750
Takashi Iwai604401a2011-04-27 15:14:23 +02002751/* go down to the selector widget before the mixer */
2752static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2753{
2754 hda_nid_t srcs[5];
2755 int num = snd_hda_get_connections(codec, pin, srcs,
2756 ARRAY_SIZE(srcs));
2757 if (num != 1 ||
2758 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2759 return pin;
2760 return srcs[0];
2761}
2762
Takashi Iwai7085ec12009-10-02 09:03:58 +02002763/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002764static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002765 hda_nid_t dac)
2766{
David Henningssoncc1c4522010-11-24 14:17:47 +01002767 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002768 int i, num;
2769
Takashi Iwai604401a2011-04-27 15:14:23 +02002770 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002771 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2772 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002773 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002774 return mix[i];
2775 }
2776 return 0;
2777}
2778
Takashi Iwaice764ab2011-04-27 16:35:23 +02002779/* select the connection from pin to DAC if needed */
2780static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2781 hda_nid_t dac)
2782{
2783 hda_nid_t mix[5];
2784 int i, num;
2785
2786 pin = alc_go_down_to_selector(codec, pin);
2787 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2788 if (num < 2)
2789 return 0;
2790 for (i = 0; i < num; i++) {
2791 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2792 snd_hda_codec_update_cache(codec, pin, 0,
2793 AC_VERB_SET_CONNECT_SEL, i);
2794 return 0;
2795 }
2796 }
2797 return 0;
2798}
2799
Takashi Iwai7085ec12009-10-02 09:03:58 +02002800/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002801static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002802{
2803 struct alc_spec *spec = codec->spec;
2804 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002805 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002806
Takashi Iwai604401a2011-04-27 15:14:23 +02002807 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002808 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002809 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002810 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002811 if (!nid)
2812 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002813 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2814 spec->multiout.num_dacs))
2815 continue;
Takashi Iwaie23832a2011-08-23 18:16:56 +02002816 if (spec->multiout.hp_out_nid[0] == nid)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002817 continue;
2818 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2819 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2820 continue;
2821 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002822 }
2823 return 0;
2824}
2825
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002826static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2827{
2828 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2829 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2830 return alc_auto_look_for_dac(codec, pin);
2831 return 0;
2832}
2833
Takashi Iwai7085ec12009-10-02 09:03:58 +02002834/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02002835static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002836{
2837 struct alc_spec *spec = codec->spec;
Takashi Iwaicb053a82011-06-27 11:32:07 +02002838 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai350434e2011-06-30 21:29:12 +02002839 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002840 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002841
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002842 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002843 /* set num_dacs once to full for alc_auto_look_for_dac() */
2844 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02002845 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002846 spec->multiout.extra_out_nid[0] = 0;
2847 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2848 spec->multiout.dac_nids = spec->private_dac_nids;
2849
2850 /* fill hard-wired DACs first */
2851 if (!redone) {
2852 for (i = 0; i < cfg->line_outs; i++)
2853 spec->private_dac_nids[i] =
2854 get_dac_if_single(codec, cfg->line_out_pins[i]);
2855 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02002856 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002857 get_dac_if_single(codec, cfg->hp_pins[0]);
2858 if (cfg->speaker_outs)
2859 spec->multiout.extra_out_nid[0] =
2860 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002861 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002862
2863 for (i = 0; i < cfg->line_outs; i++) {
2864 hda_nid_t pin = cfg->line_out_pins[i];
2865 if (spec->private_dac_nids[i])
2866 continue;
2867 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
2868 if (!spec->private_dac_nids[i] && !redone) {
2869 /* if we can't find primary DACs, re-probe without
2870 * checking the hard-wired DACs
2871 */
2872 redone = true;
2873 goto again;
2874 }
2875 }
2876
Takashi Iwai8f398ae2011-07-23 18:57:11 +02002877 /* re-count num_dacs and squash invalid entries */
2878 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002879 for (i = 0; i < cfg->line_outs; i++) {
2880 if (spec->private_dac_nids[i])
2881 spec->multiout.num_dacs++;
2882 else
2883 memmove(spec->private_dac_nids + i,
2884 spec->private_dac_nids + i + 1,
2885 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2886 }
2887
Takashi Iwaie23832a2011-08-23 18:16:56 +02002888 if (cfg->hp_outs && !spec->multiout.hp_out_nid[0])
2889 spec->multiout.hp_out_nid[0] =
Takashi Iwaibb8bf4d2011-07-06 13:07:54 +02002890 alc_auto_look_for_dac(codec, cfg->hp_pins[0]);
2891 if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0])
2892 spec->multiout.extra_out_nid[0] =
2893 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2894
Takashi Iwai7085ec12009-10-02 09:03:58 +02002895 return 0;
2896}
2897
Takashi Iwai23c09b02011-08-19 09:05:35 +02002898/* fill in the dac_nids table for surround speakers, etc */
2899static int alc_auto_fill_extra_dacs(struct hda_codec *codec)
2900{
2901 struct alc_spec *spec = codec->spec;
2902 const struct auto_pin_cfg *cfg = &spec->autocfg;
2903 int i;
2904
2905 if (cfg->speaker_outs < 2 || !spec->multiout.extra_out_nid[0])
2906 return 0;
2907
2908 for (i = 1; i < cfg->speaker_outs; i++)
2909 spec->multiout.extra_out_nid[i] =
2910 get_dac_if_single(codec, cfg->speaker_pins[i]);
2911 for (i = 1; i < cfg->speaker_outs; i++) {
2912 if (spec->multiout.extra_out_nid[i])
2913 continue;
2914 spec->multiout.extra_out_nid[i] =
2915 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]);
2916 }
2917 return 0;
2918}
2919
Takashi Iwai343a04b2011-07-06 14:28:39 +02002920static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02002921 const char *pfx, int cidx,
2922 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02002923{
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002924 if (!nid)
2925 return 0;
Takashi Iwai97aaab72011-07-06 14:02:55 +02002926 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
2927 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002928}
2929
Takashi Iwai343a04b2011-07-06 14:28:39 +02002930#define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
2931 alc_auto_add_vol_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai97aaab72011-07-06 14:02:55 +02002932
2933/* create a mute-switch for the given mixer widget;
2934 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
2935 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02002936static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02002937 const char *pfx, int cidx,
2938 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002939{
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002940 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02002941 int type;
2942 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002943 if (!nid)
2944 return 0;
2945 wid_type = get_wcaps_type(get_wcaps(codec, nid));
2946 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
2947 type = ALC_CTL_WIDGET_MUTE;
2948 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
2949 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02002950 type = ALC_CTL_WIDGET_MUTE;
2951 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
2952 } else {
2953 type = ALC_CTL_BIND_MUTE;
2954 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
2955 }
2956 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002957}
2958
Takashi Iwai343a04b2011-07-06 14:28:39 +02002959#define alc_auto_add_stereo_sw(codec, pfx, cidx, nid) \
2960 alc_auto_add_sw_ctl(codec, pfx, cidx, nid, 3)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002961
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002962static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
2963 hda_nid_t pin, hda_nid_t dac)
2964{
2965 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2966 if (nid_has_mute(codec, pin, HDA_OUTPUT))
2967 return pin;
2968 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
2969 return mix;
2970 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
2971 return dac;
2972 return 0;
2973}
2974
2975static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
2976 hda_nid_t pin, hda_nid_t dac)
2977{
2978 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
2979 if (nid_has_volume(codec, dac, HDA_OUTPUT))
2980 return dac;
2981 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
2982 return mix;
2983 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
2984 return pin;
2985 return 0;
2986}
2987
Takashi Iwai7085ec12009-10-02 09:03:58 +02002988/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02002989static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002990 const struct auto_pin_cfg *cfg)
2991{
2992 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002993 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02002994
Takashi Iwaice764ab2011-04-27 16:35:23 +02002995 noutputs = cfg->line_outs;
2996 if (spec->multi_ios > 0)
2997 noutputs += spec->multi_ios;
2998
2999 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003000 const char *name;
3001 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003002 hda_nid_t dac, pin;
3003 hda_nid_t sw, vol;
3004
3005 dac = spec->multiout.dac_nids[i];
3006 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003007 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003008 if (i >= cfg->line_outs)
3009 pin = spec->multi_io[i - 1].pin;
3010 else
3011 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003012
3013 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3014 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003015 name = alc_get_line_out_pfx(spec, i, true, &index);
3016 if (!name) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003017 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003018 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003019 if (err < 0)
3020 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003021 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003022 if (err < 0)
3023 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003024 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003025 if (err < 0)
3026 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003027 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003028 if (err < 0)
3029 return err;
3030 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003031 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003032 if (err < 0)
3033 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003034 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003035 if (err < 0)
3036 return err;
3037 }
3038 }
3039 return 0;
3040}
3041
Takashi Iwai343a04b2011-07-06 14:28:39 +02003042static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai23c09b02011-08-19 09:05:35 +02003043 hda_nid_t dac, const char *pfx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003044{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003045 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003046 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003047 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003048
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003049 if (!dac) {
Takashi Iwai7085ec12009-10-02 09:03:58 +02003050 /* the corresponding DAC is already occupied */
3051 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3052 return 0; /* no way */
3053 /* create a switch only */
Takashi Iwai0afe5f82009-10-02 09:20:00 +02003054 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003055 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT));
3056 }
3057
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003058 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3059 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3060 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003061 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003062 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003063 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003064 if (err < 0)
3065 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003066 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003067}
3068
Takashi Iwai23c09b02011-08-19 09:05:35 +02003069static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3070 unsigned int nums,
3071 struct hda_ctl_ops *ops)
3072{
3073 struct alc_spec *spec = codec->spec;
3074 struct hda_bind_ctls **ctlp, *ctl;
3075 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3076 ctlp = snd_array_new(&spec->bind_ctls);
3077 if (!ctlp)
3078 return NULL;
3079 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3080 *ctlp = ctl;
3081 if (ctl)
3082 ctl->ops = ops;
3083 return ctl;
3084}
3085
3086/* add playback controls for speaker and HP outputs */
3087static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3088 const hda_nid_t *pins,
3089 const hda_nid_t *dacs,
3090 const char *pfx)
3091{
3092 struct alc_spec *spec = codec->spec;
3093 struct hda_bind_ctls *ctl;
3094 char name[32];
3095 int i, n, err;
3096
3097 if (!num_pins || !pins[0])
3098 return 0;
3099
3100 if (num_pins == 1)
3101 return alc_auto_create_extra_out(codec, *pins, *dacs, pfx);
3102
3103 if (dacs[num_pins - 1]) {
3104 /* OK, we have a multi-output system with individual volumes */
3105 for (i = 0; i < num_pins; i++) {
3106 snprintf(name, sizeof(name), "%s %s",
3107 pfx, channel_name[i]);
3108 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3109 name);
3110 if (err < 0)
3111 return err;
3112 }
3113 return 0;
3114 }
3115
3116 /* Let's create a bind-controls */
3117 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3118 if (!ctl)
3119 return -ENOMEM;
3120 n = 0;
3121 for (i = 0; i < num_pins; i++) {
3122 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3123 ctl->values[n++] =
3124 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3125 }
3126 if (n) {
3127 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3128 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3129 if (err < 0)
3130 return err;
3131 }
3132
3133 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3134 if (!ctl)
3135 return -ENOMEM;
3136 n = 0;
3137 for (i = 0; i < num_pins; i++) {
3138 hda_nid_t vol;
3139 if (!pins[i] || !dacs[i])
3140 continue;
3141 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3142 if (vol)
3143 ctl->values[n++] =
3144 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3145 }
3146 if (n) {
3147 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3148 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3149 if (err < 0)
3150 return err;
3151 }
3152 return 0;
3153}
3154
Takashi Iwai343a04b2011-07-06 14:28:39 +02003155static int alc_auto_create_hp_out(struct hda_codec *codec)
3156{
3157 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003158 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3159 spec->autocfg.hp_pins,
3160 spec->multiout.hp_out_nid,
3161 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003162}
3163
3164static int alc_auto_create_speaker_out(struct hda_codec *codec)
3165{
3166 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003167 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3168 spec->autocfg.speaker_pins,
3169 spec->multiout.extra_out_nid,
3170 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003171}
3172
Takashi Iwai343a04b2011-07-06 14:28:39 +02003173static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003174 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003175 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003176{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003177 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003178 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003179 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003180
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003181 alc_set_pin_output(codec, pin, pin_type);
3182 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003183 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003184 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003185 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003186 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003187 mix = srcs[i];
3188 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003189 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003190 if (!mix)
3191 return;
3192
3193 /* need the manual connection? */
3194 if (num > 1)
3195 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3196 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003197 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3198 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003199 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003200 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003201 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003202 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003203 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003204 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3205 if (nid)
3206 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3207 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003208}
3209
Takashi Iwai343a04b2011-07-06 14:28:39 +02003210static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003211{
3212 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003213 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003214 int i;
3215
3216 for (i = 0; i <= HDA_SIDE; i++) {
3217 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3218 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003219 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003220 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003221 }
3222}
3223
Takashi Iwai343a04b2011-07-06 14:28:39 +02003224static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003225{
3226 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003227 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003228 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003229
Takashi Iwaie23832a2011-08-23 18:16:56 +02003230 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3231 pin = spec->autocfg.hp_pins[i];
3232 if (!pin)
3233 break;
3234 dac = spec->multiout.hp_out_nid[i];
3235 if (!dac) {
3236 if (i > 0 && spec->multiout.hp_out_nid[0])
3237 dac = spec->multiout.hp_out_nid[0];
3238 else
3239 dac = spec->multiout.dac_nids[0];
3240 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003241 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3242 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003243 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3244 pin = spec->autocfg.speaker_pins[i];
3245 if (!pin)
3246 break;
3247 dac = spec->multiout.extra_out_nid[i];
3248 if (!dac) {
3249 if (i > 0 && spec->multiout.extra_out_nid[0])
3250 dac = spec->multiout.extra_out_nid[0];
3251 else
3252 dac = spec->multiout.dac_nids[0];
3253 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003254 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3255 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003256}
3257
Takashi Iwaice764ab2011-04-27 16:35:23 +02003258/*
3259 * multi-io helper
3260 */
3261static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3262 unsigned int location)
3263{
3264 struct alc_spec *spec = codec->spec;
3265 struct auto_pin_cfg *cfg = &spec->autocfg;
3266 int type, i, num_pins = 0;
3267
3268 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3269 for (i = 0; i < cfg->num_inputs; i++) {
3270 hda_nid_t nid = cfg->inputs[i].pin;
3271 hda_nid_t dac;
3272 unsigned int defcfg, caps;
3273 if (cfg->inputs[i].type != type)
3274 continue;
3275 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3276 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3277 continue;
3278 if (location && get_defcfg_location(defcfg) != location)
3279 continue;
3280 caps = snd_hda_query_pin_caps(codec, nid);
3281 if (!(caps & AC_PINCAP_OUT))
3282 continue;
3283 dac = alc_auto_look_for_dac(codec, nid);
3284 if (!dac)
3285 continue;
3286 spec->multi_io[num_pins].pin = nid;
3287 spec->multi_io[num_pins].dac = dac;
3288 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003289 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003290 }
3291 }
3292 spec->multiout.num_dacs = 1;
3293 if (num_pins < 2)
3294 return 0;
3295 return num_pins;
3296}
3297
3298static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3299 struct snd_ctl_elem_info *uinfo)
3300{
3301 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3302 struct alc_spec *spec = codec->spec;
3303
3304 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3305 uinfo->count = 1;
3306 uinfo->value.enumerated.items = spec->multi_ios + 1;
3307 if (uinfo->value.enumerated.item > spec->multi_ios)
3308 uinfo->value.enumerated.item = spec->multi_ios;
3309 sprintf(uinfo->value.enumerated.name, "%dch",
3310 (uinfo->value.enumerated.item + 1) * 2);
3311 return 0;
3312}
3313
3314static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3315 struct snd_ctl_elem_value *ucontrol)
3316{
3317 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3318 struct alc_spec *spec = codec->spec;
3319 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3320 return 0;
3321}
3322
3323static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3324{
3325 struct alc_spec *spec = codec->spec;
3326 hda_nid_t nid = spec->multi_io[idx].pin;
3327
3328 if (!spec->multi_io[idx].ctl_in)
3329 spec->multi_io[idx].ctl_in =
3330 snd_hda_codec_read(codec, nid, 0,
3331 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3332 if (output) {
3333 snd_hda_codec_update_cache(codec, nid, 0,
3334 AC_VERB_SET_PIN_WIDGET_CONTROL,
3335 PIN_OUT);
3336 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3337 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3338 HDA_AMP_MUTE, 0);
3339 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3340 } else {
3341 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3342 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3343 HDA_AMP_MUTE, HDA_AMP_MUTE);
3344 snd_hda_codec_update_cache(codec, nid, 0,
3345 AC_VERB_SET_PIN_WIDGET_CONTROL,
3346 spec->multi_io[idx].ctl_in);
3347 }
3348 return 0;
3349}
3350
3351static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3352 struct snd_ctl_elem_value *ucontrol)
3353{
3354 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3355 struct alc_spec *spec = codec->spec;
3356 int i, ch;
3357
3358 ch = ucontrol->value.enumerated.item[0];
3359 if (ch < 0 || ch > spec->multi_ios)
3360 return -EINVAL;
3361 if (ch == (spec->ext_channel_count - 1) / 2)
3362 return 0;
3363 spec->ext_channel_count = (ch + 1) * 2;
3364 for (i = 0; i < spec->multi_ios; i++)
3365 alc_set_multi_io(codec, i, i < ch);
3366 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003367 if (spec->need_dac_fix && !spec->const_channel_count)
3368 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003369 return 1;
3370}
3371
Takashi Iwaia9111322011-05-02 11:30:18 +02003372static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003373 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3374 .name = "Channel Mode",
3375 .info = alc_auto_ch_mode_info,
3376 .get = alc_auto_ch_mode_get,
3377 .put = alc_auto_ch_mode_put,
3378};
3379
Takashi Iwai23c09b02011-08-19 09:05:35 +02003380static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003381{
3382 struct alc_spec *spec = codec->spec;
3383 struct auto_pin_cfg *cfg = &spec->autocfg;
3384 unsigned int location, defcfg;
3385 int num_pins;
3386
3387 if (cfg->line_outs != 1 ||
Takashi Iwai3fccdfd2011-06-24 10:35:05 +02003388 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003389 return 0;
3390
3391 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3392 location = get_defcfg_location(defcfg);
3393
3394 num_pins = alc_auto_fill_multi_ios(codec, location);
3395 if (num_pins > 0) {
3396 struct snd_kcontrol_new *knew;
3397
3398 knew = alc_kcontrol_new(spec);
3399 if (!knew)
3400 return -ENOMEM;
3401 *knew = alc_auto_channel_mode_enum;
3402 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3403 if (!knew->name)
3404 return -ENOMEM;
3405
3406 spec->multi_ios = num_pins;
3407 spec->ext_channel_count = 2;
3408 spec->multiout.num_dacs = num_pins + 1;
3409 }
3410 return 0;
3411}
3412
Takashi Iwai1d045db2011-07-07 18:23:21 +02003413/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3414 * active input pins
3415 */
3416static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3417{
3418 struct alc_spec *spec = codec->spec;
3419 const struct hda_input_mux *imux;
3420 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3421 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3422 int i, n, nums;
3423
3424 imux = spec->input_mux;
3425 if (!imux)
3426 return;
3427 if (spec->dyn_adc_switch)
3428 return;
3429
3430 nums = 0;
3431 for (n = 0; n < spec->num_adc_nids; n++) {
3432 hda_nid_t cap = spec->private_capsrc_nids[n];
3433 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3434 for (i = 0; i < imux->num_items; i++) {
3435 hda_nid_t pin = spec->imux_pins[i];
3436 if (pin) {
3437 if (get_connection_index(codec, cap, pin) < 0)
3438 break;
3439 } else if (num_conns <= imux->items[i].index)
3440 break;
3441 }
3442 if (i >= imux->num_items) {
3443 adc_nids[nums] = spec->private_adc_nids[n];
3444 capsrc_nids[nums++] = cap;
3445 }
3446 }
3447 if (!nums) {
3448 /* check whether ADC-switch is possible */
3449 if (!alc_check_dyn_adc_switch(codec)) {
3450 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3451 " using fallback 0x%x\n",
3452 codec->chip_name, spec->private_adc_nids[0]);
3453 spec->num_adc_nids = 1;
3454 spec->auto_mic = 0;
3455 return;
3456 }
3457 } else if (nums != spec->num_adc_nids) {
3458 memcpy(spec->private_adc_nids, adc_nids,
3459 nums * sizeof(hda_nid_t));
3460 memcpy(spec->private_capsrc_nids, capsrc_nids,
3461 nums * sizeof(hda_nid_t));
3462 spec->num_adc_nids = nums;
3463 }
3464
3465 if (spec->auto_mic)
3466 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3467 else if (spec->input_mux->num_items == 1)
3468 spec->num_adc_nids = 1; /* reduce to a single ADC */
3469}
3470
3471/*
3472 * initialize ADC paths
3473 */
3474static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3475{
3476 struct alc_spec *spec = codec->spec;
3477 hda_nid_t nid;
3478
3479 nid = spec->adc_nids[adc_idx];
3480 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003481 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003482 snd_hda_codec_write(codec, nid, 0,
3483 AC_VERB_SET_AMP_GAIN_MUTE,
3484 AMP_IN_MUTE(0));
3485 return;
3486 }
3487 if (!spec->capsrc_nids)
3488 return;
3489 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003490 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003491 snd_hda_codec_write(codec, nid, 0,
3492 AC_VERB_SET_AMP_GAIN_MUTE,
3493 AMP_OUT_MUTE);
3494}
3495
3496static void alc_auto_init_input_src(struct hda_codec *codec)
3497{
3498 struct alc_spec *spec = codec->spec;
3499 int c, nums;
3500
3501 for (c = 0; c < spec->num_adc_nids; c++)
3502 alc_auto_init_adc(codec, c);
3503 if (spec->dyn_adc_switch)
3504 nums = 1;
3505 else
3506 nums = spec->num_adc_nids;
3507 for (c = 0; c < nums; c++)
3508 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3509}
3510
3511/* add mic boosts if needed */
3512static int alc_auto_add_mic_boost(struct hda_codec *codec)
3513{
3514 struct alc_spec *spec = codec->spec;
3515 struct auto_pin_cfg *cfg = &spec->autocfg;
3516 int i, err;
3517 int type_idx = 0;
3518 hda_nid_t nid;
3519 const char *prev_label = NULL;
3520
3521 for (i = 0; i < cfg->num_inputs; i++) {
3522 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3523 break;
3524 nid = cfg->inputs[i].pin;
3525 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3526 const char *label;
3527 char boost_label[32];
3528
3529 label = hda_get_autocfg_input_label(codec, cfg, i);
3530 if (prev_label && !strcmp(label, prev_label))
3531 type_idx++;
3532 else
3533 type_idx = 0;
3534 prev_label = label;
3535
3536 snprintf(boost_label, sizeof(boost_label),
3537 "%s Boost Volume", label);
3538 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3539 boost_label, type_idx,
3540 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3541 if (err < 0)
3542 return err;
3543 }
3544 }
3545 return 0;
3546}
3547
3548/* select or unmute the given capsrc route */
3549static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3550 int idx)
3551{
3552 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3553 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3554 HDA_AMP_MUTE, 0);
3555 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3556 snd_hda_codec_write_cache(codec, cap, 0,
3557 AC_VERB_SET_CONNECT_SEL, idx);
3558 }
3559}
3560
3561/* set the default connection to that pin */
3562static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3563{
3564 struct alc_spec *spec = codec->spec;
3565 int i;
3566
3567 if (!pin)
3568 return 0;
3569 for (i = 0; i < spec->num_adc_nids; i++) {
3570 hda_nid_t cap = spec->capsrc_nids ?
3571 spec->capsrc_nids[i] : spec->adc_nids[i];
3572 int idx;
3573
3574 idx = get_connection_index(codec, cap, pin);
3575 if (idx < 0)
3576 continue;
3577 select_or_unmute_capsrc(codec, cap, idx);
3578 return i; /* return the found index */
3579 }
3580 return -1; /* not found */
3581}
3582
3583/* initialize some special cases for input sources */
3584static void alc_init_special_input_src(struct hda_codec *codec)
3585{
3586 struct alc_spec *spec = codec->spec;
3587 int i;
3588
3589 for (i = 0; i < spec->autocfg.num_inputs; i++)
3590 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3591}
3592
3593/* assign appropriate capture mixers */
3594static void set_capture_mixer(struct hda_codec *codec)
3595{
3596 struct alc_spec *spec = codec->spec;
3597 static const struct snd_kcontrol_new *caps[2][3] = {
3598 { alc_capture_mixer_nosrc1,
3599 alc_capture_mixer_nosrc2,
3600 alc_capture_mixer_nosrc3 },
3601 { alc_capture_mixer1,
3602 alc_capture_mixer2,
3603 alc_capture_mixer3 },
3604 };
3605
3606 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003607 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003608 if (!spec->capsrc_nids)
3609 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003610 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003611 return; /* no volume in capsrc, too */
3612 spec->vol_in_capsrc = 1;
3613 }
3614
3615 if (spec->num_adc_nids > 0) {
3616 int mux = 0;
3617 int num_adcs = 0;
3618
3619 if (spec->input_mux && spec->input_mux->num_items > 1)
3620 mux = 1;
3621 if (spec->auto_mic) {
3622 num_adcs = 1;
3623 mux = 0;
3624 } else if (spec->dyn_adc_switch)
3625 num_adcs = 1;
3626 if (!num_adcs) {
3627 if (spec->num_adc_nids > 3)
3628 spec->num_adc_nids = 3;
3629 else if (!spec->num_adc_nids)
3630 return;
3631 num_adcs = spec->num_adc_nids;
3632 }
3633 spec->cap_mixer = caps[mux][num_adcs - 1];
3634 }
3635}
3636
3637/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003638 * standard auto-parser initializations
3639 */
3640static void alc_auto_init_std(struct hda_codec *codec)
3641{
3642 struct alc_spec *spec = codec->spec;
3643 alc_auto_init_multi_out(codec);
3644 alc_auto_init_extra_out(codec);
3645 alc_auto_init_analog_input(codec);
3646 alc_auto_init_input_src(codec);
3647 alc_auto_init_digital(codec);
3648 if (spec->unsol_event)
3649 alc_inithook(codec);
3650}
3651
3652/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003653 * Digital-beep handlers
3654 */
3655#ifdef CONFIG_SND_HDA_INPUT_BEEP
3656#define set_beep_amp(spec, nid, idx, dir) \
3657 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3658
3659static const struct snd_pci_quirk beep_white_list[] = {
3660 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3661 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3662 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3663 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3664 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3665 {}
3666};
3667
3668static inline int has_cdefine_beep(struct hda_codec *codec)
3669{
3670 struct alc_spec *spec = codec->spec;
3671 const struct snd_pci_quirk *q;
3672 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3673 if (q)
3674 return q->value;
3675 return spec->cdefine.enable_pcbeep;
3676}
3677#else
3678#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3679#define has_cdefine_beep(codec) 0
3680#endif
3681
3682/* parse the BIOS configuration and set up the alc_spec */
3683/* return 1 if successful, 0 if the proper config is not found,
3684 * or a negative error code
3685 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003686static int alc_parse_auto_config(struct hda_codec *codec,
3687 const hda_nid_t *ignore_nids,
3688 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003689{
3690 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003691 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003692 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003693
Takashi Iwai23c09b02011-08-19 09:05:35 +02003694 err = snd_hda_parse_pin_def_config(codec, cfg, ignore_nids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003695 if (err < 0)
3696 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003697 if (!cfg->line_outs) {
3698 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003699 spec->multiout.max_channels = 2;
3700 spec->no_analog = 1;
3701 goto dig_only;
3702 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003703 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003704 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003705
Takashi Iwaie23832a2011-08-23 18:16:56 +02003706 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs > 0) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003707 /* use HP as primary out */
3708 cfg->speaker_outs = cfg->line_outs;
3709 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3710 sizeof(cfg->speaker_pins));
3711 cfg->line_outs = cfg->hp_outs;
3712 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3713 cfg->hp_outs = 0;
3714 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3715 cfg->line_out_type = AUTO_PIN_HP_OUT;
3716 }
3717
Takashi Iwai1d045db2011-07-07 18:23:21 +02003718 err = alc_auto_fill_dac_nids(codec);
3719 if (err < 0)
3720 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003721 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003722 if (err < 0)
3723 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003724 err = alc_auto_fill_extra_dacs(codec);
3725 if (err < 0)
3726 return err;
3727 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003728 if (err < 0)
3729 return err;
3730 err = alc_auto_create_hp_out(codec);
3731 if (err < 0)
3732 return err;
3733 err = alc_auto_create_speaker_out(codec);
3734 if (err < 0)
3735 return err;
3736 err = alc_auto_create_input_ctls(codec);
3737 if (err < 0)
3738 return err;
3739
3740 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3741
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003742 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02003743 alc_auto_parse_digital(codec);
3744
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003745 if (!spec->no_analog)
3746 alc_remove_invalid_adc_nids(codec);
3747
3748 if (ssid_nids)
3749 alc_ssid_check(codec, ssid_nids);
3750
3751 if (!spec->no_analog) {
3752 alc_auto_check_switches(codec);
3753 err = alc_auto_add_mic_boost(codec);
3754 if (err < 0)
3755 return err;
3756 }
3757
Takashi Iwai1d045db2011-07-07 18:23:21 +02003758 if (spec->kctls.list)
3759 add_mixer(spec, spec->kctls.list);
3760
Takashi Iwai1d045db2011-07-07 18:23:21 +02003761 return 1;
3762}
3763
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003764static int alc880_parse_auto_config(struct hda_codec *codec)
3765{
3766 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
3767 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
3768 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
3769}
3770
Takashi Iwai1d045db2011-07-07 18:23:21 +02003771#ifdef CONFIG_SND_HDA_POWER_SAVE
3772static const struct hda_amp_list alc880_loopbacks[] = {
3773 { 0x0b, HDA_INPUT, 0 },
3774 { 0x0b, HDA_INPUT, 1 },
3775 { 0x0b, HDA_INPUT, 2 },
3776 { 0x0b, HDA_INPUT, 3 },
3777 { 0x0b, HDA_INPUT, 4 },
3778 { } /* end */
3779};
3780#endif
3781
3782/*
3783 * board setups
3784 */
3785#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3786#define alc_board_config \
3787 snd_hda_check_board_config
3788#define alc_board_codec_sid_config \
3789 snd_hda_check_board_codec_sid_config
3790#include "alc_quirks.c"
3791#else
3792#define alc_board_config(codec, nums, models, tbl) -1
3793#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
3794#define setup_preset(codec, x) /* NOP */
3795#endif
3796
3797/*
3798 * OK, here we have finally the patch for ALC880
3799 */
3800#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3801#include "alc880_quirks.c"
3802#endif
3803
3804static int patch_alc880(struct hda_codec *codec)
3805{
3806 struct alc_spec *spec;
3807 int board_config;
3808 int err;
3809
3810 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3811 if (spec == NULL)
3812 return -ENOMEM;
3813
3814 codec->spec = spec;
3815
3816 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003817 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003818
3819 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
3820 alc880_models, alc880_cfg_tbl);
3821 if (board_config < 0) {
3822 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3823 codec->chip_name);
3824 board_config = ALC_MODEL_AUTO;
3825 }
3826
3827 if (board_config == ALC_MODEL_AUTO) {
3828 /* automatic parse from the BIOS config */
3829 err = alc880_parse_auto_config(codec);
3830 if (err < 0) {
3831 alc_free(codec);
3832 return err;
3833 }
3834#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3835 else if (!err) {
3836 printk(KERN_INFO
3837 "hda_codec: Cannot set up configuration "
3838 "from BIOS. Using 3-stack mode...\n");
3839 board_config = ALC880_3ST;
3840 }
3841#endif
3842 }
3843
Takashi Iwai1d045db2011-07-07 18:23:21 +02003844 if (board_config != ALC_MODEL_AUTO)
3845 setup_preset(codec, &alc880_presets[board_config]);
3846
Takashi Iwai60a6a842011-07-27 14:01:24 +02003847 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003848 alc_auto_fill_adc_caps(codec);
3849 alc_rebuild_imux_for_auto_mic(codec);
3850 alc_remove_invalid_adc_nids(codec);
3851 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003852
3853 if (!spec->no_analog && !spec->cap_mixer)
3854 set_capture_mixer(codec);
3855
3856 if (!spec->no_analog) {
3857 err = snd_hda_attach_beep_device(codec, 0x1);
3858 if (err < 0) {
3859 alc_free(codec);
3860 return err;
3861 }
3862 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3863 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003864
3865 spec->vmaster_nid = 0x0c;
3866
3867 codec->patch_ops = alc_patch_ops;
3868 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02003869 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003870#ifdef CONFIG_SND_HDA_POWER_SAVE
3871 if (!spec->loopback.amplist)
3872 spec->loopback.amplist = alc880_loopbacks;
3873#endif
3874
3875 return 0;
3876}
3877
3878
3879/*
3880 * ALC260 support
3881 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02003882static int alc260_parse_auto_config(struct hda_codec *codec)
3883{
Takashi Iwai1d045db2011-07-07 18:23:21 +02003884 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003885 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
3886 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003887}
3888
Takashi Iwai1d045db2011-07-07 18:23:21 +02003889#ifdef CONFIG_SND_HDA_POWER_SAVE
3890static const struct hda_amp_list alc260_loopbacks[] = {
3891 { 0x07, HDA_INPUT, 0 },
3892 { 0x07, HDA_INPUT, 1 },
3893 { 0x07, HDA_INPUT, 2 },
3894 { 0x07, HDA_INPUT, 3 },
3895 { 0x07, HDA_INPUT, 4 },
3896 { } /* end */
3897};
3898#endif
3899
3900/*
3901 * Pin config fixes
3902 */
3903enum {
3904 PINFIX_HP_DC5750,
3905};
3906
3907static const struct alc_fixup alc260_fixups[] = {
3908 [PINFIX_HP_DC5750] = {
3909 .type = ALC_FIXUP_PINS,
3910 .v.pins = (const struct alc_pincfg[]) {
3911 { 0x11, 0x90130110 }, /* speaker */
3912 { }
3913 }
3914 },
3915};
3916
3917static const struct snd_pci_quirk alc260_fixup_tbl[] = {
3918 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
3919 {}
3920};
3921
3922/*
3923 */
3924#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3925#include "alc260_quirks.c"
3926#endif
3927
3928static int patch_alc260(struct hda_codec *codec)
3929{
3930 struct alc_spec *spec;
3931 int err, board_config;
3932
3933 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3934 if (spec == NULL)
3935 return -ENOMEM;
3936
3937 codec->spec = spec;
3938
3939 spec->mixer_nid = 0x07;
3940
3941 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
3942 alc260_models, alc260_cfg_tbl);
3943 if (board_config < 0) {
3944 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
3945 codec->chip_name);
3946 board_config = ALC_MODEL_AUTO;
3947 }
3948
3949 if (board_config == ALC_MODEL_AUTO) {
3950 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
3951 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
3952 }
3953
3954 if (board_config == ALC_MODEL_AUTO) {
3955 /* automatic parse from the BIOS config */
3956 err = alc260_parse_auto_config(codec);
3957 if (err < 0) {
3958 alc_free(codec);
3959 return err;
3960 }
3961#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3962 else if (!err) {
3963 printk(KERN_INFO
3964 "hda_codec: Cannot set up configuration "
3965 "from BIOS. Using base mode...\n");
3966 board_config = ALC260_BASIC;
3967 }
3968#endif
3969 }
3970
Takashi Iwai1d045db2011-07-07 18:23:21 +02003971 if (board_config != ALC_MODEL_AUTO)
3972 setup_preset(codec, &alc260_presets[board_config]);
3973
Takashi Iwai60a6a842011-07-27 14:01:24 +02003974 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003975 alc_auto_fill_adc_caps(codec);
3976 alc_rebuild_imux_for_auto_mic(codec);
3977 alc_remove_invalid_adc_nids(codec);
3978 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003979
3980 if (!spec->no_analog && !spec->cap_mixer)
3981 set_capture_mixer(codec);
3982
3983 if (!spec->no_analog) {
3984 err = snd_hda_attach_beep_device(codec, 0x1);
3985 if (err < 0) {
3986 alc_free(codec);
3987 return err;
3988 }
3989 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
3990 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003991
3992 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
3993
3994 spec->vmaster_nid = 0x08;
3995
3996 codec->patch_ops = alc_patch_ops;
3997 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02003998 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003999 spec->shutup = alc_eapd_shutup;
4000#ifdef CONFIG_SND_HDA_POWER_SAVE
4001 if (!spec->loopback.amplist)
4002 spec->loopback.amplist = alc260_loopbacks;
4003#endif
4004
4005 return 0;
4006}
4007
4008
4009/*
4010 * ALC882/883/885/888/889 support
4011 *
4012 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4013 * configuration. Each pin widget can choose any input DACs and a mixer.
4014 * Each ADC is connected from a mixer of all inputs. This makes possible
4015 * 6-channel independent captures.
4016 *
4017 * In addition, an independent DAC for the multi-playback (not used in this
4018 * driver yet).
4019 */
4020#ifdef CONFIG_SND_HDA_POWER_SAVE
4021#define alc882_loopbacks alc880_loopbacks
4022#endif
4023
4024/*
4025 * Pin config fixes
4026 */
4027enum {
4028 PINFIX_ABIT_AW9D_MAX,
4029 PINFIX_LENOVO_Y530,
4030 PINFIX_PB_M5210,
4031 PINFIX_ACER_ASPIRE_7736,
4032};
4033
4034static const struct alc_fixup alc882_fixups[] = {
4035 [PINFIX_ABIT_AW9D_MAX] = {
4036 .type = ALC_FIXUP_PINS,
4037 .v.pins = (const struct alc_pincfg[]) {
4038 { 0x15, 0x01080104 }, /* side */
4039 { 0x16, 0x01011012 }, /* rear */
4040 { 0x17, 0x01016011 }, /* clfe */
4041 { }
4042 }
4043 },
4044 [PINFIX_LENOVO_Y530] = {
4045 .type = ALC_FIXUP_PINS,
4046 .v.pins = (const struct alc_pincfg[]) {
4047 { 0x15, 0x99130112 }, /* rear int speakers */
4048 { 0x16, 0x99130111 }, /* subwoofer */
4049 { }
4050 }
4051 },
4052 [PINFIX_PB_M5210] = {
4053 .type = ALC_FIXUP_VERBS,
4054 .v.verbs = (const struct hda_verb[]) {
4055 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4056 {}
4057 }
4058 },
4059 [PINFIX_ACER_ASPIRE_7736] = {
4060 .type = ALC_FIXUP_SKU,
4061 .v.sku = ALC_FIXUP_SKU_IGNORE,
4062 },
4063};
4064
4065static const struct snd_pci_quirk alc882_fixup_tbl[] = {
4066 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4067 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
4068 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
4069 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
4070 {}
4071};
4072
4073/*
4074 * BIOS auto configuration
4075 */
4076/* almost identical with ALC880 parser... */
4077static int alc882_parse_auto_config(struct hda_codec *codec)
4078{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004079 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004080 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4081 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004082}
4083
Takashi Iwai1d045db2011-07-07 18:23:21 +02004084/*
4085 */
4086#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4087#include "alc882_quirks.c"
4088#endif
4089
4090static int patch_alc882(struct hda_codec *codec)
4091{
4092 struct alc_spec *spec;
4093 int err, board_config;
4094
4095 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4096 if (spec == NULL)
4097 return -ENOMEM;
4098
4099 codec->spec = spec;
4100
4101 spec->mixer_nid = 0x0b;
4102
4103 switch (codec->vendor_id) {
4104 case 0x10ec0882:
4105 case 0x10ec0885:
4106 break;
4107 default:
4108 /* ALC883 and variants */
4109 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4110 break;
4111 }
4112
4113 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4114 alc882_models, alc882_cfg_tbl);
4115
4116 if (board_config < 0)
4117 board_config = alc_board_codec_sid_config(codec,
4118 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4119
4120 if (board_config < 0) {
4121 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4122 codec->chip_name);
4123 board_config = ALC_MODEL_AUTO;
4124 }
4125
4126 if (board_config == ALC_MODEL_AUTO) {
4127 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4128 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4129 }
4130
4131 alc_auto_parse_customize_define(codec);
4132
4133 if (board_config == ALC_MODEL_AUTO) {
4134 /* automatic parse from the BIOS config */
4135 err = alc882_parse_auto_config(codec);
4136 if (err < 0) {
4137 alc_free(codec);
4138 return err;
4139 }
4140#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4141 else if (!err) {
4142 printk(KERN_INFO
4143 "hda_codec: Cannot set up configuration "
4144 "from BIOS. Using base mode...\n");
4145 board_config = ALC882_3ST_DIG;
4146 }
4147#endif
4148 }
4149
Takashi Iwai1d045db2011-07-07 18:23:21 +02004150 if (board_config != ALC_MODEL_AUTO)
4151 setup_preset(codec, &alc882_presets[board_config]);
4152
Takashi Iwai60a6a842011-07-27 14:01:24 +02004153 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004154 alc_auto_fill_adc_caps(codec);
4155 alc_rebuild_imux_for_auto_mic(codec);
4156 alc_remove_invalid_adc_nids(codec);
4157 }
4158
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004159 if (!spec->no_analog && !spec->cap_mixer)
4160 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004161
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004162 if (!spec->no_analog && has_cdefine_beep(codec)) {
4163 err = snd_hda_attach_beep_device(codec, 0x1);
4164 if (err < 0) {
4165 alc_free(codec);
4166 return err;
4167 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004168 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004169 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004170
4171 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4172
4173 spec->vmaster_nid = 0x0c;
4174
4175 codec->patch_ops = alc_patch_ops;
4176 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004177 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004178
4179 alc_init_jacks(codec);
4180#ifdef CONFIG_SND_HDA_POWER_SAVE
4181 if (!spec->loopback.amplist)
4182 spec->loopback.amplist = alc882_loopbacks;
4183#endif
4184
4185 return 0;
4186}
4187
4188
4189/*
4190 * ALC262 support
4191 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004192static int alc262_parse_auto_config(struct hda_codec *codec)
4193{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004194 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004195 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4196 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004197}
4198
4199/*
4200 * Pin config fixes
4201 */
4202enum {
4203 PINFIX_FSC_H270,
4204 PINFIX_HP_Z200,
4205};
4206
4207static const struct alc_fixup alc262_fixups[] = {
4208 [PINFIX_FSC_H270] = {
4209 .type = ALC_FIXUP_PINS,
4210 .v.pins = (const struct alc_pincfg[]) {
4211 { 0x14, 0x99130110 }, /* speaker */
4212 { 0x15, 0x0221142f }, /* front HP */
4213 { 0x1b, 0x0121141f }, /* rear HP */
4214 { }
4215 }
4216 },
4217 [PINFIX_HP_Z200] = {
4218 .type = ALC_FIXUP_PINS,
4219 .v.pins = (const struct alc_pincfg[]) {
4220 { 0x16, 0x99130120 }, /* internal speaker */
4221 { }
4222 }
4223 },
4224};
4225
4226static const struct snd_pci_quirk alc262_fixup_tbl[] = {
4227 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", PINFIX_HP_Z200),
4228 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", PINFIX_FSC_H270),
4229 {}
4230};
4231
4232
4233#ifdef CONFIG_SND_HDA_POWER_SAVE
4234#define alc262_loopbacks alc880_loopbacks
4235#endif
4236
Takashi Iwai1d045db2011-07-07 18:23:21 +02004237/*
4238 */
4239#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4240#include "alc262_quirks.c"
4241#endif
4242
4243static int patch_alc262(struct hda_codec *codec)
4244{
4245 struct alc_spec *spec;
4246 int board_config;
4247 int err;
4248
4249 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4250 if (spec == NULL)
4251 return -ENOMEM;
4252
4253 codec->spec = spec;
4254
4255 spec->mixer_nid = 0x0b;
4256
4257#if 0
4258 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4259 * under-run
4260 */
4261 {
4262 int tmp;
4263 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4264 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4265 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4266 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4267 }
4268#endif
4269 alc_auto_parse_customize_define(codec);
4270
4271 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4272
4273 board_config = alc_board_config(codec, ALC262_MODEL_LAST,
4274 alc262_models, alc262_cfg_tbl);
4275
4276 if (board_config < 0) {
4277 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4278 codec->chip_name);
4279 board_config = ALC_MODEL_AUTO;
4280 }
4281
4282 if (board_config == ALC_MODEL_AUTO) {
4283 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4284 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4285 }
4286
4287 if (board_config == ALC_MODEL_AUTO) {
4288 /* automatic parse from the BIOS config */
4289 err = alc262_parse_auto_config(codec);
4290 if (err < 0) {
4291 alc_free(codec);
4292 return err;
4293 }
4294#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4295 else if (!err) {
4296 printk(KERN_INFO
4297 "hda_codec: Cannot set up configuration "
4298 "from BIOS. Using base mode...\n");
4299 board_config = ALC262_BASIC;
4300 }
4301#endif
4302 }
4303
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004304 if (board_config != ALC_MODEL_AUTO)
4305 setup_preset(codec, &alc262_presets[board_config]);
4306
Takashi Iwai60a6a842011-07-27 14:01:24 +02004307 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004308 alc_auto_fill_adc_caps(codec);
4309 alc_rebuild_imux_for_auto_mic(codec);
4310 alc_remove_invalid_adc_nids(codec);
4311 }
4312
4313 if (!spec->no_analog && !spec->cap_mixer)
4314 set_capture_mixer(codec);
4315
Takashi Iwai1d045db2011-07-07 18:23:21 +02004316 if (!spec->no_analog && has_cdefine_beep(codec)) {
4317 err = snd_hda_attach_beep_device(codec, 0x1);
4318 if (err < 0) {
4319 alc_free(codec);
4320 return err;
4321 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004322 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004323 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004324
4325 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4326
4327 spec->vmaster_nid = 0x0c;
4328
4329 codec->patch_ops = alc_patch_ops;
4330 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004331 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004332 spec->shutup = alc_eapd_shutup;
4333
4334 alc_init_jacks(codec);
4335#ifdef CONFIG_SND_HDA_POWER_SAVE
4336 if (!spec->loopback.amplist)
4337 spec->loopback.amplist = alc262_loopbacks;
4338#endif
4339
4340 return 0;
4341}
4342
4343/*
4344 * ALC268
4345 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004346/* bind Beep switches of both NID 0x0f and 0x10 */
4347static const struct hda_bind_ctls alc268_bind_beep_sw = {
4348 .ops = &snd_hda_bind_sw,
4349 .values = {
4350 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4351 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4352 0
4353 },
4354};
4355
4356static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4357 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4358 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4359 { }
4360};
4361
4362/* set PCBEEP vol = 0, mute connections */
4363static const struct hda_verb alc268_beep_init_verbs[] = {
4364 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4365 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4366 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4367 { }
4368};
4369
4370/*
4371 * BIOS auto configuration
4372 */
4373static int alc268_parse_auto_config(struct hda_codec *codec)
4374{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004375 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004376 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004377 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4378 if (err > 0) {
4379 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4380 add_mixer(spec, alc268_beep_mixer);
4381 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004382 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004383 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004384 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004385}
4386
Takashi Iwai1d045db2011-07-07 18:23:21 +02004387/*
4388 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004389static int patch_alc268(struct hda_codec *codec)
4390{
4391 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004392 int i, has_beep, err;
4393
4394 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4395 if (spec == NULL)
4396 return -ENOMEM;
4397
4398 codec->spec = spec;
4399
4400 /* ALC268 has no aa-loopback mixer */
4401
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004402 /* automatic parse from the BIOS config */
4403 err = alc268_parse_auto_config(codec);
4404 if (err < 0) {
4405 alc_free(codec);
4406 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004407 }
4408
Takashi Iwai1d045db2011-07-07 18:23:21 +02004409 has_beep = 0;
4410 for (i = 0; i < spec->num_mixers; i++) {
4411 if (spec->mixers[i] == alc268_beep_mixer) {
4412 has_beep = 1;
4413 break;
4414 }
4415 }
4416
4417 if (has_beep) {
4418 err = snd_hda_attach_beep_device(codec, 0x1);
4419 if (err < 0) {
4420 alc_free(codec);
4421 return err;
4422 }
4423 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4424 /* override the amp caps for beep generator */
4425 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4426 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4427 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4428 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4429 (0 << AC_AMPCAP_MUTE_SHIFT));
4430 }
4431
Takashi Iwai60a6a842011-07-27 14:01:24 +02004432 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004433 alc_auto_fill_adc_caps(codec);
4434 alc_rebuild_imux_for_auto_mic(codec);
4435 alc_remove_invalid_adc_nids(codec);
4436 }
4437
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004438 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004439 set_capture_mixer(codec);
4440
4441 spec->vmaster_nid = 0x02;
4442
4443 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004444 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004445 spec->shutup = alc_eapd_shutup;
4446
4447 alc_init_jacks(codec);
4448
4449 return 0;
4450}
4451
4452/*
4453 * ALC269
4454 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004455#ifdef CONFIG_SND_HDA_POWER_SAVE
4456#define alc269_loopbacks alc880_loopbacks
4457#endif
4458
4459static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4460 .substreams = 1,
4461 .channels_min = 2,
4462 .channels_max = 8,
4463 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4464 /* NID is set in alc_build_pcms */
4465 .ops = {
4466 .open = alc_playback_pcm_open,
4467 .prepare = alc_playback_pcm_prepare,
4468 .cleanup = alc_playback_pcm_cleanup
4469 },
4470};
4471
4472static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
4473 .substreams = 1,
4474 .channels_min = 2,
4475 .channels_max = 2,
4476 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4477 /* NID is set in alc_build_pcms */
4478};
4479
4480#ifdef CONFIG_SND_HDA_POWER_SAVE
4481static int alc269_mic2_for_mute_led(struct hda_codec *codec)
4482{
4483 switch (codec->subsystem_id) {
4484 case 0x103c1586:
4485 return 1;
4486 }
4487 return 0;
4488}
4489
4490static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
4491{
4492 /* update mute-LED according to the speaker mute state */
4493 if (nid == 0x01 || nid == 0x14) {
4494 int pinval;
4495 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
4496 HDA_AMP_MUTE)
4497 pinval = 0x24;
4498 else
4499 pinval = 0x20;
4500 /* mic2 vref pin is used for mute LED control */
4501 snd_hda_codec_update_cache(codec, 0x19, 0,
4502 AC_VERB_SET_PIN_WIDGET_CONTROL,
4503 pinval);
4504 }
4505 return alc_check_power_status(codec, nid);
4506}
4507#endif /* CONFIG_SND_HDA_POWER_SAVE */
4508
4509/* different alc269-variants */
4510enum {
4511 ALC269_TYPE_ALC269VA,
4512 ALC269_TYPE_ALC269VB,
4513 ALC269_TYPE_ALC269VC,
4514};
4515
4516/*
4517 * BIOS auto configuration
4518 */
4519static int alc269_parse_auto_config(struct hda_codec *codec)
4520{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004521 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004522 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
4523 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4524 struct alc_spec *spec = codec->spec;
4525 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
4526 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004527
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004528 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004529}
4530
Takashi Iwai1d045db2011-07-07 18:23:21 +02004531static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4532{
4533 int val = alc_read_coef_idx(codec, 0x04);
4534 if (power_up)
4535 val |= 1 << 11;
4536 else
4537 val &= ~(1 << 11);
4538 alc_write_coef_idx(codec, 0x04, val);
4539}
4540
4541static void alc269_shutup(struct hda_codec *codec)
4542{
4543 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017)
4544 alc269_toggle_power_output(codec, 0);
4545 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4546 alc269_toggle_power_output(codec, 0);
4547 msleep(150);
4548 }
4549}
4550
Takashi Iwai2a439522011-07-26 09:52:50 +02004551#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02004552static int alc269_resume(struct hda_codec *codec)
4553{
4554 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4555 alc269_toggle_power_output(codec, 0);
4556 msleep(150);
4557 }
4558
4559 codec->patch_ops.init(codec);
4560
4561 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4562 alc269_toggle_power_output(codec, 1);
4563 msleep(200);
4564 }
4565
4566 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018)
4567 alc269_toggle_power_output(codec, 1);
4568
4569 snd_hda_codec_resume_amp(codec);
4570 snd_hda_codec_resume_cache(codec);
4571 hda_call_check_power_status(codec, 0x01);
4572 return 0;
4573}
Takashi Iwai2a439522011-07-26 09:52:50 +02004574#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004575
4576static void alc269_fixup_hweq(struct hda_codec *codec,
4577 const struct alc_fixup *fix, int action)
4578{
4579 int coef;
4580
4581 if (action != ALC_FIXUP_ACT_INIT)
4582 return;
4583 coef = alc_read_coef_idx(codec, 0x1e);
4584 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
4585}
4586
4587static void alc271_fixup_dmic(struct hda_codec *codec,
4588 const struct alc_fixup *fix, int action)
4589{
4590 static const struct hda_verb verbs[] = {
4591 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
4592 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
4593 {}
4594 };
4595 unsigned int cfg;
4596
4597 if (strcmp(codec->chip_name, "ALC271X"))
4598 return;
4599 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
4600 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
4601 snd_hda_sequence_write(codec, verbs);
4602}
4603
Takashi Iwai017f2a12011-07-09 14:42:25 +02004604static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4605 const struct alc_fixup *fix, int action)
4606{
4607 struct alc_spec *spec = codec->spec;
4608
4609 if (action != ALC_FIXUP_ACT_PROBE)
4610 return;
4611
4612 /* Due to a hardware problem on Lenovo Ideadpad, we need to
4613 * fix the sample rate of analog I/O to 44.1kHz
4614 */
4615 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
4616 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4617}
4618
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004619static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4620 const struct alc_fixup *fix, int action)
4621{
4622 int coef;
4623
4624 if (action != ALC_FIXUP_ACT_INIT)
4625 return;
4626 /* The digital-mic unit sends PDM (differential signal) instead of
4627 * the standard PCM, thus you can't record a valid mono stream as is.
4628 * Below is a workaround specific to ALC269 to control the dmic
4629 * signal source as mono.
4630 */
4631 coef = alc_read_coef_idx(codec, 0x07);
4632 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4633}
4634
Takashi Iwai24519912011-08-16 15:08:49 +02004635static void alc269_quanta_automute(struct hda_codec *codec)
4636{
4637 update_speakers(codec);
4638
4639 snd_hda_codec_write(codec, 0x20, 0,
4640 AC_VERB_SET_COEF_INDEX, 0x0c);
4641 snd_hda_codec_write(codec, 0x20, 0,
4642 AC_VERB_SET_PROC_COEF, 0x680);
4643
4644 snd_hda_codec_write(codec, 0x20, 0,
4645 AC_VERB_SET_COEF_INDEX, 0x0c);
4646 snd_hda_codec_write(codec, 0x20, 0,
4647 AC_VERB_SET_PROC_COEF, 0x480);
4648}
4649
4650static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4651 const struct alc_fixup *fix, int action)
4652{
4653 struct alc_spec *spec = codec->spec;
4654 if (action != ALC_FIXUP_ACT_PROBE)
4655 return;
4656 spec->automute_hook = alc269_quanta_automute;
4657}
4658
Takashi Iwai1d045db2011-07-07 18:23:21 +02004659enum {
4660 ALC269_FIXUP_SONY_VAIO,
4661 ALC275_FIXUP_SONY_VAIO_GPIO2,
4662 ALC269_FIXUP_DELL_M101Z,
4663 ALC269_FIXUP_SKU_IGNORE,
4664 ALC269_FIXUP_ASUS_G73JW,
4665 ALC269_FIXUP_LENOVO_EAPD,
4666 ALC275_FIXUP_SONY_HWEQ,
4667 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02004668 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004669 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02004670 ALC269_FIXUP_QUANTA_MUTE,
4671 ALC269_FIXUP_LIFEBOOK,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004672};
4673
4674static const struct alc_fixup alc269_fixups[] = {
4675 [ALC269_FIXUP_SONY_VAIO] = {
4676 .type = ALC_FIXUP_VERBS,
4677 .v.verbs = (const struct hda_verb[]) {
4678 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
4679 {}
4680 }
4681 },
4682 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
4683 .type = ALC_FIXUP_VERBS,
4684 .v.verbs = (const struct hda_verb[]) {
4685 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
4686 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
4687 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
4688 { }
4689 },
4690 .chained = true,
4691 .chain_id = ALC269_FIXUP_SONY_VAIO
4692 },
4693 [ALC269_FIXUP_DELL_M101Z] = {
4694 .type = ALC_FIXUP_VERBS,
4695 .v.verbs = (const struct hda_verb[]) {
4696 /* Enables internal speaker */
4697 {0x20, AC_VERB_SET_COEF_INDEX, 13},
4698 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
4699 {}
4700 }
4701 },
4702 [ALC269_FIXUP_SKU_IGNORE] = {
4703 .type = ALC_FIXUP_SKU,
4704 .v.sku = ALC_FIXUP_SKU_IGNORE,
4705 },
4706 [ALC269_FIXUP_ASUS_G73JW] = {
4707 .type = ALC_FIXUP_PINS,
4708 .v.pins = (const struct alc_pincfg[]) {
4709 { 0x17, 0x99130111 }, /* subwoofer */
4710 { }
4711 }
4712 },
4713 [ALC269_FIXUP_LENOVO_EAPD] = {
4714 .type = ALC_FIXUP_VERBS,
4715 .v.verbs = (const struct hda_verb[]) {
4716 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
4717 {}
4718 }
4719 },
4720 [ALC275_FIXUP_SONY_HWEQ] = {
4721 .type = ALC_FIXUP_FUNC,
4722 .v.func = alc269_fixup_hweq,
4723 .chained = true,
4724 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
4725 },
4726 [ALC271_FIXUP_DMIC] = {
4727 .type = ALC_FIXUP_FUNC,
4728 .v.func = alc271_fixup_dmic,
4729 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02004730 [ALC269_FIXUP_PCM_44K] = {
4731 .type = ALC_FIXUP_FUNC,
4732 .v.func = alc269_fixup_pcm_44k,
4733 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004734 [ALC269_FIXUP_STEREO_DMIC] = {
4735 .type = ALC_FIXUP_FUNC,
4736 .v.func = alc269_fixup_stereo_dmic,
4737 },
Takashi Iwai24519912011-08-16 15:08:49 +02004738 [ALC269_FIXUP_QUANTA_MUTE] = {
4739 .type = ALC_FIXUP_FUNC,
4740 .v.func = alc269_fixup_quanta_mute,
4741 },
4742 [ALC269_FIXUP_LIFEBOOK] = {
4743 .type = ALC_FIXUP_PINS,
4744 .v.pins = (const struct alc_pincfg[]) {
4745 { 0x1a, 0x2101103f }, /* dock line-out */
4746 { 0x1b, 0x23a11040 }, /* dock mic-in */
4747 { }
4748 },
4749 .chained = true,
4750 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4751 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004752};
4753
4754static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02004755 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02004756 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4757 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4758 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4759 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4760 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004761 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4762 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4763 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4764 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4765 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4766 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02004767 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004768 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4769 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4770 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4771 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4772 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02004773 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02004774 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004775 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
4776 {}
4777};
4778
4779
4780static int alc269_fill_coef(struct hda_codec *codec)
4781{
4782 int val;
4783
4784 if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) {
4785 alc_write_coef_idx(codec, 0xf, 0x960b);
4786 alc_write_coef_idx(codec, 0xe, 0x8817);
4787 }
4788
4789 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) {
4790 alc_write_coef_idx(codec, 0xf, 0x960b);
4791 alc_write_coef_idx(codec, 0xe, 0x8814);
4792 }
4793
4794 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) {
4795 val = alc_read_coef_idx(codec, 0x04);
4796 /* Power up output pin */
4797 alc_write_coef_idx(codec, 0x04, val | (1<<11));
4798 }
4799
4800 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) {
4801 val = alc_read_coef_idx(codec, 0xd);
4802 if ((val & 0x0c00) >> 10 != 0x1) {
4803 /* Capless ramp up clock control */
4804 alc_write_coef_idx(codec, 0xd, val | (1<<10));
4805 }
4806 val = alc_read_coef_idx(codec, 0x17);
4807 if ((val & 0x01c0) >> 6 != 0x4) {
4808 /* Class D power on reset */
4809 alc_write_coef_idx(codec, 0x17, val | (1<<7));
4810 }
4811 }
4812
4813 val = alc_read_coef_idx(codec, 0xd); /* Class D */
4814 alc_write_coef_idx(codec, 0xd, val | (1<<14));
4815
4816 val = alc_read_coef_idx(codec, 0x4); /* HP */
4817 alc_write_coef_idx(codec, 0x4, val | (1<<11));
4818
4819 return 0;
4820}
4821
4822/*
4823 */
4824#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4825#include "alc269_quirks.c"
4826#endif
4827
4828static int patch_alc269(struct hda_codec *codec)
4829{
4830 struct alc_spec *spec;
4831 int board_config, coef;
4832 int err;
4833
4834 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4835 if (spec == NULL)
4836 return -ENOMEM;
4837
4838 codec->spec = spec;
4839
4840 spec->mixer_nid = 0x0b;
4841
4842 alc_auto_parse_customize_define(codec);
4843
4844 if (codec->vendor_id == 0x10ec0269) {
4845 spec->codec_variant = ALC269_TYPE_ALC269VA;
4846 coef = alc_read_coef_idx(codec, 0);
4847 if ((coef & 0x00f0) == 0x0010) {
4848 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
4849 spec->cdefine.platform_type == 1) {
4850 alc_codec_rename(codec, "ALC271X");
4851 } else if ((coef & 0xf000) == 0x2000) {
4852 alc_codec_rename(codec, "ALC259");
4853 } else if ((coef & 0xf000) == 0x3000) {
4854 alc_codec_rename(codec, "ALC258");
4855 } else if ((coef & 0xfff0) == 0x3010) {
4856 alc_codec_rename(codec, "ALC277");
4857 } else {
4858 alc_codec_rename(codec, "ALC269VB");
4859 }
4860 spec->codec_variant = ALC269_TYPE_ALC269VB;
4861 } else if ((coef & 0x00f0) == 0x0020) {
4862 if (coef == 0xa023)
4863 alc_codec_rename(codec, "ALC259");
4864 else if (coef == 0x6023)
4865 alc_codec_rename(codec, "ALC281X");
4866 else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
4867 codec->bus->pci->subsystem_device == 0x21f3)
4868 alc_codec_rename(codec, "ALC3202");
4869 else
4870 alc_codec_rename(codec, "ALC269VC");
4871 spec->codec_variant = ALC269_TYPE_ALC269VC;
4872 } else
4873 alc_fix_pll_init(codec, 0x20, 0x04, 15);
4874 alc269_fill_coef(codec);
4875 }
4876
4877 board_config = alc_board_config(codec, ALC269_MODEL_LAST,
4878 alc269_models, alc269_cfg_tbl);
4879
4880 if (board_config < 0) {
4881 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4882 codec->chip_name);
4883 board_config = ALC_MODEL_AUTO;
4884 }
4885
4886 if (board_config == ALC_MODEL_AUTO) {
4887 alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
4888 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4889 }
4890
4891 if (board_config == ALC_MODEL_AUTO) {
4892 /* automatic parse from the BIOS config */
4893 err = alc269_parse_auto_config(codec);
4894 if (err < 0) {
4895 alc_free(codec);
4896 return err;
4897 }
4898#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4899 else if (!err) {
4900 printk(KERN_INFO
4901 "hda_codec: Cannot set up configuration "
4902 "from BIOS. Using base mode...\n");
4903 board_config = ALC269_BASIC;
4904 }
4905#endif
4906 }
4907
Takashi Iwai1d045db2011-07-07 18:23:21 +02004908 if (board_config != ALC_MODEL_AUTO)
4909 setup_preset(codec, &alc269_presets[board_config]);
4910
Takashi Iwai60a6a842011-07-27 14:01:24 +02004911 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004912 alc_auto_fill_adc_caps(codec);
4913 alc_rebuild_imux_for_auto_mic(codec);
4914 alc_remove_invalid_adc_nids(codec);
4915 }
4916
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004917 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004918 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004919
4920 if (!spec->no_analog && has_cdefine_beep(codec)) {
4921 err = snd_hda_attach_beep_device(codec, 0x1);
4922 if (err < 0) {
4923 alc_free(codec);
4924 return err;
4925 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004926 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004927 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004928
4929 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4930
4931 spec->vmaster_nid = 0x02;
4932
4933 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02004934#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02004935 codec->patch_ops.resume = alc269_resume;
4936#endif
4937 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaibe9bc372011-07-08 16:01:47 +02004938 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004939 spec->shutup = alc269_shutup;
4940
4941 alc_init_jacks(codec);
4942#ifdef CONFIG_SND_HDA_POWER_SAVE
4943 if (!spec->loopback.amplist)
4944 spec->loopback.amplist = alc269_loopbacks;
4945 if (alc269_mic2_for_mute_led(codec))
4946 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
4947#endif
4948
4949 return 0;
4950}
4951
4952/*
4953 * ALC861
4954 */
4955
Takashi Iwai1d045db2011-07-07 18:23:21 +02004956static int alc861_parse_auto_config(struct hda_codec *codec)
4957{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004958 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004959 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
4960 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004961}
4962
Takashi Iwai1d045db2011-07-07 18:23:21 +02004963#ifdef CONFIG_SND_HDA_POWER_SAVE
4964static const struct hda_amp_list alc861_loopbacks[] = {
4965 { 0x15, HDA_INPUT, 0 },
4966 { 0x15, HDA_INPUT, 1 },
4967 { 0x15, HDA_INPUT, 2 },
4968 { 0x15, HDA_INPUT, 3 },
4969 { } /* end */
4970};
4971#endif
4972
4973
4974/* Pin config fixes */
4975enum {
4976 PINFIX_FSC_AMILO_PI1505,
4977};
4978
4979static const struct alc_fixup alc861_fixups[] = {
4980 [PINFIX_FSC_AMILO_PI1505] = {
4981 .type = ALC_FIXUP_PINS,
4982 .v.pins = (const struct alc_pincfg[]) {
4983 { 0x0b, 0x0221101f }, /* HP */
4984 { 0x0f, 0x90170310 }, /* speaker */
4985 { }
4986 }
4987 },
4988};
4989
4990static const struct snd_pci_quirk alc861_fixup_tbl[] = {
4991 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
4992 {}
4993};
4994
4995/*
4996 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004997static int patch_alc861(struct hda_codec *codec)
4998{
4999 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000 int err;
5001
5002 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5003 if (spec == NULL)
5004 return -ENOMEM;
5005
5006 codec->spec = spec;
5007
5008 spec->mixer_nid = 0x15;
5009
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005010 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5011 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005012
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005013 /* automatic parse from the BIOS config */
5014 err = alc861_parse_auto_config(codec);
5015 if (err < 0) {
5016 alc_free(codec);
5017 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005018 }
5019
Takashi Iwai60a6a842011-07-27 14:01:24 +02005020 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005021 alc_auto_fill_adc_caps(codec);
5022 alc_rebuild_imux_for_auto_mic(codec);
5023 alc_remove_invalid_adc_nids(codec);
5024 }
5025
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005026 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005027 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005028
5029 if (!spec->no_analog) {
5030 err = snd_hda_attach_beep_device(codec, 0x23);
5031 if (err < 0) {
5032 alc_free(codec);
5033 return err;
5034 }
5035 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5036 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005037
5038 spec->vmaster_nid = 0x03;
5039
5040 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5041
5042 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005043 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005044#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005045 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005046 if (!spec->loopback.amplist)
5047 spec->loopback.amplist = alc861_loopbacks;
5048#endif
5049
5050 return 0;
5051}
5052
5053/*
5054 * ALC861-VD support
5055 *
5056 * Based on ALC882
5057 *
5058 * In addition, an independent DAC
5059 */
5060#ifdef CONFIG_SND_HDA_POWER_SAVE
5061#define alc861vd_loopbacks alc880_loopbacks
5062#endif
5063
Takashi Iwai1d045db2011-07-07 18:23:21 +02005064static int alc861vd_parse_auto_config(struct hda_codec *codec)
5065{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005066 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005067 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5068 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005069}
5070
Takashi Iwai1d045db2011-07-07 18:23:21 +02005071enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005072 ALC660VD_FIX_ASUS_GPIO1,
5073 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005074};
5075
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005076/* exclude VREF80 */
5077static void alc861vd_fixup_dallas(struct hda_codec *codec,
5078 const struct alc_fixup *fix, int action)
5079{
5080 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5081 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5082 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5083 }
5084}
5085
Takashi Iwai1d045db2011-07-07 18:23:21 +02005086static const struct alc_fixup alc861vd_fixups[] = {
5087 [ALC660VD_FIX_ASUS_GPIO1] = {
5088 .type = ALC_FIXUP_VERBS,
5089 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005090 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005091 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5092 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5093 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5094 { }
5095 }
5096 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005097 [ALC861VD_FIX_DALLAS] = {
5098 .type = ALC_FIXUP_FUNC,
5099 .v.func = alc861vd_fixup_dallas,
5100 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005101};
5102
5103static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005104 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005105 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005106 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005107 {}
5108};
5109
5110static const struct hda_verb alc660vd_eapd_verbs[] = {
5111 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5112 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5113 { }
5114};
5115
5116/*
5117 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005118static int patch_alc861vd(struct hda_codec *codec)
5119{
5120 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005121 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005122
5123 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5124 if (spec == NULL)
5125 return -ENOMEM;
5126
5127 codec->spec = spec;
5128
5129 spec->mixer_nid = 0x0b;
5130
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005131 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5132 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005133
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005134 /* automatic parse from the BIOS config */
5135 err = alc861vd_parse_auto_config(codec);
5136 if (err < 0) {
5137 alc_free(codec);
5138 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005139 }
5140
Takashi Iwai1d045db2011-07-07 18:23:21 +02005141 if (codec->vendor_id == 0x10ec0660) {
5142 /* always turn on EAPD */
5143 add_verb(spec, alc660vd_eapd_verbs);
5144 }
5145
Takashi Iwai60a6a842011-07-27 14:01:24 +02005146 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005147 alc_auto_fill_adc_caps(codec);
5148 alc_rebuild_imux_for_auto_mic(codec);
5149 alc_remove_invalid_adc_nids(codec);
5150 }
5151
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005152 if (!spec->no_analog && !spec->cap_mixer)
5153 set_capture_mixer(codec);
5154
5155 if (!spec->no_analog) {
5156 err = snd_hda_attach_beep_device(codec, 0x23);
5157 if (err < 0) {
5158 alc_free(codec);
5159 return err;
5160 }
5161 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5162 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005163
5164 spec->vmaster_nid = 0x02;
5165
5166 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5167
5168 codec->patch_ops = alc_patch_ops;
5169
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005170 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005171 spec->shutup = alc_eapd_shutup;
5172#ifdef CONFIG_SND_HDA_POWER_SAVE
5173 if (!spec->loopback.amplist)
5174 spec->loopback.amplist = alc861vd_loopbacks;
5175#endif
5176
5177 return 0;
5178}
5179
5180/*
5181 * ALC662 support
5182 *
5183 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5184 * configuration. Each pin widget can choose any input DACs and a mixer.
5185 * Each ADC is connected from a mixer of all inputs. This makes possible
5186 * 6-channel independent captures.
5187 *
5188 * In addition, an independent DAC for the multi-playback (not used in this
5189 * driver yet).
5190 */
5191#ifdef CONFIG_SND_HDA_POWER_SAVE
5192#define alc662_loopbacks alc880_loopbacks
5193#endif
5194
5195/*
5196 * BIOS auto configuration
5197 */
5198
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005199static int alc662_parse_auto_config(struct hda_codec *codec)
5200{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005201 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005202 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5203 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5204 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005205
Kailang Yang6227cdc2010-02-25 08:36:52 +01005206 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5207 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005208 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005209 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005210 ssids = alc662_ssids;
5211 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005212}
5213
Todd Broch6be79482010-12-07 16:51:05 -08005214static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005215 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005216{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005217 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005218 return;
Todd Broch6be79482010-12-07 16:51:05 -08005219 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5220 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5221 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5222 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5223 (0 << AC_AMPCAP_MUTE_SHIFT)))
5224 printk(KERN_WARNING
5225 "hda_codec: failed to override amp caps for NID 0x2\n");
5226}
5227
David Henningsson6cb3b702010-09-09 08:51:44 +02005228enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005229 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005230 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005231 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005232 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005233 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005234 ALC662_FIXUP_HP_RP5800,
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005235 ALC662_FIXUP_ECS,
David Henningsson6cb3b702010-09-09 08:51:44 +02005236};
5237
5238static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005239 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005240 .type = ALC_FIXUP_PINS,
5241 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005242 { 0x15, 0x99130112 }, /* subwoofer */
5243 { }
5244 }
5245 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005246 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005247 .type = ALC_FIXUP_PINS,
5248 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005249 { 0x17, 0x99130112 }, /* subwoofer */
5250 { }
5251 }
5252 },
Todd Broch6be79482010-12-07 16:51:05 -08005253 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005254 .type = ALC_FIXUP_FUNC,
5255 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005256 },
5257 [ALC662_FIXUP_CZC_P10T] = {
5258 .type = ALC_FIXUP_VERBS,
5259 .v.verbs = (const struct hda_verb[]) {
5260 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5261 {}
5262 }
5263 },
David Henningsson94024cd2011-04-29 14:10:55 +02005264 [ALC662_FIXUP_SKU_IGNORE] = {
5265 .type = ALC_FIXUP_SKU,
5266 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005267 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005268 [ALC662_FIXUP_HP_RP5800] = {
5269 .type = ALC_FIXUP_PINS,
5270 .v.pins = (const struct alc_pincfg[]) {
5271 { 0x14, 0x0221201f }, /* HP out */
5272 { }
5273 },
5274 .chained = true,
5275 .chain_id = ALC662_FIXUP_SKU_IGNORE
5276 },
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005277 [ALC662_FIXUP_ECS] = {
5278 .type = ALC_FIXUP_PINS,
5279 .v.pins = (const struct alc_pincfg[]) {
5280 { 0x14, 0x99130110 }, /* speaker */
5281 { 0x18, 0x01a19820 }, /* mic */
5282 { 0x19, 0x99a3092f }, /* int-mic */
5283 { 0x1b, 0x0121401f }, /* HP out */
5284 { }
5285 },
5286 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005287};
5288
Takashi Iwaia9111322011-05-02 11:30:18 +02005289static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005290 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ECS),
David Henningssona6c47a82011-02-10 15:39:19 +01005291 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02005292 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04005293 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005294 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005295 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ECS),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05005296 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06005297 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02005298 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01005299 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
David Henningsson6cb3b702010-09-09 08:51:44 +02005300 {}
5301};
5302
Todd Broch6be79482010-12-07 16:51:05 -08005303static const struct alc_model_fixup alc662_fixup_models[] = {
5304 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5305 {}
5306};
David Henningsson6cb3b702010-09-09 08:51:44 +02005307
5308
Takashi Iwai1d045db2011-07-07 18:23:21 +02005309/*
5310 */
5311#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5312#include "alc662_quirks.c"
5313#endif
5314
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005315static int patch_alc662(struct hda_codec *codec)
5316{
5317 struct alc_spec *spec;
5318 int err, board_config;
Kailang Yang693194f2010-10-21 08:51:48 +02005319 int coef;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005320
5321 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5322 if (!spec)
5323 return -ENOMEM;
5324
5325 codec->spec = spec;
5326
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005327 spec->mixer_nid = 0x0b;
5328
Kailang Yangda00c242010-03-19 11:23:45 +01005329 alc_auto_parse_customize_define(codec);
5330
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02005331 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5332
Kailang Yang693194f2010-10-21 08:51:48 +02005333 coef = alc_read_coef_idx(codec, 0);
5334 if (coef == 0x8020 || coef == 0x8011)
Kailang Yangc027ddc2010-03-19 11:33:06 +01005335 alc_codec_rename(codec, "ALC661");
Kailang Yang693194f2010-10-21 08:51:48 +02005336 else if (coef & (1 << 14) &&
5337 codec->bus->pci->subsystem_vendor == 0x1025 &&
5338 spec->cdefine.platform_type == 1)
Kailang Yangc027ddc2010-03-19 11:33:06 +01005339 alc_codec_rename(codec, "ALC272X");
Kailang Yang693194f2010-10-21 08:51:48 +02005340 else if (coef == 0x4011)
5341 alc_codec_rename(codec, "ALC656");
Kailang Yang274693f2009-12-03 10:07:50 +01005342
Takashi Iwai1d045db2011-07-07 18:23:21 +02005343 board_config = alc_board_config(codec, ALC662_MODEL_LAST,
5344 alc662_models, alc662_cfg_tbl);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005345 if (board_config < 0) {
Takashi Iwai9a11f1a2009-07-28 16:01:20 +02005346 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5347 codec->chip_name);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005348 board_config = ALC_MODEL_AUTO;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005349 }
5350
Takashi Iwai1d045db2011-07-07 18:23:21 +02005351 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005352 alc_pick_fixup(codec, alc662_fixup_models,
5353 alc662_fixup_tbl, alc662_fixups);
5354 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005355 /* automatic parse from the BIOS config */
5356 err = alc662_parse_auto_config(codec);
5357 if (err < 0) {
5358 alc_free(codec);
5359 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005360 }
5361#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5362 else if (!err) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005363 printk(KERN_INFO
5364 "hda_codec: Cannot set up configuration "
5365 "from BIOS. Using base mode...\n");
5366 board_config = ALC662_3ST_2ch_DIG;
5367 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005368#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005369 }
5370
Takashi Iwai1d045db2011-07-07 18:23:21 +02005371 if (board_config != ALC_MODEL_AUTO)
Takashi Iwaie9c364c2009-08-11 17:16:13 +02005372 setup_preset(codec, &alc662_presets[board_config]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005373
Takashi Iwai60a6a842011-07-27 14:01:24 +02005374 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005375 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02005376 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02005377 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02005378 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005379
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005380 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02005381 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01005382
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005383 if (!spec->no_analog && has_cdefine_beep(codec)) {
5384 err = snd_hda_attach_beep_device(codec, 0x1);
5385 if (err < 0) {
5386 alc_free(codec);
5387 return err;
5388 }
Kailang Yangda00c242010-03-19 11:23:45 +01005389 switch (codec->vendor_id) {
5390 case 0x10ec0662:
5391 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5392 break;
5393 case 0x10ec0272:
5394 case 0x10ec0663:
5395 case 0x10ec0665:
5396 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
5397 break;
5398 case 0x10ec0273:
5399 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
5400 break;
5401 }
Kailang Yangcec27c82010-02-04 14:18:18 +01005402 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01005403 spec->vmaster_nid = 0x02;
5404
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005405 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5406
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005407 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005408 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02005409 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c7161532011-04-07 10:37:16 +02005410 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02005411
Kailang Yangbf1b0222010-10-21 08:49:56 +02005412 alc_init_jacks(codec);
5413
Takashi Iwaicb53c622007-08-10 17:21:45 +02005414#ifdef CONFIG_SND_HDA_POWER_SAVE
5415 if (!spec->loopback.amplist)
5416 spec->loopback.amplist = alc662_loopbacks;
5417#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005418
5419 return 0;
5420}
5421
Kailang Yang274693f2009-12-03 10:07:50 +01005422static int patch_alc888(struct hda_codec *codec)
5423{
5424 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
5425 kfree(codec->chip_name);
Kailang Yang01e0f132010-11-22 10:59:36 +01005426 if (codec->vendor_id == 0x10ec0887)
5427 codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
5428 else
5429 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
Takashi Iwaiac2c92e2009-12-03 10:14:10 +01005430 if (!codec->chip_name) {
5431 alc_free(codec);
Kailang Yang274693f2009-12-03 10:07:50 +01005432 return -ENOMEM;
Takashi Iwaiac2c92e2009-12-03 10:14:10 +01005433 }
5434 return patch_alc662(codec);
Kailang Yang274693f2009-12-03 10:07:50 +01005435 }
Takashi Iwaiac2c92e2009-12-03 10:14:10 +01005436 return patch_alc882(codec);
Kailang Yang274693f2009-12-03 10:07:50 +01005437}
5438
Kailang Yangb478b992011-05-18 11:51:15 +02005439static int patch_alc899(struct hda_codec *codec)
5440{
5441 if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) {
5442 kfree(codec->chip_name);
5443 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
5444 }
5445 return patch_alc882(codec);
5446}
5447
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005448/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005449 * ALC680 support
5450 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005451
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005452static int alc680_parse_auto_config(struct hda_codec *codec)
5453{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005454 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005455}
5456
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005457/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005458 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005459static int patch_alc680(struct hda_codec *codec)
5460{
5461 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005462 int err;
5463
5464 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5465 if (spec == NULL)
5466 return -ENOMEM;
5467
5468 codec->spec = spec;
5469
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02005470 /* ALC680 has no aa-loopback mixer */
5471
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005472 /* automatic parse from the BIOS config */
5473 err = alc680_parse_auto_config(codec);
5474 if (err < 0) {
5475 alc_free(codec);
5476 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005477 }
5478
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005479 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005480 set_capture_mixer(codec);
5481
5482 spec->vmaster_nid = 0x02;
5483
5484 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02005485 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005486
5487 return 0;
5488}
5489
5490/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491 * patch entries
5492 */
Takashi Iwaia9111322011-05-02 11:30:18 +02005493static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02005494 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005495 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005496 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005497 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02005498 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01005499 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005500 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02005501 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01005502 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02005503 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005504 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005505 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005506 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
5507 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
5508 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005509 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005510 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005511 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5512 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02005513 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01005514 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01005515 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02005516 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01005517 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005518 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02005519 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02005520 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005521 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02005522 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005523 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01005524 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Kailang Yang01e0f132010-11-22 10:59:36 +01005525 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 },
Kailang Yang44426082008-10-15 11:18:05 +02005526 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02005527 .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01005528 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02005529 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01005530 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Kailang Yangb478b992011-05-18 11:51:15 +02005531 { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 {} /* terminator */
5533};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01005534
5535MODULE_ALIAS("snd-hda-codec-id:10ec*");
5536
5537MODULE_LICENSE("GPL");
5538MODULE_DESCRIPTION("Realtek HD-audio codec");
5539
5540static struct hda_codec_preset_list realtek_list = {
5541 .preset = snd_hda_preset_realtek,
5542 .owner = THIS_MODULE,
5543};
5544
5545static int __init patch_realtek_init(void)
5546{
5547 return snd_hda_add_codec_preset(&realtek_list);
5548}
5549
5550static void __exit patch_realtek_exit(void)
5551{
5552 snd_hda_delete_codec_preset(&realtek_list);
5553}
5554
5555module_init(patch_realtek_init)
5556module_exit(patch_realtek_exit)