blob: da9d2276e68bf5c2287b4cc3f36173a369d529ea [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e42006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083struct alc_spec {
84 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020085 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010088 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Takashi Iwai2d9c6482009-10-13 08:06:55 +020090 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020091 * don't forget NULL
92 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020093 */
94 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Takashi Iwaiaa563af2009-07-31 10:05:11 +020096 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020097 const struct hda_pcm_stream *stream_analog_playback;
98 const struct hda_pcm_stream *stream_analog_capture;
99 const struct hda_pcm_stream *stream_analog_alt_playback;
100 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200102 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200103 const struct hda_pcm_stream *stream_digital_playback;
104 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200107 struct hda_multi_out multiout; /* playback set-up
108 * max_channels, dacs must be set
109 * dig_out_nid and hp_nid are optional
110 */
Takashi Iwai63300792008-01-24 15:31:36 +0100111 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100112 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100113 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* capture */
116 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200117 const hda_nid_t *adc_nids;
118 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200119 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200120 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwai527e4d72011-10-27 16:33:27 +0200121 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
122 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Takashi Iwai840b64c2010-07-13 22:49:01 +0200124 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200125 hda_nid_t cur_adc;
126 unsigned int cur_adc_stream_tag;
127 unsigned int cur_adc_format;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200130 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 const struct hda_input_mux *input_mux;
132 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200133 hda_nid_t ext_mic_pin;
134 hda_nid_t dock_mic_pin;
135 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100138 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200140 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200141 int const_channel_count;
142 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100145 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200146
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200147 /* dynamic controls, init_verbs and input_mux */
148 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100149 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200150 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200151 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200152 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai49535502009-06-30 15:28:30 +0200153 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200155 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
156 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
157 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100158
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100159 /* hooks */
160 void (*init_hook)(struct hda_codec *codec);
161 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100162#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500163 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200165 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200166 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100167
Takashi Iwai834be882006-03-01 14:16:17 +0100168 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200169 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200170 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200171 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200172 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200173 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200174 unsigned int automute_speaker:1; /* automute speaker outputs */
175 unsigned int automute_lo:1; /* automute LO outputs */
176 unsigned int detect_hp:1; /* Headphone detection enabled */
177 unsigned int detect_lo:1; /* Line-out detection enabled */
178 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
179 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200180
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100181 /* other flags */
182 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200183 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100184 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200185 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200186 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100187 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200188
189 /* auto-mute control */
190 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200191 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200192
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200193 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200194 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100195
Takashi Iwai2134ea42008-01-10 16:53:55 +0100196 /* for virtual master */
197 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200198#ifdef CONFIG_SND_HDA_POWER_SAVE
199 struct hda_loopback_check loopback;
200#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200201
202 /* for PLL fix */
203 hda_nid_t pll_nid;
204 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200205 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100206
207 /* fix-up list */
208 int fixup_id;
209 const struct alc_fixup *fixup_list;
210 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200211
212 /* multi-io */
213 int multi_ios;
214 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200215
216 /* bind volumes */
217 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100218};
219
Takashi Iwai1d045db2011-07-07 18:23:21 +0200220#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Takashi Iwai44c02402011-07-08 15:14:19 +0200222static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
223 int dir, unsigned int bits)
224{
225 if (!nid)
226 return false;
227 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
228 if (query_amp_caps(codec, nid, dir) & bits)
229 return true;
230 return false;
231}
232
233#define nid_has_mute(codec, nid, dir) \
234 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
235#define nid_has_volume(codec, nid, dir) \
236 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
237
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238/*
239 * input MUX handling
240 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200241static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
242 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
245 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200246 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
247 if (mux_idx >= spec->num_mux_defs)
248 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100249 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
250 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200251 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252}
253
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200254static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
255 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256{
257 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
258 struct alc_spec *spec = codec->spec;
259 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
260
261 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
262 return 0;
263}
264
Takashi Iwai21268962011-07-07 15:01:13 +0200265static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266{
Takashi Iwai21268962011-07-07 15:01:13 +0200267 struct alc_spec *spec = codec->spec;
268 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
269
270 if (spec->cur_adc && spec->cur_adc != new_adc) {
271 /* stream is running, let's swap the current ADC */
272 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
273 spec->cur_adc = new_adc;
274 snd_hda_codec_setup_stream(codec, new_adc,
275 spec->cur_adc_stream_tag, 0,
276 spec->cur_adc_format);
277 return true;
278 }
279 return false;
280}
281
Takashi Iwai24de1832011-11-07 17:13:39 +0100282static void call_update_outputs(struct hda_codec *codec);
283
Takashi Iwai21268962011-07-07 15:01:13 +0200284/* select the given imux item; either unmute exclusively or select the route */
285static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
286 unsigned int idx, bool force)
287{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100289 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100290 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100291 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200292 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
Takashi Iwaicd896c32008-11-18 12:36:33 +0100294 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
295 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100296 if (!imux->num_items && mux_idx > 0)
297 imux = &spec->input_mux[0];
Takashi Iwaicd896c32008-11-18 12:36:33 +0100298
Takashi Iwai21268962011-07-07 15:01:13 +0200299 if (idx >= imux->num_items)
300 idx = imux->num_items - 1;
301 if (spec->cur_mux[adc_idx] == idx && !force)
302 return 0;
303 spec->cur_mux[adc_idx] = idx;
304
Takashi Iwai24de1832011-11-07 17:13:39 +0100305 /* for shared I/O, change the pin-control accordingly */
306 if (spec->shared_mic_hp) {
307 /* NOTE: this assumes that there are only two inputs, the
308 * first is the real internal mic and the second is HP jack.
309 */
310 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
311 AC_VERB_SET_PIN_WIDGET_CONTROL,
312 spec->cur_mux[adc_idx] ?
313 PIN_VREF80 : PIN_HP);
314 spec->automute_speaker = !spec->cur_mux[adc_idx];
315 call_update_outputs(codec);
316 }
317
Takashi Iwai21268962011-07-07 15:01:13 +0200318 if (spec->dyn_adc_switch) {
319 alc_dyn_adc_pcm_resetup(codec, idx);
320 adc_idx = spec->dyn_adc_idx[idx];
321 }
322
323 nid = spec->capsrc_nids ?
324 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
325
326 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100327 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
328 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200329 return 1;
330
Takashi Iwaia22d5432009-07-27 12:54:26 +0200331 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200332 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100333 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100334 int active = imux->items[idx].index;
335 for (i = 0; i < num_conns; i++) {
336 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
337 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100338 HDA_AMP_MUTE, v);
339 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100340 } else {
341 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200342 snd_hda_codec_write_cache(codec, nid, 0,
343 AC_VERB_SET_CONNECT_SEL,
344 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100345 }
Takashi Iwai21268962011-07-07 15:01:13 +0200346 return 1;
347}
348
349static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
350 struct snd_ctl_elem_value *ucontrol)
351{
352 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
353 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
354 return alc_mux_select(codec, adc_idx,
355 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100356}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200357
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100359 * set up the input pin config (depending on the given auto-pin type)
360 */
361static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
362 int auto_pin_type)
363{
364 unsigned int val = PIN_IN;
365
Takashi Iwai86e29592010-09-09 14:50:17 +0200366 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100367 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200368 unsigned int oldval;
369 oldval = snd_hda_codec_read(codec, nid, 0,
370 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100371 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100372 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200373 /* if the default pin setup is vref50, we give it priority */
374 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100375 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200376 else if (pincap & AC_PINCAP_VREF_50)
377 val = PIN_VREF50;
378 else if (pincap & AC_PINCAP_VREF_100)
379 val = PIN_VREF100;
380 else if (pincap & AC_PINCAP_VREF_GRD)
381 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100382 }
383 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
384}
385
386/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200387 * Append the given mixer and verb elements for the later use
388 * The mixer array is referred in build_controls(), and init_verbs are
389 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100390 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200391static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100392{
393 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
394 return;
395 spec->mixers[spec->num_mixers++] = mix;
396}
397
398static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
399{
400 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
401 return;
402 spec->init_verbs[spec->num_init_verbs++] = verb;
403}
404
405/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200406 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100407 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200408/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200409static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200410 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
411 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
412 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
413 { }
414};
415
Takashi Iwaia9111322011-05-02 11:30:18 +0200416static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200417 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
418 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
419 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
420 { }
421};
422
Takashi Iwaia9111322011-05-02 11:30:18 +0200423static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200424 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
425 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
426 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
427 { }
428};
429
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200430/*
431 * Fix hardware PLL issue
432 * On some codecs, the analog PLL gating control must be off while
433 * the default value is 1.
434 */
435static void alc_fix_pll(struct hda_codec *codec)
436{
437 struct alc_spec *spec = codec->spec;
438 unsigned int val;
439
440 if (!spec->pll_nid)
441 return;
442 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
443 spec->pll_coef_idx);
444 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
445 AC_VERB_GET_PROC_COEF, 0);
446 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
447 spec->pll_coef_idx);
448 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
449 val & ~(1 << spec->pll_coef_bit));
450}
451
452static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
453 unsigned int coef_idx, unsigned int coef_bit)
454{
455 struct alc_spec *spec = codec->spec;
456 spec->pll_nid = nid;
457 spec->pll_coef_idx = coef_idx;
458 spec->pll_coef_bit = coef_bit;
459 alc_fix_pll(codec);
460}
461
Takashi Iwai1d045db2011-07-07 18:23:21 +0200462/*
463 * Jack-reporting via input-jack layer
464 */
465
466/* initialization of jacks; currently checks only a few known pins */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200467static int alc_init_jacks(struct hda_codec *codec)
468{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100469#ifdef CONFIG_SND_HDA_INPUT_JACK
Kailang Yang9ad0e492010-09-14 23:22:00 +0200470 struct alc_spec *spec = codec->spec;
471 int err;
472 unsigned int hp_nid = spec->autocfg.hp_pins[0];
Takashi Iwai21268962011-07-07 15:01:13 +0200473 unsigned int mic_nid = spec->ext_mic_pin;
474 unsigned int dock_nid = spec->dock_mic_pin;
Kailang Yang9ad0e492010-09-14 23:22:00 +0200475
Takashi Iwai265a0242010-09-21 11:26:21 +0200476 if (hp_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100477 err = snd_hda_input_jack_add(codec, hp_nid,
478 SND_JACK_HEADPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200479 if (err < 0)
480 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100481 snd_hda_input_jack_report(codec, hp_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200482 }
Kailang Yang9ad0e492010-09-14 23:22:00 +0200483
Takashi Iwai265a0242010-09-21 11:26:21 +0200484 if (mic_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100485 err = snd_hda_input_jack_add(codec, mic_nid,
486 SND_JACK_MICROPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200487 if (err < 0)
488 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100489 snd_hda_input_jack_report(codec, mic_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200490 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200491 if (dock_nid) {
492 err = snd_hda_input_jack_add(codec, dock_nid,
493 SND_JACK_MICROPHONE, NULL);
494 if (err < 0)
495 return err;
496 snd_hda_input_jack_report(codec, dock_nid);
497 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100498#endif /* CONFIG_SND_HDA_INPUT_JACK */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200499 return 0;
500}
Kailang Yang9ad0e492010-09-14 23:22:00 +0200501
Takashi Iwai1d045db2011-07-07 18:23:21 +0200502/*
503 * Jack detections for HP auto-mute and mic-switch
504 */
505
506/* check each pin in the given array; returns true if any of them is plugged */
507static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200508{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200509 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200510
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200511 for (i = 0; i < num_pins; i++) {
512 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200513 if (!nid)
514 break;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100515 snd_hda_input_jack_report(codec, nid);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200516 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200517 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200518 return present;
519}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200520
Takashi Iwai1d045db2011-07-07 18:23:21 +0200521/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200522static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200523 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200524{
525 struct alc_spec *spec = codec->spec;
526 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200527 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200528 int i;
529
530 for (i = 0; i < num_pins; i++) {
531 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200532 if (!nid)
533 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200534 switch (spec->automute_mode) {
535 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200536 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537 AC_VERB_SET_PIN_WIDGET_CONTROL,
538 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200539 break;
540 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200541 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200542 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200543 break;
544 case ALC_AUTOMUTE_MIXER:
545 nid = spec->automute_mixer_nid[i];
546 if (!nid)
547 break;
548 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200549 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200550 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200551 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200552 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200553 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200554 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200555}
556
David Henningsson42cf0d02011-09-20 12:04:56 +0200557/* Toggle outputs muting */
558static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200559{
560 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200561 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200562
Takashi Iwaic0a20262011-06-10 15:28:15 +0200563 /* Control HP pins/amps depending on master_mute state;
564 * in general, HP pins/amps control should be enabled in all cases,
565 * but currently set only for master_mute, just to be safe
566 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100567 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
568 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200569 spec->autocfg.hp_pins, spec->master_mute, true);
570
David Henningsson42cf0d02011-09-20 12:04:56 +0200571 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200572 on = 0;
573 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200574 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200575 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200576 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200577 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200578
579 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200580 /* if LO is a copy of either HP or Speaker, don't need to handle it */
581 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
582 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200584 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200585 on = 0;
586 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200587 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200588 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200589 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200590 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591}
592
David Henningsson42cf0d02011-09-20 12:04:56 +0200593static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200594{
595 struct alc_spec *spec = codec->spec;
596 if (spec->automute_hook)
597 spec->automute_hook(codec);
598 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200599 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200600}
601
Takashi Iwai1d045db2011-07-07 18:23:21 +0200602/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200603static void alc_hp_automute(struct hda_codec *codec)
604{
605 struct alc_spec *spec = codec->spec;
606
David Henningsson42cf0d02011-09-20 12:04:56 +0200607 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200608 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
609 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200610 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200611 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200612 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200613}
614
Takashi Iwai1d045db2011-07-07 18:23:21 +0200615/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200616static void alc_line_automute(struct hda_codec *codec)
617{
618 struct alc_spec *spec = codec->spec;
619
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200620 /* check LO jack only when it's different from HP */
621 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
622 return;
623
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200624 spec->line_jack_present =
625 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
626 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200627 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200628 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200629 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200630}
631
Takashi Iwai8d087c72011-06-28 12:45:47 +0200632#define get_connection_index(codec, mux, nid) \
633 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200634
Takashi Iwai1d045db2011-07-07 18:23:21 +0200635/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200636static void alc_mic_automute(struct hda_codec *codec)
637{
638 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200639 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200640
Takashi Iwai21268962011-07-07 15:01:13 +0200641 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200642 return;
643 if (snd_BUG_ON(!spec->adc_nids))
644 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200645 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200646 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200647
Takashi Iwai21268962011-07-07 15:01:13 +0200648 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
649 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
650 else if (spec->dock_mic_idx >= 0 &&
651 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
652 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
653 else
654 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Takashi Iwai6c819492009-08-10 18:47:44 +0200655
Takashi Iwai21268962011-07-07 15:01:13 +0200656 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
657 if (spec->dock_mic_idx >= 0)
658 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200659}
660
Kailang Yangc9b58002007-10-16 14:30:01 +0200661/* unsolicited event for HP jack sensing */
662static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
663{
664 if (codec->vendor_id == 0x10ec0880)
665 res >>= 28;
666 else
667 res >>= 26;
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200668 snd_hda_jack_set_dirty_all(codec); /* FIXME: to be more fine-grained */
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200669 switch (res) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200670 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200671 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200672 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200673 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200674 alc_line_automute(codec);
675 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200676 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200677 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200678 break;
679 }
Kailang Yang7fb0d782008-10-15 11:12:35 +0200680}
681
Takashi Iwai1d045db2011-07-07 18:23:21 +0200682/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200683static void alc_inithook(struct hda_codec *codec)
684{
Takashi Iwaid922b512011-04-28 12:18:53 +0200685 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200686 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200687 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200688}
689
Kailang Yangf9423e72008-05-27 12:32:25 +0200690/* additional initialization for ALC888 variants */
691static void alc888_coef_init(struct hda_codec *codec)
692{
693 unsigned int tmp;
694
695 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
696 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
697 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100698 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200699 /* alc888S-VC */
700 snd_hda_codec_read(codec, 0x20, 0,
701 AC_VERB_SET_PROC_COEF, 0x830);
702 else
703 /* alc888-VB */
704 snd_hda_codec_read(codec, 0x20, 0,
705 AC_VERB_SET_PROC_COEF, 0x3030);
706}
707
Takashi Iwai1d045db2011-07-07 18:23:21 +0200708/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200709static void alc889_coef_init(struct hda_codec *codec)
710{
711 unsigned int tmp;
712
713 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
714 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
715 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
716 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
717}
718
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100719/* turn on/off EAPD control (only if available) */
720static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
721{
722 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
723 return;
724 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
725 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
726 on ? 2 : 0);
727}
728
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200729/* turn on/off EAPD controls of the codec */
730static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
731{
732 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200733 static hda_nid_t pins[] = {
734 0x0f, 0x10, 0x14, 0x15, 0
735 };
736 hda_nid_t *p;
737 for (p = pins; *p; p++)
738 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200739}
740
Takashi Iwai1c716152011-04-07 10:37:16 +0200741/* generic shutup callback;
742 * just turning off EPAD and a little pause for avoiding pop-noise
743 */
744static void alc_eapd_shutup(struct hda_codec *codec)
745{
746 alc_auto_setup_eapd(codec, false);
747 msleep(200);
748}
749
Takashi Iwai1d045db2011-07-07 18:23:21 +0200750/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200751static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200752{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200753 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200754
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200755 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200756 switch (type) {
757 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200758 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
759 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200760 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200761 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
762 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200763 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200764 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
765 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200766 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200767 switch (codec->vendor_id) {
768 case 0x10ec0260:
769 snd_hda_codec_write(codec, 0x1a, 0,
770 AC_VERB_SET_COEF_INDEX, 7);
771 tmp = snd_hda_codec_read(codec, 0x1a, 0,
772 AC_VERB_GET_PROC_COEF, 0);
773 snd_hda_codec_write(codec, 0x1a, 0,
774 AC_VERB_SET_COEF_INDEX, 7);
775 snd_hda_codec_write(codec, 0x1a, 0,
776 AC_VERB_SET_PROC_COEF,
777 tmp | 0x2010);
778 break;
779 case 0x10ec0262:
780 case 0x10ec0880:
781 case 0x10ec0882:
782 case 0x10ec0883:
783 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100784 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100785 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200786 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200787 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200788 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200789 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200790 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100791#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200792 case 0x10ec0267:
793 case 0x10ec0268:
794 snd_hda_codec_write(codec, 0x20, 0,
795 AC_VERB_SET_COEF_INDEX, 7);
796 tmp = snd_hda_codec_read(codec, 0x20, 0,
797 AC_VERB_GET_PROC_COEF, 0);
798 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200799 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200800 snd_hda_codec_write(codec, 0x20, 0,
801 AC_VERB_SET_PROC_COEF,
802 tmp | 0x3000);
803 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100804#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200805 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200806 break;
807 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200808}
Kailang Yangea1fb292008-08-26 12:58:38 +0200809
Takashi Iwai1d045db2011-07-07 18:23:21 +0200810/*
811 * Auto-Mute mode mixer enum support
812 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200813static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
814 struct snd_ctl_elem_info *uinfo)
815{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200816 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
817 struct alc_spec *spec = codec->spec;
818 static const char * const texts2[] = {
819 "Disabled", "Enabled"
820 };
821 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200822 "Disabled", "Speaker Only", "Line-Out+Speaker"
823 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200824 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200825
826 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
827 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200828 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200829 uinfo->value.enumerated.items = 3;
830 texts = texts3;
831 } else {
832 uinfo->value.enumerated.items = 2;
833 texts = texts2;
834 }
835 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
836 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200837 strcpy(uinfo->value.enumerated.name,
838 texts[uinfo->value.enumerated.item]);
839 return 0;
840}
841
842static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
843 struct snd_ctl_elem_value *ucontrol)
844{
845 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
846 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200847 unsigned int val = 0;
848 if (spec->automute_speaker)
849 val++;
850 if (spec->automute_lo)
851 val++;
852
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200853 ucontrol->value.enumerated.item[0] = val;
854 return 0;
855}
856
857static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
858 struct snd_ctl_elem_value *ucontrol)
859{
860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
861 struct alc_spec *spec = codec->spec;
862
863 switch (ucontrol->value.enumerated.item[0]) {
864 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200865 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200866 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200867 spec->automute_speaker = 0;
868 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200869 break;
870 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200871 if (spec->automute_speaker_possible) {
872 if (!spec->automute_lo && spec->automute_speaker)
873 return 0;
874 spec->automute_speaker = 1;
875 spec->automute_lo = 0;
876 } else if (spec->automute_lo_possible) {
877 if (spec->automute_lo)
878 return 0;
879 spec->automute_lo = 1;
880 } else
881 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200882 break;
883 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200884 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200885 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200886 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200887 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200888 spec->automute_speaker = 1;
889 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200890 break;
891 default:
892 return -EINVAL;
893 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200894 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200895 return 1;
896}
897
Takashi Iwaia9111322011-05-02 11:30:18 +0200898static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
900 .name = "Auto-Mute Mode",
901 .info = alc_automute_mode_info,
902 .get = alc_automute_mode_get,
903 .put = alc_automute_mode_put,
904};
905
Takashi Iwai1d045db2011-07-07 18:23:21 +0200906static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
907{
908 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
909 return snd_array_new(&spec->kctls);
910}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200911
912static int alc_add_automute_mode_enum(struct hda_codec *codec)
913{
914 struct alc_spec *spec = codec->spec;
915 struct snd_kcontrol_new *knew;
916
917 knew = alc_kcontrol_new(spec);
918 if (!knew)
919 return -ENOMEM;
920 *knew = alc_automute_mode_enum;
921 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
922 if (!knew->name)
923 return -ENOMEM;
924 return 0;
925}
926
Takashi Iwai1d045db2011-07-07 18:23:21 +0200927/*
928 * Check the availability of HP/line-out auto-mute;
929 * Set up appropriately if really supported
930 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200931static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200932{
933 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200934 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200935 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200936 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200937
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200938 if (cfg->hp_pins[0])
939 present++;
940 if (cfg->line_out_pins[0])
941 present++;
942 if (cfg->speaker_pins[0])
943 present++;
944 if (present < 2) /* need two different output types */
945 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200946
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200947 if (!cfg->speaker_pins[0] &&
948 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200949 memcpy(cfg->speaker_pins, cfg->line_out_pins,
950 sizeof(cfg->speaker_pins));
951 cfg->speaker_outs = cfg->line_outs;
952 }
953
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200954 if (!cfg->hp_pins[0] &&
955 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200956 memcpy(cfg->hp_pins, cfg->line_out_pins,
957 sizeof(cfg->hp_pins));
958 cfg->hp_outs = cfg->line_outs;
959 }
960
David Henningsson42cf0d02011-09-20 12:04:56 +0200961 spec->automute_mode = ALC_AUTOMUTE_PIN;
962
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200963 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200964 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200965 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200966 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200967 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200968 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200969 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200970 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200971 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200972
David Henningsson42cf0d02011-09-20 12:04:56 +0200973 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
974 if (cfg->speaker_outs)
975 for (i = 0; i < cfg->line_outs; i++) {
976 hda_nid_t nid = cfg->line_out_pins[i];
977 if (!is_jack_detectable(codec, nid))
978 continue;
979 snd_printdd("realtek: Enable Line-Out "
980 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200981 snd_hda_jack_detect_enable(codec, nid,
982 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200983 spec->detect_lo = 1;
984 }
985 spec->automute_lo_possible = spec->detect_hp;
986 }
987
988 spec->automute_speaker_possible = cfg->speaker_outs &&
989 (spec->detect_hp || spec->detect_lo);
990
991 spec->automute_lo = spec->automute_lo_possible;
992 spec->automute_speaker = spec->automute_speaker_possible;
993
994 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200995 /* create a control for automute mode */
996 alc_add_automute_mode_enum(codec);
997 spec->unsol_event = alc_sku_unsol_event;
998 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200999}
1000
Takashi Iwai1d045db2011-07-07 18:23:21 +02001001/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001002static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1003{
1004 int i;
1005 for (i = 0; i < nums; i++)
1006 if (list[i] == nid)
1007 return i;
1008 return -1;
1009}
1010
Takashi Iwai1d045db2011-07-07 18:23:21 +02001011/* check whether dynamic ADC-switching is available */
1012static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1013{
1014 struct alc_spec *spec = codec->spec;
1015 struct hda_input_mux *imux = &spec->private_imux[0];
1016 int i, n, idx;
1017 hda_nid_t cap, pin;
1018
1019 if (imux != spec->input_mux) /* no dynamic imux? */
1020 return false;
1021
1022 for (n = 0; n < spec->num_adc_nids; n++) {
1023 cap = spec->private_capsrc_nids[n];
1024 for (i = 0; i < imux->num_items; i++) {
1025 pin = spec->imux_pins[i];
1026 if (!pin)
1027 return false;
1028 if (get_connection_index(codec, cap, pin) < 0)
1029 break;
1030 }
1031 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001032 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001033 }
1034
1035 for (i = 0; i < imux->num_items; i++) {
1036 pin = spec->imux_pins[i];
1037 for (n = 0; n < spec->num_adc_nids; n++) {
1038 cap = spec->private_capsrc_nids[n];
1039 idx = get_connection_index(codec, cap, pin);
1040 if (idx >= 0) {
1041 imux->items[i].index = idx;
1042 spec->dyn_adc_idx[i] = n;
1043 break;
1044 }
1045 }
1046 }
1047
1048 snd_printdd("realtek: enabling ADC switching\n");
1049 spec->dyn_adc_switch = 1;
1050 return true;
1051}
Takashi Iwai21268962011-07-07 15:01:13 +02001052
1053/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1054static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1055{
1056 struct alc_spec *spec = codec->spec;
1057 struct hda_input_mux *imux;
1058 static char * const texts[3] = {
1059 "Mic", "Internal Mic", "Dock Mic"
1060 };
1061 int i;
1062
1063 if (!spec->auto_mic)
1064 return false;
1065 imux = &spec->private_imux[0];
1066 if (spec->input_mux == imux)
1067 return true;
1068 spec->imux_pins[0] = spec->ext_mic_pin;
1069 spec->imux_pins[1] = spec->int_mic_pin;
1070 spec->imux_pins[2] = spec->dock_mic_pin;
1071 for (i = 0; i < 3; i++) {
1072 strcpy(imux->items[i].label, texts[i]);
1073 if (spec->imux_pins[i])
1074 imux->num_items = i + 1;
1075 }
1076 spec->num_mux_defs = 1;
1077 spec->input_mux = imux;
1078 return true;
1079}
1080
1081/* check whether all auto-mic pins are valid; setup indices if OK */
1082static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1083{
1084 struct alc_spec *spec = codec->spec;
1085 const struct hda_input_mux *imux;
1086
1087 if (!spec->auto_mic)
1088 return false;
1089 if (spec->auto_mic_valid_imux)
1090 return true; /* already checked */
1091
1092 /* fill up imux indices */
1093 if (!alc_check_dyn_adc_switch(codec)) {
1094 spec->auto_mic = 0;
1095 return false;
1096 }
1097
1098 imux = spec->input_mux;
1099 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1100 spec->imux_pins, imux->num_items);
1101 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1102 spec->imux_pins, imux->num_items);
1103 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1104 spec->imux_pins, imux->num_items);
1105 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1106 spec->auto_mic = 0;
1107 return false; /* no corresponding imux */
1108 }
1109
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001110 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001111 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001112 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1113 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001114
1115 spec->auto_mic_valid_imux = 1;
1116 spec->auto_mic = 1;
1117 return true;
1118}
1119
Takashi Iwai1d045db2011-07-07 18:23:21 +02001120/*
1121 * Check the availability of auto-mic switch;
1122 * Set up if really supported
1123 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001124static void alc_init_auto_mic(struct hda_codec *codec)
1125{
1126 struct alc_spec *spec = codec->spec;
1127 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001128 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001129 int i;
1130
Takashi Iwai24de1832011-11-07 17:13:39 +01001131 if (spec->shared_mic_hp)
1132 return; /* no auto-mic for the shared I/O */
1133
Takashi Iwai21268962011-07-07 15:01:13 +02001134 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1135
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001136 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001137 for (i = 0; i < cfg->num_inputs; i++) {
1138 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001139 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001140 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001141 switch (snd_hda_get_input_pin_attr(defcfg)) {
1142 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001143 if (fixed)
1144 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001145 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1146 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001147 fixed = nid;
1148 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001149 case INPUT_PIN_ATTR_UNUSED:
1150 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001151 case INPUT_PIN_ATTR_DOCK:
1152 if (dock)
1153 return; /* already occupied */
1154 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1155 return; /* invalid type */
1156 dock = nid;
1157 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001158 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001159 if (ext)
1160 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001161 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1162 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001163 ext = nid;
1164 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001165 }
1166 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001167 if (!ext && dock) {
1168 ext = dock;
1169 dock = 0;
1170 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001171 if (!ext || !fixed)
1172 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001173 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001174 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001175 if (dock && !is_jack_detectable(codec, dock))
1176 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001177
1178 /* check imux indices */
1179 spec->ext_mic_pin = ext;
1180 spec->int_mic_pin = fixed;
1181 spec->dock_mic_pin = dock;
1182
1183 spec->auto_mic = 1;
1184 if (!alc_auto_mic_check_imux(codec))
1185 return;
1186
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001187 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1188 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001189 spec->unsol_event = alc_sku_unsol_event;
1190}
1191
Takashi Iwai1d045db2011-07-07 18:23:21 +02001192/* check the availabilities of auto-mute and auto-mic switches */
1193static void alc_auto_check_switches(struct hda_codec *codec)
1194{
David Henningsson42cf0d02011-09-20 12:04:56 +02001195 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001196 alc_init_auto_mic(codec);
1197}
1198
1199/*
1200 * Realtek SSID verification
1201 */
1202
David Henningsson90622912010-10-14 14:50:18 +02001203/* Could be any non-zero and even value. When used as fixup, tells
1204 * the driver to ignore any present sku defines.
1205 */
1206#define ALC_FIXUP_SKU_IGNORE (2)
1207
Kailang Yangda00c242010-03-19 11:23:45 +01001208static int alc_auto_parse_customize_define(struct hda_codec *codec)
1209{
1210 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001211 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001212 struct alc_spec *spec = codec->spec;
1213
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001214 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1215
David Henningsson90622912010-10-14 14:50:18 +02001216 if (spec->cdefine.fixup) {
1217 ass = spec->cdefine.sku_cfg;
1218 if (ass == ALC_FIXUP_SKU_IGNORE)
1219 return -1;
1220 goto do_sku;
1221 }
1222
Kailang Yangda00c242010-03-19 11:23:45 +01001223 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001224 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001225 goto do_sku;
1226
1227 nid = 0x1d;
1228 if (codec->vendor_id == 0x10ec0260)
1229 nid = 0x17;
1230 ass = snd_hda_codec_get_pincfg(codec, nid);
1231
1232 if (!(ass & 1)) {
1233 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1234 codec->chip_name, ass);
1235 return -1;
1236 }
1237
1238 /* check sum */
1239 tmp = 0;
1240 for (i = 1; i < 16; i++) {
1241 if ((ass >> i) & 1)
1242 tmp++;
1243 }
1244 if (((ass >> 16) & 0xf) != tmp)
1245 return -1;
1246
1247 spec->cdefine.port_connectivity = ass >> 30;
1248 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1249 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1250 spec->cdefine.customization = ass >> 8;
1251do_sku:
1252 spec->cdefine.sku_cfg = ass;
1253 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1254 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1255 spec->cdefine.swap = (ass & 0x2) >> 1;
1256 spec->cdefine.override = ass & 0x1;
1257
1258 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1259 nid, spec->cdefine.sku_cfg);
1260 snd_printd("SKU: port_connectivity=0x%x\n",
1261 spec->cdefine.port_connectivity);
1262 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1263 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1264 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1265 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1266 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1267 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1268 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1269
1270 return 0;
1271}
1272
Takashi Iwai1d045db2011-07-07 18:23:21 +02001273/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001274static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1275{
Takashi Iwai21268962011-07-07 15:01:13 +02001276 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001277}
1278
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001279/* check subsystem ID and set up device-specific initialization;
1280 * return 1 if initialized, 0 if invalid SSID
1281 */
1282/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1283 * 31 ~ 16 : Manufacture ID
1284 * 15 ~ 8 : SKU ID
1285 * 7 ~ 0 : Assembly ID
1286 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1287 */
1288static int alc_subsystem_id(struct hda_codec *codec,
1289 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001290 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001291{
1292 unsigned int ass, tmp, i;
1293 unsigned nid;
1294 struct alc_spec *spec = codec->spec;
1295
David Henningsson90622912010-10-14 14:50:18 +02001296 if (spec->cdefine.fixup) {
1297 ass = spec->cdefine.sku_cfg;
1298 if (ass == ALC_FIXUP_SKU_IGNORE)
1299 return 0;
1300 goto do_sku;
1301 }
1302
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001303 ass = codec->subsystem_id & 0xffff;
1304 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1305 goto do_sku;
1306
1307 /* invalid SSID, check the special NID pin defcfg instead */
1308 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001309 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001310 * 29~21 : reserve
1311 * 20 : PCBEEP input
1312 * 19~16 : Check sum (15:1)
1313 * 15~1 : Custom
1314 * 0 : override
1315 */
1316 nid = 0x1d;
1317 if (codec->vendor_id == 0x10ec0260)
1318 nid = 0x17;
1319 ass = snd_hda_codec_get_pincfg(codec, nid);
1320 snd_printd("realtek: No valid SSID, "
1321 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001322 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001323 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001324 return 0;
1325 if ((ass >> 30) != 1) /* no physical connection */
1326 return 0;
1327
1328 /* check sum */
1329 tmp = 0;
1330 for (i = 1; i < 16; i++) {
1331 if ((ass >> i) & 1)
1332 tmp++;
1333 }
1334 if (((ass >> 16) & 0xf) != tmp)
1335 return 0;
1336do_sku:
1337 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1338 ass & 0xffff, codec->vendor_id);
1339 /*
1340 * 0 : override
1341 * 1 : Swap Jack
1342 * 2 : 0 --> Desktop, 1 --> Laptop
1343 * 3~5 : External Amplifier control
1344 * 7~6 : Reserved
1345 */
1346 tmp = (ass & 0x38) >> 3; /* external Amp control */
1347 switch (tmp) {
1348 case 1:
1349 spec->init_amp = ALC_INIT_GPIO1;
1350 break;
1351 case 3:
1352 spec->init_amp = ALC_INIT_GPIO2;
1353 break;
1354 case 7:
1355 spec->init_amp = ALC_INIT_GPIO3;
1356 break;
1357 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001358 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001359 spec->init_amp = ALC_INIT_DEFAULT;
1360 break;
1361 }
1362
1363 /* is laptop or Desktop and enable the function "Mute internal speaker
1364 * when the external headphone out jack is plugged"
1365 */
1366 if (!(ass & 0x8000))
1367 return 1;
1368 /*
1369 * 10~8 : Jack location
1370 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1371 * 14~13: Resvered
1372 * 15 : 1 --> enable the function "Mute internal speaker
1373 * when the external headphone out jack is plugged"
1374 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001375 if (!spec->autocfg.hp_pins[0] &&
1376 !(spec->autocfg.line_out_pins[0] &&
1377 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001378 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001379 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1380 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001381 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001382 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001383 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001384 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001385 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001386 else if (tmp == 3)
1387 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001388 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001389 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001390 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1391 spec->autocfg.line_outs))
1392 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001393 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001394 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001395 return 1;
1396}
Kailang Yangea1fb292008-08-26 12:58:38 +02001397
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001398/* Check the validity of ALC subsystem-id
1399 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1400static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001401{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001402 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001403 struct alc_spec *spec = codec->spec;
1404 snd_printd("realtek: "
1405 "Enable default setup for auto mode as fallback\n");
1406 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001407 }
Takashi Iwai21268962011-07-07 15:01:13 +02001408}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001409
Takashi Iwai41e41f12005-06-08 14:48:49 +02001410/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001411 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001412 */
1413
1414struct alc_pincfg {
1415 hda_nid_t nid;
1416 u32 val;
1417};
1418
Todd Broche1eb5f12010-12-06 11:19:51 -08001419struct alc_model_fixup {
1420 const int id;
1421 const char *name;
1422};
1423
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001424struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001425 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001426 bool chained;
1427 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001428 union {
1429 unsigned int sku;
1430 const struct alc_pincfg *pins;
1431 const struct hda_verb *verbs;
1432 void (*func)(struct hda_codec *codec,
1433 const struct alc_fixup *fix,
1434 int action);
1435 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001436};
1437
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001438enum {
1439 ALC_FIXUP_INVALID,
1440 ALC_FIXUP_SKU,
1441 ALC_FIXUP_PINS,
1442 ALC_FIXUP_VERBS,
1443 ALC_FIXUP_FUNC,
1444};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001445
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001446enum {
1447 ALC_FIXUP_ACT_PRE_PROBE,
1448 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001449 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001450};
1451
1452static void alc_apply_fixup(struct hda_codec *codec, int action)
1453{
1454 struct alc_spec *spec = codec->spec;
1455 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001456#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001457 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001458#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001459 int depth = 0;
1460
1461 if (!spec->fixup_list)
1462 return;
1463
1464 while (id >= 0) {
1465 const struct alc_fixup *fix = spec->fixup_list + id;
1466 const struct alc_pincfg *cfg;
1467
1468 switch (fix->type) {
1469 case ALC_FIXUP_SKU:
1470 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001471 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001472 snd_printdd(KERN_INFO "hda_codec: %s: "
1473 "Apply sku override for %s\n",
1474 codec->chip_name, modelname);
1475 spec->cdefine.sku_cfg = fix->v.sku;
1476 spec->cdefine.fixup = 1;
1477 break;
1478 case ALC_FIXUP_PINS:
1479 cfg = fix->v.pins;
1480 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1481 break;
1482 snd_printdd(KERN_INFO "hda_codec: %s: "
1483 "Apply pincfg for %s\n",
1484 codec->chip_name, modelname);
1485 for (; cfg->nid; cfg++)
1486 snd_hda_codec_set_pincfg(codec, cfg->nid,
1487 cfg->val);
1488 break;
1489 case ALC_FIXUP_VERBS:
1490 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1491 break;
1492 snd_printdd(KERN_INFO "hda_codec: %s: "
1493 "Apply fix-verbs for %s\n",
1494 codec->chip_name, modelname);
1495 add_verb(codec->spec, fix->v.verbs);
1496 break;
1497 case ALC_FIXUP_FUNC:
1498 if (!fix->v.func)
1499 break;
1500 snd_printdd(KERN_INFO "hda_codec: %s: "
1501 "Apply fix-func for %s\n",
1502 codec->chip_name, modelname);
1503 fix->v.func(codec, fix, action);
1504 break;
1505 default:
1506 snd_printk(KERN_ERR "hda_codec: %s: "
1507 "Invalid fixup type %d\n",
1508 codec->chip_name, fix->type);
1509 break;
1510 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001511 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001512 break;
1513 if (++depth > 10)
1514 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001515 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001516 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001517}
1518
Todd Broche1eb5f12010-12-06 11:19:51 -08001519static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001520 const struct alc_model_fixup *models,
1521 const struct snd_pci_quirk *quirk,
1522 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001523{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001524 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001525 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001526 int id = -1;
1527 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001528
Todd Broche1eb5f12010-12-06 11:19:51 -08001529 if (codec->modelname && models) {
1530 while (models->name) {
1531 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001532 id = models->id;
1533 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001534 break;
1535 }
1536 models++;
1537 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001538 }
1539 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001540 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1541 if (q) {
1542 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001543#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001544 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001545#endif
1546 }
1547 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001548 if (id < 0) {
1549 for (q = quirk; q->subvendor; q++) {
1550 unsigned int vendorid =
1551 q->subdevice | (q->subvendor << 16);
1552 if (vendorid == codec->subsystem_id) {
1553 id = q->value;
1554#ifdef CONFIG_SND_DEBUG_VERBOSE
1555 name = q->name;
1556#endif
1557 break;
1558 }
1559 }
1560 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001561
1562 spec->fixup_id = id;
1563 if (id >= 0) {
1564 spec->fixup_list = fixlist;
1565 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001566 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001567}
1568
Takashi Iwai1d045db2011-07-07 18:23:21 +02001569/*
1570 * COEF access helper functions
1571 */
Kailang Yang274693f2009-12-03 10:07:50 +01001572static int alc_read_coef_idx(struct hda_codec *codec,
1573 unsigned int coef_idx)
1574{
1575 unsigned int val;
1576 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1577 coef_idx);
1578 val = snd_hda_codec_read(codec, 0x20, 0,
1579 AC_VERB_GET_PROC_COEF, 0);
1580 return val;
1581}
1582
Kailang Yang977ddd62010-09-15 10:02:29 +02001583static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1584 unsigned int coef_val)
1585{
1586 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1587 coef_idx);
1588 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1589 coef_val);
1590}
1591
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001592/* a special bypass for COEF 0; read the cached value at the second time */
1593static unsigned int alc_get_coef0(struct hda_codec *codec)
1594{
1595 struct alc_spec *spec = codec->spec;
1596 if (!spec->coef0)
1597 spec->coef0 = alc_read_coef_idx(codec, 0);
1598 return spec->coef0;
1599}
1600
Takashi Iwai1d045db2011-07-07 18:23:21 +02001601/*
1602 * Digital I/O handling
1603 */
1604
Takashi Iwai757899a2010-07-30 10:48:14 +02001605/* set right pin controls for digital I/O */
1606static void alc_auto_init_digital(struct hda_codec *codec)
1607{
1608 struct alc_spec *spec = codec->spec;
1609 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001610 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001611
1612 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1613 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001614 if (!pin)
1615 continue;
1616 snd_hda_codec_write(codec, pin, 0,
1617 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1618 if (!i)
1619 dac = spec->multiout.dig_out_nid;
1620 else
1621 dac = spec->slave_dig_outs[i - 1];
1622 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1623 continue;
1624 snd_hda_codec_write(codec, dac, 0,
1625 AC_VERB_SET_AMP_GAIN_MUTE,
1626 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001627 }
1628 pin = spec->autocfg.dig_in_pin;
1629 if (pin)
1630 snd_hda_codec_write(codec, pin, 0,
1631 AC_VERB_SET_PIN_WIDGET_CONTROL,
1632 PIN_IN);
1633}
1634
1635/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1636static void alc_auto_parse_digital(struct hda_codec *codec)
1637{
1638 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001639 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001640 hda_nid_t dig_nid;
1641
1642 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001643 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001644 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001645 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001646 err = snd_hda_get_connections(codec,
1647 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001648 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001649 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001650 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001651 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001652 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001653 spec->multiout.dig_out_nid = dig_nid;
1654 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1655 } else {
1656 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001657 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001658 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001659 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001660 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001661 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001662 }
1663
1664 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001665 dig_nid = codec->start_nid;
1666 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1667 unsigned int wcaps = get_wcaps(codec, dig_nid);
1668 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1669 continue;
1670 if (!(wcaps & AC_WCAP_DIGITAL))
1671 continue;
1672 if (!(wcaps & AC_WCAP_CONN_LIST))
1673 continue;
1674 err = get_connection_index(codec, dig_nid,
1675 spec->autocfg.dig_in_pin);
1676 if (err >= 0) {
1677 spec->dig_in_nid = dig_nid;
1678 break;
1679 }
1680 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001681 }
1682}
1683
Takashi Iwaif95474e2007-07-10 00:47:43 +02001684/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001685 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001686 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001687static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1688 struct snd_ctl_elem_info *uinfo)
1689{
1690 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1691 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001692 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001693 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001694
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001695 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001696 if (spec->vol_in_capsrc)
1697 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1698 else
1699 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1700 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001701 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001702 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001703 return err;
1704}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001706static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1707 unsigned int size, unsigned int __user *tlv)
1708{
1709 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1710 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001711 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001712 int err;
1713
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001714 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001715 if (spec->vol_in_capsrc)
1716 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1717 else
1718 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1719 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001720 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001721 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001722 return err;
1723}
1724
1725typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1726 struct snd_ctl_elem_value *ucontrol);
1727
1728static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1729 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001730 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001731{
1732 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1733 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001734 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001735
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001736 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001737 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001738 for (i = 0; i < spec->num_adc_nids; i++) {
1739 kcontrol->private_value =
1740 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1741 3, 0, HDA_INPUT);
1742 err = func(kcontrol, ucontrol);
1743 if (err < 0)
1744 goto error;
1745 }
1746 } else {
1747 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001748 if (spec->vol_in_capsrc)
1749 kcontrol->private_value =
1750 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1751 3, 0, HDA_OUTPUT);
1752 else
1753 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001754 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1755 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001756 err = func(kcontrol, ucontrol);
1757 }
1758 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001759 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001760 return err;
1761}
1762
1763static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1764 struct snd_ctl_elem_value *ucontrol)
1765{
1766 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001767 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001768}
1769
1770static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1771 struct snd_ctl_elem_value *ucontrol)
1772{
1773 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001774 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001775}
1776
1777/* capture mixer elements */
1778#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1779
1780static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1781 struct snd_ctl_elem_value *ucontrol)
1782{
1783 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001784 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001785}
1786
1787static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1788 struct snd_ctl_elem_value *ucontrol)
1789{
1790 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001791 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001792}
1793
Takashi Iwaia23b6882009-03-23 15:21:36 +01001794#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001795 { \
1796 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1797 .name = "Capture Switch", \
1798 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1799 .count = num, \
1800 .info = alc_cap_sw_info, \
1801 .get = alc_cap_sw_get, \
1802 .put = alc_cap_sw_put, \
1803 }, \
1804 { \
1805 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1806 .name = "Capture Volume", \
1807 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1808 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1809 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1810 .count = num, \
1811 .info = alc_cap_vol_info, \
1812 .get = alc_cap_vol_get, \
1813 .put = alc_cap_vol_put, \
1814 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001815 }
1816
1817#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001818 { \
1819 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1820 /* .name = "Capture Source", */ \
1821 .name = "Input Source", \
1822 .count = num, \
1823 .info = alc_mux_enum_info, \
1824 .get = alc_mux_enum_get, \
1825 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001826 }
1827
1828#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001829static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001830 _DEFINE_CAPMIX(num), \
1831 _DEFINE_CAPSRC(num), \
1832 { } /* end */ \
1833}
1834
1835#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001836static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001837 _DEFINE_CAPMIX(num), \
1838 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001839}
1840
1841/* up to three ADCs */
1842DEFINE_CAPMIX(1);
1843DEFINE_CAPMIX(2);
1844DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001845DEFINE_CAPMIX_NOSRC(1);
1846DEFINE_CAPMIX_NOSRC(2);
1847DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001848
1849/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001850 * virtual master controls
1851 */
1852
1853/*
1854 * slave controls for virtual master
1855 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001856static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001857 "Front Playback Volume",
1858 "Surround Playback Volume",
1859 "Center Playback Volume",
1860 "LFE Playback Volume",
1861 "Side Playback Volume",
1862 "Headphone Playback Volume",
1863 "Speaker Playback Volume",
1864 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001865 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001866 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001867 NULL,
1868};
1869
Takashi Iwaiea734962011-01-17 11:29:34 +01001870static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001871 "Front Playback Switch",
1872 "Surround Playback Switch",
1873 "Center Playback Switch",
1874 "LFE Playback Switch",
1875 "Side Playback Switch",
1876 "Headphone Playback Switch",
1877 "Speaker Playback Switch",
1878 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001879 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001880 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001881 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001882 NULL,
1883};
1884
1885/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001886 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001888
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001889#define NID_MAPPING (-1)
1890
1891#define SUBDEV_SPEAKER_ (0 << 6)
1892#define SUBDEV_HP_ (1 << 6)
1893#define SUBDEV_LINE_ (2 << 6)
1894#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1895#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1896#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1897
Takashi Iwai603c4012008-07-30 15:01:44 +02001898static void alc_free_kctls(struct hda_codec *codec);
1899
Takashi Iwai67d634c2009-11-16 15:35:59 +01001900#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001901/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001902static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001903 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001904 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001905 { } /* end */
1906};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001907#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001908
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909static int alc_build_controls(struct hda_codec *codec)
1910{
1911 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001912 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001913 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001914 int i, j, err;
1915 unsigned int u;
1916 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
1918 for (i = 0; i < spec->num_mixers; i++) {
1919 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1920 if (err < 0)
1921 return err;
1922 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001923 if (spec->cap_mixer) {
1924 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1925 if (err < 0)
1926 return err;
1927 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001928 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001929 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001930 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001931 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 if (err < 0)
1933 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001934 if (!spec->no_analog) {
1935 err = snd_hda_create_spdif_share_sw(codec,
1936 &spec->multiout);
1937 if (err < 0)
1938 return err;
1939 spec->multiout.share_spdif = 1;
1940 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941 }
1942 if (spec->dig_in_nid) {
1943 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1944 if (err < 0)
1945 return err;
1946 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001947
Takashi Iwai67d634c2009-11-16 15:35:59 +01001948#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001949 /* create beep controls if needed */
1950 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001951 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001952 for (knew = alc_beep_mixer; knew->name; knew++) {
1953 struct snd_kcontrol *kctl;
1954 kctl = snd_ctl_new1(knew, codec);
1955 if (!kctl)
1956 return -ENOMEM;
1957 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001958 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001959 if (err < 0)
1960 return err;
1961 }
1962 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001963#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001964
Takashi Iwai2134ea42008-01-10 16:53:55 +01001965 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001966 if (!spec->no_analog &&
1967 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001968 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001969 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001970 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001971 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001972 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001973 if (err < 0)
1974 return err;
1975 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001976 if (!spec->no_analog &&
1977 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001978 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1979 NULL, alc_slave_sws);
1980 if (err < 0)
1981 return err;
1982 }
1983
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001984 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001985 if (spec->capsrc_nids || spec->adc_nids) {
1986 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1987 if (!kctl)
1988 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1989 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02001990 const hda_nid_t *nids = spec->capsrc_nids;
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001991 if (!nids)
1992 nids = spec->adc_nids;
1993 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1994 if (err < 0)
1995 return err;
1996 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001997 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001998 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001999 const char *kname = kctl ? kctl->id.name : NULL;
2000 for (knew = spec->cap_mixer; knew->name; knew++) {
2001 if (kname && strcmp(knew->name, kname) == 0)
2002 continue;
2003 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2004 for (i = 0; kctl && i < kctl->count; i++) {
2005 err = snd_hda_add_nid(codec, kctl, i,
2006 spec->adc_nids[i]);
2007 if (err < 0)
2008 return err;
2009 }
2010 }
2011 }
2012
2013 /* other nid->control mapping */
2014 for (i = 0; i < spec->num_mixers; i++) {
2015 for (knew = spec->mixers[i]; knew->name; knew++) {
2016 if (knew->iface != NID_MAPPING)
2017 continue;
2018 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2019 if (kctl == NULL)
2020 continue;
2021 u = knew->subdevice;
2022 for (j = 0; j < 4; j++, u >>= 8) {
2023 nid = u & 0x3f;
2024 if (nid == 0)
2025 continue;
2026 switch (u & 0xc0) {
2027 case SUBDEV_SPEAKER_:
2028 nid = spec->autocfg.speaker_pins[nid];
2029 break;
2030 case SUBDEV_LINE_:
2031 nid = spec->autocfg.line_out_pins[nid];
2032 break;
2033 case SUBDEV_HP_:
2034 nid = spec->autocfg.hp_pins[nid];
2035 break;
2036 default:
2037 continue;
2038 }
2039 err = snd_hda_add_nid(codec, kctl, 0, nid);
2040 if (err < 0)
2041 return err;
2042 }
2043 u = knew->private_value;
2044 for (j = 0; j < 4; j++, u >>= 8) {
2045 nid = u & 0xff;
2046 if (nid == 0)
2047 continue;
2048 err = snd_hda_add_nid(codec, kctl, 0, nid);
2049 if (err < 0)
2050 return err;
2051 }
2052 }
2053 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002054
2055 alc_free_kctls(codec); /* no longer needed */
2056
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 return 0;
2058}
2059
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002060
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002062 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002063 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002064
Takashi Iwai584c0c42011-03-10 12:51:11 +01002065static void alc_init_special_input_src(struct hda_codec *codec);
2066
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067static int alc_init(struct hda_codec *codec)
2068{
2069 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002070 unsigned int i;
2071
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002072 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002073 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002074
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002075 for (i = 0; i < spec->num_init_verbs; i++)
2076 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002077 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002078
2079 if (spec->init_hook)
2080 spec->init_hook(codec);
2081
Takashi Iwai58701122011-01-13 15:41:45 +01002082 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2083
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002084 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 return 0;
2086}
2087
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002088static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2089{
2090 struct alc_spec *spec = codec->spec;
2091
2092 if (spec->unsol_event)
2093 spec->unsol_event(codec, res);
2094}
2095
Takashi Iwaicb53c622007-08-10 17:21:45 +02002096#ifdef CONFIG_SND_HDA_POWER_SAVE
2097static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2098{
2099 struct alc_spec *spec = codec->spec;
2100 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2101}
2102#endif
2103
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104/*
2105 * Analog playback callbacks
2106 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002107static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002109 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002110{
2111 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002112 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2113 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114}
2115
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002116static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 struct hda_codec *codec,
2118 unsigned int stream_tag,
2119 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002120 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121{
2122 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002123 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2124 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125}
2126
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002127static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002129 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130{
2131 struct alc_spec *spec = codec->spec;
2132 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2133}
2134
2135/*
2136 * Digital out
2137 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002138static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002140 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
2142 struct alc_spec *spec = codec->spec;
2143 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2144}
2145
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002146static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002147 struct hda_codec *codec,
2148 unsigned int stream_tag,
2149 unsigned int format,
2150 struct snd_pcm_substream *substream)
2151{
2152 struct alc_spec *spec = codec->spec;
2153 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2154 stream_tag, format, substream);
2155}
2156
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002157static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002158 struct hda_codec *codec,
2159 struct snd_pcm_substream *substream)
2160{
2161 struct alc_spec *spec = codec->spec;
2162 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2163}
2164
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002165static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002167 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168{
2169 struct alc_spec *spec = codec->spec;
2170 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2171}
2172
2173/*
2174 * Analog capture
2175 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002176static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177 struct hda_codec *codec,
2178 unsigned int stream_tag,
2179 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002180 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181{
2182 struct alc_spec *spec = codec->spec;
2183
Takashi Iwai63300792008-01-24 15:31:36 +01002184 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 stream_tag, 0, format);
2186 return 0;
2187}
2188
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002189static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002191 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192{
2193 struct alc_spec *spec = codec->spec;
2194
Takashi Iwai888afa12008-03-18 09:57:50 +01002195 snd_hda_codec_cleanup_stream(codec,
2196 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 return 0;
2198}
2199
Takashi Iwai840b64c2010-07-13 22:49:01 +02002200/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002201static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002202 struct hda_codec *codec,
2203 unsigned int stream_tag,
2204 unsigned int format,
2205 struct snd_pcm_substream *substream)
2206{
2207 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002208 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002209 spec->cur_adc_stream_tag = stream_tag;
2210 spec->cur_adc_format = format;
2211 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2212 return 0;
2213}
2214
Takashi Iwai21268962011-07-07 15:01:13 +02002215static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002216 struct hda_codec *codec,
2217 struct snd_pcm_substream *substream)
2218{
2219 struct alc_spec *spec = codec->spec;
2220 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2221 spec->cur_adc = 0;
2222 return 0;
2223}
2224
Takashi Iwai21268962011-07-07 15:01:13 +02002225static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002226 .substreams = 1,
2227 .channels_min = 2,
2228 .channels_max = 2,
2229 .nid = 0, /* fill later */
2230 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002231 .prepare = dyn_adc_capture_pcm_prepare,
2232 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002233 },
2234};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235
2236/*
2237 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002238static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 .substreams = 1,
2240 .channels_min = 2,
2241 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002242 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002244 .open = alc_playback_pcm_open,
2245 .prepare = alc_playback_pcm_prepare,
2246 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247 },
2248};
2249
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002250static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002251 .substreams = 1,
2252 .channels_min = 2,
2253 .channels_max = 2,
2254 /* NID is set in alc_build_pcms */
2255};
2256
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002257static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002258 .substreams = 1,
2259 .channels_min = 2,
2260 .channels_max = 2,
2261 /* NID is set in alc_build_pcms */
2262};
2263
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002264static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002265 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 .channels_min = 2,
2267 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002268 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002270 .prepare = alc_alt_capture_pcm_prepare,
2271 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 },
2273};
2274
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002275static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 .substreams = 1,
2277 .channels_min = 2,
2278 .channels_max = 2,
2279 /* NID is set in alc_build_pcms */
2280 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002281 .open = alc_dig_playback_pcm_open,
2282 .close = alc_dig_playback_pcm_close,
2283 .prepare = alc_dig_playback_pcm_prepare,
2284 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 },
2286};
2287
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002288static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 .substreams = 1,
2290 .channels_min = 2,
2291 .channels_max = 2,
2292 /* NID is set in alc_build_pcms */
2293};
2294
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002295/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002296static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002297 .substreams = 0,
2298 .channels_min = 0,
2299 .channels_max = 0,
2300};
2301
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302static int alc_build_pcms(struct hda_codec *codec)
2303{
2304 struct alc_spec *spec = codec->spec;
2305 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002306 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002307 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 int i;
2309
2310 codec->num_pcms = 1;
2311 codec->pcm_info = info;
2312
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002313 if (spec->no_analog)
2314 goto skip_analog;
2315
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002316 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2317 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002319
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002320 if (spec->multiout.dac_nids > 0) {
2321 p = spec->stream_analog_playback;
2322 if (!p)
2323 p = &alc_pcm_analog_playback;
2324 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002325 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2326 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002327 if (spec->adc_nids) {
2328 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002329 if (!p) {
2330 if (spec->dyn_adc_switch)
2331 p = &dyn_adc_pcm_analog_capture;
2332 else
2333 p = &alc_pcm_analog_capture;
2334 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002335 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002336 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2337 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
Takashi Iwai4a471b72005-12-07 13:56:29 +01002339 if (spec->channel_mode) {
2340 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2341 for (i = 0; i < spec->num_channel_mode; i++) {
2342 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2343 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 }
2346 }
2347
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002348 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002349 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002351 snprintf(spec->stream_name_digital,
2352 sizeof(spec->stream_name_digital),
2353 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002354 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002355 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002356 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002358 if (spec->dig_out_type)
2359 info->pcm_type = spec->dig_out_type;
2360 else
2361 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002362 if (spec->multiout.dig_out_nid) {
2363 p = spec->stream_digital_playback;
2364 if (!p)
2365 p = &alc_pcm_digital_playback;
2366 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2368 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002369 if (spec->dig_in_nid) {
2370 p = spec->stream_digital_capture;
2371 if (!p)
2372 p = &alc_pcm_digital_capture;
2373 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2375 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002376 /* FIXME: do we need this for all Realtek codec models? */
2377 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 }
2379
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002380 if (spec->no_analog)
2381 return 0;
2382
Takashi Iwaie08a0072006-09-07 17:52:14 +02002383 /* If the use of more than one ADC is requested for the current
2384 * model, configure a second analog capture-only PCM.
2385 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002386 have_multi_adcs = (spec->num_adc_nids > 1) &&
2387 !spec->dyn_adc_switch && !spec->auto_mic &&
2388 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002389 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002390 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002391 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002392 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002393 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002394 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002395 p = spec->stream_analog_alt_playback;
2396 if (!p)
2397 p = &alc_pcm_analog_alt_playback;
2398 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002399 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2400 spec->alt_dac_nid;
2401 } else {
2402 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2403 alc_pcm_null_stream;
2404 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2405 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002406 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002407 p = spec->stream_analog_alt_capture;
2408 if (!p)
2409 p = &alc_pcm_analog_alt_capture;
2410 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002411 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2412 spec->adc_nids[1];
2413 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2414 spec->num_adc_nids - 1;
2415 } else {
2416 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2417 alc_pcm_null_stream;
2418 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002419 }
2420 }
2421
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 return 0;
2423}
2424
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002425static inline void alc_shutup(struct hda_codec *codec)
2426{
Takashi Iwai1c716152011-04-07 10:37:16 +02002427 struct alc_spec *spec = codec->spec;
2428
2429 if (spec && spec->shutup)
2430 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002431 snd_hda_shutup_pins(codec);
2432}
2433
Takashi Iwai603c4012008-07-30 15:01:44 +02002434static void alc_free_kctls(struct hda_codec *codec)
2435{
2436 struct alc_spec *spec = codec->spec;
2437
2438 if (spec->kctls.list) {
2439 struct snd_kcontrol_new *kctl = spec->kctls.list;
2440 int i;
2441 for (i = 0; i < spec->kctls.used; i++)
2442 kfree(kctl[i].name);
2443 }
2444 snd_array_free(&spec->kctls);
2445}
2446
Takashi Iwai23c09b02011-08-19 09:05:35 +02002447static void alc_free_bind_ctls(struct hda_codec *codec)
2448{
2449 struct alc_spec *spec = codec->spec;
2450 if (spec->bind_ctls.list) {
2451 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2452 int i;
2453 for (i = 0; i < spec->bind_ctls.used; i++)
2454 kfree(ctl[i]);
2455 }
2456 snd_array_free(&spec->bind_ctls);
2457}
2458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459static void alc_free(struct hda_codec *codec)
2460{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002461 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002462
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002463 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002464 return;
2465
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002466 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002467 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002468 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002469 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002470 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002471 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472}
2473
Hector Martinf5de24b2009-12-20 22:51:31 +01002474#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002475static void alc_power_eapd(struct hda_codec *codec)
2476{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002477 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002478}
2479
Hector Martinf5de24b2009-12-20 22:51:31 +01002480static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2481{
2482 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002483 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002484 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002485 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002486 return 0;
2487}
2488#endif
2489
Takashi Iwai2a439522011-07-26 09:52:50 +02002490#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002491static int alc_resume(struct hda_codec *codec)
2492{
Takashi Iwai1c716152011-04-07 10:37:16 +02002493 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002494 codec->patch_ops.init(codec);
2495 snd_hda_codec_resume_amp(codec);
2496 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002497 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002498 return 0;
2499}
Takashi Iwaie044c392008-10-27 16:56:24 +01002500#endif
2501
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502/*
2503 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002504static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 .build_controls = alc_build_controls,
2506 .build_pcms = alc_build_pcms,
2507 .init = alc_init,
2508 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002509 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002510#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002511 .resume = alc_resume,
2512#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002513#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002514 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002515 .check_power_status = alc_check_power_status,
2516#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002517 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518};
2519
Kailang Yangc027ddc2010-03-19 11:33:06 +01002520/* replace the codec chip_name with the given string */
2521static int alc_codec_rename(struct hda_codec *codec, const char *name)
2522{
2523 kfree(codec->chip_name);
2524 codec->chip_name = kstrdup(name, GFP_KERNEL);
2525 if (!codec->chip_name) {
2526 alc_free(codec);
2527 return -ENOMEM;
2528 }
2529 return 0;
2530}
2531
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002532/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002533 * Rename codecs appropriately from COEF value
2534 */
2535struct alc_codec_rename_table {
2536 unsigned int vendor_id;
2537 unsigned short coef_mask;
2538 unsigned short coef_bits;
2539 const char *name;
2540};
2541
2542static struct alc_codec_rename_table rename_tbl[] = {
2543 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2544 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2545 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2546 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2547 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2548 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2549 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2550 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2551 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2552 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2553 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2554 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2555 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2556 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2557 { } /* terminator */
2558};
2559
2560static int alc_codec_rename_from_preset(struct hda_codec *codec)
2561{
2562 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002563
2564 for (p = rename_tbl; p->vendor_id; p++) {
2565 if (p->vendor_id != codec->vendor_id)
2566 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002567 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002568 return alc_codec_rename(codec, p->name);
2569 }
2570 return 0;
2571}
2572
2573/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002574 * Automatic parse of I/O pins from the BIOS configuration
2575 */
2576
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002577enum {
2578 ALC_CTL_WIDGET_VOL,
2579 ALC_CTL_WIDGET_MUTE,
2580 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002581 ALC_CTL_BIND_VOL,
2582 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002583};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002584static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002585 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2586 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002587 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002588 HDA_BIND_VOL(NULL, 0),
2589 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002590};
2591
2592/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002593static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002594 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002595{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002596 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002597
Takashi Iwaice764ab2011-04-27 16:35:23 +02002598 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002599 if (!knew)
2600 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002601 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002602 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002603 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002604 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002605 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002606 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002607 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002608 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002609 return 0;
2610}
2611
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002612static int add_control_with_pfx(struct alc_spec *spec, int type,
2613 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002614 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002615{
2616 char name[32];
2617 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002618 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002619}
2620
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002621#define add_pb_vol_ctrl(spec, type, pfx, val) \
2622 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2623#define add_pb_sw_ctrl(spec, type, pfx, val) \
2624 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2625#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2626 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2627#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2628 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002629
Takashi Iwai23c09b02011-08-19 09:05:35 +02002630static const char * const channel_name[4] = {
2631 "Front", "Surround", "CLFE", "Side"
2632};
2633
Takashi Iwai6843ca12011-06-24 11:03:58 +02002634static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2635 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002636{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002637 struct auto_pin_cfg *cfg = &spec->autocfg;
2638
Takashi Iwai6843ca12011-06-24 11:03:58 +02002639 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002640 if (cfg->line_outs == 1 && !spec->multi_ios &&
2641 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002642 return "Master";
2643
2644 switch (cfg->line_out_type) {
2645 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002646 if (cfg->line_outs == 1)
2647 return "Speaker";
2648 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002649 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002650 /* for multi-io case, only the primary out */
2651 if (ch && spec->multi_ios)
2652 break;
2653 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002654 return "Headphone";
2655 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002656 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002657 return "PCM";
2658 break;
2659 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002660 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2661 return "PCM";
2662
2663 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002664}
2665
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002666/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002667static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002668 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002669 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002670{
Kailang Yangdf694da2005-12-05 19:42:22 +01002671 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002672
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002673 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002674 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2675 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002676 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002677 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002678 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2679 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002680 return err;
2681 return 0;
2682}
2683
Takashi Iwai05f5f472009-08-25 13:10:18 +02002684static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002685{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002686 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2687 return (pincap & AC_PINCAP_IN) != 0;
2688}
2689
Takashi Iwai1d045db2011-07-07 18:23:21 +02002690/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002691static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002692{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002693 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002694 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002695 hda_nid_t *adc_nids = spec->private_adc_nids;
2696 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2697 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002698 int i, nums = 0;
2699
Takashi Iwai24de1832011-11-07 17:13:39 +01002700 if (spec->shared_mic_hp)
2701 max_nums = 1; /* no multi streams with the shared HP/mic */
2702
Takashi Iwaib7821702011-07-06 15:12:46 +02002703 nid = codec->start_nid;
2704 for (i = 0; i < codec->num_nodes; i++, nid++) {
2705 hda_nid_t src;
2706 const hda_nid_t *list;
2707 unsigned int caps = get_wcaps(codec, nid);
2708 int type = get_wcaps_type(caps);
2709
2710 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2711 continue;
2712 adc_nids[nums] = nid;
2713 cap_nids[nums] = nid;
2714 src = nid;
2715 for (;;) {
2716 int n;
2717 type = get_wcaps_type(get_wcaps(codec, src));
2718 if (type == AC_WID_PIN)
2719 break;
2720 if (type == AC_WID_AUD_SEL) {
2721 cap_nids[nums] = src;
2722 break;
2723 }
2724 n = snd_hda_get_conn_list(codec, src, &list);
2725 if (n > 1) {
2726 cap_nids[nums] = src;
2727 break;
2728 } else if (n != 1)
2729 break;
2730 src = *list;
2731 }
2732 if (++nums >= max_nums)
2733 break;
2734 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002735 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002736 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002737 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002738 return nums;
2739}
2740
Takashi Iwai05f5f472009-08-25 13:10:18 +02002741/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002742static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002743{
2744 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002745 const struct auto_pin_cfg *cfg = &spec->autocfg;
2746 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002747 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002748 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002749 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002750 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002751
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002752 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002753 if (num_adcs < 0)
2754 return 0;
2755
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002756 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002757 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002758 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002759
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002760 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002761 if (!alc_is_input_pin(codec, pin))
2762 continue;
2763
David Henningsson5322bf22011-01-05 11:03:56 +01002764 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002765 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2766 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002767 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002768 type_idx++;
2769 else
2770 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002771 prev_label = label;
2772
Takashi Iwai05f5f472009-08-25 13:10:18 +02002773 if (mixer) {
2774 idx = get_connection_index(codec, mixer, pin);
2775 if (idx >= 0) {
2776 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002777 label, type_idx,
2778 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002779 if (err < 0)
2780 return err;
2781 }
2782 }
2783
Takashi Iwaib7821702011-07-06 15:12:46 +02002784 for (c = 0; c < num_adcs; c++) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002785 hda_nid_t cap = spec->capsrc_nids ?
2786 spec->capsrc_nids[c] : spec->adc_nids[c];
2787 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002788 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002789 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002790 snd_hda_add_imux_item(imux, label, idx, NULL);
2791 break;
2792 }
2793 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002794 }
Takashi Iwai21268962011-07-07 15:01:13 +02002795
2796 spec->num_mux_defs = 1;
2797 spec->input_mux = imux;
2798
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002799 return 0;
2800}
2801
Takashi Iwai24de1832011-11-07 17:13:39 +01002802/* create a shared input with the headphone out */
2803static int alc_auto_create_shared_input(struct hda_codec *codec)
2804{
2805 struct alc_spec *spec = codec->spec;
2806 struct auto_pin_cfg *cfg = &spec->autocfg;
2807 unsigned int defcfg;
2808 hda_nid_t nid;
2809
2810 /* only one internal input pin? */
2811 if (cfg->num_inputs != 1)
2812 return 0;
2813 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2814 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2815 return 0;
2816
2817 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2818 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2819 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2820 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2821 else
2822 return 0; /* both not available */
2823
2824 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2825 return 0; /* no input */
2826
2827 cfg->inputs[1].pin = nid;
2828 cfg->inputs[1].type = AUTO_PIN_MIC;
2829 cfg->num_inputs = 2;
2830 spec->shared_mic_hp = 1;
2831 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2832 return 0;
2833}
2834
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002835static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2836 unsigned int pin_type)
2837{
2838 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2839 pin_type);
2840 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002841 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2842 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002843 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002844}
2845
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002846static int get_pin_type(int line_out_type)
2847{
2848 if (line_out_type == AUTO_PIN_HP_OUT)
2849 return PIN_HP;
2850 else
2851 return PIN_OUT;
2852}
2853
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002854static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002855{
2856 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002857 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002858 int i;
2859
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002860 for (i = 0; i < cfg->num_inputs; i++) {
2861 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002862 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002863 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002864 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002865 snd_hda_codec_write(codec, nid, 0,
2866 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002867 AMP_OUT_MUTE);
2868 }
2869 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002870
2871 /* mute all loopback inputs */
2872 if (spec->mixer_nid) {
2873 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2874 for (i = 0; i < nums; i++)
2875 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2876 AC_VERB_SET_AMP_GAIN_MUTE,
2877 AMP_IN_MUTE(i));
2878 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002879}
2880
Takashi Iwai7085ec12009-10-02 09:03:58 +02002881/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002882static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002883{
Takashi Iwai604401a2011-04-27 15:14:23 +02002884 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002885 int i, num;
2886
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002887 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2888 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002889 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2890 for (i = 0; i < num; i++) {
2891 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2892 return list[i];
2893 }
2894 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002895}
2896
Takashi Iwai604401a2011-04-27 15:14:23 +02002897/* go down to the selector widget before the mixer */
2898static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2899{
2900 hda_nid_t srcs[5];
2901 int num = snd_hda_get_connections(codec, pin, srcs,
2902 ARRAY_SIZE(srcs));
2903 if (num != 1 ||
2904 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2905 return pin;
2906 return srcs[0];
2907}
2908
Takashi Iwai7085ec12009-10-02 09:03:58 +02002909/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002910static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002911 hda_nid_t dac)
2912{
David Henningssoncc1c4522010-11-24 14:17:47 +01002913 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002914 int i, num;
2915
Takashi Iwai604401a2011-04-27 15:14:23 +02002916 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002917 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2918 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002919 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002920 return mix[i];
2921 }
2922 return 0;
2923}
2924
Takashi Iwaice764ab2011-04-27 16:35:23 +02002925/* select the connection from pin to DAC if needed */
2926static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2927 hda_nid_t dac)
2928{
2929 hda_nid_t mix[5];
2930 int i, num;
2931
2932 pin = alc_go_down_to_selector(codec, pin);
2933 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2934 if (num < 2)
2935 return 0;
2936 for (i = 0; i < num; i++) {
2937 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2938 snd_hda_codec_update_cache(codec, pin, 0,
2939 AC_VERB_SET_CONNECT_SEL, i);
2940 return 0;
2941 }
2942 }
2943 return 0;
2944}
2945
Takashi Iwai7085ec12009-10-02 09:03:58 +02002946/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002947static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002948{
2949 struct alc_spec *spec = codec->spec;
2950 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002951 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002952
Takashi Iwai604401a2011-04-27 15:14:23 +02002953 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002954 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002955 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002956 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002957 if (!nid)
2958 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002959 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2960 spec->multiout.num_dacs))
2961 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002962 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2963 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2964 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002965 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2966 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2967 continue;
2968 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002969 }
2970 return 0;
2971}
2972
Takashi Iwai07b18f62011-11-10 15:42:54 +01002973/* check whether the DAC is reachable from the pin */
2974static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2975 hda_nid_t pin, hda_nid_t dac)
2976{
2977 hda_nid_t srcs[5];
2978 int i, num;
2979
2980 pin = alc_go_down_to_selector(codec, pin);
2981 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2982 for (i = 0; i < num; i++) {
2983 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2984 if (nid == dac)
2985 return true;
2986 }
2987 return false;
2988}
2989
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002990static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2991{
2992 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
2993 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
2994 return alc_auto_look_for_dac(codec, pin);
2995 return 0;
2996}
2997
Takashi Iwaic2674682011-08-24 17:57:44 +02002998static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2999 const hda_nid_t *pins, hda_nid_t *dacs)
3000{
3001 int i;
3002
3003 if (num_outs && !dacs[0]) {
3004 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3005 if (!dacs[0])
3006 return 0;
3007 }
3008
3009 for (i = 1; i < num_outs; i++)
3010 dacs[i] = get_dac_if_single(codec, pins[i]);
3011 for (i = 1; i < num_outs; i++) {
3012 if (!dacs[i])
3013 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3014 }
3015 return 0;
3016}
3017
3018static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003019 unsigned int location, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003020
Takashi Iwai7085ec12009-10-02 09:03:58 +02003021/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003022static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003023{
3024 struct alc_spec *spec = codec->spec;
Takashi Iwaicb053a82011-06-27 11:32:07 +02003025 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003026 unsigned int location, defcfg;
3027 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003028 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003029 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003030
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003031 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003032 /* set num_dacs once to full for alc_auto_look_for_dac() */
3033 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003034 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003035 spec->multiout.extra_out_nid[0] = 0;
3036 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3037 spec->multiout.dac_nids = spec->private_dac_nids;
3038
3039 /* fill hard-wired DACs first */
3040 if (!redone) {
3041 for (i = 0; i < cfg->line_outs; i++)
3042 spec->private_dac_nids[i] =
3043 get_dac_if_single(codec, cfg->line_out_pins[i]);
3044 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003045 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003046 get_dac_if_single(codec, cfg->hp_pins[0]);
3047 if (cfg->speaker_outs)
3048 spec->multiout.extra_out_nid[0] =
3049 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003050 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003051
3052 for (i = 0; i < cfg->line_outs; i++) {
3053 hda_nid_t pin = cfg->line_out_pins[i];
3054 if (spec->private_dac_nids[i])
3055 continue;
3056 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3057 if (!spec->private_dac_nids[i] && !redone) {
3058 /* if we can't find primary DACs, re-probe without
3059 * checking the hard-wired DACs
3060 */
3061 redone = true;
3062 goto again;
3063 }
3064 }
3065
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003066 /* re-count num_dacs and squash invalid entries */
3067 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003068 for (i = 0; i < cfg->line_outs; i++) {
3069 if (spec->private_dac_nids[i])
3070 spec->multiout.num_dacs++;
3071 else
3072 memmove(spec->private_dac_nids + i,
3073 spec->private_dac_nids + i + 1,
3074 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3075 }
3076
Takashi Iwaic2674682011-08-24 17:57:44 +02003077 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3078 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003079 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3080 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003081
Takashi Iwai07b18f62011-11-10 15:42:54 +01003082 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003083 if (num_pins > 0) {
3084 spec->multi_ios = num_pins;
3085 spec->ext_channel_count = 2;
3086 spec->multiout.num_dacs = num_pins + 1;
3087 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003088 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003089
Takashi Iwai716eef02011-10-21 15:07:42 +02003090 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3091 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003092 spec->multiout.hp_out_nid);
Takashi Iwai716eef02011-10-21 15:07:42 +02003093 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3094 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003095 spec->multiout.extra_out_nid);
3096
Takashi Iwai07b18f62011-11-10 15:42:54 +01003097 if (!spec->multi_ios &&
3098 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3099 cfg->hp_outs) {
3100 /* try multi-ios with HP + inputs */
3101 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3102 location = get_defcfg_location(defcfg);
3103
3104 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3105 if (num_pins > 0) {
3106 spec->multi_ios = num_pins;
3107 spec->ext_channel_count = 2;
3108 spec->multiout.num_dacs = num_pins + 1;
3109 }
3110 }
3111
Takashi Iwai23c09b02011-08-19 09:05:35 +02003112 return 0;
3113}
3114
Takashi Iwai527e4d72011-10-27 16:33:27 +02003115static inline unsigned int get_ctl_pos(unsigned int data)
3116{
3117 hda_nid_t nid = get_amp_nid_(data);
3118 unsigned int dir = get_amp_direction_(data);
3119 return (nid << 1) | dir;
3120}
3121
3122#define is_ctl_used(bits, data) \
3123 test_bit(get_ctl_pos(data), bits)
3124#define mark_ctl_usage(bits, data) \
3125 set_bit(get_ctl_pos(data), bits)
3126
Takashi Iwai343a04b2011-07-06 14:28:39 +02003127static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003128 const char *pfx, int cidx,
3129 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003130{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003131 struct alc_spec *spec = codec->spec;
3132 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003133 if (!nid)
3134 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003135 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3136 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3137 return 0;
3138 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003139 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003140 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003141}
3142
Takashi Iwaie29d3772011-11-14 17:13:23 +01003143static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3144 const char *pfx, int cidx,
3145 hda_nid_t nid)
3146{
3147 int chs = 1;
3148 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3149 chs = 3;
3150 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3151}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003152
3153/* create a mute-switch for the given mixer widget;
3154 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3155 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003156static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003157 const char *pfx, int cidx,
3158 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003159{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003160 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003161 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003162 int type;
3163 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003164 if (!nid)
3165 return 0;
3166 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3167 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3168 type = ALC_CTL_WIDGET_MUTE;
3169 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3170 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003171 type = ALC_CTL_WIDGET_MUTE;
3172 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3173 } else {
3174 type = ALC_CTL_BIND_MUTE;
3175 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3176 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003177 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3178 return 0;
3179 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003180 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003181}
3182
Takashi Iwaie29d3772011-11-14 17:13:23 +01003183static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3184 int cidx, hda_nid_t nid)
3185{
3186 int chs = 1;
3187 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3188 chs = 3;
3189 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3190}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003191
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003192static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3193 hda_nid_t pin, hda_nid_t dac)
3194{
3195 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3196 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3197 return pin;
3198 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3199 return mix;
3200 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3201 return dac;
3202 return 0;
3203}
3204
3205static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3206 hda_nid_t pin, hda_nid_t dac)
3207{
3208 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3209 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3210 return dac;
3211 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3212 return mix;
3213 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3214 return pin;
3215 return 0;
3216}
3217
Takashi Iwai7085ec12009-10-02 09:03:58 +02003218/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003219static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003220 const struct auto_pin_cfg *cfg)
3221{
3222 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003223 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003224
Takashi Iwaice764ab2011-04-27 16:35:23 +02003225 noutputs = cfg->line_outs;
3226 if (spec->multi_ios > 0)
3227 noutputs += spec->multi_ios;
3228
3229 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003230 const char *name;
3231 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003232 hda_nid_t dac, pin;
3233 hda_nid_t sw, vol;
3234
3235 dac = spec->multiout.dac_nids[i];
3236 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003237 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003238 if (i >= cfg->line_outs)
3239 pin = spec->multi_io[i - 1].pin;
3240 else
3241 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003242
3243 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3244 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003245 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003246 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003247 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003248 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003249 if (err < 0)
3250 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003251 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003252 if (err < 0)
3253 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003254 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003255 if (err < 0)
3256 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003257 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003258 if (err < 0)
3259 return err;
3260 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003261 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003262 if (err < 0)
3263 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003264 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003265 if (err < 0)
3266 return err;
3267 }
3268 }
3269 return 0;
3270}
3271
Takashi Iwai343a04b2011-07-06 14:28:39 +02003272static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai23c09b02011-08-19 09:05:35 +02003273 hda_nid_t dac, const char *pfx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003274{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003275 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003276 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003277 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003278
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003279 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003280 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003281 /* the corresponding DAC is already occupied */
3282 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3283 return 0; /* no way */
3284 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003285 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3286 if (is_ctl_used(spec->sw_ctls, val))
3287 return 0; /* already created */
3288 mark_ctl_usage(spec->sw_ctls, val);
3289 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003290 }
3291
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003292 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3293 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3294 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003295 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003296 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003297 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003298 if (err < 0)
3299 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003300 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003301}
3302
Takashi Iwai23c09b02011-08-19 09:05:35 +02003303static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3304 unsigned int nums,
3305 struct hda_ctl_ops *ops)
3306{
3307 struct alc_spec *spec = codec->spec;
3308 struct hda_bind_ctls **ctlp, *ctl;
3309 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3310 ctlp = snd_array_new(&spec->bind_ctls);
3311 if (!ctlp)
3312 return NULL;
3313 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3314 *ctlp = ctl;
3315 if (ctl)
3316 ctl->ops = ops;
3317 return ctl;
3318}
3319
3320/* add playback controls for speaker and HP outputs */
3321static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3322 const hda_nid_t *pins,
3323 const hda_nid_t *dacs,
3324 const char *pfx)
3325{
3326 struct alc_spec *spec = codec->spec;
3327 struct hda_bind_ctls *ctl;
3328 char name[32];
3329 int i, n, err;
3330
3331 if (!num_pins || !pins[0])
3332 return 0;
3333
Takashi Iwai527e4d72011-10-27 16:33:27 +02003334 if (num_pins == 1) {
3335 hda_nid_t dac = *dacs;
3336 if (!dac)
3337 dac = spec->multiout.dac_nids[0];
3338 return alc_auto_create_extra_out(codec, *pins, dac, pfx);
3339 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003340
3341 if (dacs[num_pins - 1]) {
3342 /* OK, we have a multi-output system with individual volumes */
3343 for (i = 0; i < num_pins; i++) {
3344 snprintf(name, sizeof(name), "%s %s",
3345 pfx, channel_name[i]);
3346 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3347 name);
3348 if (err < 0)
3349 return err;
3350 }
3351 return 0;
3352 }
3353
3354 /* Let's create a bind-controls */
3355 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3356 if (!ctl)
3357 return -ENOMEM;
3358 n = 0;
3359 for (i = 0; i < num_pins; i++) {
3360 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3361 ctl->values[n++] =
3362 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3363 }
3364 if (n) {
3365 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3366 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3367 if (err < 0)
3368 return err;
3369 }
3370
3371 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3372 if (!ctl)
3373 return -ENOMEM;
3374 n = 0;
3375 for (i = 0; i < num_pins; i++) {
3376 hda_nid_t vol;
3377 if (!pins[i] || !dacs[i])
3378 continue;
3379 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3380 if (vol)
3381 ctl->values[n++] =
3382 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3383 }
3384 if (n) {
3385 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3386 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3387 if (err < 0)
3388 return err;
3389 }
3390 return 0;
3391}
3392
Takashi Iwai343a04b2011-07-06 14:28:39 +02003393static int alc_auto_create_hp_out(struct hda_codec *codec)
3394{
3395 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003396 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3397 spec->autocfg.hp_pins,
3398 spec->multiout.hp_out_nid,
3399 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003400}
3401
3402static int alc_auto_create_speaker_out(struct hda_codec *codec)
3403{
3404 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003405 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3406 spec->autocfg.speaker_pins,
3407 spec->multiout.extra_out_nid,
3408 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003409}
3410
Takashi Iwai343a04b2011-07-06 14:28:39 +02003411static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003412 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003413 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003414{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003415 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003416 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003417 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003418
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003419 alc_set_pin_output(codec, pin, pin_type);
3420 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003421 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003422 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003423 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003424 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003425 mix = srcs[i];
3426 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003427 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003428 if (!mix)
3429 return;
3430
3431 /* need the manual connection? */
3432 if (num > 1)
3433 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3434 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003435 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3436 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003437 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003438 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003439 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003440 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003441 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003442 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3443 if (nid)
3444 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3445 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003446
3447 /* unmute DAC if it's not assigned to a mixer */
3448 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3449 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3450 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3451 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003452}
3453
Takashi Iwai343a04b2011-07-06 14:28:39 +02003454static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003455{
3456 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003457 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003458 int i;
3459
3460 for (i = 0; i <= HDA_SIDE; i++) {
3461 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3462 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003463 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003464 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003465 }
3466}
3467
Takashi Iwai343a04b2011-07-06 14:28:39 +02003468static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003469{
3470 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003471 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003472 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003473
David Henningsson636030e2011-10-12 19:26:03 +02003474 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003475 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3476 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003477 pin = spec->autocfg.hp_pins[i];
3478 if (!pin)
3479 break;
3480 dac = spec->multiout.hp_out_nid[i];
3481 if (!dac) {
3482 if (i > 0 && spec->multiout.hp_out_nid[0])
3483 dac = spec->multiout.hp_out_nid[0];
3484 else
3485 dac = spec->multiout.dac_nids[0];
3486 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003487 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3488 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003489 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003490 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3491 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003492 pin = spec->autocfg.speaker_pins[i];
3493 if (!pin)
3494 break;
3495 dac = spec->multiout.extra_out_nid[i];
3496 if (!dac) {
3497 if (i > 0 && spec->multiout.extra_out_nid[0])
3498 dac = spec->multiout.extra_out_nid[0];
3499 else
3500 dac = spec->multiout.dac_nids[0];
3501 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003502 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3503 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003504}
3505
Takashi Iwaice764ab2011-04-27 16:35:23 +02003506/*
3507 * multi-io helper
3508 */
3509static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003510 unsigned int location,
3511 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003512{
3513 struct alc_spec *spec = codec->spec;
3514 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003515 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003516 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003517
Takashi Iwai07b18f62011-11-10 15:42:54 +01003518 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003519 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3520 for (i = 0; i < cfg->num_inputs; i++) {
3521 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003522 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003523 unsigned int defcfg, caps;
3524 if (cfg->inputs[i].type != type)
3525 continue;
3526 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3527 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3528 continue;
3529 if (location && get_defcfg_location(defcfg) != location)
3530 continue;
3531 caps = snd_hda_query_pin_caps(codec, nid);
3532 if (!(caps & AC_PINCAP_OUT))
3533 continue;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003534 if (offset && offset + num_pins < dacs) {
3535 dac = spec->private_dac_nids[offset + num_pins];
3536 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3537 dac = 0;
3538 }
3539 if (!dac)
3540 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003541 if (!dac)
3542 continue;
3543 spec->multi_io[num_pins].pin = nid;
3544 spec->multi_io[num_pins].dac = dac;
3545 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003546 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003547 }
3548 }
Takashi Iwai07b18f62011-11-10 15:42:54 +01003549 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003550 if (num_pins < 2) {
3551 /* clear up again */
Takashi Iwai07b18f62011-11-10 15:42:54 +01003552 memset(spec->private_dac_nids + dacs, 0,
3553 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003554 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003555 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003556 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003557 return num_pins;
3558}
3559
3560static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3561 struct snd_ctl_elem_info *uinfo)
3562{
3563 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3564 struct alc_spec *spec = codec->spec;
3565
3566 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3567 uinfo->count = 1;
3568 uinfo->value.enumerated.items = spec->multi_ios + 1;
3569 if (uinfo->value.enumerated.item > spec->multi_ios)
3570 uinfo->value.enumerated.item = spec->multi_ios;
3571 sprintf(uinfo->value.enumerated.name, "%dch",
3572 (uinfo->value.enumerated.item + 1) * 2);
3573 return 0;
3574}
3575
3576static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3577 struct snd_ctl_elem_value *ucontrol)
3578{
3579 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3580 struct alc_spec *spec = codec->spec;
3581 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3582 return 0;
3583}
3584
3585static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3586{
3587 struct alc_spec *spec = codec->spec;
3588 hda_nid_t nid = spec->multi_io[idx].pin;
3589
3590 if (!spec->multi_io[idx].ctl_in)
3591 spec->multi_io[idx].ctl_in =
3592 snd_hda_codec_read(codec, nid, 0,
3593 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3594 if (output) {
3595 snd_hda_codec_update_cache(codec, nid, 0,
3596 AC_VERB_SET_PIN_WIDGET_CONTROL,
3597 PIN_OUT);
3598 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3599 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3600 HDA_AMP_MUTE, 0);
3601 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3602 } else {
3603 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3604 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3605 HDA_AMP_MUTE, HDA_AMP_MUTE);
3606 snd_hda_codec_update_cache(codec, nid, 0,
3607 AC_VERB_SET_PIN_WIDGET_CONTROL,
3608 spec->multi_io[idx].ctl_in);
3609 }
3610 return 0;
3611}
3612
3613static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3614 struct snd_ctl_elem_value *ucontrol)
3615{
3616 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3617 struct alc_spec *spec = codec->spec;
3618 int i, ch;
3619
3620 ch = ucontrol->value.enumerated.item[0];
3621 if (ch < 0 || ch > spec->multi_ios)
3622 return -EINVAL;
3623 if (ch == (spec->ext_channel_count - 1) / 2)
3624 return 0;
3625 spec->ext_channel_count = (ch + 1) * 2;
3626 for (i = 0; i < spec->multi_ios; i++)
3627 alc_set_multi_io(codec, i, i < ch);
3628 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003629 if (spec->need_dac_fix && !spec->const_channel_count)
3630 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003631 return 1;
3632}
3633
Takashi Iwaia9111322011-05-02 11:30:18 +02003634static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003635 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3636 .name = "Channel Mode",
3637 .info = alc_auto_ch_mode_info,
3638 .get = alc_auto_ch_mode_get,
3639 .put = alc_auto_ch_mode_put,
3640};
3641
Takashi Iwai23c09b02011-08-19 09:05:35 +02003642static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003643{
3644 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003645
Takashi Iwaic2674682011-08-24 17:57:44 +02003646 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003647 struct snd_kcontrol_new *knew;
3648
3649 knew = alc_kcontrol_new(spec);
3650 if (!knew)
3651 return -ENOMEM;
3652 *knew = alc_auto_channel_mode_enum;
3653 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3654 if (!knew->name)
3655 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003656 }
3657 return 0;
3658}
3659
Takashi Iwai1d045db2011-07-07 18:23:21 +02003660/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3661 * active input pins
3662 */
3663static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3664{
3665 struct alc_spec *spec = codec->spec;
3666 const struct hda_input_mux *imux;
3667 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3668 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3669 int i, n, nums;
3670
3671 imux = spec->input_mux;
3672 if (!imux)
3673 return;
3674 if (spec->dyn_adc_switch)
3675 return;
3676
3677 nums = 0;
3678 for (n = 0; n < spec->num_adc_nids; n++) {
3679 hda_nid_t cap = spec->private_capsrc_nids[n];
3680 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3681 for (i = 0; i < imux->num_items; i++) {
3682 hda_nid_t pin = spec->imux_pins[i];
3683 if (pin) {
3684 if (get_connection_index(codec, cap, pin) < 0)
3685 break;
3686 } else if (num_conns <= imux->items[i].index)
3687 break;
3688 }
3689 if (i >= imux->num_items) {
3690 adc_nids[nums] = spec->private_adc_nids[n];
3691 capsrc_nids[nums++] = cap;
3692 }
3693 }
3694 if (!nums) {
3695 /* check whether ADC-switch is possible */
3696 if (!alc_check_dyn_adc_switch(codec)) {
3697 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3698 " using fallback 0x%x\n",
3699 codec->chip_name, spec->private_adc_nids[0]);
3700 spec->num_adc_nids = 1;
3701 spec->auto_mic = 0;
3702 return;
3703 }
3704 } else if (nums != spec->num_adc_nids) {
3705 memcpy(spec->private_adc_nids, adc_nids,
3706 nums * sizeof(hda_nid_t));
3707 memcpy(spec->private_capsrc_nids, capsrc_nids,
3708 nums * sizeof(hda_nid_t));
3709 spec->num_adc_nids = nums;
3710 }
3711
3712 if (spec->auto_mic)
3713 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3714 else if (spec->input_mux->num_items == 1)
3715 spec->num_adc_nids = 1; /* reduce to a single ADC */
3716}
3717
3718/*
3719 * initialize ADC paths
3720 */
3721static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3722{
3723 struct alc_spec *spec = codec->spec;
3724 hda_nid_t nid;
3725
3726 nid = spec->adc_nids[adc_idx];
3727 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003728 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003729 snd_hda_codec_write(codec, nid, 0,
3730 AC_VERB_SET_AMP_GAIN_MUTE,
3731 AMP_IN_MUTE(0));
3732 return;
3733 }
3734 if (!spec->capsrc_nids)
3735 return;
3736 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003737 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003738 snd_hda_codec_write(codec, nid, 0,
3739 AC_VERB_SET_AMP_GAIN_MUTE,
3740 AMP_OUT_MUTE);
3741}
3742
3743static void alc_auto_init_input_src(struct hda_codec *codec)
3744{
3745 struct alc_spec *spec = codec->spec;
3746 int c, nums;
3747
3748 for (c = 0; c < spec->num_adc_nids; c++)
3749 alc_auto_init_adc(codec, c);
3750 if (spec->dyn_adc_switch)
3751 nums = 1;
3752 else
3753 nums = spec->num_adc_nids;
3754 for (c = 0; c < nums; c++)
3755 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3756}
3757
3758/* add mic boosts if needed */
3759static int alc_auto_add_mic_boost(struct hda_codec *codec)
3760{
3761 struct alc_spec *spec = codec->spec;
3762 struct auto_pin_cfg *cfg = &spec->autocfg;
3763 int i, err;
3764 int type_idx = 0;
3765 hda_nid_t nid;
3766 const char *prev_label = NULL;
3767
3768 for (i = 0; i < cfg->num_inputs; i++) {
3769 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3770 break;
3771 nid = cfg->inputs[i].pin;
3772 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3773 const char *label;
3774 char boost_label[32];
3775
3776 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003777 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3778 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003779 if (prev_label && !strcmp(label, prev_label))
3780 type_idx++;
3781 else
3782 type_idx = 0;
3783 prev_label = label;
3784
3785 snprintf(boost_label, sizeof(boost_label),
3786 "%s Boost Volume", label);
3787 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3788 boost_label, type_idx,
3789 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3790 if (err < 0)
3791 return err;
3792 }
3793 }
3794 return 0;
3795}
3796
3797/* select or unmute the given capsrc route */
3798static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3799 int idx)
3800{
3801 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3802 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3803 HDA_AMP_MUTE, 0);
3804 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3805 snd_hda_codec_write_cache(codec, cap, 0,
3806 AC_VERB_SET_CONNECT_SEL, idx);
3807 }
3808}
3809
3810/* set the default connection to that pin */
3811static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3812{
3813 struct alc_spec *spec = codec->spec;
3814 int i;
3815
3816 if (!pin)
3817 return 0;
3818 for (i = 0; i < spec->num_adc_nids; i++) {
3819 hda_nid_t cap = spec->capsrc_nids ?
3820 spec->capsrc_nids[i] : spec->adc_nids[i];
3821 int idx;
3822
3823 idx = get_connection_index(codec, cap, pin);
3824 if (idx < 0)
3825 continue;
3826 select_or_unmute_capsrc(codec, cap, idx);
3827 return i; /* return the found index */
3828 }
3829 return -1; /* not found */
3830}
3831
3832/* initialize some special cases for input sources */
3833static void alc_init_special_input_src(struct hda_codec *codec)
3834{
3835 struct alc_spec *spec = codec->spec;
3836 int i;
3837
3838 for (i = 0; i < spec->autocfg.num_inputs; i++)
3839 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3840}
3841
3842/* assign appropriate capture mixers */
3843static void set_capture_mixer(struct hda_codec *codec)
3844{
3845 struct alc_spec *spec = codec->spec;
3846 static const struct snd_kcontrol_new *caps[2][3] = {
3847 { alc_capture_mixer_nosrc1,
3848 alc_capture_mixer_nosrc2,
3849 alc_capture_mixer_nosrc3 },
3850 { alc_capture_mixer1,
3851 alc_capture_mixer2,
3852 alc_capture_mixer3 },
3853 };
3854
3855 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003856 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003857 if (!spec->capsrc_nids)
3858 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003859 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003860 return; /* no volume in capsrc, too */
3861 spec->vol_in_capsrc = 1;
3862 }
3863
3864 if (spec->num_adc_nids > 0) {
3865 int mux = 0;
3866 int num_adcs = 0;
3867
3868 if (spec->input_mux && spec->input_mux->num_items > 1)
3869 mux = 1;
3870 if (spec->auto_mic) {
3871 num_adcs = 1;
3872 mux = 0;
3873 } else if (spec->dyn_adc_switch)
3874 num_adcs = 1;
3875 if (!num_adcs) {
3876 if (spec->num_adc_nids > 3)
3877 spec->num_adc_nids = 3;
3878 else if (!spec->num_adc_nids)
3879 return;
3880 num_adcs = spec->num_adc_nids;
3881 }
3882 spec->cap_mixer = caps[mux][num_adcs - 1];
3883 }
3884}
3885
3886/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003887 * standard auto-parser initializations
3888 */
3889static void alc_auto_init_std(struct hda_codec *codec)
3890{
3891 struct alc_spec *spec = codec->spec;
3892 alc_auto_init_multi_out(codec);
3893 alc_auto_init_extra_out(codec);
3894 alc_auto_init_analog_input(codec);
3895 alc_auto_init_input_src(codec);
3896 alc_auto_init_digital(codec);
3897 if (spec->unsol_event)
3898 alc_inithook(codec);
3899}
3900
3901/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003902 * Digital-beep handlers
3903 */
3904#ifdef CONFIG_SND_HDA_INPUT_BEEP
3905#define set_beep_amp(spec, nid, idx, dir) \
3906 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3907
3908static const struct snd_pci_quirk beep_white_list[] = {
3909 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3910 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3911 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3912 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3913 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3914 {}
3915};
3916
3917static inline int has_cdefine_beep(struct hda_codec *codec)
3918{
3919 struct alc_spec *spec = codec->spec;
3920 const struct snd_pci_quirk *q;
3921 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3922 if (q)
3923 return q->value;
3924 return spec->cdefine.enable_pcbeep;
3925}
3926#else
3927#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3928#define has_cdefine_beep(codec) 0
3929#endif
3930
3931/* parse the BIOS configuration and set up the alc_spec */
3932/* return 1 if successful, 0 if the proper config is not found,
3933 * or a negative error code
3934 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003935static int alc_parse_auto_config(struct hda_codec *codec,
3936 const hda_nid_t *ignore_nids,
3937 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003938{
3939 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003940 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003941 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003942
Takashi Iwai53c334a2011-08-23 18:27:14 +02003943 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3944 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003945 if (err < 0)
3946 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003947 if (!cfg->line_outs) {
3948 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003949 spec->multiout.max_channels = 2;
3950 spec->no_analog = 1;
3951 goto dig_only;
3952 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003953 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003954 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003955
Takashi Iwai06503672011-10-06 08:27:19 +02003956 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3957 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003958 /* use HP as primary out */
3959 cfg->speaker_outs = cfg->line_outs;
3960 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3961 sizeof(cfg->speaker_pins));
3962 cfg->line_outs = cfg->hp_outs;
3963 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3964 cfg->hp_outs = 0;
3965 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3966 cfg->line_out_type = AUTO_PIN_HP_OUT;
3967 }
3968
Takashi Iwai1d045db2011-07-07 18:23:21 +02003969 err = alc_auto_fill_dac_nids(codec);
3970 if (err < 0)
3971 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003972 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003973 if (err < 0)
3974 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003975 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003976 if (err < 0)
3977 return err;
3978 err = alc_auto_create_hp_out(codec);
3979 if (err < 0)
3980 return err;
3981 err = alc_auto_create_speaker_out(codec);
3982 if (err < 0)
3983 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01003984 err = alc_auto_create_shared_input(codec);
3985 if (err < 0)
3986 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003987 err = alc_auto_create_input_ctls(codec);
3988 if (err < 0)
3989 return err;
3990
3991 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3992
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003993 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02003994 alc_auto_parse_digital(codec);
3995
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003996 if (!spec->no_analog)
3997 alc_remove_invalid_adc_nids(codec);
3998
3999 if (ssid_nids)
4000 alc_ssid_check(codec, ssid_nids);
4001
4002 if (!spec->no_analog) {
4003 alc_auto_check_switches(codec);
4004 err = alc_auto_add_mic_boost(codec);
4005 if (err < 0)
4006 return err;
4007 }
4008
Takashi Iwai1d045db2011-07-07 18:23:21 +02004009 if (spec->kctls.list)
4010 add_mixer(spec, spec->kctls.list);
4011
Takashi Iwai1d045db2011-07-07 18:23:21 +02004012 return 1;
4013}
4014
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004015static int alc880_parse_auto_config(struct hda_codec *codec)
4016{
4017 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4018 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4019 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4020}
4021
Takashi Iwai1d045db2011-07-07 18:23:21 +02004022#ifdef CONFIG_SND_HDA_POWER_SAVE
4023static const struct hda_amp_list alc880_loopbacks[] = {
4024 { 0x0b, HDA_INPUT, 0 },
4025 { 0x0b, HDA_INPUT, 1 },
4026 { 0x0b, HDA_INPUT, 2 },
4027 { 0x0b, HDA_INPUT, 3 },
4028 { 0x0b, HDA_INPUT, 4 },
4029 { } /* end */
4030};
4031#endif
4032
4033/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004034 * ALC880 fix-ups
4035 */
4036enum {
4037 ALC880_FIXUP_GPIO2,
4038 ALC880_FIXUP_MEDION_RIM,
4039};
4040
4041static const struct alc_fixup alc880_fixups[] = {
4042 [ALC880_FIXUP_GPIO2] = {
4043 .type = ALC_FIXUP_VERBS,
4044 .v.verbs = alc_gpio2_init_verbs,
4045 },
4046 [ALC880_FIXUP_MEDION_RIM] = {
4047 .type = ALC_FIXUP_VERBS,
4048 .v.verbs = (const struct hda_verb[]) {
4049 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4050 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4051 { }
4052 },
4053 .chained = true,
4054 .chain_id = ALC880_FIXUP_GPIO2,
4055 },
4056};
4057
4058static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4059 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4060 {}
4061};
4062
4063
4064/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004065 * board setups
4066 */
4067#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4068#define alc_board_config \
4069 snd_hda_check_board_config
4070#define alc_board_codec_sid_config \
4071 snd_hda_check_board_codec_sid_config
4072#include "alc_quirks.c"
4073#else
4074#define alc_board_config(codec, nums, models, tbl) -1
4075#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4076#define setup_preset(codec, x) /* NOP */
4077#endif
4078
4079/*
4080 * OK, here we have finally the patch for ALC880
4081 */
4082#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4083#include "alc880_quirks.c"
4084#endif
4085
4086static int patch_alc880(struct hda_codec *codec)
4087{
4088 struct alc_spec *spec;
4089 int board_config;
4090 int err;
4091
4092 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4093 if (spec == NULL)
4094 return -ENOMEM;
4095
4096 codec->spec = spec;
4097
4098 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004099 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004100
4101 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4102 alc880_models, alc880_cfg_tbl);
4103 if (board_config < 0) {
4104 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4105 codec->chip_name);
4106 board_config = ALC_MODEL_AUTO;
4107 }
4108
4109 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004110 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4111 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4112 }
4113
4114 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004115 /* automatic parse from the BIOS config */
4116 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004117 if (err < 0)
4118 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004119#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4120 else if (!err) {
4121 printk(KERN_INFO
4122 "hda_codec: Cannot set up configuration "
4123 "from BIOS. Using 3-stack mode...\n");
4124 board_config = ALC880_3ST;
4125 }
4126#endif
4127 }
4128
Takashi Iwai1d045db2011-07-07 18:23:21 +02004129 if (board_config != ALC_MODEL_AUTO)
4130 setup_preset(codec, &alc880_presets[board_config]);
4131
Takashi Iwai60a6a842011-07-27 14:01:24 +02004132 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004133 alc_auto_fill_adc_caps(codec);
4134 alc_rebuild_imux_for_auto_mic(codec);
4135 alc_remove_invalid_adc_nids(codec);
4136 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004137
4138 if (!spec->no_analog && !spec->cap_mixer)
4139 set_capture_mixer(codec);
4140
4141 if (!spec->no_analog) {
4142 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004143 if (err < 0)
4144 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004145 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4146 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004147
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004148 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4149
Takashi Iwai1d045db2011-07-07 18:23:21 +02004150 spec->vmaster_nid = 0x0c;
4151
4152 codec->patch_ops = alc_patch_ops;
4153 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004154 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004155#ifdef CONFIG_SND_HDA_POWER_SAVE
4156 if (!spec->loopback.amplist)
4157 spec->loopback.amplist = alc880_loopbacks;
4158#endif
4159
4160 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004161
4162 error:
4163 alc_free(codec);
4164 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004165}
4166
4167
4168/*
4169 * ALC260 support
4170 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004171static int alc260_parse_auto_config(struct hda_codec *codec)
4172{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004173 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004174 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4175 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004176}
4177
Takashi Iwai1d045db2011-07-07 18:23:21 +02004178#ifdef CONFIG_SND_HDA_POWER_SAVE
4179static const struct hda_amp_list alc260_loopbacks[] = {
4180 { 0x07, HDA_INPUT, 0 },
4181 { 0x07, HDA_INPUT, 1 },
4182 { 0x07, HDA_INPUT, 2 },
4183 { 0x07, HDA_INPUT, 3 },
4184 { 0x07, HDA_INPUT, 4 },
4185 { } /* end */
4186};
4187#endif
4188
4189/*
4190 * Pin config fixes
4191 */
4192enum {
4193 PINFIX_HP_DC5750,
4194};
4195
4196static const struct alc_fixup alc260_fixups[] = {
4197 [PINFIX_HP_DC5750] = {
4198 .type = ALC_FIXUP_PINS,
4199 .v.pins = (const struct alc_pincfg[]) {
4200 { 0x11, 0x90130110 }, /* speaker */
4201 { }
4202 }
4203 },
4204};
4205
4206static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4207 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4208 {}
4209};
4210
4211/*
4212 */
4213#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4214#include "alc260_quirks.c"
4215#endif
4216
4217static int patch_alc260(struct hda_codec *codec)
4218{
4219 struct alc_spec *spec;
4220 int err, board_config;
4221
4222 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4223 if (spec == NULL)
4224 return -ENOMEM;
4225
4226 codec->spec = spec;
4227
4228 spec->mixer_nid = 0x07;
4229
4230 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4231 alc260_models, alc260_cfg_tbl);
4232 if (board_config < 0) {
4233 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4234 codec->chip_name);
4235 board_config = ALC_MODEL_AUTO;
4236 }
4237
4238 if (board_config == ALC_MODEL_AUTO) {
4239 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4240 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4241 }
4242
4243 if (board_config == ALC_MODEL_AUTO) {
4244 /* automatic parse from the BIOS config */
4245 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004246 if (err < 0)
4247 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004248#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4249 else if (!err) {
4250 printk(KERN_INFO
4251 "hda_codec: Cannot set up configuration "
4252 "from BIOS. Using base mode...\n");
4253 board_config = ALC260_BASIC;
4254 }
4255#endif
4256 }
4257
Takashi Iwai1d045db2011-07-07 18:23:21 +02004258 if (board_config != ALC_MODEL_AUTO)
4259 setup_preset(codec, &alc260_presets[board_config]);
4260
Takashi Iwai60a6a842011-07-27 14:01:24 +02004261 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004262 alc_auto_fill_adc_caps(codec);
4263 alc_rebuild_imux_for_auto_mic(codec);
4264 alc_remove_invalid_adc_nids(codec);
4265 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004266
4267 if (!spec->no_analog && !spec->cap_mixer)
4268 set_capture_mixer(codec);
4269
4270 if (!spec->no_analog) {
4271 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004272 if (err < 0)
4273 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004274 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4275 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004276
4277 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4278
4279 spec->vmaster_nid = 0x08;
4280
4281 codec->patch_ops = alc_patch_ops;
4282 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004283 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004284 spec->shutup = alc_eapd_shutup;
4285#ifdef CONFIG_SND_HDA_POWER_SAVE
4286 if (!spec->loopback.amplist)
4287 spec->loopback.amplist = alc260_loopbacks;
4288#endif
4289
4290 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004291
4292 error:
4293 alc_free(codec);
4294 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004295}
4296
4297
4298/*
4299 * ALC882/883/885/888/889 support
4300 *
4301 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4302 * configuration. Each pin widget can choose any input DACs and a mixer.
4303 * Each ADC is connected from a mixer of all inputs. This makes possible
4304 * 6-channel independent captures.
4305 *
4306 * In addition, an independent DAC for the multi-playback (not used in this
4307 * driver yet).
4308 */
4309#ifdef CONFIG_SND_HDA_POWER_SAVE
4310#define alc882_loopbacks alc880_loopbacks
4311#endif
4312
4313/*
4314 * Pin config fixes
4315 */
4316enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004317 ALC882_FIXUP_ABIT_AW9D_MAX,
4318 ALC882_FIXUP_LENOVO_Y530,
4319 ALC882_FIXUP_PB_M5210,
4320 ALC882_FIXUP_ACER_ASPIRE_7736,
4321 ALC882_FIXUP_ASUS_W90V,
4322 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004323 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004324 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004325 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004326 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004327 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004328 ALC889_FIXUP_COEF,
4329 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004330 ALC882_FIXUP_ACER_ASPIRE_4930G,
4331 ALC882_FIXUP_ACER_ASPIRE_8930G,
4332 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004333 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004334};
4335
Takashi Iwai68ef0562011-11-09 18:24:44 +01004336static void alc889_fixup_coef(struct hda_codec *codec,
4337 const struct alc_fixup *fix, int action)
4338{
4339 if (action != ALC_FIXUP_ACT_INIT)
4340 return;
4341 alc889_coef_init(codec);
4342}
4343
Takashi Iwai56710872011-11-14 17:42:11 +01004344/* toggle speaker-output according to the hp-jack state */
4345static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4346{
4347 unsigned int gpiostate, gpiomask, gpiodir;
4348
4349 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4350 AC_VERB_GET_GPIO_DATA, 0);
4351
4352 if (!muted)
4353 gpiostate |= (1 << pin);
4354 else
4355 gpiostate &= ~(1 << pin);
4356
4357 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4358 AC_VERB_GET_GPIO_MASK, 0);
4359 gpiomask |= (1 << pin);
4360
4361 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4362 AC_VERB_GET_GPIO_DIRECTION, 0);
4363 gpiodir |= (1 << pin);
4364
4365
4366 snd_hda_codec_write(codec, codec->afg, 0,
4367 AC_VERB_SET_GPIO_MASK, gpiomask);
4368 snd_hda_codec_write(codec, codec->afg, 0,
4369 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4370
4371 msleep(1);
4372
4373 snd_hda_codec_write(codec, codec->afg, 0,
4374 AC_VERB_SET_GPIO_DATA, gpiostate);
4375}
4376
4377/* set up GPIO at initialization */
4378static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4379 const struct alc_fixup *fix, int action)
4380{
4381 if (action != ALC_FIXUP_ACT_INIT)
4382 return;
4383 alc882_gpio_mute(codec, 0, 0);
4384 alc882_gpio_mute(codec, 1, 0);
4385}
4386
Takashi Iwai1d045db2011-07-07 18:23:21 +02004387static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004388 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004389 .type = ALC_FIXUP_PINS,
4390 .v.pins = (const struct alc_pincfg[]) {
4391 { 0x15, 0x01080104 }, /* side */
4392 { 0x16, 0x01011012 }, /* rear */
4393 { 0x17, 0x01016011 }, /* clfe */
4394 { }
4395 }
4396 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004397 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004398 .type = ALC_FIXUP_PINS,
4399 .v.pins = (const struct alc_pincfg[]) {
4400 { 0x15, 0x99130112 }, /* rear int speakers */
4401 { 0x16, 0x99130111 }, /* subwoofer */
4402 { }
4403 }
4404 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004405 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004406 .type = ALC_FIXUP_VERBS,
4407 .v.verbs = (const struct hda_verb[]) {
4408 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4409 {}
4410 }
4411 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004412 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004413 .type = ALC_FIXUP_SKU,
4414 .v.sku = ALC_FIXUP_SKU_IGNORE,
4415 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004416 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004417 .type = ALC_FIXUP_PINS,
4418 .v.pins = (const struct alc_pincfg[]) {
4419 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4420 { }
4421 }
4422 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004423 [ALC889_FIXUP_VAIO_TT] = {
4424 .type = ALC_FIXUP_PINS,
4425 .v.pins = (const struct alc_pincfg[]) {
4426 { 0x17, 0x90170111 }, /* hidden surround speaker */
4427 { }
4428 }
4429 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004430 [ALC888_FIXUP_EEE1601] = {
4431 .type = ALC_FIXUP_VERBS,
4432 .v.verbs = (const struct hda_verb[]) {
4433 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4434 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4435 { }
4436 }
Takashi Iwai177943a2011-11-09 12:55:18 +01004437 },
4438 [ALC882_FIXUP_EAPD] = {
4439 .type = ALC_FIXUP_VERBS,
4440 .v.verbs = (const struct hda_verb[]) {
4441 /* change to EAPD mode */
4442 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4443 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4444 { }
4445 }
4446 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004447 [ALC883_FIXUP_EAPD] = {
4448 .type = ALC_FIXUP_VERBS,
4449 .v.verbs = (const struct hda_verb[]) {
4450 /* change to EAPD mode */
4451 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4452 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4453 { }
4454 }
4455 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004456 [ALC883_FIXUP_ACER_EAPD] = {
4457 .type = ALC_FIXUP_VERBS,
4458 .v.verbs = (const struct hda_verb[]) {
4459 /* eanable EAPD on Acer laptops */
4460 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4461 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4462 { }
4463 }
4464 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004465 [ALC882_FIXUP_GPIO3] = {
4466 .type = ALC_FIXUP_VERBS,
4467 .v.verbs = alc_gpio3_init_verbs,
4468 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004469 [ALC882_FIXUP_ASUS_W2JC] = {
4470 .type = ALC_FIXUP_VERBS,
4471 .v.verbs = alc_gpio1_init_verbs,
4472 .chained = true,
4473 .chain_id = ALC882_FIXUP_EAPD,
4474 },
4475 [ALC889_FIXUP_COEF] = {
4476 .type = ALC_FIXUP_FUNC,
4477 .v.func = alc889_fixup_coef,
4478 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004479 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4480 .type = ALC_FIXUP_PINS,
4481 .v.pins = (const struct alc_pincfg[]) {
4482 { 0x16, 0x99130111 }, /* CLFE speaker */
4483 { 0x17, 0x99130112 }, /* surround speaker */
4484 { }
4485 }
4486 },
4487 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4488 .type = ALC_FIXUP_PINS,
4489 .v.pins = (const struct alc_pincfg[]) {
4490 { 0x16, 0x99130111 }, /* CLFE speaker */
4491 { 0x1b, 0x99130112 }, /* surround speaker */
4492 { }
4493 },
4494 .chained = true,
4495 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4496 },
4497 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4498 /* additional init verbs for Acer Aspire 8930G */
4499 .type = ALC_FIXUP_VERBS,
4500 .v.verbs = (const struct hda_verb[]) {
4501 /* Enable all DACs */
4502 /* DAC DISABLE/MUTE 1? */
4503 /* setting bits 1-5 disables DAC nids 0x02-0x06
4504 * apparently. Init=0x38 */
4505 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4506 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4507 /* DAC DISABLE/MUTE 2? */
4508 /* some bit here disables the other DACs.
4509 * Init=0x4900 */
4510 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4511 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4512 /* DMIC fix
4513 * This laptop has a stereo digital microphone.
4514 * The mics are only 1cm apart which makes the stereo
4515 * useless. However, either the mic or the ALC889
4516 * makes the signal become a difference/sum signal
4517 * instead of standard stereo, which is annoying.
4518 * So instead we flip this bit which makes the
4519 * codec replicate the sum signal to both channels,
4520 * turning it into a normal mono mic.
4521 */
4522 /* DMIC_CONTROL? Init value = 0x0001 */
4523 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4524 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4525 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4526 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4527 { }
4528 }
4529 },
Takashi Iwai56710872011-11-14 17:42:11 +01004530 [ALC885_FIXUP_MACPRO_GPIO] = {
4531 .type = ALC_FIXUP_FUNC,
4532 .v.func = alc885_fixup_macpro_gpio,
4533 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004534};
4535
4536static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004537 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4538 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4539 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4540 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4541 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4542 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004543 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4544 ALC882_FIXUP_ACER_ASPIRE_4930G),
4545 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4546 ALC882_FIXUP_ACER_ASPIRE_4930G),
4547 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4548 ALC882_FIXUP_ACER_ASPIRE_8930G),
4549 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4550 ALC882_FIXUP_ACER_ASPIRE_8930G),
4551 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4552 ALC882_FIXUP_ACER_ASPIRE_4930G),
4553 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4554 ALC882_FIXUP_ACER_ASPIRE_4930G),
4555 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4556 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004557 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004558 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01004559 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004560 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004561 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004562 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004563 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01004564
4565 /* All Apple entries are in codec SSIDs */
4566 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4567 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4568 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4569 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4570 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4571
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004572 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004573 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004574 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004575 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4576 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004577 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004578 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004579 {}
4580};
4581
4582/*
4583 * BIOS auto configuration
4584 */
4585/* almost identical with ALC880 parser... */
4586static int alc882_parse_auto_config(struct hda_codec *codec)
4587{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004588 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004589 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4590 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004591}
4592
Takashi Iwai1d045db2011-07-07 18:23:21 +02004593/*
4594 */
4595#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4596#include "alc882_quirks.c"
4597#endif
4598
4599static int patch_alc882(struct hda_codec *codec)
4600{
4601 struct alc_spec *spec;
4602 int err, board_config;
4603
4604 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4605 if (spec == NULL)
4606 return -ENOMEM;
4607
4608 codec->spec = spec;
4609
4610 spec->mixer_nid = 0x0b;
4611
4612 switch (codec->vendor_id) {
4613 case 0x10ec0882:
4614 case 0x10ec0885:
4615 break;
4616 default:
4617 /* ALC883 and variants */
4618 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4619 break;
4620 }
4621
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004622 err = alc_codec_rename_from_preset(codec);
4623 if (err < 0)
4624 goto error;
4625
Takashi Iwaib2539692011-11-14 17:32:17 +01004626 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4627 alc882_models, NULL);
4628 if (board_config < 0)
4629 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004630 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4631
4632 if (board_config < 0) {
4633 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4634 codec->chip_name);
4635 board_config = ALC_MODEL_AUTO;
4636 }
4637
4638 if (board_config == ALC_MODEL_AUTO) {
4639 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4640 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4641 }
4642
4643 alc_auto_parse_customize_define(codec);
4644
4645 if (board_config == ALC_MODEL_AUTO) {
4646 /* automatic parse from the BIOS config */
4647 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004648 if (err < 0)
4649 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004650 }
4651
Takashi Iwai1d045db2011-07-07 18:23:21 +02004652 if (board_config != ALC_MODEL_AUTO)
4653 setup_preset(codec, &alc882_presets[board_config]);
4654
Takashi Iwai60a6a842011-07-27 14:01:24 +02004655 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004656 alc_auto_fill_adc_caps(codec);
4657 alc_rebuild_imux_for_auto_mic(codec);
4658 alc_remove_invalid_adc_nids(codec);
4659 }
4660
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004661 if (!spec->no_analog && !spec->cap_mixer)
4662 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004663
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004664 if (!spec->no_analog && has_cdefine_beep(codec)) {
4665 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004666 if (err < 0)
4667 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004668 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004669 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004670
4671 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4672
4673 spec->vmaster_nid = 0x0c;
4674
4675 codec->patch_ops = alc_patch_ops;
4676 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004677 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004678
4679 alc_init_jacks(codec);
4680#ifdef CONFIG_SND_HDA_POWER_SAVE
4681 if (!spec->loopback.amplist)
4682 spec->loopback.amplist = alc882_loopbacks;
4683#endif
4684
4685 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004686
4687 error:
4688 alc_free(codec);
4689 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004690}
4691
4692
4693/*
4694 * ALC262 support
4695 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004696static int alc262_parse_auto_config(struct hda_codec *codec)
4697{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004698 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004699 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4700 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004701}
4702
4703/*
4704 * Pin config fixes
4705 */
4706enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004707 ALC262_FIXUP_FSC_H270,
4708 ALC262_FIXUP_HP_Z200,
4709 ALC262_FIXUP_TYAN,
Takashi Iwai12837c92011-11-07 12:45:24 +01004710 ALC262_FIXUP_TOSHIBA_RX1,
Takashi Iwaic4701502011-11-07 14:20:07 +01004711 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004712 ALC262_FIXUP_BENQ,
4713 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004714};
4715
4716static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004717 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004718 .type = ALC_FIXUP_PINS,
4719 .v.pins = (const struct alc_pincfg[]) {
4720 { 0x14, 0x99130110 }, /* speaker */
4721 { 0x15, 0x0221142f }, /* front HP */
4722 { 0x1b, 0x0121141f }, /* rear HP */
4723 { }
4724 }
4725 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004726 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004727 .type = ALC_FIXUP_PINS,
4728 .v.pins = (const struct alc_pincfg[]) {
4729 { 0x16, 0x99130120 }, /* internal speaker */
4730 { }
4731 }
4732 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004733 [ALC262_FIXUP_TYAN] = {
4734 .type = ALC_FIXUP_PINS,
4735 .v.pins = (const struct alc_pincfg[]) {
4736 { 0x14, 0x1993e1f0 }, /* int AUX */
4737 { }
4738 }
4739 },
Takashi Iwai12837c92011-11-07 12:45:24 +01004740 [ALC262_FIXUP_TOSHIBA_RX1] = {
4741 .type = ALC_FIXUP_PINS,
4742 .v.pins = (const struct alc_pincfg[]) {
4743 { 0x14, 0x90170110 }, /* speaker */
4744 { 0x15, 0x0421101f }, /* HP */
4745 { 0x1a, 0x40f000f0 }, /* N/A */
4746 { 0x1b, 0x40f000f0 }, /* N/A */
4747 { 0x1e, 0x40f000f0 }, /* N/A */
4748 }
4749 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004750 [ALC262_FIXUP_LENOVO_3000] = {
4751 .type = ALC_FIXUP_VERBS,
4752 .v.verbs = (const struct hda_verb[]) {
4753 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004754 {}
4755 },
4756 .chained = true,
4757 .chain_id = ALC262_FIXUP_BENQ,
4758 },
4759 [ALC262_FIXUP_BENQ] = {
4760 .type = ALC_FIXUP_VERBS,
4761 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004762 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4763 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4764 {}
4765 }
4766 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004767 [ALC262_FIXUP_BENQ_T31] = {
4768 .type = ALC_FIXUP_VERBS,
4769 .v.verbs = (const struct hda_verb[]) {
4770 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4771 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4772 {}
4773 }
4774 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004775};
4776
4777static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004778 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004779 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4780 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004781 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
Takashi Iwai12837c92011-11-07 12:45:24 +01004782 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4783 ALC262_FIXUP_TOSHIBA_RX1),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004784 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004785 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004786 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4787 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004788 {}
4789};
4790
4791
4792#ifdef CONFIG_SND_HDA_POWER_SAVE
4793#define alc262_loopbacks alc880_loopbacks
4794#endif
4795
Takashi Iwai1d045db2011-07-07 18:23:21 +02004796/*
4797 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004798static int patch_alc262(struct hda_codec *codec)
4799{
4800 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004801 int err;
4802
4803 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4804 if (spec == NULL)
4805 return -ENOMEM;
4806
4807 codec->spec = spec;
4808
4809 spec->mixer_nid = 0x0b;
4810
4811#if 0
4812 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4813 * under-run
4814 */
4815 {
4816 int tmp;
4817 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4818 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4819 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4820 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4821 }
4822#endif
4823 alc_auto_parse_customize_define(codec);
4824
4825 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4826
Takashi Iwai42399f72011-11-07 17:18:44 +01004827 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4828 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004829
Takashi Iwai42399f72011-11-07 17:18:44 +01004830 /* automatic parse from the BIOS config */
4831 err = alc262_parse_auto_config(codec);
4832 if (err < 0)
4833 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004834
Takashi Iwai60a6a842011-07-27 14:01:24 +02004835 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004836 alc_auto_fill_adc_caps(codec);
4837 alc_rebuild_imux_for_auto_mic(codec);
4838 alc_remove_invalid_adc_nids(codec);
4839 }
4840
4841 if (!spec->no_analog && !spec->cap_mixer)
4842 set_capture_mixer(codec);
4843
Takashi Iwai1d045db2011-07-07 18:23:21 +02004844 if (!spec->no_analog && has_cdefine_beep(codec)) {
4845 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004846 if (err < 0)
4847 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004848 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004849 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004850
4851 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4852
4853 spec->vmaster_nid = 0x0c;
4854
4855 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004856 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004857 spec->shutup = alc_eapd_shutup;
4858
4859 alc_init_jacks(codec);
4860#ifdef CONFIG_SND_HDA_POWER_SAVE
4861 if (!spec->loopback.amplist)
4862 spec->loopback.amplist = alc262_loopbacks;
4863#endif
4864
4865 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004866
4867 error:
4868 alc_free(codec);
4869 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004870}
4871
4872/*
4873 * ALC268
4874 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004875/* bind Beep switches of both NID 0x0f and 0x10 */
4876static const struct hda_bind_ctls alc268_bind_beep_sw = {
4877 .ops = &snd_hda_bind_sw,
4878 .values = {
4879 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4880 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4881 0
4882 },
4883};
4884
4885static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4886 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4887 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4888 { }
4889};
4890
4891/* set PCBEEP vol = 0, mute connections */
4892static const struct hda_verb alc268_beep_init_verbs[] = {
4893 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4894 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4895 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4896 { }
4897};
4898
4899/*
4900 * BIOS auto configuration
4901 */
4902static int alc268_parse_auto_config(struct hda_codec *codec)
4903{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004904 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004905 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004906 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4907 if (err > 0) {
4908 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4909 add_mixer(spec, alc268_beep_mixer);
4910 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004911 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004912 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004913 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004914}
4915
Takashi Iwai1d045db2011-07-07 18:23:21 +02004916/*
4917 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004918static int patch_alc268(struct hda_codec *codec)
4919{
4920 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004921 int i, has_beep, err;
4922
4923 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4924 if (spec == NULL)
4925 return -ENOMEM;
4926
4927 codec->spec = spec;
4928
4929 /* ALC268 has no aa-loopback mixer */
4930
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004931 /* automatic parse from the BIOS config */
4932 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004933 if (err < 0)
4934 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004935
Takashi Iwai1d045db2011-07-07 18:23:21 +02004936 has_beep = 0;
4937 for (i = 0; i < spec->num_mixers; i++) {
4938 if (spec->mixers[i] == alc268_beep_mixer) {
4939 has_beep = 1;
4940 break;
4941 }
4942 }
4943
4944 if (has_beep) {
4945 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004946 if (err < 0)
4947 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004948 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4949 /* override the amp caps for beep generator */
4950 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4951 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4952 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4953 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4954 (0 << AC_AMPCAP_MUTE_SHIFT));
4955 }
4956
Takashi Iwai60a6a842011-07-27 14:01:24 +02004957 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004958 alc_auto_fill_adc_caps(codec);
4959 alc_rebuild_imux_for_auto_mic(codec);
4960 alc_remove_invalid_adc_nids(codec);
4961 }
4962
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004963 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004964 set_capture_mixer(codec);
4965
4966 spec->vmaster_nid = 0x02;
4967
4968 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004969 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004970 spec->shutup = alc_eapd_shutup;
4971
4972 alc_init_jacks(codec);
4973
4974 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004975
4976 error:
4977 alc_free(codec);
4978 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004979}
4980
4981/*
4982 * ALC269
4983 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004984#ifdef CONFIG_SND_HDA_POWER_SAVE
4985#define alc269_loopbacks alc880_loopbacks
4986#endif
4987
4988static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4989 .substreams = 1,
4990 .channels_min = 2,
4991 .channels_max = 8,
4992 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
4993 /* NID is set in alc_build_pcms */
4994 .ops = {
4995 .open = alc_playback_pcm_open,
4996 .prepare = alc_playback_pcm_prepare,
4997 .cleanup = alc_playback_pcm_cleanup
4998 },
4999};
5000
5001static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5002 .substreams = 1,
5003 .channels_min = 2,
5004 .channels_max = 2,
5005 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5006 /* NID is set in alc_build_pcms */
5007};
5008
5009#ifdef CONFIG_SND_HDA_POWER_SAVE
5010static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5011{
5012 switch (codec->subsystem_id) {
5013 case 0x103c1586:
5014 return 1;
5015 }
5016 return 0;
5017}
5018
5019static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5020{
5021 /* update mute-LED according to the speaker mute state */
5022 if (nid == 0x01 || nid == 0x14) {
5023 int pinval;
5024 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5025 HDA_AMP_MUTE)
5026 pinval = 0x24;
5027 else
5028 pinval = 0x20;
5029 /* mic2 vref pin is used for mute LED control */
5030 snd_hda_codec_update_cache(codec, 0x19, 0,
5031 AC_VERB_SET_PIN_WIDGET_CONTROL,
5032 pinval);
5033 }
5034 return alc_check_power_status(codec, nid);
5035}
5036#endif /* CONFIG_SND_HDA_POWER_SAVE */
5037
5038/* different alc269-variants */
5039enum {
5040 ALC269_TYPE_ALC269VA,
5041 ALC269_TYPE_ALC269VB,
5042 ALC269_TYPE_ALC269VC,
5043};
5044
5045/*
5046 * BIOS auto configuration
5047 */
5048static int alc269_parse_auto_config(struct hda_codec *codec)
5049{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005050 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005051 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5052 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5053 struct alc_spec *spec = codec->spec;
5054 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5055 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005056
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005057 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005058}
5059
Takashi Iwai1d045db2011-07-07 18:23:21 +02005060static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5061{
5062 int val = alc_read_coef_idx(codec, 0x04);
5063 if (power_up)
5064 val |= 1 << 11;
5065 else
5066 val &= ~(1 << 11);
5067 alc_write_coef_idx(codec, 0x04, val);
5068}
5069
5070static void alc269_shutup(struct hda_codec *codec)
5071{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005072 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005073 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005074 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005075 alc269_toggle_power_output(codec, 0);
5076 msleep(150);
5077 }
5078}
5079
Takashi Iwai2a439522011-07-26 09:52:50 +02005080#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005081static int alc269_resume(struct hda_codec *codec)
5082{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005083 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005084 alc269_toggle_power_output(codec, 0);
5085 msleep(150);
5086 }
5087
5088 codec->patch_ops.init(codec);
5089
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005090 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005091 alc269_toggle_power_output(codec, 1);
5092 msleep(200);
5093 }
5094
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005095 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005096 alc269_toggle_power_output(codec, 1);
5097
5098 snd_hda_codec_resume_amp(codec);
5099 snd_hda_codec_resume_cache(codec);
5100 hda_call_check_power_status(codec, 0x01);
5101 return 0;
5102}
Takashi Iwai2a439522011-07-26 09:52:50 +02005103#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005104
5105static void alc269_fixup_hweq(struct hda_codec *codec,
5106 const struct alc_fixup *fix, int action)
5107{
5108 int coef;
5109
5110 if (action != ALC_FIXUP_ACT_INIT)
5111 return;
5112 coef = alc_read_coef_idx(codec, 0x1e);
5113 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5114}
5115
5116static void alc271_fixup_dmic(struct hda_codec *codec,
5117 const struct alc_fixup *fix, int action)
5118{
5119 static const struct hda_verb verbs[] = {
5120 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5121 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5122 {}
5123 };
5124 unsigned int cfg;
5125
5126 if (strcmp(codec->chip_name, "ALC271X"))
5127 return;
5128 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5129 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5130 snd_hda_sequence_write(codec, verbs);
5131}
5132
Takashi Iwai017f2a12011-07-09 14:42:25 +02005133static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5134 const struct alc_fixup *fix, int action)
5135{
5136 struct alc_spec *spec = codec->spec;
5137
5138 if (action != ALC_FIXUP_ACT_PROBE)
5139 return;
5140
5141 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5142 * fix the sample rate of analog I/O to 44.1kHz
5143 */
5144 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5145 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5146}
5147
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005148static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5149 const struct alc_fixup *fix, int action)
5150{
5151 int coef;
5152
5153 if (action != ALC_FIXUP_ACT_INIT)
5154 return;
5155 /* The digital-mic unit sends PDM (differential signal) instead of
5156 * the standard PCM, thus you can't record a valid mono stream as is.
5157 * Below is a workaround specific to ALC269 to control the dmic
5158 * signal source as mono.
5159 */
5160 coef = alc_read_coef_idx(codec, 0x07);
5161 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5162}
5163
Takashi Iwai24519912011-08-16 15:08:49 +02005164static void alc269_quanta_automute(struct hda_codec *codec)
5165{
David Henningsson42cf0d02011-09-20 12:04:56 +02005166 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005167
5168 snd_hda_codec_write(codec, 0x20, 0,
5169 AC_VERB_SET_COEF_INDEX, 0x0c);
5170 snd_hda_codec_write(codec, 0x20, 0,
5171 AC_VERB_SET_PROC_COEF, 0x680);
5172
5173 snd_hda_codec_write(codec, 0x20, 0,
5174 AC_VERB_SET_COEF_INDEX, 0x0c);
5175 snd_hda_codec_write(codec, 0x20, 0,
5176 AC_VERB_SET_PROC_COEF, 0x480);
5177}
5178
5179static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5180 const struct alc_fixup *fix, int action)
5181{
5182 struct alc_spec *spec = codec->spec;
5183 if (action != ALC_FIXUP_ACT_PROBE)
5184 return;
5185 spec->automute_hook = alc269_quanta_automute;
5186}
5187
Takashi Iwai1d045db2011-07-07 18:23:21 +02005188enum {
5189 ALC269_FIXUP_SONY_VAIO,
5190 ALC275_FIXUP_SONY_VAIO_GPIO2,
5191 ALC269_FIXUP_DELL_M101Z,
5192 ALC269_FIXUP_SKU_IGNORE,
5193 ALC269_FIXUP_ASUS_G73JW,
5194 ALC269_FIXUP_LENOVO_EAPD,
5195 ALC275_FIXUP_SONY_HWEQ,
5196 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005197 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005198 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005199 ALC269_FIXUP_QUANTA_MUTE,
5200 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005201 ALC269_FIXUP_AMIC,
5202 ALC269_FIXUP_DMIC,
5203 ALC269VB_FIXUP_AMIC,
5204 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005205};
5206
5207static const struct alc_fixup alc269_fixups[] = {
5208 [ALC269_FIXUP_SONY_VAIO] = {
5209 .type = ALC_FIXUP_VERBS,
5210 .v.verbs = (const struct hda_verb[]) {
5211 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5212 {}
5213 }
5214 },
5215 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5216 .type = ALC_FIXUP_VERBS,
5217 .v.verbs = (const struct hda_verb[]) {
5218 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5219 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5220 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5221 { }
5222 },
5223 .chained = true,
5224 .chain_id = ALC269_FIXUP_SONY_VAIO
5225 },
5226 [ALC269_FIXUP_DELL_M101Z] = {
5227 .type = ALC_FIXUP_VERBS,
5228 .v.verbs = (const struct hda_verb[]) {
5229 /* Enables internal speaker */
5230 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5231 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5232 {}
5233 }
5234 },
5235 [ALC269_FIXUP_SKU_IGNORE] = {
5236 .type = ALC_FIXUP_SKU,
5237 .v.sku = ALC_FIXUP_SKU_IGNORE,
5238 },
5239 [ALC269_FIXUP_ASUS_G73JW] = {
5240 .type = ALC_FIXUP_PINS,
5241 .v.pins = (const struct alc_pincfg[]) {
5242 { 0x17, 0x99130111 }, /* subwoofer */
5243 { }
5244 }
5245 },
5246 [ALC269_FIXUP_LENOVO_EAPD] = {
5247 .type = ALC_FIXUP_VERBS,
5248 .v.verbs = (const struct hda_verb[]) {
5249 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5250 {}
5251 }
5252 },
5253 [ALC275_FIXUP_SONY_HWEQ] = {
5254 .type = ALC_FIXUP_FUNC,
5255 .v.func = alc269_fixup_hweq,
5256 .chained = true,
5257 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5258 },
5259 [ALC271_FIXUP_DMIC] = {
5260 .type = ALC_FIXUP_FUNC,
5261 .v.func = alc271_fixup_dmic,
5262 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005263 [ALC269_FIXUP_PCM_44K] = {
5264 .type = ALC_FIXUP_FUNC,
5265 .v.func = alc269_fixup_pcm_44k,
5266 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005267 [ALC269_FIXUP_STEREO_DMIC] = {
5268 .type = ALC_FIXUP_FUNC,
5269 .v.func = alc269_fixup_stereo_dmic,
5270 },
Takashi Iwai24519912011-08-16 15:08:49 +02005271 [ALC269_FIXUP_QUANTA_MUTE] = {
5272 .type = ALC_FIXUP_FUNC,
5273 .v.func = alc269_fixup_quanta_mute,
5274 },
5275 [ALC269_FIXUP_LIFEBOOK] = {
5276 .type = ALC_FIXUP_PINS,
5277 .v.pins = (const struct alc_pincfg[]) {
5278 { 0x1a, 0x2101103f }, /* dock line-out */
5279 { 0x1b, 0x23a11040 }, /* dock mic-in */
5280 { }
5281 },
5282 .chained = true,
5283 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5284 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005285 [ALC269_FIXUP_AMIC] = {
5286 .type = ALC_FIXUP_PINS,
5287 .v.pins = (const struct alc_pincfg[]) {
5288 { 0x14, 0x99130110 }, /* speaker */
5289 { 0x15, 0x0121401f }, /* HP out */
5290 { 0x18, 0x01a19c20 }, /* mic */
5291 { 0x19, 0x99a3092f }, /* int-mic */
5292 { }
5293 },
5294 },
5295 [ALC269_FIXUP_DMIC] = {
5296 .type = ALC_FIXUP_PINS,
5297 .v.pins = (const struct alc_pincfg[]) {
5298 { 0x12, 0x99a3092f }, /* int-mic */
5299 { 0x14, 0x99130110 }, /* speaker */
5300 { 0x15, 0x0121401f }, /* HP out */
5301 { 0x18, 0x01a19c20 }, /* mic */
5302 { }
5303 },
5304 },
5305 [ALC269VB_FIXUP_AMIC] = {
5306 .type = ALC_FIXUP_PINS,
5307 .v.pins = (const struct alc_pincfg[]) {
5308 { 0x14, 0x99130110 }, /* speaker */
5309 { 0x18, 0x01a19c20 }, /* mic */
5310 { 0x19, 0x99a3092f }, /* int-mic */
5311 { 0x21, 0x0121401f }, /* HP out */
5312 { }
5313 },
5314 },
5315 [ALC269_FIXUP_DMIC] = {
5316 .type = ALC_FIXUP_PINS,
5317 .v.pins = (const struct alc_pincfg[]) {
5318 { 0x12, 0x99a3092f }, /* int-mic */
5319 { 0x14, 0x99130110 }, /* speaker */
5320 { 0x18, 0x01a19c20 }, /* mic */
5321 { 0x21, 0x0121401f }, /* HP out */
5322 { }
5323 },
5324 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005325};
5326
5327static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005328 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005329 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5330 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5331 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5332 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5333 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005334 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5335 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5336 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5337 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5338 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5339 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005340 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005341 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5342 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5343 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5344 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5345 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005346 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005347 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005348 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005349
5350#if 1
5351 /* Below is a quirk table taken from the old code.
5352 * Basically the device should work as is without the fixup table.
5353 * If BIOS doesn't give a proper info, enable the corresponding
5354 * fixup entry.
5355 */
5356 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5357 ALC269_FIXUP_AMIC),
5358 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5359 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
5360 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5361 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5362 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5363 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5364 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5365 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5366 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5367 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5368 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5369 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5370 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5371 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5372 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5373 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5374 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5375 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5376 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5377 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5378 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5379 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5380 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5381 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5382 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5383 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5384 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5385 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5386 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5387 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5388 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5389 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5390 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5391 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5392 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5393 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5394 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5395 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5396 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5397 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5398#endif
5399 {}
5400};
5401
5402static const struct alc_model_fixup alc269_fixup_models[] = {
5403 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5404 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005405 {}
5406};
5407
5408
5409static int alc269_fill_coef(struct hda_codec *codec)
5410{
5411 int val;
5412
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005413 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005414 alc_write_coef_idx(codec, 0xf, 0x960b);
5415 alc_write_coef_idx(codec, 0xe, 0x8817);
5416 }
5417
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005418 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005419 alc_write_coef_idx(codec, 0xf, 0x960b);
5420 alc_write_coef_idx(codec, 0xe, 0x8814);
5421 }
5422
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005423 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005424 val = alc_read_coef_idx(codec, 0x04);
5425 /* Power up output pin */
5426 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5427 }
5428
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005429 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005430 val = alc_read_coef_idx(codec, 0xd);
5431 if ((val & 0x0c00) >> 10 != 0x1) {
5432 /* Capless ramp up clock control */
5433 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5434 }
5435 val = alc_read_coef_idx(codec, 0x17);
5436 if ((val & 0x01c0) >> 6 != 0x4) {
5437 /* Class D power on reset */
5438 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5439 }
5440 }
5441
5442 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5443 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5444
5445 val = alc_read_coef_idx(codec, 0x4); /* HP */
5446 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5447
5448 return 0;
5449}
5450
5451/*
5452 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005453static int patch_alc269(struct hda_codec *codec)
5454{
5455 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005456 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005457
5458 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5459 if (spec == NULL)
5460 return -ENOMEM;
5461
5462 codec->spec = spec;
5463
5464 spec->mixer_nid = 0x0b;
5465
5466 alc_auto_parse_customize_define(codec);
5467
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005468 err = alc_codec_rename_from_preset(codec);
5469 if (err < 0)
5470 goto error;
5471
Takashi Iwai1d045db2011-07-07 18:23:21 +02005472 if (codec->vendor_id == 0x10ec0269) {
5473 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005474 switch (alc_get_coef0(codec) & 0x00f0) {
5475 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005476 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005477 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005478 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005479 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005480 break;
5481 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005482 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5483 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005484 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005485 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005486 break;
5487 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005488 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005489 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005490 if (err < 0)
5491 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005492 alc269_fill_coef(codec);
5493 }
5494
Takashi Iwaia4297b52011-08-23 18:40:12 +02005495 alc_pick_fixup(codec, alc269_fixup_models,
5496 alc269_fixup_tbl, alc269_fixups);
5497 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005498
Takashi Iwaia4297b52011-08-23 18:40:12 +02005499 /* automatic parse from the BIOS config */
5500 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005501 if (err < 0)
5502 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005503
Takashi Iwai60a6a842011-07-27 14:01:24 +02005504 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505 alc_auto_fill_adc_caps(codec);
5506 alc_rebuild_imux_for_auto_mic(codec);
5507 alc_remove_invalid_adc_nids(codec);
5508 }
5509
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005510 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005511 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005512
5513 if (!spec->no_analog && has_cdefine_beep(codec)) {
5514 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005515 if (err < 0)
5516 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005517 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005518 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005519
5520 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5521
5522 spec->vmaster_nid = 0x02;
5523
5524 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005525#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005526 codec->patch_ops.resume = alc269_resume;
5527#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005528 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005529 spec->shutup = alc269_shutup;
5530
5531 alc_init_jacks(codec);
5532#ifdef CONFIG_SND_HDA_POWER_SAVE
5533 if (!spec->loopback.amplist)
5534 spec->loopback.amplist = alc269_loopbacks;
5535 if (alc269_mic2_for_mute_led(codec))
5536 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5537#endif
5538
5539 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005540
5541 error:
5542 alc_free(codec);
5543 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005544}
5545
5546/*
5547 * ALC861
5548 */
5549
Takashi Iwai1d045db2011-07-07 18:23:21 +02005550static int alc861_parse_auto_config(struct hda_codec *codec)
5551{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005552 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005553 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5554 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005555}
5556
Takashi Iwai1d045db2011-07-07 18:23:21 +02005557#ifdef CONFIG_SND_HDA_POWER_SAVE
5558static const struct hda_amp_list alc861_loopbacks[] = {
5559 { 0x15, HDA_INPUT, 0 },
5560 { 0x15, HDA_INPUT, 1 },
5561 { 0x15, HDA_INPUT, 2 },
5562 { 0x15, HDA_INPUT, 3 },
5563 { } /* end */
5564};
5565#endif
5566
5567
5568/* Pin config fixes */
5569enum {
5570 PINFIX_FSC_AMILO_PI1505,
5571};
5572
5573static const struct alc_fixup alc861_fixups[] = {
5574 [PINFIX_FSC_AMILO_PI1505] = {
5575 .type = ALC_FIXUP_PINS,
5576 .v.pins = (const struct alc_pincfg[]) {
5577 { 0x0b, 0x0221101f }, /* HP */
5578 { 0x0f, 0x90170310 }, /* speaker */
5579 { }
5580 }
5581 },
5582};
5583
5584static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5585 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5586 {}
5587};
5588
5589/*
5590 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005591static int patch_alc861(struct hda_codec *codec)
5592{
5593 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005594 int err;
5595
5596 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5597 if (spec == NULL)
5598 return -ENOMEM;
5599
5600 codec->spec = spec;
5601
5602 spec->mixer_nid = 0x15;
5603
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005604 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5605 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005606
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005607 /* automatic parse from the BIOS config */
5608 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005609 if (err < 0)
5610 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005611
Takashi Iwai60a6a842011-07-27 14:01:24 +02005612 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005613 alc_auto_fill_adc_caps(codec);
5614 alc_rebuild_imux_for_auto_mic(codec);
5615 alc_remove_invalid_adc_nids(codec);
5616 }
5617
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005618 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005619 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005620
5621 if (!spec->no_analog) {
5622 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005623 if (err < 0)
5624 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005625 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5626 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005627
5628 spec->vmaster_nid = 0x03;
5629
5630 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5631
5632 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005633 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005634#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005635 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005636 if (!spec->loopback.amplist)
5637 spec->loopback.amplist = alc861_loopbacks;
5638#endif
5639
5640 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005641
5642 error:
5643 alc_free(codec);
5644 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645}
5646
5647/*
5648 * ALC861-VD support
5649 *
5650 * Based on ALC882
5651 *
5652 * In addition, an independent DAC
5653 */
5654#ifdef CONFIG_SND_HDA_POWER_SAVE
5655#define alc861vd_loopbacks alc880_loopbacks
5656#endif
5657
Takashi Iwai1d045db2011-07-07 18:23:21 +02005658static int alc861vd_parse_auto_config(struct hda_codec *codec)
5659{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005660 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005661 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5662 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005663}
5664
Takashi Iwai1d045db2011-07-07 18:23:21 +02005665enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005666 ALC660VD_FIX_ASUS_GPIO1,
5667 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005668};
5669
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005670/* exclude VREF80 */
5671static void alc861vd_fixup_dallas(struct hda_codec *codec,
5672 const struct alc_fixup *fix, int action)
5673{
5674 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5675 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5676 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5677 }
5678}
5679
Takashi Iwai1d045db2011-07-07 18:23:21 +02005680static const struct alc_fixup alc861vd_fixups[] = {
5681 [ALC660VD_FIX_ASUS_GPIO1] = {
5682 .type = ALC_FIXUP_VERBS,
5683 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005684 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005685 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5686 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5687 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5688 { }
5689 }
5690 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005691 [ALC861VD_FIX_DALLAS] = {
5692 .type = ALC_FIXUP_FUNC,
5693 .v.func = alc861vd_fixup_dallas,
5694 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005695};
5696
5697static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005698 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005699 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005700 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005701 {}
5702};
5703
5704static const struct hda_verb alc660vd_eapd_verbs[] = {
5705 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5706 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5707 { }
5708};
5709
5710/*
5711 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712static int patch_alc861vd(struct hda_codec *codec)
5713{
5714 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005715 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005716
5717 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5718 if (spec == NULL)
5719 return -ENOMEM;
5720
5721 codec->spec = spec;
5722
5723 spec->mixer_nid = 0x0b;
5724
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005725 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5726 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005728 /* automatic parse from the BIOS config */
5729 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005730 if (err < 0)
5731 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005732
Takashi Iwai1d045db2011-07-07 18:23:21 +02005733 if (codec->vendor_id == 0x10ec0660) {
5734 /* always turn on EAPD */
5735 add_verb(spec, alc660vd_eapd_verbs);
5736 }
5737
Takashi Iwai60a6a842011-07-27 14:01:24 +02005738 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005739 alc_auto_fill_adc_caps(codec);
5740 alc_rebuild_imux_for_auto_mic(codec);
5741 alc_remove_invalid_adc_nids(codec);
5742 }
5743
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005744 if (!spec->no_analog && !spec->cap_mixer)
5745 set_capture_mixer(codec);
5746
5747 if (!spec->no_analog) {
5748 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005749 if (err < 0)
5750 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005751 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5752 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005753
5754 spec->vmaster_nid = 0x02;
5755
5756 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5757
5758 codec->patch_ops = alc_patch_ops;
5759
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005760 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005761 spec->shutup = alc_eapd_shutup;
5762#ifdef CONFIG_SND_HDA_POWER_SAVE
5763 if (!spec->loopback.amplist)
5764 spec->loopback.amplist = alc861vd_loopbacks;
5765#endif
5766
5767 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005768
5769 error:
5770 alc_free(codec);
5771 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005772}
5773
5774/*
5775 * ALC662 support
5776 *
5777 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5778 * configuration. Each pin widget can choose any input DACs and a mixer.
5779 * Each ADC is connected from a mixer of all inputs. This makes possible
5780 * 6-channel independent captures.
5781 *
5782 * In addition, an independent DAC for the multi-playback (not used in this
5783 * driver yet).
5784 */
5785#ifdef CONFIG_SND_HDA_POWER_SAVE
5786#define alc662_loopbacks alc880_loopbacks
5787#endif
5788
5789/*
5790 * BIOS auto configuration
5791 */
5792
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005793static int alc662_parse_auto_config(struct hda_codec *codec)
5794{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005795 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005796 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5797 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5798 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005799
Kailang Yang6227cdc2010-02-25 08:36:52 +01005800 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5801 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005802 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005803 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005804 ssids = alc662_ssids;
5805 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005806}
5807
Todd Broch6be79482010-12-07 16:51:05 -08005808static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005809 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005810{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005811 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005812 return;
Todd Broch6be79482010-12-07 16:51:05 -08005813 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5814 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5815 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5816 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5817 (0 << AC_AMPCAP_MUTE_SHIFT)))
5818 printk(KERN_WARNING
5819 "hda_codec: failed to override amp caps for NID 0x2\n");
5820}
5821
David Henningsson6cb3b702010-09-09 08:51:44 +02005822enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005823 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005824 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005825 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005826 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005827 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005828 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005829 ALC662_FIXUP_ASUS_MODE1,
5830 ALC662_FIXUP_ASUS_MODE2,
5831 ALC662_FIXUP_ASUS_MODE3,
5832 ALC662_FIXUP_ASUS_MODE4,
5833 ALC662_FIXUP_ASUS_MODE5,
5834 ALC662_FIXUP_ASUS_MODE6,
5835 ALC662_FIXUP_ASUS_MODE7,
5836 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005837};
5838
5839static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005840 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005841 .type = ALC_FIXUP_PINS,
5842 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005843 { 0x15, 0x99130112 }, /* subwoofer */
5844 { }
5845 }
5846 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005847 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005848 .type = ALC_FIXUP_PINS,
5849 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005850 { 0x17, 0x99130112 }, /* subwoofer */
5851 { }
5852 }
5853 },
Todd Broch6be79482010-12-07 16:51:05 -08005854 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005855 .type = ALC_FIXUP_FUNC,
5856 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005857 },
5858 [ALC662_FIXUP_CZC_P10T] = {
5859 .type = ALC_FIXUP_VERBS,
5860 .v.verbs = (const struct hda_verb[]) {
5861 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5862 {}
5863 }
5864 },
David Henningsson94024cd2011-04-29 14:10:55 +02005865 [ALC662_FIXUP_SKU_IGNORE] = {
5866 .type = ALC_FIXUP_SKU,
5867 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005868 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005869 [ALC662_FIXUP_HP_RP5800] = {
5870 .type = ALC_FIXUP_PINS,
5871 .v.pins = (const struct alc_pincfg[]) {
5872 { 0x14, 0x0221201f }, /* HP out */
5873 { }
5874 },
5875 .chained = true,
5876 .chain_id = ALC662_FIXUP_SKU_IGNORE
5877 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005878 [ALC662_FIXUP_ASUS_MODE1] = {
5879 .type = ALC_FIXUP_PINS,
5880 .v.pins = (const struct alc_pincfg[]) {
5881 { 0x14, 0x99130110 }, /* speaker */
5882 { 0x18, 0x01a19c20 }, /* mic */
5883 { 0x19, 0x99a3092f }, /* int-mic */
5884 { 0x21, 0x0121401f }, /* HP out */
5885 { }
5886 },
5887 .chained = true,
5888 .chain_id = ALC662_FIXUP_SKU_IGNORE
5889 },
5890 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005891 .type = ALC_FIXUP_PINS,
5892 .v.pins = (const struct alc_pincfg[]) {
5893 { 0x14, 0x99130110 }, /* speaker */
5894 { 0x18, 0x01a19820 }, /* mic */
5895 { 0x19, 0x99a3092f }, /* int-mic */
5896 { 0x1b, 0x0121401f }, /* HP out */
5897 { }
5898 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005899 .chained = true,
5900 .chain_id = ALC662_FIXUP_SKU_IGNORE
5901 },
5902 [ALC662_FIXUP_ASUS_MODE3] = {
5903 .type = ALC_FIXUP_PINS,
5904 .v.pins = (const struct alc_pincfg[]) {
5905 { 0x14, 0x99130110 }, /* speaker */
5906 { 0x15, 0x0121441f }, /* HP */
5907 { 0x18, 0x01a19840 }, /* mic */
5908 { 0x19, 0x99a3094f }, /* int-mic */
5909 { 0x21, 0x01211420 }, /* HP2 */
5910 { }
5911 },
5912 .chained = true,
5913 .chain_id = ALC662_FIXUP_SKU_IGNORE
5914 },
5915 [ALC662_FIXUP_ASUS_MODE4] = {
5916 .type = ALC_FIXUP_PINS,
5917 .v.pins = (const struct alc_pincfg[]) {
5918 { 0x14, 0x99130110 }, /* speaker */
5919 { 0x16, 0x99130111 }, /* speaker */
5920 { 0x18, 0x01a19840 }, /* mic */
5921 { 0x19, 0x99a3094f }, /* int-mic */
5922 { 0x21, 0x0121441f }, /* HP */
5923 { }
5924 },
5925 .chained = true,
5926 .chain_id = ALC662_FIXUP_SKU_IGNORE
5927 },
5928 [ALC662_FIXUP_ASUS_MODE5] = {
5929 .type = ALC_FIXUP_PINS,
5930 .v.pins = (const struct alc_pincfg[]) {
5931 { 0x14, 0x99130110 }, /* speaker */
5932 { 0x15, 0x0121441f }, /* HP */
5933 { 0x16, 0x99130111 }, /* speaker */
5934 { 0x18, 0x01a19840 }, /* mic */
5935 { 0x19, 0x99a3094f }, /* int-mic */
5936 { }
5937 },
5938 .chained = true,
5939 .chain_id = ALC662_FIXUP_SKU_IGNORE
5940 },
5941 [ALC662_FIXUP_ASUS_MODE6] = {
5942 .type = ALC_FIXUP_PINS,
5943 .v.pins = (const struct alc_pincfg[]) {
5944 { 0x14, 0x99130110 }, /* speaker */
5945 { 0x15, 0x01211420 }, /* HP2 */
5946 { 0x18, 0x01a19840 }, /* mic */
5947 { 0x19, 0x99a3094f }, /* int-mic */
5948 { 0x1b, 0x0121441f }, /* HP */
5949 { }
5950 },
5951 .chained = true,
5952 .chain_id = ALC662_FIXUP_SKU_IGNORE
5953 },
5954 [ALC662_FIXUP_ASUS_MODE7] = {
5955 .type = ALC_FIXUP_PINS,
5956 .v.pins = (const struct alc_pincfg[]) {
5957 { 0x14, 0x99130110 }, /* speaker */
5958 { 0x17, 0x99130111 }, /* speaker */
5959 { 0x18, 0x01a19840 }, /* mic */
5960 { 0x19, 0x99a3094f }, /* int-mic */
5961 { 0x1b, 0x01214020 }, /* HP */
5962 { 0x21, 0x0121401f }, /* HP */
5963 { }
5964 },
5965 .chained = true,
5966 .chain_id = ALC662_FIXUP_SKU_IGNORE
5967 },
5968 [ALC662_FIXUP_ASUS_MODE8] = {
5969 .type = ALC_FIXUP_PINS,
5970 .v.pins = (const struct alc_pincfg[]) {
5971 { 0x14, 0x99130110 }, /* speaker */
5972 { 0x12, 0x99a30970 }, /* int-mic */
5973 { 0x15, 0x01214020 }, /* HP */
5974 { 0x17, 0x99130111 }, /* speaker */
5975 { 0x18, 0x01a19840 }, /* mic */
5976 { 0x21, 0x0121401f }, /* HP */
5977 { }
5978 },
5979 .chained = true,
5980 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005981 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005982};
5983
Takashi Iwaia9111322011-05-02 11:30:18 +02005984static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02005985 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01005986 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02005987 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04005988 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005989 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005990 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05005991 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06005992 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02005993 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01005994 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005995
5996#if 0
5997 /* Below is a quirk table taken from the old code.
5998 * Basically the device should work as is without the fixup table.
5999 * If BIOS doesn't give a proper info, enable the corresponding
6000 * fixup entry.
6001 */
6002 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6003 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6004 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6005 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6006 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6007 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6008 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6009 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6010 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6011 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6012 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6013 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6014 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6015 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6016 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6017 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6018 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6019 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6020 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6021 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6022 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6023 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6024 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6025 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6026 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6027 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6028 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6029 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6030 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6031 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6032 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6033 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6034 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6035 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6036 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6037 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6038 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6039 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6040 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6041 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6042 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6043 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6044 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6045 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6046 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6047 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6048 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6049 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6050 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6051 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6052#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006053 {}
6054};
6055
Todd Broch6be79482010-12-07 16:51:05 -08006056static const struct alc_model_fixup alc662_fixup_models[] = {
6057 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006058 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6059 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6060 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6061 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6062 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6063 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6064 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6065 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006066 {}
6067};
David Henningsson6cb3b702010-09-09 08:51:44 +02006068
6069
Takashi Iwai1d045db2011-07-07 18:23:21 +02006070/*
6071 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006072static int patch_alc662(struct hda_codec *codec)
6073{
6074 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006075 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006076
6077 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6078 if (!spec)
6079 return -ENOMEM;
6080
6081 codec->spec = spec;
6082
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006083 spec->mixer_nid = 0x0b;
6084
Takashi Iwai53c334a2011-08-23 18:27:14 +02006085 /* handle multiple HPs as is */
6086 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6087
Kailang Yangda00c242010-03-19 11:23:45 +01006088 alc_auto_parse_customize_define(codec);
6089
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006090 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6091
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006092 err = alc_codec_rename_from_preset(codec);
6093 if (err < 0)
6094 goto error;
6095
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006096 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006097 codec->bus->pci->subsystem_vendor == 0x1025 &&
6098 spec->cdefine.platform_type == 1) {
6099 if (alc_codec_rename(codec, "ALC272X") < 0)
6100 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006101 }
Kailang Yang274693f2009-12-03 10:07:50 +01006102
Takashi Iwaib9c51062011-08-24 18:08:07 +02006103 alc_pick_fixup(codec, alc662_fixup_models,
6104 alc662_fixup_tbl, alc662_fixups);
6105 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6106 /* automatic parse from the BIOS config */
6107 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006108 if (err < 0)
6109 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006110
Takashi Iwai60a6a842011-07-27 14:01:24 +02006111 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006112 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006113 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006114 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006115 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006116
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006117 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006118 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006119
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006120 if (!spec->no_analog && has_cdefine_beep(codec)) {
6121 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006122 if (err < 0)
6123 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006124 switch (codec->vendor_id) {
6125 case 0x10ec0662:
6126 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6127 break;
6128 case 0x10ec0272:
6129 case 0x10ec0663:
6130 case 0x10ec0665:
6131 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6132 break;
6133 case 0x10ec0273:
6134 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6135 break;
6136 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006137 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006138 spec->vmaster_nid = 0x02;
6139
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006140 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6141
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006142 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006143 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006144 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006145
Kailang Yangbf1b0222010-10-21 08:49:56 +02006146 alc_init_jacks(codec);
6147
Takashi Iwaicb53c622007-08-10 17:21:45 +02006148#ifdef CONFIG_SND_HDA_POWER_SAVE
6149 if (!spec->loopback.amplist)
6150 spec->loopback.amplist = alc662_loopbacks;
6151#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006152
6153 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006154
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006155 error:
6156 alc_free(codec);
6157 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006158}
6159
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006160/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006161 * ALC680 support
6162 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006163
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006164static int alc680_parse_auto_config(struct hda_codec *codec)
6165{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006166 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006167}
6168
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006169/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006170 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006171static int patch_alc680(struct hda_codec *codec)
6172{
6173 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006174 int err;
6175
6176 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6177 if (spec == NULL)
6178 return -ENOMEM;
6179
6180 codec->spec = spec;
6181
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006182 /* ALC680 has no aa-loopback mixer */
6183
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006184 /* automatic parse from the BIOS config */
6185 err = alc680_parse_auto_config(codec);
6186 if (err < 0) {
6187 alc_free(codec);
6188 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006189 }
6190
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006191 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006192 set_capture_mixer(codec);
6193
6194 spec->vmaster_nid = 0x02;
6195
6196 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006197 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006198
6199 return 0;
6200}
6201
6202/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 * patch entries
6204 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006205static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006206 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006208 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006209 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006210 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006211 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006212 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006213 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006214 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006215 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006216 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006217 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006218 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6219 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6220 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006221 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02006222 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006223 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6224 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006225 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6226 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006227 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006228 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006229 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006230 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006231 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006232 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006233 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006234 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006235 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006236 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006237 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006238 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006239 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006240 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02006241 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006242 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006243 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006244 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006245 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006246 {} /* terminator */
6247};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006248
6249MODULE_ALIAS("snd-hda-codec-id:10ec*");
6250
6251MODULE_LICENSE("GPL");
6252MODULE_DESCRIPTION("Realtek HD-audio codec");
6253
6254static struct hda_codec_preset_list realtek_list = {
6255 .preset = snd_hda_preset_realtek,
6256 .owner = THIS_MODULE,
6257};
6258
6259static int __init patch_realtek_init(void)
6260{
6261 return snd_hda_add_codec_preset(&realtek_list);
6262}
6263
6264static void __exit patch_realtek_exit(void)
6265{
6266 snd_hda_delete_codec_preset(&realtek_list);
6267}
6268
6269module_init(patch_realtek_init)
6270module_exit(patch_realtek_exit)