blob: 04beae034fea608db37e69d4d1308cd5663359dd [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 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200680 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200681}
682
Takashi Iwai1d045db2011-07-07 18:23:21 +0200683/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200684static void alc_inithook(struct hda_codec *codec)
685{
Takashi Iwaid922b512011-04-28 12:18:53 +0200686 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200687 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200688 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200689}
690
Kailang Yangf9423e72008-05-27 12:32:25 +0200691/* additional initialization for ALC888 variants */
692static void alc888_coef_init(struct hda_codec *codec)
693{
694 unsigned int tmp;
695
696 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
697 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
698 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100699 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200700 /* alc888S-VC */
701 snd_hda_codec_read(codec, 0x20, 0,
702 AC_VERB_SET_PROC_COEF, 0x830);
703 else
704 /* alc888-VB */
705 snd_hda_codec_read(codec, 0x20, 0,
706 AC_VERB_SET_PROC_COEF, 0x3030);
707}
708
Takashi Iwai1d045db2011-07-07 18:23:21 +0200709/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200710static void alc889_coef_init(struct hda_codec *codec)
711{
712 unsigned int tmp;
713
714 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
715 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
716 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
717 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
718}
719
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100720/* turn on/off EAPD control (only if available) */
721static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
722{
723 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
724 return;
725 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
726 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
727 on ? 2 : 0);
728}
729
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200730/* turn on/off EAPD controls of the codec */
731static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
732{
733 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200734 static hda_nid_t pins[] = {
735 0x0f, 0x10, 0x14, 0x15, 0
736 };
737 hda_nid_t *p;
738 for (p = pins; *p; p++)
739 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200740}
741
Takashi Iwai1c716152011-04-07 10:37:16 +0200742/* generic shutup callback;
743 * just turning off EPAD and a little pause for avoiding pop-noise
744 */
745static void alc_eapd_shutup(struct hda_codec *codec)
746{
747 alc_auto_setup_eapd(codec, false);
748 msleep(200);
749}
750
Takashi Iwai1d045db2011-07-07 18:23:21 +0200751/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200752static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200753{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200754 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200755
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200756 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200757 switch (type) {
758 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200759 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
760 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200761 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200762 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
763 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200764 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200765 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
766 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200767 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200768 switch (codec->vendor_id) {
769 case 0x10ec0260:
770 snd_hda_codec_write(codec, 0x1a, 0,
771 AC_VERB_SET_COEF_INDEX, 7);
772 tmp = snd_hda_codec_read(codec, 0x1a, 0,
773 AC_VERB_GET_PROC_COEF, 0);
774 snd_hda_codec_write(codec, 0x1a, 0,
775 AC_VERB_SET_COEF_INDEX, 7);
776 snd_hda_codec_write(codec, 0x1a, 0,
777 AC_VERB_SET_PROC_COEF,
778 tmp | 0x2010);
779 break;
780 case 0x10ec0262:
781 case 0x10ec0880:
782 case 0x10ec0882:
783 case 0x10ec0883:
784 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100785 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100786 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200787 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200788 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200789 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200790 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200791 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100792#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200793 case 0x10ec0267:
794 case 0x10ec0268:
795 snd_hda_codec_write(codec, 0x20, 0,
796 AC_VERB_SET_COEF_INDEX, 7);
797 tmp = snd_hda_codec_read(codec, 0x20, 0,
798 AC_VERB_GET_PROC_COEF, 0);
799 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200800 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200801 snd_hda_codec_write(codec, 0x20, 0,
802 AC_VERB_SET_PROC_COEF,
803 tmp | 0x3000);
804 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100805#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200806 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200807 break;
808 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200809}
Kailang Yangea1fb292008-08-26 12:58:38 +0200810
Takashi Iwai1d045db2011-07-07 18:23:21 +0200811/*
812 * Auto-Mute mode mixer enum support
813 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200814static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
815 struct snd_ctl_elem_info *uinfo)
816{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200817 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
818 struct alc_spec *spec = codec->spec;
819 static const char * const texts2[] = {
820 "Disabled", "Enabled"
821 };
822 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200823 "Disabled", "Speaker Only", "Line-Out+Speaker"
824 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200825 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200826
827 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
828 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200829 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200830 uinfo->value.enumerated.items = 3;
831 texts = texts3;
832 } else {
833 uinfo->value.enumerated.items = 2;
834 texts = texts2;
835 }
836 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
837 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200838 strcpy(uinfo->value.enumerated.name,
839 texts[uinfo->value.enumerated.item]);
840 return 0;
841}
842
843static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
844 struct snd_ctl_elem_value *ucontrol)
845{
846 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
847 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200848 unsigned int val = 0;
849 if (spec->automute_speaker)
850 val++;
851 if (spec->automute_lo)
852 val++;
853
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200854 ucontrol->value.enumerated.item[0] = val;
855 return 0;
856}
857
858static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
859 struct snd_ctl_elem_value *ucontrol)
860{
861 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
862 struct alc_spec *spec = codec->spec;
863
864 switch (ucontrol->value.enumerated.item[0]) {
865 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200866 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200867 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200868 spec->automute_speaker = 0;
869 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200870 break;
871 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200872 if (spec->automute_speaker_possible) {
873 if (!spec->automute_lo && spec->automute_speaker)
874 return 0;
875 spec->automute_speaker = 1;
876 spec->automute_lo = 0;
877 } else if (spec->automute_lo_possible) {
878 if (spec->automute_lo)
879 return 0;
880 spec->automute_lo = 1;
881 } else
882 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200883 break;
884 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200885 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200886 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200887 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200888 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200889 spec->automute_speaker = 1;
890 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200891 break;
892 default:
893 return -EINVAL;
894 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200895 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200896 return 1;
897}
898
Takashi Iwaia9111322011-05-02 11:30:18 +0200899static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200900 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
901 .name = "Auto-Mute Mode",
902 .info = alc_automute_mode_info,
903 .get = alc_automute_mode_get,
904 .put = alc_automute_mode_put,
905};
906
Takashi Iwai1d045db2011-07-07 18:23:21 +0200907static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
908{
909 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
910 return snd_array_new(&spec->kctls);
911}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200912
913static int alc_add_automute_mode_enum(struct hda_codec *codec)
914{
915 struct alc_spec *spec = codec->spec;
916 struct snd_kcontrol_new *knew;
917
918 knew = alc_kcontrol_new(spec);
919 if (!knew)
920 return -ENOMEM;
921 *knew = alc_automute_mode_enum;
922 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
923 if (!knew->name)
924 return -ENOMEM;
925 return 0;
926}
927
Takashi Iwai1d045db2011-07-07 18:23:21 +0200928/*
929 * Check the availability of HP/line-out auto-mute;
930 * Set up appropriately if really supported
931 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200932static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200933{
934 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200935 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200936 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200937 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200938
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200939 if (cfg->hp_pins[0])
940 present++;
941 if (cfg->line_out_pins[0])
942 present++;
943 if (cfg->speaker_pins[0])
944 present++;
945 if (present < 2) /* need two different output types */
946 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200947
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200948 if (!cfg->speaker_pins[0] &&
949 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200950 memcpy(cfg->speaker_pins, cfg->line_out_pins,
951 sizeof(cfg->speaker_pins));
952 cfg->speaker_outs = cfg->line_outs;
953 }
954
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200955 if (!cfg->hp_pins[0] &&
956 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200957 memcpy(cfg->hp_pins, cfg->line_out_pins,
958 sizeof(cfg->hp_pins));
959 cfg->hp_outs = cfg->line_outs;
960 }
961
David Henningsson42cf0d02011-09-20 12:04:56 +0200962 spec->automute_mode = ALC_AUTOMUTE_PIN;
963
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200964 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200965 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200966 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200967 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200968 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200969 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200970 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200971 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200972 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200973
David Henningsson42cf0d02011-09-20 12:04:56 +0200974 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
975 if (cfg->speaker_outs)
976 for (i = 0; i < cfg->line_outs; i++) {
977 hda_nid_t nid = cfg->line_out_pins[i];
978 if (!is_jack_detectable(codec, nid))
979 continue;
980 snd_printdd("realtek: Enable Line-Out "
981 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200982 snd_hda_jack_detect_enable(codec, nid,
983 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200984 spec->detect_lo = 1;
985 }
986 spec->automute_lo_possible = spec->detect_hp;
987 }
988
989 spec->automute_speaker_possible = cfg->speaker_outs &&
990 (spec->detect_hp || spec->detect_lo);
991
992 spec->automute_lo = spec->automute_lo_possible;
993 spec->automute_speaker = spec->automute_speaker_possible;
994
995 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200996 /* create a control for automute mode */
997 alc_add_automute_mode_enum(codec);
998 spec->unsol_event = alc_sku_unsol_event;
999 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001000}
1001
Takashi Iwai1d045db2011-07-07 18:23:21 +02001002/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001003static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1004{
1005 int i;
1006 for (i = 0; i < nums; i++)
1007 if (list[i] == nid)
1008 return i;
1009 return -1;
1010}
1011
Takashi Iwai1d045db2011-07-07 18:23:21 +02001012/* check whether dynamic ADC-switching is available */
1013static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1014{
1015 struct alc_spec *spec = codec->spec;
1016 struct hda_input_mux *imux = &spec->private_imux[0];
1017 int i, n, idx;
1018 hda_nid_t cap, pin;
1019
1020 if (imux != spec->input_mux) /* no dynamic imux? */
1021 return false;
1022
1023 for (n = 0; n < spec->num_adc_nids; n++) {
1024 cap = spec->private_capsrc_nids[n];
1025 for (i = 0; i < imux->num_items; i++) {
1026 pin = spec->imux_pins[i];
1027 if (!pin)
1028 return false;
1029 if (get_connection_index(codec, cap, pin) < 0)
1030 break;
1031 }
1032 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001033 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001034 }
1035
1036 for (i = 0; i < imux->num_items; i++) {
1037 pin = spec->imux_pins[i];
1038 for (n = 0; n < spec->num_adc_nids; n++) {
1039 cap = spec->private_capsrc_nids[n];
1040 idx = get_connection_index(codec, cap, pin);
1041 if (idx >= 0) {
1042 imux->items[i].index = idx;
1043 spec->dyn_adc_idx[i] = n;
1044 break;
1045 }
1046 }
1047 }
1048
1049 snd_printdd("realtek: enabling ADC switching\n");
1050 spec->dyn_adc_switch = 1;
1051 return true;
1052}
Takashi Iwai21268962011-07-07 15:01:13 +02001053
1054/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1055static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1056{
1057 struct alc_spec *spec = codec->spec;
1058 struct hda_input_mux *imux;
1059 static char * const texts[3] = {
1060 "Mic", "Internal Mic", "Dock Mic"
1061 };
1062 int i;
1063
1064 if (!spec->auto_mic)
1065 return false;
1066 imux = &spec->private_imux[0];
1067 if (spec->input_mux == imux)
1068 return true;
1069 spec->imux_pins[0] = spec->ext_mic_pin;
1070 spec->imux_pins[1] = spec->int_mic_pin;
1071 spec->imux_pins[2] = spec->dock_mic_pin;
1072 for (i = 0; i < 3; i++) {
1073 strcpy(imux->items[i].label, texts[i]);
1074 if (spec->imux_pins[i])
1075 imux->num_items = i + 1;
1076 }
1077 spec->num_mux_defs = 1;
1078 spec->input_mux = imux;
1079 return true;
1080}
1081
1082/* check whether all auto-mic pins are valid; setup indices if OK */
1083static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1084{
1085 struct alc_spec *spec = codec->spec;
1086 const struct hda_input_mux *imux;
1087
1088 if (!spec->auto_mic)
1089 return false;
1090 if (spec->auto_mic_valid_imux)
1091 return true; /* already checked */
1092
1093 /* fill up imux indices */
1094 if (!alc_check_dyn_adc_switch(codec)) {
1095 spec->auto_mic = 0;
1096 return false;
1097 }
1098
1099 imux = spec->input_mux;
1100 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1101 spec->imux_pins, imux->num_items);
1102 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1103 spec->imux_pins, imux->num_items);
1104 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1105 spec->imux_pins, imux->num_items);
1106 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1107 spec->auto_mic = 0;
1108 return false; /* no corresponding imux */
1109 }
1110
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001111 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001112 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001113 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1114 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001115
1116 spec->auto_mic_valid_imux = 1;
1117 spec->auto_mic = 1;
1118 return true;
1119}
1120
Takashi Iwai1d045db2011-07-07 18:23:21 +02001121/*
1122 * Check the availability of auto-mic switch;
1123 * Set up if really supported
1124 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001125static void alc_init_auto_mic(struct hda_codec *codec)
1126{
1127 struct alc_spec *spec = codec->spec;
1128 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001129 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001130 int i;
1131
Takashi Iwai24de1832011-11-07 17:13:39 +01001132 if (spec->shared_mic_hp)
1133 return; /* no auto-mic for the shared I/O */
1134
Takashi Iwai21268962011-07-07 15:01:13 +02001135 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1136
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001137 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001138 for (i = 0; i < cfg->num_inputs; i++) {
1139 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001140 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001141 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001142 switch (snd_hda_get_input_pin_attr(defcfg)) {
1143 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001144 if (fixed)
1145 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001146 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1147 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001148 fixed = nid;
1149 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001150 case INPUT_PIN_ATTR_UNUSED:
1151 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001152 case INPUT_PIN_ATTR_DOCK:
1153 if (dock)
1154 return; /* already occupied */
1155 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1156 return; /* invalid type */
1157 dock = nid;
1158 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001159 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001160 if (ext)
1161 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001162 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1163 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001164 ext = nid;
1165 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001166 }
1167 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001168 if (!ext && dock) {
1169 ext = dock;
1170 dock = 0;
1171 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001172 if (!ext || !fixed)
1173 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001174 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001175 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001176 if (dock && !is_jack_detectable(codec, dock))
1177 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001178
1179 /* check imux indices */
1180 spec->ext_mic_pin = ext;
1181 spec->int_mic_pin = fixed;
1182 spec->dock_mic_pin = dock;
1183
1184 spec->auto_mic = 1;
1185 if (!alc_auto_mic_check_imux(codec))
1186 return;
1187
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001188 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1189 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001190 spec->unsol_event = alc_sku_unsol_event;
1191}
1192
Takashi Iwai1d045db2011-07-07 18:23:21 +02001193/* check the availabilities of auto-mute and auto-mic switches */
1194static void alc_auto_check_switches(struct hda_codec *codec)
1195{
David Henningsson42cf0d02011-09-20 12:04:56 +02001196 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001197 alc_init_auto_mic(codec);
1198}
1199
1200/*
1201 * Realtek SSID verification
1202 */
1203
David Henningsson90622912010-10-14 14:50:18 +02001204/* Could be any non-zero and even value. When used as fixup, tells
1205 * the driver to ignore any present sku defines.
1206 */
1207#define ALC_FIXUP_SKU_IGNORE (2)
1208
Kailang Yangda00c242010-03-19 11:23:45 +01001209static int alc_auto_parse_customize_define(struct hda_codec *codec)
1210{
1211 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001212 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001213 struct alc_spec *spec = codec->spec;
1214
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001215 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1216
David Henningsson90622912010-10-14 14:50:18 +02001217 if (spec->cdefine.fixup) {
1218 ass = spec->cdefine.sku_cfg;
1219 if (ass == ALC_FIXUP_SKU_IGNORE)
1220 return -1;
1221 goto do_sku;
1222 }
1223
Kailang Yangda00c242010-03-19 11:23:45 +01001224 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001225 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001226 goto do_sku;
1227
1228 nid = 0x1d;
1229 if (codec->vendor_id == 0x10ec0260)
1230 nid = 0x17;
1231 ass = snd_hda_codec_get_pincfg(codec, nid);
1232
1233 if (!(ass & 1)) {
1234 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1235 codec->chip_name, ass);
1236 return -1;
1237 }
1238
1239 /* check sum */
1240 tmp = 0;
1241 for (i = 1; i < 16; i++) {
1242 if ((ass >> i) & 1)
1243 tmp++;
1244 }
1245 if (((ass >> 16) & 0xf) != tmp)
1246 return -1;
1247
1248 spec->cdefine.port_connectivity = ass >> 30;
1249 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1250 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1251 spec->cdefine.customization = ass >> 8;
1252do_sku:
1253 spec->cdefine.sku_cfg = ass;
1254 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1255 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1256 spec->cdefine.swap = (ass & 0x2) >> 1;
1257 spec->cdefine.override = ass & 0x1;
1258
1259 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1260 nid, spec->cdefine.sku_cfg);
1261 snd_printd("SKU: port_connectivity=0x%x\n",
1262 spec->cdefine.port_connectivity);
1263 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1264 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1265 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1266 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1267 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1268 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1269 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1270
1271 return 0;
1272}
1273
Takashi Iwai1d045db2011-07-07 18:23:21 +02001274/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001275static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1276{
Takashi Iwai21268962011-07-07 15:01:13 +02001277 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001278}
1279
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001280/* check subsystem ID and set up device-specific initialization;
1281 * return 1 if initialized, 0 if invalid SSID
1282 */
1283/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1284 * 31 ~ 16 : Manufacture ID
1285 * 15 ~ 8 : SKU ID
1286 * 7 ~ 0 : Assembly ID
1287 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1288 */
1289static int alc_subsystem_id(struct hda_codec *codec,
1290 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001291 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001292{
1293 unsigned int ass, tmp, i;
1294 unsigned nid;
1295 struct alc_spec *spec = codec->spec;
1296
David Henningsson90622912010-10-14 14:50:18 +02001297 if (spec->cdefine.fixup) {
1298 ass = spec->cdefine.sku_cfg;
1299 if (ass == ALC_FIXUP_SKU_IGNORE)
1300 return 0;
1301 goto do_sku;
1302 }
1303
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001304 ass = codec->subsystem_id & 0xffff;
1305 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1306 goto do_sku;
1307
1308 /* invalid SSID, check the special NID pin defcfg instead */
1309 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001310 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001311 * 29~21 : reserve
1312 * 20 : PCBEEP input
1313 * 19~16 : Check sum (15:1)
1314 * 15~1 : Custom
1315 * 0 : override
1316 */
1317 nid = 0x1d;
1318 if (codec->vendor_id == 0x10ec0260)
1319 nid = 0x17;
1320 ass = snd_hda_codec_get_pincfg(codec, nid);
1321 snd_printd("realtek: No valid SSID, "
1322 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001323 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001324 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001325 return 0;
1326 if ((ass >> 30) != 1) /* no physical connection */
1327 return 0;
1328
1329 /* check sum */
1330 tmp = 0;
1331 for (i = 1; i < 16; i++) {
1332 if ((ass >> i) & 1)
1333 tmp++;
1334 }
1335 if (((ass >> 16) & 0xf) != tmp)
1336 return 0;
1337do_sku:
1338 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1339 ass & 0xffff, codec->vendor_id);
1340 /*
1341 * 0 : override
1342 * 1 : Swap Jack
1343 * 2 : 0 --> Desktop, 1 --> Laptop
1344 * 3~5 : External Amplifier control
1345 * 7~6 : Reserved
1346 */
1347 tmp = (ass & 0x38) >> 3; /* external Amp control */
1348 switch (tmp) {
1349 case 1:
1350 spec->init_amp = ALC_INIT_GPIO1;
1351 break;
1352 case 3:
1353 spec->init_amp = ALC_INIT_GPIO2;
1354 break;
1355 case 7:
1356 spec->init_amp = ALC_INIT_GPIO3;
1357 break;
1358 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001359 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001360 spec->init_amp = ALC_INIT_DEFAULT;
1361 break;
1362 }
1363
1364 /* is laptop or Desktop and enable the function "Mute internal speaker
1365 * when the external headphone out jack is plugged"
1366 */
1367 if (!(ass & 0x8000))
1368 return 1;
1369 /*
1370 * 10~8 : Jack location
1371 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1372 * 14~13: Resvered
1373 * 15 : 1 --> enable the function "Mute internal speaker
1374 * when the external headphone out jack is plugged"
1375 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001376 if (!spec->autocfg.hp_pins[0] &&
1377 !(spec->autocfg.line_out_pins[0] &&
1378 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001379 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001380 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1381 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001382 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001383 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001384 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001385 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001386 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001387 else if (tmp == 3)
1388 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001389 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001390 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001391 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1392 spec->autocfg.line_outs))
1393 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001394 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001395 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001396 return 1;
1397}
Kailang Yangea1fb292008-08-26 12:58:38 +02001398
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001399/* Check the validity of ALC subsystem-id
1400 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1401static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001402{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001403 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001404 struct alc_spec *spec = codec->spec;
1405 snd_printd("realtek: "
1406 "Enable default setup for auto mode as fallback\n");
1407 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001408 }
Takashi Iwai21268962011-07-07 15:01:13 +02001409}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001410
Takashi Iwai41e41f12005-06-08 14:48:49 +02001411/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001412 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001413 */
1414
1415struct alc_pincfg {
1416 hda_nid_t nid;
1417 u32 val;
1418};
1419
Todd Broche1eb5f12010-12-06 11:19:51 -08001420struct alc_model_fixup {
1421 const int id;
1422 const char *name;
1423};
1424
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001425struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001426 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001427 bool chained;
1428 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001429 union {
1430 unsigned int sku;
1431 const struct alc_pincfg *pins;
1432 const struct hda_verb *verbs;
1433 void (*func)(struct hda_codec *codec,
1434 const struct alc_fixup *fix,
1435 int action);
1436 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001437};
1438
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001439enum {
1440 ALC_FIXUP_INVALID,
1441 ALC_FIXUP_SKU,
1442 ALC_FIXUP_PINS,
1443 ALC_FIXUP_VERBS,
1444 ALC_FIXUP_FUNC,
1445};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001446
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001447enum {
1448 ALC_FIXUP_ACT_PRE_PROBE,
1449 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001450 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001451};
1452
1453static void alc_apply_fixup(struct hda_codec *codec, int action)
1454{
1455 struct alc_spec *spec = codec->spec;
1456 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001457#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001458 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001459#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001460 int depth = 0;
1461
1462 if (!spec->fixup_list)
1463 return;
1464
1465 while (id >= 0) {
1466 const struct alc_fixup *fix = spec->fixup_list + id;
1467 const struct alc_pincfg *cfg;
1468
1469 switch (fix->type) {
1470 case ALC_FIXUP_SKU:
1471 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001472 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001473 snd_printdd(KERN_INFO "hda_codec: %s: "
1474 "Apply sku override for %s\n",
1475 codec->chip_name, modelname);
1476 spec->cdefine.sku_cfg = fix->v.sku;
1477 spec->cdefine.fixup = 1;
1478 break;
1479 case ALC_FIXUP_PINS:
1480 cfg = fix->v.pins;
1481 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1482 break;
1483 snd_printdd(KERN_INFO "hda_codec: %s: "
1484 "Apply pincfg for %s\n",
1485 codec->chip_name, modelname);
1486 for (; cfg->nid; cfg++)
1487 snd_hda_codec_set_pincfg(codec, cfg->nid,
1488 cfg->val);
1489 break;
1490 case ALC_FIXUP_VERBS:
1491 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1492 break;
1493 snd_printdd(KERN_INFO "hda_codec: %s: "
1494 "Apply fix-verbs for %s\n",
1495 codec->chip_name, modelname);
1496 add_verb(codec->spec, fix->v.verbs);
1497 break;
1498 case ALC_FIXUP_FUNC:
1499 if (!fix->v.func)
1500 break;
1501 snd_printdd(KERN_INFO "hda_codec: %s: "
1502 "Apply fix-func for %s\n",
1503 codec->chip_name, modelname);
1504 fix->v.func(codec, fix, action);
1505 break;
1506 default:
1507 snd_printk(KERN_ERR "hda_codec: %s: "
1508 "Invalid fixup type %d\n",
1509 codec->chip_name, fix->type);
1510 break;
1511 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001512 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001513 break;
1514 if (++depth > 10)
1515 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001516 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001517 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001518}
1519
Todd Broche1eb5f12010-12-06 11:19:51 -08001520static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001521 const struct alc_model_fixup *models,
1522 const struct snd_pci_quirk *quirk,
1523 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001524{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001525 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001526 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001527 int id = -1;
1528 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001529
Todd Broche1eb5f12010-12-06 11:19:51 -08001530 if (codec->modelname && models) {
1531 while (models->name) {
1532 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001533 id = models->id;
1534 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001535 break;
1536 }
1537 models++;
1538 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001539 }
1540 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001541 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1542 if (q) {
1543 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001544#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001545 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001546#endif
1547 }
1548 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001549 if (id < 0) {
1550 for (q = quirk; q->subvendor; q++) {
1551 unsigned int vendorid =
1552 q->subdevice | (q->subvendor << 16);
1553 if (vendorid == codec->subsystem_id) {
1554 id = q->value;
1555#ifdef CONFIG_SND_DEBUG_VERBOSE
1556 name = q->name;
1557#endif
1558 break;
1559 }
1560 }
1561 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001562
1563 spec->fixup_id = id;
1564 if (id >= 0) {
1565 spec->fixup_list = fixlist;
1566 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001567 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001568}
1569
Takashi Iwai1d045db2011-07-07 18:23:21 +02001570/*
1571 * COEF access helper functions
1572 */
Kailang Yang274693f2009-12-03 10:07:50 +01001573static int alc_read_coef_idx(struct hda_codec *codec,
1574 unsigned int coef_idx)
1575{
1576 unsigned int val;
1577 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1578 coef_idx);
1579 val = snd_hda_codec_read(codec, 0x20, 0,
1580 AC_VERB_GET_PROC_COEF, 0);
1581 return val;
1582}
1583
Kailang Yang977ddd62010-09-15 10:02:29 +02001584static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1585 unsigned int coef_val)
1586{
1587 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1588 coef_idx);
1589 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1590 coef_val);
1591}
1592
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001593/* a special bypass for COEF 0; read the cached value at the second time */
1594static unsigned int alc_get_coef0(struct hda_codec *codec)
1595{
1596 struct alc_spec *spec = codec->spec;
1597 if (!spec->coef0)
1598 spec->coef0 = alc_read_coef_idx(codec, 0);
1599 return spec->coef0;
1600}
1601
Takashi Iwai1d045db2011-07-07 18:23:21 +02001602/*
1603 * Digital I/O handling
1604 */
1605
Takashi Iwai757899a2010-07-30 10:48:14 +02001606/* set right pin controls for digital I/O */
1607static void alc_auto_init_digital(struct hda_codec *codec)
1608{
1609 struct alc_spec *spec = codec->spec;
1610 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001611 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001612
1613 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1614 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001615 if (!pin)
1616 continue;
1617 snd_hda_codec_write(codec, pin, 0,
1618 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1619 if (!i)
1620 dac = spec->multiout.dig_out_nid;
1621 else
1622 dac = spec->slave_dig_outs[i - 1];
1623 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1624 continue;
1625 snd_hda_codec_write(codec, dac, 0,
1626 AC_VERB_SET_AMP_GAIN_MUTE,
1627 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001628 }
1629 pin = spec->autocfg.dig_in_pin;
1630 if (pin)
1631 snd_hda_codec_write(codec, pin, 0,
1632 AC_VERB_SET_PIN_WIDGET_CONTROL,
1633 PIN_IN);
1634}
1635
1636/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1637static void alc_auto_parse_digital(struct hda_codec *codec)
1638{
1639 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001640 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001641 hda_nid_t dig_nid;
1642
1643 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001644 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001645 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001646 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001647 err = snd_hda_get_connections(codec,
1648 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001649 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001650 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001651 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001652 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001653 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001654 spec->multiout.dig_out_nid = dig_nid;
1655 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1656 } else {
1657 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001658 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001659 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001660 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001661 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001662 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001663 }
1664
1665 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001666 dig_nid = codec->start_nid;
1667 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1668 unsigned int wcaps = get_wcaps(codec, dig_nid);
1669 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1670 continue;
1671 if (!(wcaps & AC_WCAP_DIGITAL))
1672 continue;
1673 if (!(wcaps & AC_WCAP_CONN_LIST))
1674 continue;
1675 err = get_connection_index(codec, dig_nid,
1676 spec->autocfg.dig_in_pin);
1677 if (err >= 0) {
1678 spec->dig_in_nid = dig_nid;
1679 break;
1680 }
1681 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001682 }
1683}
1684
Takashi Iwaif95474e2007-07-10 00:47:43 +02001685/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001686 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001687 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001688static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1689 struct snd_ctl_elem_info *uinfo)
1690{
1691 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1692 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001693 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001694 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001695
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001696 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001697 if (spec->vol_in_capsrc)
1698 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1699 else
1700 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1701 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001702 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001703 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001704 return err;
1705}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001707static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1708 unsigned int size, unsigned int __user *tlv)
1709{
1710 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1711 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001712 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001713 int err;
1714
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001715 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001716 if (spec->vol_in_capsrc)
1717 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1718 else
1719 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1720 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001721 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001722 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001723 return err;
1724}
1725
1726typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1727 struct snd_ctl_elem_value *ucontrol);
1728
1729static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001731 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001732{
1733 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1734 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001735 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001736
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001737 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001738 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001739 for (i = 0; i < spec->num_adc_nids; i++) {
1740 kcontrol->private_value =
1741 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1742 3, 0, HDA_INPUT);
1743 err = func(kcontrol, ucontrol);
1744 if (err < 0)
1745 goto error;
1746 }
1747 } else {
1748 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001749 if (spec->vol_in_capsrc)
1750 kcontrol->private_value =
1751 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1752 3, 0, HDA_OUTPUT);
1753 else
1754 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001755 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1756 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001757 err = func(kcontrol, ucontrol);
1758 }
1759 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001760 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001761 return err;
1762}
1763
1764static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1765 struct snd_ctl_elem_value *ucontrol)
1766{
1767 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001768 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001769}
1770
1771static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1772 struct snd_ctl_elem_value *ucontrol)
1773{
1774 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001775 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001776}
1777
1778/* capture mixer elements */
1779#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1780
1781static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1782 struct snd_ctl_elem_value *ucontrol)
1783{
1784 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001785 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001786}
1787
1788static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1789 struct snd_ctl_elem_value *ucontrol)
1790{
1791 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001792 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001793}
1794
Takashi Iwaia23b6882009-03-23 15:21:36 +01001795#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001796 { \
1797 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1798 .name = "Capture Switch", \
1799 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1800 .count = num, \
1801 .info = alc_cap_sw_info, \
1802 .get = alc_cap_sw_get, \
1803 .put = alc_cap_sw_put, \
1804 }, \
1805 { \
1806 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1807 .name = "Capture Volume", \
1808 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1809 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1810 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1811 .count = num, \
1812 .info = alc_cap_vol_info, \
1813 .get = alc_cap_vol_get, \
1814 .put = alc_cap_vol_put, \
1815 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001816 }
1817
1818#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001819 { \
1820 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1821 /* .name = "Capture Source", */ \
1822 .name = "Input Source", \
1823 .count = num, \
1824 .info = alc_mux_enum_info, \
1825 .get = alc_mux_enum_get, \
1826 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001827 }
1828
1829#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001830static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001831 _DEFINE_CAPMIX(num), \
1832 _DEFINE_CAPSRC(num), \
1833 { } /* end */ \
1834}
1835
1836#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001837static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001838 _DEFINE_CAPMIX(num), \
1839 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001840}
1841
1842/* up to three ADCs */
1843DEFINE_CAPMIX(1);
1844DEFINE_CAPMIX(2);
1845DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001846DEFINE_CAPMIX_NOSRC(1);
1847DEFINE_CAPMIX_NOSRC(2);
1848DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001849
1850/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001851 * virtual master controls
1852 */
1853
1854/*
1855 * slave controls for virtual master
1856 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001857static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001858 "Front Playback Volume",
1859 "Surround Playback Volume",
1860 "Center Playback Volume",
1861 "LFE Playback Volume",
1862 "Side Playback Volume",
1863 "Headphone Playback Volume",
1864 "Speaker Playback Volume",
1865 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001866 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001867 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001868 NULL,
1869};
1870
Takashi Iwaiea734962011-01-17 11:29:34 +01001871static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001872 "Front Playback Switch",
1873 "Surround Playback Switch",
1874 "Center Playback Switch",
1875 "LFE Playback Switch",
1876 "Side Playback Switch",
1877 "Headphone Playback Switch",
1878 "Speaker Playback Switch",
1879 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001880 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001881 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001882 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001883 NULL,
1884};
1885
1886/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001887 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001889
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001890#define NID_MAPPING (-1)
1891
1892#define SUBDEV_SPEAKER_ (0 << 6)
1893#define SUBDEV_HP_ (1 << 6)
1894#define SUBDEV_LINE_ (2 << 6)
1895#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1896#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1897#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1898
Takashi Iwai603c4012008-07-30 15:01:44 +02001899static void alc_free_kctls(struct hda_codec *codec);
1900
Takashi Iwai67d634c2009-11-16 15:35:59 +01001901#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001902/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001903static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001904 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001905 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001906 { } /* end */
1907};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001908#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001909
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910static int alc_build_controls(struct hda_codec *codec)
1911{
1912 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001913 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001914 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001915 int i, j, err;
1916 unsigned int u;
1917 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918
1919 for (i = 0; i < spec->num_mixers; i++) {
1920 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1921 if (err < 0)
1922 return err;
1923 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001924 if (spec->cap_mixer) {
1925 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1926 if (err < 0)
1927 return err;
1928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001930 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001931 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001932 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 if (err < 0)
1934 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001935 if (!spec->no_analog) {
1936 err = snd_hda_create_spdif_share_sw(codec,
1937 &spec->multiout);
1938 if (err < 0)
1939 return err;
1940 spec->multiout.share_spdif = 1;
1941 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 }
1943 if (spec->dig_in_nid) {
1944 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1945 if (err < 0)
1946 return err;
1947 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001948
Takashi Iwai67d634c2009-11-16 15:35:59 +01001949#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001950 /* create beep controls if needed */
1951 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001952 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001953 for (knew = alc_beep_mixer; knew->name; knew++) {
1954 struct snd_kcontrol *kctl;
1955 kctl = snd_ctl_new1(knew, codec);
1956 if (!kctl)
1957 return -ENOMEM;
1958 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001959 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001960 if (err < 0)
1961 return err;
1962 }
1963 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001964#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001965
Takashi Iwai2134ea42008-01-10 16:53:55 +01001966 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001967 if (!spec->no_analog &&
1968 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001969 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001970 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001971 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001972 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001973 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001974 if (err < 0)
1975 return err;
1976 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001977 if (!spec->no_analog &&
1978 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001979 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1980 NULL, alc_slave_sws);
1981 if (err < 0)
1982 return err;
1983 }
1984
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001985 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001986 if (spec->capsrc_nids || spec->adc_nids) {
1987 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1988 if (!kctl)
1989 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1990 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02001991 const hda_nid_t *nids = spec->capsrc_nids;
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001992 if (!nids)
1993 nids = spec->adc_nids;
1994 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1995 if (err < 0)
1996 return err;
1997 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001998 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001999 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002000 const char *kname = kctl ? kctl->id.name : NULL;
2001 for (knew = spec->cap_mixer; knew->name; knew++) {
2002 if (kname && strcmp(knew->name, kname) == 0)
2003 continue;
2004 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2005 for (i = 0; kctl && i < kctl->count; i++) {
2006 err = snd_hda_add_nid(codec, kctl, i,
2007 spec->adc_nids[i]);
2008 if (err < 0)
2009 return err;
2010 }
2011 }
2012 }
2013
2014 /* other nid->control mapping */
2015 for (i = 0; i < spec->num_mixers; i++) {
2016 for (knew = spec->mixers[i]; knew->name; knew++) {
2017 if (knew->iface != NID_MAPPING)
2018 continue;
2019 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2020 if (kctl == NULL)
2021 continue;
2022 u = knew->subdevice;
2023 for (j = 0; j < 4; j++, u >>= 8) {
2024 nid = u & 0x3f;
2025 if (nid == 0)
2026 continue;
2027 switch (u & 0xc0) {
2028 case SUBDEV_SPEAKER_:
2029 nid = spec->autocfg.speaker_pins[nid];
2030 break;
2031 case SUBDEV_LINE_:
2032 nid = spec->autocfg.line_out_pins[nid];
2033 break;
2034 case SUBDEV_HP_:
2035 nid = spec->autocfg.hp_pins[nid];
2036 break;
2037 default:
2038 continue;
2039 }
2040 err = snd_hda_add_nid(codec, kctl, 0, nid);
2041 if (err < 0)
2042 return err;
2043 }
2044 u = knew->private_value;
2045 for (j = 0; j < 4; j++, u >>= 8) {
2046 nid = u & 0xff;
2047 if (nid == 0)
2048 continue;
2049 err = snd_hda_add_nid(codec, kctl, 0, nid);
2050 if (err < 0)
2051 return err;
2052 }
2053 }
2054 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002055
2056 alc_free_kctls(codec); /* no longer needed */
2057
Takashi Iwai01a61e12011-10-28 00:03:22 +02002058 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
2059 if (err < 0)
2060 return err;
2061
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 return 0;
2063}
2064
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002065
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002067 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002068 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002069
Takashi Iwai584c0c42011-03-10 12:51:11 +01002070static void alc_init_special_input_src(struct hda_codec *codec);
2071
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072static int alc_init(struct hda_codec *codec)
2073{
2074 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002075 unsigned int i;
2076
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002077 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002078 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002079
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002080 for (i = 0; i < spec->num_init_verbs; i++)
2081 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002082 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002083
2084 if (spec->init_hook)
2085 spec->init_hook(codec);
2086
Takashi Iwai58701122011-01-13 15:41:45 +01002087 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2088
Takashi Iwai01a61e12011-10-28 00:03:22 +02002089 snd_hda_jack_report_sync(codec);
2090
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002091 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 return 0;
2093}
2094
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002095static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2096{
2097 struct alc_spec *spec = codec->spec;
2098
2099 if (spec->unsol_event)
2100 spec->unsol_event(codec, res);
2101}
2102
Takashi Iwaicb53c622007-08-10 17:21:45 +02002103#ifdef CONFIG_SND_HDA_POWER_SAVE
2104static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2105{
2106 struct alc_spec *spec = codec->spec;
2107 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2108}
2109#endif
2110
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111/*
2112 * Analog playback callbacks
2113 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002114static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002116 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
2118 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002119 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2120 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121}
2122
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002123static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 struct hda_codec *codec,
2125 unsigned int stream_tag,
2126 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002127 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128{
2129 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002130 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2131 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132}
2133
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002134static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002136 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137{
2138 struct alc_spec *spec = codec->spec;
2139 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2140}
2141
2142/*
2143 * Digital out
2144 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002145static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002147 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148{
2149 struct alc_spec *spec = codec->spec;
2150 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2151}
2152
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002153static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002154 struct hda_codec *codec,
2155 unsigned int stream_tag,
2156 unsigned int format,
2157 struct snd_pcm_substream *substream)
2158{
2159 struct alc_spec *spec = codec->spec;
2160 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2161 stream_tag, format, substream);
2162}
2163
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002164static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002165 struct hda_codec *codec,
2166 struct snd_pcm_substream *substream)
2167{
2168 struct alc_spec *spec = codec->spec;
2169 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2170}
2171
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002172static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002174 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175{
2176 struct alc_spec *spec = codec->spec;
2177 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2178}
2179
2180/*
2181 * Analog capture
2182 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002183static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 struct hda_codec *codec,
2185 unsigned int stream_tag,
2186 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002187 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188{
2189 struct alc_spec *spec = codec->spec;
2190
Takashi Iwai63300792008-01-24 15:31:36 +01002191 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 stream_tag, 0, format);
2193 return 0;
2194}
2195
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002196static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002198 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
2200 struct alc_spec *spec = codec->spec;
2201
Takashi Iwai888afa12008-03-18 09:57:50 +01002202 snd_hda_codec_cleanup_stream(codec,
2203 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 return 0;
2205}
2206
Takashi Iwai840b64c2010-07-13 22:49:01 +02002207/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002208static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002209 struct hda_codec *codec,
2210 unsigned int stream_tag,
2211 unsigned int format,
2212 struct snd_pcm_substream *substream)
2213{
2214 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002215 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002216 spec->cur_adc_stream_tag = stream_tag;
2217 spec->cur_adc_format = format;
2218 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2219 return 0;
2220}
2221
Takashi Iwai21268962011-07-07 15:01:13 +02002222static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002223 struct hda_codec *codec,
2224 struct snd_pcm_substream *substream)
2225{
2226 struct alc_spec *spec = codec->spec;
2227 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2228 spec->cur_adc = 0;
2229 return 0;
2230}
2231
Takashi Iwai21268962011-07-07 15:01:13 +02002232static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002233 .substreams = 1,
2234 .channels_min = 2,
2235 .channels_max = 2,
2236 .nid = 0, /* fill later */
2237 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002238 .prepare = dyn_adc_capture_pcm_prepare,
2239 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002240 },
2241};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242
2243/*
2244 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002245static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 .substreams = 1,
2247 .channels_min = 2,
2248 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002249 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002251 .open = alc_playback_pcm_open,
2252 .prepare = alc_playback_pcm_prepare,
2253 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 },
2255};
2256
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002257static const struct hda_pcm_stream alc_pcm_analog_capture = {
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_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002265 .substreams = 1,
2266 .channels_min = 2,
2267 .channels_max = 2,
2268 /* NID is set in alc_build_pcms */
2269};
2270
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002271static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002272 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 .channels_min = 2,
2274 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002275 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002277 .prepare = alc_alt_capture_pcm_prepare,
2278 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 },
2280};
2281
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002282static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283 .substreams = 1,
2284 .channels_min = 2,
2285 .channels_max = 2,
2286 /* NID is set in alc_build_pcms */
2287 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002288 .open = alc_dig_playback_pcm_open,
2289 .close = alc_dig_playback_pcm_close,
2290 .prepare = alc_dig_playback_pcm_prepare,
2291 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 },
2293};
2294
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002295static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 .substreams = 1,
2297 .channels_min = 2,
2298 .channels_max = 2,
2299 /* NID is set in alc_build_pcms */
2300};
2301
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002302/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002303static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002304 .substreams = 0,
2305 .channels_min = 0,
2306 .channels_max = 0,
2307};
2308
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309static int alc_build_pcms(struct hda_codec *codec)
2310{
2311 struct alc_spec *spec = codec->spec;
2312 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002313 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002314 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 int i;
2316
2317 codec->num_pcms = 1;
2318 codec->pcm_info = info;
2319
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002320 if (spec->no_analog)
2321 goto skip_analog;
2322
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002323 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2324 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002326
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002327 if (spec->multiout.dac_nids > 0) {
2328 p = spec->stream_analog_playback;
2329 if (!p)
2330 p = &alc_pcm_analog_playback;
2331 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002332 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2333 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002334 if (spec->adc_nids) {
2335 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002336 if (!p) {
2337 if (spec->dyn_adc_switch)
2338 p = &dyn_adc_pcm_analog_capture;
2339 else
2340 p = &alc_pcm_analog_capture;
2341 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002342 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002343 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2344 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345
Takashi Iwai4a471b72005-12-07 13:56:29 +01002346 if (spec->channel_mode) {
2347 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2348 for (i = 0; i < spec->num_channel_mode; i++) {
2349 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 }
2353 }
2354
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002355 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002356 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002358 snprintf(spec->stream_name_digital,
2359 sizeof(spec->stream_name_digital),
2360 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002361 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002362 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002363 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002365 if (spec->dig_out_type)
2366 info->pcm_type = spec->dig_out_type;
2367 else
2368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002369 if (spec->multiout.dig_out_nid) {
2370 p = spec->stream_digital_playback;
2371 if (!p)
2372 p = &alc_pcm_digital_playback;
2373 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002374 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2375 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002376 if (spec->dig_in_nid) {
2377 p = spec->stream_digital_capture;
2378 if (!p)
2379 p = &alc_pcm_digital_capture;
2380 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2382 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002383 /* FIXME: do we need this for all Realtek codec models? */
2384 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 }
2386
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002387 if (spec->no_analog)
2388 return 0;
2389
Takashi Iwaie08a0072006-09-07 17:52:14 +02002390 /* If the use of more than one ADC is requested for the current
2391 * model, configure a second analog capture-only PCM.
2392 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002393 have_multi_adcs = (spec->num_adc_nids > 1) &&
2394 !spec->dyn_adc_switch && !spec->auto_mic &&
2395 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002396 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002397 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002398 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002399 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002400 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002401 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002402 p = spec->stream_analog_alt_playback;
2403 if (!p)
2404 p = &alc_pcm_analog_alt_playback;
2405 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002406 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2407 spec->alt_dac_nid;
2408 } else {
2409 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2410 alc_pcm_null_stream;
2411 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2412 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002413 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002414 p = spec->stream_analog_alt_capture;
2415 if (!p)
2416 p = &alc_pcm_analog_alt_capture;
2417 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002418 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2419 spec->adc_nids[1];
2420 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2421 spec->num_adc_nids - 1;
2422 } else {
2423 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2424 alc_pcm_null_stream;
2425 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002426 }
2427 }
2428
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 return 0;
2430}
2431
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002432static inline void alc_shutup(struct hda_codec *codec)
2433{
Takashi Iwai1c716152011-04-07 10:37:16 +02002434 struct alc_spec *spec = codec->spec;
2435
2436 if (spec && spec->shutup)
2437 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002438 snd_hda_shutup_pins(codec);
2439}
2440
Takashi Iwai603c4012008-07-30 15:01:44 +02002441static void alc_free_kctls(struct hda_codec *codec)
2442{
2443 struct alc_spec *spec = codec->spec;
2444
2445 if (spec->kctls.list) {
2446 struct snd_kcontrol_new *kctl = spec->kctls.list;
2447 int i;
2448 for (i = 0; i < spec->kctls.used; i++)
2449 kfree(kctl[i].name);
2450 }
2451 snd_array_free(&spec->kctls);
2452}
2453
Takashi Iwai23c09b02011-08-19 09:05:35 +02002454static void alc_free_bind_ctls(struct hda_codec *codec)
2455{
2456 struct alc_spec *spec = codec->spec;
2457 if (spec->bind_ctls.list) {
2458 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2459 int i;
2460 for (i = 0; i < spec->bind_ctls.used; i++)
2461 kfree(ctl[i]);
2462 }
2463 snd_array_free(&spec->bind_ctls);
2464}
2465
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466static void alc_free(struct hda_codec *codec)
2467{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002468 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002469
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002470 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002471 return;
2472
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002473 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002474 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002475 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002476 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002477 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002478 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479}
2480
Hector Martinf5de24b2009-12-20 22:51:31 +01002481#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002482static void alc_power_eapd(struct hda_codec *codec)
2483{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002484 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002485}
2486
Hector Martinf5de24b2009-12-20 22:51:31 +01002487static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2488{
2489 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002490 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002491 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002492 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002493 return 0;
2494}
2495#endif
2496
Takashi Iwai2a439522011-07-26 09:52:50 +02002497#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002498static int alc_resume(struct hda_codec *codec)
2499{
Takashi Iwai1c716152011-04-07 10:37:16 +02002500 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002501 codec->patch_ops.init(codec);
2502 snd_hda_codec_resume_amp(codec);
2503 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002504 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002505 return 0;
2506}
Takashi Iwaie044c392008-10-27 16:56:24 +01002507#endif
2508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509/*
2510 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002511static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 .build_controls = alc_build_controls,
2513 .build_pcms = alc_build_pcms,
2514 .init = alc_init,
2515 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002516 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002517#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002518 .resume = alc_resume,
2519#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002520#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002521 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002522 .check_power_status = alc_check_power_status,
2523#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002524 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525};
2526
Kailang Yangc027ddc2010-03-19 11:33:06 +01002527/* replace the codec chip_name with the given string */
2528static int alc_codec_rename(struct hda_codec *codec, const char *name)
2529{
2530 kfree(codec->chip_name);
2531 codec->chip_name = kstrdup(name, GFP_KERNEL);
2532 if (!codec->chip_name) {
2533 alc_free(codec);
2534 return -ENOMEM;
2535 }
2536 return 0;
2537}
2538
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002539/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002540 * Rename codecs appropriately from COEF value
2541 */
2542struct alc_codec_rename_table {
2543 unsigned int vendor_id;
2544 unsigned short coef_mask;
2545 unsigned short coef_bits;
2546 const char *name;
2547};
2548
2549static struct alc_codec_rename_table rename_tbl[] = {
2550 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2551 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2552 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2553 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2554 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2555 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2556 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2557 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2558 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2559 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2560 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2561 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2562 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2563 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2564 { } /* terminator */
2565};
2566
2567static int alc_codec_rename_from_preset(struct hda_codec *codec)
2568{
2569 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002570
2571 for (p = rename_tbl; p->vendor_id; p++) {
2572 if (p->vendor_id != codec->vendor_id)
2573 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002574 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002575 return alc_codec_rename(codec, p->name);
2576 }
2577 return 0;
2578}
2579
2580/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002581 * Automatic parse of I/O pins from the BIOS configuration
2582 */
2583
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002584enum {
2585 ALC_CTL_WIDGET_VOL,
2586 ALC_CTL_WIDGET_MUTE,
2587 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002588 ALC_CTL_BIND_VOL,
2589 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002590};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002591static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002592 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2593 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002594 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002595 HDA_BIND_VOL(NULL, 0),
2596 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002597};
2598
2599/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002600static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002601 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002602{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002603 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002604
Takashi Iwaice764ab2011-04-27 16:35:23 +02002605 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002606 if (!knew)
2607 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002608 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002609 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002610 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002611 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002612 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002613 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002614 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002615 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002616 return 0;
2617}
2618
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002619static int add_control_with_pfx(struct alc_spec *spec, int type,
2620 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002621 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002622{
2623 char name[32];
2624 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002625 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002626}
2627
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002628#define add_pb_vol_ctrl(spec, type, pfx, val) \
2629 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2630#define add_pb_sw_ctrl(spec, type, pfx, val) \
2631 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2632#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2633 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2634#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2635 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002636
Takashi Iwai23c09b02011-08-19 09:05:35 +02002637static const char * const channel_name[4] = {
2638 "Front", "Surround", "CLFE", "Side"
2639};
2640
Takashi Iwai6843ca12011-06-24 11:03:58 +02002641static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2642 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002643{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002644 struct auto_pin_cfg *cfg = &spec->autocfg;
2645
Takashi Iwai6843ca12011-06-24 11:03:58 +02002646 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002647 if (cfg->line_outs == 1 && !spec->multi_ios &&
2648 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002649 return "Master";
2650
2651 switch (cfg->line_out_type) {
2652 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002653 if (cfg->line_outs == 1)
2654 return "Speaker";
2655 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002656 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002657 /* for multi-io case, only the primary out */
2658 if (ch && spec->multi_ios)
2659 break;
2660 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002661 return "Headphone";
2662 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002663 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002664 return "PCM";
2665 break;
2666 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002667 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2668 return "PCM";
2669
2670 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002671}
2672
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002673/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002674static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002675 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002676 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002677{
Kailang Yangdf694da2005-12-05 19:42:22 +01002678 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002679
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002680 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002681 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2682 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002683 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002684 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002685 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2686 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002687 return err;
2688 return 0;
2689}
2690
Takashi Iwai05f5f472009-08-25 13:10:18 +02002691static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002692{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002693 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2694 return (pincap & AC_PINCAP_IN) != 0;
2695}
2696
Takashi Iwai1d045db2011-07-07 18:23:21 +02002697/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002698static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002699{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002700 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002701 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002702 hda_nid_t *adc_nids = spec->private_adc_nids;
2703 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2704 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002705 int i, nums = 0;
2706
Takashi Iwai24de1832011-11-07 17:13:39 +01002707 if (spec->shared_mic_hp)
2708 max_nums = 1; /* no multi streams with the shared HP/mic */
2709
Takashi Iwaib7821702011-07-06 15:12:46 +02002710 nid = codec->start_nid;
2711 for (i = 0; i < codec->num_nodes; i++, nid++) {
2712 hda_nid_t src;
2713 const hda_nid_t *list;
2714 unsigned int caps = get_wcaps(codec, nid);
2715 int type = get_wcaps_type(caps);
2716
2717 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2718 continue;
2719 adc_nids[nums] = nid;
2720 cap_nids[nums] = nid;
2721 src = nid;
2722 for (;;) {
2723 int n;
2724 type = get_wcaps_type(get_wcaps(codec, src));
2725 if (type == AC_WID_PIN)
2726 break;
2727 if (type == AC_WID_AUD_SEL) {
2728 cap_nids[nums] = src;
2729 break;
2730 }
2731 n = snd_hda_get_conn_list(codec, src, &list);
2732 if (n > 1) {
2733 cap_nids[nums] = src;
2734 break;
2735 } else if (n != 1)
2736 break;
2737 src = *list;
2738 }
2739 if (++nums >= max_nums)
2740 break;
2741 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002742 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002743 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002744 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002745 return nums;
2746}
2747
Takashi Iwai05f5f472009-08-25 13:10:18 +02002748/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002749static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002750{
2751 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002752 const struct auto_pin_cfg *cfg = &spec->autocfg;
2753 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002754 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002755 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002756 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002757 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002758
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002759 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002760 if (num_adcs < 0)
2761 return 0;
2762
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002763 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002764 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002765 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002766
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002767 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002768 if (!alc_is_input_pin(codec, pin))
2769 continue;
2770
David Henningsson5322bf22011-01-05 11:03:56 +01002771 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002772 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2773 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002774 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002775 type_idx++;
2776 else
2777 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002778 prev_label = label;
2779
Takashi Iwai05f5f472009-08-25 13:10:18 +02002780 if (mixer) {
2781 idx = get_connection_index(codec, mixer, pin);
2782 if (idx >= 0) {
2783 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002784 label, type_idx,
2785 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002786 if (err < 0)
2787 return err;
2788 }
2789 }
2790
Takashi Iwaib7821702011-07-06 15:12:46 +02002791 for (c = 0; c < num_adcs; c++) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002792 hda_nid_t cap = spec->capsrc_nids ?
2793 spec->capsrc_nids[c] : spec->adc_nids[c];
2794 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002795 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002796 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002797 snd_hda_add_imux_item(imux, label, idx, NULL);
2798 break;
2799 }
2800 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002801 }
Takashi Iwai21268962011-07-07 15:01:13 +02002802
2803 spec->num_mux_defs = 1;
2804 spec->input_mux = imux;
2805
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002806 return 0;
2807}
2808
Takashi Iwai24de1832011-11-07 17:13:39 +01002809/* create a shared input with the headphone out */
2810static int alc_auto_create_shared_input(struct hda_codec *codec)
2811{
2812 struct alc_spec *spec = codec->spec;
2813 struct auto_pin_cfg *cfg = &spec->autocfg;
2814 unsigned int defcfg;
2815 hda_nid_t nid;
2816
2817 /* only one internal input pin? */
2818 if (cfg->num_inputs != 1)
2819 return 0;
2820 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2821 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2822 return 0;
2823
2824 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2825 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2826 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2827 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2828 else
2829 return 0; /* both not available */
2830
2831 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2832 return 0; /* no input */
2833
2834 cfg->inputs[1].pin = nid;
2835 cfg->inputs[1].type = AUTO_PIN_MIC;
2836 cfg->num_inputs = 2;
2837 spec->shared_mic_hp = 1;
2838 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2839 return 0;
2840}
2841
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002842static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2843 unsigned int pin_type)
2844{
2845 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2846 pin_type);
2847 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002848 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2849 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002850 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002851}
2852
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002853static int get_pin_type(int line_out_type)
2854{
2855 if (line_out_type == AUTO_PIN_HP_OUT)
2856 return PIN_HP;
2857 else
2858 return PIN_OUT;
2859}
2860
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002861static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002862{
2863 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002864 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002865 int i;
2866
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002867 for (i = 0; i < cfg->num_inputs; i++) {
2868 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002869 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002870 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002871 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002872 snd_hda_codec_write(codec, nid, 0,
2873 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002874 AMP_OUT_MUTE);
2875 }
2876 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002877
2878 /* mute all loopback inputs */
2879 if (spec->mixer_nid) {
2880 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2881 for (i = 0; i < nums; i++)
2882 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2883 AC_VERB_SET_AMP_GAIN_MUTE,
2884 AMP_IN_MUTE(i));
2885 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002886}
2887
Takashi Iwai7085ec12009-10-02 09:03:58 +02002888/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002889static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002890{
Takashi Iwai604401a2011-04-27 15:14:23 +02002891 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002892 int i, num;
2893
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002894 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2895 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002896 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2897 for (i = 0; i < num; i++) {
2898 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2899 return list[i];
2900 }
2901 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002902}
2903
Takashi Iwai604401a2011-04-27 15:14:23 +02002904/* go down to the selector widget before the mixer */
2905static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2906{
2907 hda_nid_t srcs[5];
2908 int num = snd_hda_get_connections(codec, pin, srcs,
2909 ARRAY_SIZE(srcs));
2910 if (num != 1 ||
2911 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2912 return pin;
2913 return srcs[0];
2914}
2915
Takashi Iwai7085ec12009-10-02 09:03:58 +02002916/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002917static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002918 hda_nid_t dac)
2919{
David Henningssoncc1c4522010-11-24 14:17:47 +01002920 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002921 int i, num;
2922
Takashi Iwai604401a2011-04-27 15:14:23 +02002923 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002924 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2925 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002926 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002927 return mix[i];
2928 }
2929 return 0;
2930}
2931
Takashi Iwaice764ab2011-04-27 16:35:23 +02002932/* select the connection from pin to DAC if needed */
2933static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2934 hda_nid_t dac)
2935{
2936 hda_nid_t mix[5];
2937 int i, num;
2938
2939 pin = alc_go_down_to_selector(codec, pin);
2940 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2941 if (num < 2)
2942 return 0;
2943 for (i = 0; i < num; i++) {
2944 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2945 snd_hda_codec_update_cache(codec, pin, 0,
2946 AC_VERB_SET_CONNECT_SEL, i);
2947 return 0;
2948 }
2949 }
2950 return 0;
2951}
2952
Takashi Iwai7085ec12009-10-02 09:03:58 +02002953/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002954static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002955{
2956 struct alc_spec *spec = codec->spec;
2957 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002958 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002959
Takashi Iwai604401a2011-04-27 15:14:23 +02002960 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002961 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002962 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002963 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002964 if (!nid)
2965 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002966 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2967 spec->multiout.num_dacs))
2968 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002969 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2970 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2971 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002972 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2973 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2974 continue;
2975 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002976 }
2977 return 0;
2978}
2979
Takashi Iwai07b18f62011-11-10 15:42:54 +01002980/* check whether the DAC is reachable from the pin */
2981static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2982 hda_nid_t pin, hda_nid_t dac)
2983{
2984 hda_nid_t srcs[5];
2985 int i, num;
2986
2987 pin = alc_go_down_to_selector(codec, pin);
2988 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2989 for (i = 0; i < num; i++) {
2990 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2991 if (nid == dac)
2992 return true;
2993 }
2994 return false;
2995}
2996
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002997static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2998{
2999 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
3000 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
3001 return alc_auto_look_for_dac(codec, pin);
3002 return 0;
3003}
3004
Takashi Iwaic2674682011-08-24 17:57:44 +02003005static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3006 const hda_nid_t *pins, hda_nid_t *dacs)
3007{
3008 int i;
3009
3010 if (num_outs && !dacs[0]) {
3011 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3012 if (!dacs[0])
3013 return 0;
3014 }
3015
3016 for (i = 1; i < num_outs; i++)
3017 dacs[i] = get_dac_if_single(codec, pins[i]);
3018 for (i = 1; i < num_outs; i++) {
3019 if (!dacs[i])
3020 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3021 }
3022 return 0;
3023}
3024
3025static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003026 unsigned int location, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003027
Takashi Iwai7085ec12009-10-02 09:03:58 +02003028/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003029static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003030{
3031 struct alc_spec *spec = codec->spec;
Takashi Iwaicb053a82011-06-27 11:32:07 +02003032 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003033 unsigned int location, defcfg;
3034 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003035 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003036 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003037
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003038 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003039 /* set num_dacs once to full for alc_auto_look_for_dac() */
3040 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003041 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003042 spec->multiout.extra_out_nid[0] = 0;
3043 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3044 spec->multiout.dac_nids = spec->private_dac_nids;
3045
3046 /* fill hard-wired DACs first */
3047 if (!redone) {
3048 for (i = 0; i < cfg->line_outs; i++)
3049 spec->private_dac_nids[i] =
3050 get_dac_if_single(codec, cfg->line_out_pins[i]);
3051 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003052 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003053 get_dac_if_single(codec, cfg->hp_pins[0]);
3054 if (cfg->speaker_outs)
3055 spec->multiout.extra_out_nid[0] =
3056 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003057 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003058
3059 for (i = 0; i < cfg->line_outs; i++) {
3060 hda_nid_t pin = cfg->line_out_pins[i];
3061 if (spec->private_dac_nids[i])
3062 continue;
3063 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3064 if (!spec->private_dac_nids[i] && !redone) {
3065 /* if we can't find primary DACs, re-probe without
3066 * checking the hard-wired DACs
3067 */
3068 redone = true;
3069 goto again;
3070 }
3071 }
3072
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003073 /* re-count num_dacs and squash invalid entries */
3074 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003075 for (i = 0; i < cfg->line_outs; i++) {
3076 if (spec->private_dac_nids[i])
3077 spec->multiout.num_dacs++;
3078 else
3079 memmove(spec->private_dac_nids + i,
3080 spec->private_dac_nids + i + 1,
3081 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3082 }
3083
Takashi Iwaic2674682011-08-24 17:57:44 +02003084 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3085 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003086 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3087 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003088
Takashi Iwai07b18f62011-11-10 15:42:54 +01003089 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003090 if (num_pins > 0) {
3091 spec->multi_ios = num_pins;
3092 spec->ext_channel_count = 2;
3093 spec->multiout.num_dacs = num_pins + 1;
3094 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003095 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003096
Takashi Iwai716eef02011-10-21 15:07:42 +02003097 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3098 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003099 spec->multiout.hp_out_nid);
Takashi Iwai716eef02011-10-21 15:07:42 +02003100 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3101 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003102 spec->multiout.extra_out_nid);
3103
Takashi Iwai07b18f62011-11-10 15:42:54 +01003104 if (!spec->multi_ios &&
3105 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3106 cfg->hp_outs) {
3107 /* try multi-ios with HP + inputs */
3108 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3109 location = get_defcfg_location(defcfg);
3110
3111 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3112 if (num_pins > 0) {
3113 spec->multi_ios = num_pins;
3114 spec->ext_channel_count = 2;
3115 spec->multiout.num_dacs = num_pins + 1;
3116 }
3117 }
3118
Takashi Iwai23c09b02011-08-19 09:05:35 +02003119 return 0;
3120}
3121
Takashi Iwai527e4d72011-10-27 16:33:27 +02003122static inline unsigned int get_ctl_pos(unsigned int data)
3123{
3124 hda_nid_t nid = get_amp_nid_(data);
3125 unsigned int dir = get_amp_direction_(data);
3126 return (nid << 1) | dir;
3127}
3128
3129#define is_ctl_used(bits, data) \
3130 test_bit(get_ctl_pos(data), bits)
3131#define mark_ctl_usage(bits, data) \
3132 set_bit(get_ctl_pos(data), bits)
3133
Takashi Iwai343a04b2011-07-06 14:28:39 +02003134static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003135 const char *pfx, int cidx,
3136 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003137{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003138 struct alc_spec *spec = codec->spec;
3139 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003140 if (!nid)
3141 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003142 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3143 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3144 return 0;
3145 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003146 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003147 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003148}
3149
Takashi Iwaie29d3772011-11-14 17:13:23 +01003150static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3151 const char *pfx, int cidx,
3152 hda_nid_t nid)
3153{
3154 int chs = 1;
3155 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3156 chs = 3;
3157 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3158}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003159
3160/* create a mute-switch for the given mixer widget;
3161 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3162 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003163static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003164 const char *pfx, int cidx,
3165 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003166{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003167 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003168 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003169 int type;
3170 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003171 if (!nid)
3172 return 0;
3173 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3174 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3175 type = ALC_CTL_WIDGET_MUTE;
3176 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3177 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003178 type = ALC_CTL_WIDGET_MUTE;
3179 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3180 } else {
3181 type = ALC_CTL_BIND_MUTE;
3182 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3183 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003184 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3185 return 0;
3186 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003187 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003188}
3189
Takashi Iwaie29d3772011-11-14 17:13:23 +01003190static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3191 int cidx, hda_nid_t nid)
3192{
3193 int chs = 1;
3194 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3195 chs = 3;
3196 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3197}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003198
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003199static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3200 hda_nid_t pin, hda_nid_t dac)
3201{
3202 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3203 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3204 return pin;
3205 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3206 return mix;
3207 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3208 return dac;
3209 return 0;
3210}
3211
3212static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3213 hda_nid_t pin, hda_nid_t dac)
3214{
3215 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3216 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3217 return dac;
3218 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3219 return mix;
3220 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3221 return pin;
3222 return 0;
3223}
3224
Takashi Iwai7085ec12009-10-02 09:03:58 +02003225/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003226static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003227 const struct auto_pin_cfg *cfg)
3228{
3229 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003230 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003231
Takashi Iwaice764ab2011-04-27 16:35:23 +02003232 noutputs = cfg->line_outs;
3233 if (spec->multi_ios > 0)
3234 noutputs += spec->multi_ios;
3235
3236 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003237 const char *name;
3238 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003239 hda_nid_t dac, pin;
3240 hda_nid_t sw, vol;
3241
3242 dac = spec->multiout.dac_nids[i];
3243 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003244 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003245 if (i >= cfg->line_outs)
3246 pin = spec->multi_io[i - 1].pin;
3247 else
3248 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003249
3250 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3251 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003252 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003253 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003254 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003255 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003256 if (err < 0)
3257 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003258 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003259 if (err < 0)
3260 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003261 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
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_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003265 if (err < 0)
3266 return err;
3267 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003268 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003269 if (err < 0)
3270 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003271 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003272 if (err < 0)
3273 return err;
3274 }
3275 }
3276 return 0;
3277}
3278
Takashi Iwai343a04b2011-07-06 14:28:39 +02003279static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai23c09b02011-08-19 09:05:35 +02003280 hda_nid_t dac, const char *pfx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003281{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003282 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003283 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003284 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003285
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003286 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003287 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003288 /* the corresponding DAC is already occupied */
3289 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3290 return 0; /* no way */
3291 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003292 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3293 if (is_ctl_used(spec->sw_ctls, val))
3294 return 0; /* already created */
3295 mark_ctl_usage(spec->sw_ctls, val);
3296 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003297 }
3298
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003299 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3300 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3301 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003302 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003303 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003304 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003305 if (err < 0)
3306 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003307 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003308}
3309
Takashi Iwai23c09b02011-08-19 09:05:35 +02003310static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3311 unsigned int nums,
3312 struct hda_ctl_ops *ops)
3313{
3314 struct alc_spec *spec = codec->spec;
3315 struct hda_bind_ctls **ctlp, *ctl;
3316 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3317 ctlp = snd_array_new(&spec->bind_ctls);
3318 if (!ctlp)
3319 return NULL;
3320 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3321 *ctlp = ctl;
3322 if (ctl)
3323 ctl->ops = ops;
3324 return ctl;
3325}
3326
3327/* add playback controls for speaker and HP outputs */
3328static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3329 const hda_nid_t *pins,
3330 const hda_nid_t *dacs,
3331 const char *pfx)
3332{
3333 struct alc_spec *spec = codec->spec;
3334 struct hda_bind_ctls *ctl;
3335 char name[32];
3336 int i, n, err;
3337
3338 if (!num_pins || !pins[0])
3339 return 0;
3340
Takashi Iwai527e4d72011-10-27 16:33:27 +02003341 if (num_pins == 1) {
3342 hda_nid_t dac = *dacs;
3343 if (!dac)
3344 dac = spec->multiout.dac_nids[0];
3345 return alc_auto_create_extra_out(codec, *pins, dac, pfx);
3346 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003347
3348 if (dacs[num_pins - 1]) {
3349 /* OK, we have a multi-output system with individual volumes */
3350 for (i = 0; i < num_pins; i++) {
3351 snprintf(name, sizeof(name), "%s %s",
3352 pfx, channel_name[i]);
3353 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3354 name);
3355 if (err < 0)
3356 return err;
3357 }
3358 return 0;
3359 }
3360
3361 /* Let's create a bind-controls */
3362 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3363 if (!ctl)
3364 return -ENOMEM;
3365 n = 0;
3366 for (i = 0; i < num_pins; i++) {
3367 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3368 ctl->values[n++] =
3369 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3370 }
3371 if (n) {
3372 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3373 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3374 if (err < 0)
3375 return err;
3376 }
3377
3378 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3379 if (!ctl)
3380 return -ENOMEM;
3381 n = 0;
3382 for (i = 0; i < num_pins; i++) {
3383 hda_nid_t vol;
3384 if (!pins[i] || !dacs[i])
3385 continue;
3386 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3387 if (vol)
3388 ctl->values[n++] =
3389 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3390 }
3391 if (n) {
3392 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3393 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3394 if (err < 0)
3395 return err;
3396 }
3397 return 0;
3398}
3399
Takashi Iwai343a04b2011-07-06 14:28:39 +02003400static int alc_auto_create_hp_out(struct hda_codec *codec)
3401{
3402 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003403 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3404 spec->autocfg.hp_pins,
3405 spec->multiout.hp_out_nid,
3406 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003407}
3408
3409static int alc_auto_create_speaker_out(struct hda_codec *codec)
3410{
3411 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003412 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3413 spec->autocfg.speaker_pins,
3414 spec->multiout.extra_out_nid,
3415 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003416}
3417
Takashi Iwai343a04b2011-07-06 14:28:39 +02003418static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003419 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003420 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003421{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003422 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003423 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003424 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003425
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003426 alc_set_pin_output(codec, pin, pin_type);
3427 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003428 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003429 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003430 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003431 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003432 mix = srcs[i];
3433 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003434 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003435 if (!mix)
3436 return;
3437
3438 /* need the manual connection? */
3439 if (num > 1)
3440 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3441 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003442 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3443 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003444 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003445 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003446 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003447 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003448 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003449 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3450 if (nid)
3451 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3452 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003453
3454 /* unmute DAC if it's not assigned to a mixer */
3455 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3456 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3457 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3458 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003459}
3460
Takashi Iwai343a04b2011-07-06 14:28:39 +02003461static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003462{
3463 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003464 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003465 int i;
3466
3467 for (i = 0; i <= HDA_SIDE; i++) {
3468 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3469 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003470 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003471 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003472 }
3473}
3474
Takashi Iwai343a04b2011-07-06 14:28:39 +02003475static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003476{
3477 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003478 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003479 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003480
David Henningsson636030e2011-10-12 19:26:03 +02003481 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003482 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3483 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003484 pin = spec->autocfg.hp_pins[i];
3485 if (!pin)
3486 break;
3487 dac = spec->multiout.hp_out_nid[i];
3488 if (!dac) {
3489 if (i > 0 && spec->multiout.hp_out_nid[0])
3490 dac = spec->multiout.hp_out_nid[0];
3491 else
3492 dac = spec->multiout.dac_nids[0];
3493 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003494 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3495 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003496 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003497 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3498 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003499 pin = spec->autocfg.speaker_pins[i];
3500 if (!pin)
3501 break;
3502 dac = spec->multiout.extra_out_nid[i];
3503 if (!dac) {
3504 if (i > 0 && spec->multiout.extra_out_nid[0])
3505 dac = spec->multiout.extra_out_nid[0];
3506 else
3507 dac = spec->multiout.dac_nids[0];
3508 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003509 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3510 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003511}
3512
Takashi Iwaice764ab2011-04-27 16:35:23 +02003513/*
3514 * multi-io helper
3515 */
3516static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003517 unsigned int location,
3518 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003519{
3520 struct alc_spec *spec = codec->spec;
3521 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003522 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003523 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003524
Takashi Iwai07b18f62011-11-10 15:42:54 +01003525 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003526 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3527 for (i = 0; i < cfg->num_inputs; i++) {
3528 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003529 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003530 unsigned int defcfg, caps;
3531 if (cfg->inputs[i].type != type)
3532 continue;
3533 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3534 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3535 continue;
3536 if (location && get_defcfg_location(defcfg) != location)
3537 continue;
3538 caps = snd_hda_query_pin_caps(codec, nid);
3539 if (!(caps & AC_PINCAP_OUT))
3540 continue;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003541 if (offset && offset + num_pins < dacs) {
3542 dac = spec->private_dac_nids[offset + num_pins];
3543 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3544 dac = 0;
3545 }
3546 if (!dac)
3547 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003548 if (!dac)
3549 continue;
3550 spec->multi_io[num_pins].pin = nid;
3551 spec->multi_io[num_pins].dac = dac;
3552 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003553 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003554 }
3555 }
Takashi Iwai07b18f62011-11-10 15:42:54 +01003556 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003557 if (num_pins < 2) {
3558 /* clear up again */
Takashi Iwai07b18f62011-11-10 15:42:54 +01003559 memset(spec->private_dac_nids + dacs, 0,
3560 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003561 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003562 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003563 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003564 return num_pins;
3565}
3566
3567static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3568 struct snd_ctl_elem_info *uinfo)
3569{
3570 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3571 struct alc_spec *spec = codec->spec;
3572
3573 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3574 uinfo->count = 1;
3575 uinfo->value.enumerated.items = spec->multi_ios + 1;
3576 if (uinfo->value.enumerated.item > spec->multi_ios)
3577 uinfo->value.enumerated.item = spec->multi_ios;
3578 sprintf(uinfo->value.enumerated.name, "%dch",
3579 (uinfo->value.enumerated.item + 1) * 2);
3580 return 0;
3581}
3582
3583static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3584 struct snd_ctl_elem_value *ucontrol)
3585{
3586 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3587 struct alc_spec *spec = codec->spec;
3588 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3589 return 0;
3590}
3591
3592static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3593{
3594 struct alc_spec *spec = codec->spec;
3595 hda_nid_t nid = spec->multi_io[idx].pin;
3596
3597 if (!spec->multi_io[idx].ctl_in)
3598 spec->multi_io[idx].ctl_in =
3599 snd_hda_codec_read(codec, nid, 0,
3600 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3601 if (output) {
3602 snd_hda_codec_update_cache(codec, nid, 0,
3603 AC_VERB_SET_PIN_WIDGET_CONTROL,
3604 PIN_OUT);
3605 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3606 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3607 HDA_AMP_MUTE, 0);
3608 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3609 } else {
3610 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3611 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3612 HDA_AMP_MUTE, HDA_AMP_MUTE);
3613 snd_hda_codec_update_cache(codec, nid, 0,
3614 AC_VERB_SET_PIN_WIDGET_CONTROL,
3615 spec->multi_io[idx].ctl_in);
3616 }
3617 return 0;
3618}
3619
3620static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3621 struct snd_ctl_elem_value *ucontrol)
3622{
3623 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3624 struct alc_spec *spec = codec->spec;
3625 int i, ch;
3626
3627 ch = ucontrol->value.enumerated.item[0];
3628 if (ch < 0 || ch > spec->multi_ios)
3629 return -EINVAL;
3630 if (ch == (spec->ext_channel_count - 1) / 2)
3631 return 0;
3632 spec->ext_channel_count = (ch + 1) * 2;
3633 for (i = 0; i < spec->multi_ios; i++)
3634 alc_set_multi_io(codec, i, i < ch);
3635 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003636 if (spec->need_dac_fix && !spec->const_channel_count)
3637 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003638 return 1;
3639}
3640
Takashi Iwaia9111322011-05-02 11:30:18 +02003641static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003642 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3643 .name = "Channel Mode",
3644 .info = alc_auto_ch_mode_info,
3645 .get = alc_auto_ch_mode_get,
3646 .put = alc_auto_ch_mode_put,
3647};
3648
Takashi Iwai23c09b02011-08-19 09:05:35 +02003649static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003650{
3651 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003652
Takashi Iwaic2674682011-08-24 17:57:44 +02003653 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003654 struct snd_kcontrol_new *knew;
3655
3656 knew = alc_kcontrol_new(spec);
3657 if (!knew)
3658 return -ENOMEM;
3659 *knew = alc_auto_channel_mode_enum;
3660 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3661 if (!knew->name)
3662 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003663 }
3664 return 0;
3665}
3666
Takashi Iwai1d045db2011-07-07 18:23:21 +02003667/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3668 * active input pins
3669 */
3670static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3671{
3672 struct alc_spec *spec = codec->spec;
3673 const struct hda_input_mux *imux;
3674 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3675 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3676 int i, n, nums;
3677
3678 imux = spec->input_mux;
3679 if (!imux)
3680 return;
3681 if (spec->dyn_adc_switch)
3682 return;
3683
3684 nums = 0;
3685 for (n = 0; n < spec->num_adc_nids; n++) {
3686 hda_nid_t cap = spec->private_capsrc_nids[n];
3687 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3688 for (i = 0; i < imux->num_items; i++) {
3689 hda_nid_t pin = spec->imux_pins[i];
3690 if (pin) {
3691 if (get_connection_index(codec, cap, pin) < 0)
3692 break;
3693 } else if (num_conns <= imux->items[i].index)
3694 break;
3695 }
3696 if (i >= imux->num_items) {
3697 adc_nids[nums] = spec->private_adc_nids[n];
3698 capsrc_nids[nums++] = cap;
3699 }
3700 }
3701 if (!nums) {
3702 /* check whether ADC-switch is possible */
3703 if (!alc_check_dyn_adc_switch(codec)) {
3704 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3705 " using fallback 0x%x\n",
3706 codec->chip_name, spec->private_adc_nids[0]);
3707 spec->num_adc_nids = 1;
3708 spec->auto_mic = 0;
3709 return;
3710 }
3711 } else if (nums != spec->num_adc_nids) {
3712 memcpy(spec->private_adc_nids, adc_nids,
3713 nums * sizeof(hda_nid_t));
3714 memcpy(spec->private_capsrc_nids, capsrc_nids,
3715 nums * sizeof(hda_nid_t));
3716 spec->num_adc_nids = nums;
3717 }
3718
3719 if (spec->auto_mic)
3720 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3721 else if (spec->input_mux->num_items == 1)
3722 spec->num_adc_nids = 1; /* reduce to a single ADC */
3723}
3724
3725/*
3726 * initialize ADC paths
3727 */
3728static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3729{
3730 struct alc_spec *spec = codec->spec;
3731 hda_nid_t nid;
3732
3733 nid = spec->adc_nids[adc_idx];
3734 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003735 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003736 snd_hda_codec_write(codec, nid, 0,
3737 AC_VERB_SET_AMP_GAIN_MUTE,
3738 AMP_IN_MUTE(0));
3739 return;
3740 }
3741 if (!spec->capsrc_nids)
3742 return;
3743 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003744 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003745 snd_hda_codec_write(codec, nid, 0,
3746 AC_VERB_SET_AMP_GAIN_MUTE,
3747 AMP_OUT_MUTE);
3748}
3749
3750static void alc_auto_init_input_src(struct hda_codec *codec)
3751{
3752 struct alc_spec *spec = codec->spec;
3753 int c, nums;
3754
3755 for (c = 0; c < spec->num_adc_nids; c++)
3756 alc_auto_init_adc(codec, c);
3757 if (spec->dyn_adc_switch)
3758 nums = 1;
3759 else
3760 nums = spec->num_adc_nids;
3761 for (c = 0; c < nums; c++)
3762 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3763}
3764
3765/* add mic boosts if needed */
3766static int alc_auto_add_mic_boost(struct hda_codec *codec)
3767{
3768 struct alc_spec *spec = codec->spec;
3769 struct auto_pin_cfg *cfg = &spec->autocfg;
3770 int i, err;
3771 int type_idx = 0;
3772 hda_nid_t nid;
3773 const char *prev_label = NULL;
3774
3775 for (i = 0; i < cfg->num_inputs; i++) {
3776 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3777 break;
3778 nid = cfg->inputs[i].pin;
3779 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3780 const char *label;
3781 char boost_label[32];
3782
3783 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003784 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3785 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003786 if (prev_label && !strcmp(label, prev_label))
3787 type_idx++;
3788 else
3789 type_idx = 0;
3790 prev_label = label;
3791
3792 snprintf(boost_label, sizeof(boost_label),
3793 "%s Boost Volume", label);
3794 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3795 boost_label, type_idx,
3796 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3797 if (err < 0)
3798 return err;
3799 }
3800 }
3801 return 0;
3802}
3803
3804/* select or unmute the given capsrc route */
3805static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3806 int idx)
3807{
3808 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3809 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3810 HDA_AMP_MUTE, 0);
3811 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3812 snd_hda_codec_write_cache(codec, cap, 0,
3813 AC_VERB_SET_CONNECT_SEL, idx);
3814 }
3815}
3816
3817/* set the default connection to that pin */
3818static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3819{
3820 struct alc_spec *spec = codec->spec;
3821 int i;
3822
3823 if (!pin)
3824 return 0;
3825 for (i = 0; i < spec->num_adc_nids; i++) {
3826 hda_nid_t cap = spec->capsrc_nids ?
3827 spec->capsrc_nids[i] : spec->adc_nids[i];
3828 int idx;
3829
3830 idx = get_connection_index(codec, cap, pin);
3831 if (idx < 0)
3832 continue;
3833 select_or_unmute_capsrc(codec, cap, idx);
3834 return i; /* return the found index */
3835 }
3836 return -1; /* not found */
3837}
3838
3839/* initialize some special cases for input sources */
3840static void alc_init_special_input_src(struct hda_codec *codec)
3841{
3842 struct alc_spec *spec = codec->spec;
3843 int i;
3844
3845 for (i = 0; i < spec->autocfg.num_inputs; i++)
3846 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3847}
3848
3849/* assign appropriate capture mixers */
3850static void set_capture_mixer(struct hda_codec *codec)
3851{
3852 struct alc_spec *spec = codec->spec;
3853 static const struct snd_kcontrol_new *caps[2][3] = {
3854 { alc_capture_mixer_nosrc1,
3855 alc_capture_mixer_nosrc2,
3856 alc_capture_mixer_nosrc3 },
3857 { alc_capture_mixer1,
3858 alc_capture_mixer2,
3859 alc_capture_mixer3 },
3860 };
3861
3862 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003863 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003864 if (!spec->capsrc_nids)
3865 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003866 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003867 return; /* no volume in capsrc, too */
3868 spec->vol_in_capsrc = 1;
3869 }
3870
3871 if (spec->num_adc_nids > 0) {
3872 int mux = 0;
3873 int num_adcs = 0;
3874
3875 if (spec->input_mux && spec->input_mux->num_items > 1)
3876 mux = 1;
3877 if (spec->auto_mic) {
3878 num_adcs = 1;
3879 mux = 0;
3880 } else if (spec->dyn_adc_switch)
3881 num_adcs = 1;
3882 if (!num_adcs) {
3883 if (spec->num_adc_nids > 3)
3884 spec->num_adc_nids = 3;
3885 else if (!spec->num_adc_nids)
3886 return;
3887 num_adcs = spec->num_adc_nids;
3888 }
3889 spec->cap_mixer = caps[mux][num_adcs - 1];
3890 }
3891}
3892
3893/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003894 * standard auto-parser initializations
3895 */
3896static void alc_auto_init_std(struct hda_codec *codec)
3897{
3898 struct alc_spec *spec = codec->spec;
3899 alc_auto_init_multi_out(codec);
3900 alc_auto_init_extra_out(codec);
3901 alc_auto_init_analog_input(codec);
3902 alc_auto_init_input_src(codec);
3903 alc_auto_init_digital(codec);
3904 if (spec->unsol_event)
3905 alc_inithook(codec);
3906}
3907
3908/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003909 * Digital-beep handlers
3910 */
3911#ifdef CONFIG_SND_HDA_INPUT_BEEP
3912#define set_beep_amp(spec, nid, idx, dir) \
3913 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3914
3915static const struct snd_pci_quirk beep_white_list[] = {
3916 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3917 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3918 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3919 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3920 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3921 {}
3922};
3923
3924static inline int has_cdefine_beep(struct hda_codec *codec)
3925{
3926 struct alc_spec *spec = codec->spec;
3927 const struct snd_pci_quirk *q;
3928 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3929 if (q)
3930 return q->value;
3931 return spec->cdefine.enable_pcbeep;
3932}
3933#else
3934#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3935#define has_cdefine_beep(codec) 0
3936#endif
3937
3938/* parse the BIOS configuration and set up the alc_spec */
3939/* return 1 if successful, 0 if the proper config is not found,
3940 * or a negative error code
3941 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003942static int alc_parse_auto_config(struct hda_codec *codec,
3943 const hda_nid_t *ignore_nids,
3944 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003945{
3946 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003947 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003948 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003949
Takashi Iwai53c334a2011-08-23 18:27:14 +02003950 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3951 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003952 if (err < 0)
3953 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003954 if (!cfg->line_outs) {
3955 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003956 spec->multiout.max_channels = 2;
3957 spec->no_analog = 1;
3958 goto dig_only;
3959 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003960 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003961 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003962
Takashi Iwai06503672011-10-06 08:27:19 +02003963 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3964 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003965 /* use HP as primary out */
3966 cfg->speaker_outs = cfg->line_outs;
3967 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3968 sizeof(cfg->speaker_pins));
3969 cfg->line_outs = cfg->hp_outs;
3970 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3971 cfg->hp_outs = 0;
3972 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3973 cfg->line_out_type = AUTO_PIN_HP_OUT;
3974 }
3975
Takashi Iwai1d045db2011-07-07 18:23:21 +02003976 err = alc_auto_fill_dac_nids(codec);
3977 if (err < 0)
3978 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003979 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003980 if (err < 0)
3981 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003982 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003983 if (err < 0)
3984 return err;
3985 err = alc_auto_create_hp_out(codec);
3986 if (err < 0)
3987 return err;
3988 err = alc_auto_create_speaker_out(codec);
3989 if (err < 0)
3990 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01003991 err = alc_auto_create_shared_input(codec);
3992 if (err < 0)
3993 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003994 err = alc_auto_create_input_ctls(codec);
3995 if (err < 0)
3996 return err;
3997
3998 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
3999
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004000 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004001 alc_auto_parse_digital(codec);
4002
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004003 if (!spec->no_analog)
4004 alc_remove_invalid_adc_nids(codec);
4005
4006 if (ssid_nids)
4007 alc_ssid_check(codec, ssid_nids);
4008
4009 if (!spec->no_analog) {
4010 alc_auto_check_switches(codec);
4011 err = alc_auto_add_mic_boost(codec);
4012 if (err < 0)
4013 return err;
4014 }
4015
Takashi Iwai1d045db2011-07-07 18:23:21 +02004016 if (spec->kctls.list)
4017 add_mixer(spec, spec->kctls.list);
4018
Takashi Iwai1d045db2011-07-07 18:23:21 +02004019 return 1;
4020}
4021
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004022static int alc880_parse_auto_config(struct hda_codec *codec)
4023{
4024 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4025 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4026 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4027}
4028
Takashi Iwai1d045db2011-07-07 18:23:21 +02004029#ifdef CONFIG_SND_HDA_POWER_SAVE
4030static const struct hda_amp_list alc880_loopbacks[] = {
4031 { 0x0b, HDA_INPUT, 0 },
4032 { 0x0b, HDA_INPUT, 1 },
4033 { 0x0b, HDA_INPUT, 2 },
4034 { 0x0b, HDA_INPUT, 3 },
4035 { 0x0b, HDA_INPUT, 4 },
4036 { } /* end */
4037};
4038#endif
4039
4040/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004041 * ALC880 fix-ups
4042 */
4043enum {
4044 ALC880_FIXUP_GPIO2,
4045 ALC880_FIXUP_MEDION_RIM,
4046};
4047
4048static const struct alc_fixup alc880_fixups[] = {
4049 [ALC880_FIXUP_GPIO2] = {
4050 .type = ALC_FIXUP_VERBS,
4051 .v.verbs = alc_gpio2_init_verbs,
4052 },
4053 [ALC880_FIXUP_MEDION_RIM] = {
4054 .type = ALC_FIXUP_VERBS,
4055 .v.verbs = (const struct hda_verb[]) {
4056 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4057 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4058 { }
4059 },
4060 .chained = true,
4061 .chain_id = ALC880_FIXUP_GPIO2,
4062 },
4063};
4064
4065static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4066 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4067 {}
4068};
4069
4070
4071/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004072 * board setups
4073 */
4074#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4075#define alc_board_config \
4076 snd_hda_check_board_config
4077#define alc_board_codec_sid_config \
4078 snd_hda_check_board_codec_sid_config
4079#include "alc_quirks.c"
4080#else
4081#define alc_board_config(codec, nums, models, tbl) -1
4082#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4083#define setup_preset(codec, x) /* NOP */
4084#endif
4085
4086/*
4087 * OK, here we have finally the patch for ALC880
4088 */
4089#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4090#include "alc880_quirks.c"
4091#endif
4092
4093static int patch_alc880(struct hda_codec *codec)
4094{
4095 struct alc_spec *spec;
4096 int board_config;
4097 int err;
4098
4099 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4100 if (spec == NULL)
4101 return -ENOMEM;
4102
4103 codec->spec = spec;
4104
4105 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004106 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004107
4108 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4109 alc880_models, alc880_cfg_tbl);
4110 if (board_config < 0) {
4111 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4112 codec->chip_name);
4113 board_config = ALC_MODEL_AUTO;
4114 }
4115
4116 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004117 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4118 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4119 }
4120
4121 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004122 /* automatic parse from the BIOS config */
4123 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004124 if (err < 0)
4125 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004126#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4127 else if (!err) {
4128 printk(KERN_INFO
4129 "hda_codec: Cannot set up configuration "
4130 "from BIOS. Using 3-stack mode...\n");
4131 board_config = ALC880_3ST;
4132 }
4133#endif
4134 }
4135
Takashi Iwai1d045db2011-07-07 18:23:21 +02004136 if (board_config != ALC_MODEL_AUTO)
4137 setup_preset(codec, &alc880_presets[board_config]);
4138
Takashi Iwai60a6a842011-07-27 14:01:24 +02004139 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004140 alc_auto_fill_adc_caps(codec);
4141 alc_rebuild_imux_for_auto_mic(codec);
4142 alc_remove_invalid_adc_nids(codec);
4143 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004144
4145 if (!spec->no_analog && !spec->cap_mixer)
4146 set_capture_mixer(codec);
4147
4148 if (!spec->no_analog) {
4149 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004150 if (err < 0)
4151 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004152 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4153 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004154
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004155 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4156
Takashi Iwai1d045db2011-07-07 18:23:21 +02004157 spec->vmaster_nid = 0x0c;
4158
4159 codec->patch_ops = alc_patch_ops;
4160 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004161 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004162#ifdef CONFIG_SND_HDA_POWER_SAVE
4163 if (!spec->loopback.amplist)
4164 spec->loopback.amplist = alc880_loopbacks;
4165#endif
4166
4167 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004168
4169 error:
4170 alc_free(codec);
4171 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004172}
4173
4174
4175/*
4176 * ALC260 support
4177 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004178static int alc260_parse_auto_config(struct hda_codec *codec)
4179{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004180 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004181 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4182 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004183}
4184
Takashi Iwai1d045db2011-07-07 18:23:21 +02004185#ifdef CONFIG_SND_HDA_POWER_SAVE
4186static const struct hda_amp_list alc260_loopbacks[] = {
4187 { 0x07, HDA_INPUT, 0 },
4188 { 0x07, HDA_INPUT, 1 },
4189 { 0x07, HDA_INPUT, 2 },
4190 { 0x07, HDA_INPUT, 3 },
4191 { 0x07, HDA_INPUT, 4 },
4192 { } /* end */
4193};
4194#endif
4195
4196/*
4197 * Pin config fixes
4198 */
4199enum {
4200 PINFIX_HP_DC5750,
4201};
4202
4203static const struct alc_fixup alc260_fixups[] = {
4204 [PINFIX_HP_DC5750] = {
4205 .type = ALC_FIXUP_PINS,
4206 .v.pins = (const struct alc_pincfg[]) {
4207 { 0x11, 0x90130110 }, /* speaker */
4208 { }
4209 }
4210 },
4211};
4212
4213static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4214 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4215 {}
4216};
4217
4218/*
4219 */
4220#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4221#include "alc260_quirks.c"
4222#endif
4223
4224static int patch_alc260(struct hda_codec *codec)
4225{
4226 struct alc_spec *spec;
4227 int err, board_config;
4228
4229 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4230 if (spec == NULL)
4231 return -ENOMEM;
4232
4233 codec->spec = spec;
4234
4235 spec->mixer_nid = 0x07;
4236
4237 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4238 alc260_models, alc260_cfg_tbl);
4239 if (board_config < 0) {
4240 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4241 codec->chip_name);
4242 board_config = ALC_MODEL_AUTO;
4243 }
4244
4245 if (board_config == ALC_MODEL_AUTO) {
4246 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4247 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4248 }
4249
4250 if (board_config == ALC_MODEL_AUTO) {
4251 /* automatic parse from the BIOS config */
4252 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004253 if (err < 0)
4254 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004255#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4256 else if (!err) {
4257 printk(KERN_INFO
4258 "hda_codec: Cannot set up configuration "
4259 "from BIOS. Using base mode...\n");
4260 board_config = ALC260_BASIC;
4261 }
4262#endif
4263 }
4264
Takashi Iwai1d045db2011-07-07 18:23:21 +02004265 if (board_config != ALC_MODEL_AUTO)
4266 setup_preset(codec, &alc260_presets[board_config]);
4267
Takashi Iwai60a6a842011-07-27 14:01:24 +02004268 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004269 alc_auto_fill_adc_caps(codec);
4270 alc_rebuild_imux_for_auto_mic(codec);
4271 alc_remove_invalid_adc_nids(codec);
4272 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004273
4274 if (!spec->no_analog && !spec->cap_mixer)
4275 set_capture_mixer(codec);
4276
4277 if (!spec->no_analog) {
4278 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004279 if (err < 0)
4280 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004281 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4282 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004283
4284 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4285
4286 spec->vmaster_nid = 0x08;
4287
4288 codec->patch_ops = alc_patch_ops;
4289 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004290 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004291 spec->shutup = alc_eapd_shutup;
4292#ifdef CONFIG_SND_HDA_POWER_SAVE
4293 if (!spec->loopback.amplist)
4294 spec->loopback.amplist = alc260_loopbacks;
4295#endif
4296
4297 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004298
4299 error:
4300 alc_free(codec);
4301 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004302}
4303
4304
4305/*
4306 * ALC882/883/885/888/889 support
4307 *
4308 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4309 * configuration. Each pin widget can choose any input DACs and a mixer.
4310 * Each ADC is connected from a mixer of all inputs. This makes possible
4311 * 6-channel independent captures.
4312 *
4313 * In addition, an independent DAC for the multi-playback (not used in this
4314 * driver yet).
4315 */
4316#ifdef CONFIG_SND_HDA_POWER_SAVE
4317#define alc882_loopbacks alc880_loopbacks
4318#endif
4319
4320/*
4321 * Pin config fixes
4322 */
4323enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004324 ALC882_FIXUP_ABIT_AW9D_MAX,
4325 ALC882_FIXUP_LENOVO_Y530,
4326 ALC882_FIXUP_PB_M5210,
4327 ALC882_FIXUP_ACER_ASPIRE_7736,
4328 ALC882_FIXUP_ASUS_W90V,
4329 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004330 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004331 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004332 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004333 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004334 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004335 ALC889_FIXUP_COEF,
4336 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004337 ALC882_FIXUP_ACER_ASPIRE_4930G,
4338 ALC882_FIXUP_ACER_ASPIRE_8930G,
4339 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004340 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004341};
4342
Takashi Iwai68ef0562011-11-09 18:24:44 +01004343static void alc889_fixup_coef(struct hda_codec *codec,
4344 const struct alc_fixup *fix, int action)
4345{
4346 if (action != ALC_FIXUP_ACT_INIT)
4347 return;
4348 alc889_coef_init(codec);
4349}
4350
Takashi Iwai56710872011-11-14 17:42:11 +01004351/* toggle speaker-output according to the hp-jack state */
4352static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4353{
4354 unsigned int gpiostate, gpiomask, gpiodir;
4355
4356 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4357 AC_VERB_GET_GPIO_DATA, 0);
4358
4359 if (!muted)
4360 gpiostate |= (1 << pin);
4361 else
4362 gpiostate &= ~(1 << pin);
4363
4364 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4365 AC_VERB_GET_GPIO_MASK, 0);
4366 gpiomask |= (1 << pin);
4367
4368 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4369 AC_VERB_GET_GPIO_DIRECTION, 0);
4370 gpiodir |= (1 << pin);
4371
4372
4373 snd_hda_codec_write(codec, codec->afg, 0,
4374 AC_VERB_SET_GPIO_MASK, gpiomask);
4375 snd_hda_codec_write(codec, codec->afg, 0,
4376 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4377
4378 msleep(1);
4379
4380 snd_hda_codec_write(codec, codec->afg, 0,
4381 AC_VERB_SET_GPIO_DATA, gpiostate);
4382}
4383
4384/* set up GPIO at initialization */
4385static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4386 const struct alc_fixup *fix, int action)
4387{
4388 if (action != ALC_FIXUP_ACT_INIT)
4389 return;
4390 alc882_gpio_mute(codec, 0, 0);
4391 alc882_gpio_mute(codec, 1, 0);
4392}
4393
Takashi Iwai1d045db2011-07-07 18:23:21 +02004394static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004395 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004396 .type = ALC_FIXUP_PINS,
4397 .v.pins = (const struct alc_pincfg[]) {
4398 { 0x15, 0x01080104 }, /* side */
4399 { 0x16, 0x01011012 }, /* rear */
4400 { 0x17, 0x01016011 }, /* clfe */
4401 { }
4402 }
4403 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004404 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004405 .type = ALC_FIXUP_PINS,
4406 .v.pins = (const struct alc_pincfg[]) {
4407 { 0x15, 0x99130112 }, /* rear int speakers */
4408 { 0x16, 0x99130111 }, /* subwoofer */
4409 { }
4410 }
4411 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004412 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004413 .type = ALC_FIXUP_VERBS,
4414 .v.verbs = (const struct hda_verb[]) {
4415 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4416 {}
4417 }
4418 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004419 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004420 .type = ALC_FIXUP_SKU,
4421 .v.sku = ALC_FIXUP_SKU_IGNORE,
4422 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004423 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004424 .type = ALC_FIXUP_PINS,
4425 .v.pins = (const struct alc_pincfg[]) {
4426 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4427 { }
4428 }
4429 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004430 [ALC889_FIXUP_VAIO_TT] = {
4431 .type = ALC_FIXUP_PINS,
4432 .v.pins = (const struct alc_pincfg[]) {
4433 { 0x17, 0x90170111 }, /* hidden surround speaker */
4434 { }
4435 }
4436 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004437 [ALC888_FIXUP_EEE1601] = {
4438 .type = ALC_FIXUP_VERBS,
4439 .v.verbs = (const struct hda_verb[]) {
4440 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4441 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4442 { }
4443 }
Takashi Iwai177943a2011-11-09 12:55:18 +01004444 },
4445 [ALC882_FIXUP_EAPD] = {
4446 .type = ALC_FIXUP_VERBS,
4447 .v.verbs = (const struct hda_verb[]) {
4448 /* change to EAPD mode */
4449 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4450 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4451 { }
4452 }
4453 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004454 [ALC883_FIXUP_EAPD] = {
4455 .type = ALC_FIXUP_VERBS,
4456 .v.verbs = (const struct hda_verb[]) {
4457 /* change to EAPD mode */
4458 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4459 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4460 { }
4461 }
4462 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004463 [ALC883_FIXUP_ACER_EAPD] = {
4464 .type = ALC_FIXUP_VERBS,
4465 .v.verbs = (const struct hda_verb[]) {
4466 /* eanable EAPD on Acer laptops */
4467 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4468 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4469 { }
4470 }
4471 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004472 [ALC882_FIXUP_GPIO3] = {
4473 .type = ALC_FIXUP_VERBS,
4474 .v.verbs = alc_gpio3_init_verbs,
4475 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004476 [ALC882_FIXUP_ASUS_W2JC] = {
4477 .type = ALC_FIXUP_VERBS,
4478 .v.verbs = alc_gpio1_init_verbs,
4479 .chained = true,
4480 .chain_id = ALC882_FIXUP_EAPD,
4481 },
4482 [ALC889_FIXUP_COEF] = {
4483 .type = ALC_FIXUP_FUNC,
4484 .v.func = alc889_fixup_coef,
4485 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004486 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4487 .type = ALC_FIXUP_PINS,
4488 .v.pins = (const struct alc_pincfg[]) {
4489 { 0x16, 0x99130111 }, /* CLFE speaker */
4490 { 0x17, 0x99130112 }, /* surround speaker */
4491 { }
4492 }
4493 },
4494 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4495 .type = ALC_FIXUP_PINS,
4496 .v.pins = (const struct alc_pincfg[]) {
4497 { 0x16, 0x99130111 }, /* CLFE speaker */
4498 { 0x1b, 0x99130112 }, /* surround speaker */
4499 { }
4500 },
4501 .chained = true,
4502 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4503 },
4504 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4505 /* additional init verbs for Acer Aspire 8930G */
4506 .type = ALC_FIXUP_VERBS,
4507 .v.verbs = (const struct hda_verb[]) {
4508 /* Enable all DACs */
4509 /* DAC DISABLE/MUTE 1? */
4510 /* setting bits 1-5 disables DAC nids 0x02-0x06
4511 * apparently. Init=0x38 */
4512 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4513 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4514 /* DAC DISABLE/MUTE 2? */
4515 /* some bit here disables the other DACs.
4516 * Init=0x4900 */
4517 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4518 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4519 /* DMIC fix
4520 * This laptop has a stereo digital microphone.
4521 * The mics are only 1cm apart which makes the stereo
4522 * useless. However, either the mic or the ALC889
4523 * makes the signal become a difference/sum signal
4524 * instead of standard stereo, which is annoying.
4525 * So instead we flip this bit which makes the
4526 * codec replicate the sum signal to both channels,
4527 * turning it into a normal mono mic.
4528 */
4529 /* DMIC_CONTROL? Init value = 0x0001 */
4530 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4531 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4532 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4533 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4534 { }
4535 }
4536 },
Takashi Iwai56710872011-11-14 17:42:11 +01004537 [ALC885_FIXUP_MACPRO_GPIO] = {
4538 .type = ALC_FIXUP_FUNC,
4539 .v.func = alc885_fixup_macpro_gpio,
4540 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004541};
4542
4543static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004544 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4545 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4546 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4547 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4548 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4549 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004550 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4551 ALC882_FIXUP_ACER_ASPIRE_4930G),
4552 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4553 ALC882_FIXUP_ACER_ASPIRE_4930G),
4554 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4555 ALC882_FIXUP_ACER_ASPIRE_8930G),
4556 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4557 ALC882_FIXUP_ACER_ASPIRE_8930G),
4558 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4559 ALC882_FIXUP_ACER_ASPIRE_4930G),
4560 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4561 ALC882_FIXUP_ACER_ASPIRE_4930G),
4562 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4563 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004564 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004565 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01004566 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004567 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004568 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004569 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004570 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01004571
4572 /* All Apple entries are in codec SSIDs */
4573 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4574 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4575 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4576 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4577 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4578
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004579 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004580 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004581 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004582 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4583 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004584 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004585 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004586 {}
4587};
4588
4589/*
4590 * BIOS auto configuration
4591 */
4592/* almost identical with ALC880 parser... */
4593static int alc882_parse_auto_config(struct hda_codec *codec)
4594{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004595 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004596 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4597 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004598}
4599
Takashi Iwai1d045db2011-07-07 18:23:21 +02004600/*
4601 */
4602#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4603#include "alc882_quirks.c"
4604#endif
4605
4606static int patch_alc882(struct hda_codec *codec)
4607{
4608 struct alc_spec *spec;
4609 int err, board_config;
4610
4611 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4612 if (spec == NULL)
4613 return -ENOMEM;
4614
4615 codec->spec = spec;
4616
4617 spec->mixer_nid = 0x0b;
4618
4619 switch (codec->vendor_id) {
4620 case 0x10ec0882:
4621 case 0x10ec0885:
4622 break;
4623 default:
4624 /* ALC883 and variants */
4625 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4626 break;
4627 }
4628
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004629 err = alc_codec_rename_from_preset(codec);
4630 if (err < 0)
4631 goto error;
4632
Takashi Iwaib2539692011-11-14 17:32:17 +01004633 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4634 alc882_models, NULL);
4635 if (board_config < 0)
4636 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004637 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4638
4639 if (board_config < 0) {
4640 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4641 codec->chip_name);
4642 board_config = ALC_MODEL_AUTO;
4643 }
4644
4645 if (board_config == ALC_MODEL_AUTO) {
4646 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4647 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4648 }
4649
4650 alc_auto_parse_customize_define(codec);
4651
4652 if (board_config == ALC_MODEL_AUTO) {
4653 /* automatic parse from the BIOS config */
4654 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004655 if (err < 0)
4656 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004657 }
4658
Takashi Iwai1d045db2011-07-07 18:23:21 +02004659 if (board_config != ALC_MODEL_AUTO)
4660 setup_preset(codec, &alc882_presets[board_config]);
4661
Takashi Iwai60a6a842011-07-27 14:01:24 +02004662 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004663 alc_auto_fill_adc_caps(codec);
4664 alc_rebuild_imux_for_auto_mic(codec);
4665 alc_remove_invalid_adc_nids(codec);
4666 }
4667
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004668 if (!spec->no_analog && !spec->cap_mixer)
4669 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004670
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004671 if (!spec->no_analog && has_cdefine_beep(codec)) {
4672 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004673 if (err < 0)
4674 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004675 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004676 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004677
4678 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4679
4680 spec->vmaster_nid = 0x0c;
4681
4682 codec->patch_ops = alc_patch_ops;
4683 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004684 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004685
4686 alc_init_jacks(codec);
4687#ifdef CONFIG_SND_HDA_POWER_SAVE
4688 if (!spec->loopback.amplist)
4689 spec->loopback.amplist = alc882_loopbacks;
4690#endif
4691
4692 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004693
4694 error:
4695 alc_free(codec);
4696 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004697}
4698
4699
4700/*
4701 * ALC262 support
4702 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004703static int alc262_parse_auto_config(struct hda_codec *codec)
4704{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004705 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004706 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4707 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004708}
4709
4710/*
4711 * Pin config fixes
4712 */
4713enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004714 ALC262_FIXUP_FSC_H270,
4715 ALC262_FIXUP_HP_Z200,
4716 ALC262_FIXUP_TYAN,
Takashi Iwai12837c92011-11-07 12:45:24 +01004717 ALC262_FIXUP_TOSHIBA_RX1,
Takashi Iwaic4701502011-11-07 14:20:07 +01004718 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004719 ALC262_FIXUP_BENQ,
4720 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004721};
4722
4723static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004724 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004725 .type = ALC_FIXUP_PINS,
4726 .v.pins = (const struct alc_pincfg[]) {
4727 { 0x14, 0x99130110 }, /* speaker */
4728 { 0x15, 0x0221142f }, /* front HP */
4729 { 0x1b, 0x0121141f }, /* rear HP */
4730 { }
4731 }
4732 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004733 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004734 .type = ALC_FIXUP_PINS,
4735 .v.pins = (const struct alc_pincfg[]) {
4736 { 0x16, 0x99130120 }, /* internal speaker */
4737 { }
4738 }
4739 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004740 [ALC262_FIXUP_TYAN] = {
4741 .type = ALC_FIXUP_PINS,
4742 .v.pins = (const struct alc_pincfg[]) {
4743 { 0x14, 0x1993e1f0 }, /* int AUX */
4744 { }
4745 }
4746 },
Takashi Iwai12837c92011-11-07 12:45:24 +01004747 [ALC262_FIXUP_TOSHIBA_RX1] = {
4748 .type = ALC_FIXUP_PINS,
4749 .v.pins = (const struct alc_pincfg[]) {
4750 { 0x14, 0x90170110 }, /* speaker */
4751 { 0x15, 0x0421101f }, /* HP */
4752 { 0x1a, 0x40f000f0 }, /* N/A */
4753 { 0x1b, 0x40f000f0 }, /* N/A */
4754 { 0x1e, 0x40f000f0 }, /* N/A */
4755 }
4756 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004757 [ALC262_FIXUP_LENOVO_3000] = {
4758 .type = ALC_FIXUP_VERBS,
4759 .v.verbs = (const struct hda_verb[]) {
4760 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004761 {}
4762 },
4763 .chained = true,
4764 .chain_id = ALC262_FIXUP_BENQ,
4765 },
4766 [ALC262_FIXUP_BENQ] = {
4767 .type = ALC_FIXUP_VERBS,
4768 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004769 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4770 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4771 {}
4772 }
4773 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004774 [ALC262_FIXUP_BENQ_T31] = {
4775 .type = ALC_FIXUP_VERBS,
4776 .v.verbs = (const struct hda_verb[]) {
4777 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4778 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4779 {}
4780 }
4781 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004782};
4783
4784static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004785 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004786 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4787 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004788 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
Takashi Iwai12837c92011-11-07 12:45:24 +01004789 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4790 ALC262_FIXUP_TOSHIBA_RX1),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004791 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004792 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004793 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4794 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004795 {}
4796};
4797
4798
4799#ifdef CONFIG_SND_HDA_POWER_SAVE
4800#define alc262_loopbacks alc880_loopbacks
4801#endif
4802
Takashi Iwai1d045db2011-07-07 18:23:21 +02004803/*
4804 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004805static int patch_alc262(struct hda_codec *codec)
4806{
4807 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004808 int err;
4809
4810 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4811 if (spec == NULL)
4812 return -ENOMEM;
4813
4814 codec->spec = spec;
4815
4816 spec->mixer_nid = 0x0b;
4817
4818#if 0
4819 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4820 * under-run
4821 */
4822 {
4823 int tmp;
4824 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4825 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4826 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4827 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4828 }
4829#endif
4830 alc_auto_parse_customize_define(codec);
4831
4832 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4833
Takashi Iwai42399f72011-11-07 17:18:44 +01004834 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4835 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004836
Takashi Iwai42399f72011-11-07 17:18:44 +01004837 /* automatic parse from the BIOS config */
4838 err = alc262_parse_auto_config(codec);
4839 if (err < 0)
4840 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004841
Takashi Iwai60a6a842011-07-27 14:01:24 +02004842 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004843 alc_auto_fill_adc_caps(codec);
4844 alc_rebuild_imux_for_auto_mic(codec);
4845 alc_remove_invalid_adc_nids(codec);
4846 }
4847
4848 if (!spec->no_analog && !spec->cap_mixer)
4849 set_capture_mixer(codec);
4850
Takashi Iwai1d045db2011-07-07 18:23:21 +02004851 if (!spec->no_analog && has_cdefine_beep(codec)) {
4852 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004853 if (err < 0)
4854 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004855 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004856 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004857
4858 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4859
4860 spec->vmaster_nid = 0x0c;
4861
4862 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004863 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004864 spec->shutup = alc_eapd_shutup;
4865
4866 alc_init_jacks(codec);
4867#ifdef CONFIG_SND_HDA_POWER_SAVE
4868 if (!spec->loopback.amplist)
4869 spec->loopback.amplist = alc262_loopbacks;
4870#endif
4871
4872 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004873
4874 error:
4875 alc_free(codec);
4876 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004877}
4878
4879/*
4880 * ALC268
4881 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004882/* bind Beep switches of both NID 0x0f and 0x10 */
4883static const struct hda_bind_ctls alc268_bind_beep_sw = {
4884 .ops = &snd_hda_bind_sw,
4885 .values = {
4886 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4887 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4888 0
4889 },
4890};
4891
4892static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4893 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4894 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4895 { }
4896};
4897
4898/* set PCBEEP vol = 0, mute connections */
4899static const struct hda_verb alc268_beep_init_verbs[] = {
4900 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4901 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4902 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4903 { }
4904};
4905
4906/*
4907 * BIOS auto configuration
4908 */
4909static int alc268_parse_auto_config(struct hda_codec *codec)
4910{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004911 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004912 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004913 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4914 if (err > 0) {
4915 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4916 add_mixer(spec, alc268_beep_mixer);
4917 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004918 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004919 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004920 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004921}
4922
Takashi Iwai1d045db2011-07-07 18:23:21 +02004923/*
4924 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004925static int patch_alc268(struct hda_codec *codec)
4926{
4927 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004928 int i, has_beep, err;
4929
4930 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4931 if (spec == NULL)
4932 return -ENOMEM;
4933
4934 codec->spec = spec;
4935
4936 /* ALC268 has no aa-loopback mixer */
4937
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004938 /* automatic parse from the BIOS config */
4939 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004940 if (err < 0)
4941 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004942
Takashi Iwai1d045db2011-07-07 18:23:21 +02004943 has_beep = 0;
4944 for (i = 0; i < spec->num_mixers; i++) {
4945 if (spec->mixers[i] == alc268_beep_mixer) {
4946 has_beep = 1;
4947 break;
4948 }
4949 }
4950
4951 if (has_beep) {
4952 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004953 if (err < 0)
4954 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004955 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4956 /* override the amp caps for beep generator */
4957 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4958 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4959 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4960 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4961 (0 << AC_AMPCAP_MUTE_SHIFT));
4962 }
4963
Takashi Iwai60a6a842011-07-27 14:01:24 +02004964 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004965 alc_auto_fill_adc_caps(codec);
4966 alc_rebuild_imux_for_auto_mic(codec);
4967 alc_remove_invalid_adc_nids(codec);
4968 }
4969
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004970 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004971 set_capture_mixer(codec);
4972
4973 spec->vmaster_nid = 0x02;
4974
4975 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004976 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004977 spec->shutup = alc_eapd_shutup;
4978
4979 alc_init_jacks(codec);
4980
4981 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004982
4983 error:
4984 alc_free(codec);
4985 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004986}
4987
4988/*
4989 * ALC269
4990 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004991#ifdef CONFIG_SND_HDA_POWER_SAVE
4992#define alc269_loopbacks alc880_loopbacks
4993#endif
4994
4995static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
4996 .substreams = 1,
4997 .channels_min = 2,
4998 .channels_max = 8,
4999 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5000 /* NID is set in alc_build_pcms */
5001 .ops = {
5002 .open = alc_playback_pcm_open,
5003 .prepare = alc_playback_pcm_prepare,
5004 .cleanup = alc_playback_pcm_cleanup
5005 },
5006};
5007
5008static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5009 .substreams = 1,
5010 .channels_min = 2,
5011 .channels_max = 2,
5012 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5013 /* NID is set in alc_build_pcms */
5014};
5015
5016#ifdef CONFIG_SND_HDA_POWER_SAVE
5017static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5018{
5019 switch (codec->subsystem_id) {
5020 case 0x103c1586:
5021 return 1;
5022 }
5023 return 0;
5024}
5025
5026static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5027{
5028 /* update mute-LED according to the speaker mute state */
5029 if (nid == 0x01 || nid == 0x14) {
5030 int pinval;
5031 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5032 HDA_AMP_MUTE)
5033 pinval = 0x24;
5034 else
5035 pinval = 0x20;
5036 /* mic2 vref pin is used for mute LED control */
5037 snd_hda_codec_update_cache(codec, 0x19, 0,
5038 AC_VERB_SET_PIN_WIDGET_CONTROL,
5039 pinval);
5040 }
5041 return alc_check_power_status(codec, nid);
5042}
5043#endif /* CONFIG_SND_HDA_POWER_SAVE */
5044
5045/* different alc269-variants */
5046enum {
5047 ALC269_TYPE_ALC269VA,
5048 ALC269_TYPE_ALC269VB,
5049 ALC269_TYPE_ALC269VC,
5050};
5051
5052/*
5053 * BIOS auto configuration
5054 */
5055static int alc269_parse_auto_config(struct hda_codec *codec)
5056{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005057 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005058 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5059 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5060 struct alc_spec *spec = codec->spec;
5061 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5062 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005063
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005064 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005065}
5066
Takashi Iwai1d045db2011-07-07 18:23:21 +02005067static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5068{
5069 int val = alc_read_coef_idx(codec, 0x04);
5070 if (power_up)
5071 val |= 1 << 11;
5072 else
5073 val &= ~(1 << 11);
5074 alc_write_coef_idx(codec, 0x04, val);
5075}
5076
5077static void alc269_shutup(struct hda_codec *codec)
5078{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005079 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005080 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005081 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005082 alc269_toggle_power_output(codec, 0);
5083 msleep(150);
5084 }
5085}
5086
Takashi Iwai2a439522011-07-26 09:52:50 +02005087#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005088static int alc269_resume(struct hda_codec *codec)
5089{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005090 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005091 alc269_toggle_power_output(codec, 0);
5092 msleep(150);
5093 }
5094
5095 codec->patch_ops.init(codec);
5096
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005097 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005098 alc269_toggle_power_output(codec, 1);
5099 msleep(200);
5100 }
5101
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005102 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005103 alc269_toggle_power_output(codec, 1);
5104
5105 snd_hda_codec_resume_amp(codec);
5106 snd_hda_codec_resume_cache(codec);
5107 hda_call_check_power_status(codec, 0x01);
5108 return 0;
5109}
Takashi Iwai2a439522011-07-26 09:52:50 +02005110#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005111
5112static void alc269_fixup_hweq(struct hda_codec *codec,
5113 const struct alc_fixup *fix, int action)
5114{
5115 int coef;
5116
5117 if (action != ALC_FIXUP_ACT_INIT)
5118 return;
5119 coef = alc_read_coef_idx(codec, 0x1e);
5120 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5121}
5122
5123static void alc271_fixup_dmic(struct hda_codec *codec,
5124 const struct alc_fixup *fix, int action)
5125{
5126 static const struct hda_verb verbs[] = {
5127 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5128 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5129 {}
5130 };
5131 unsigned int cfg;
5132
5133 if (strcmp(codec->chip_name, "ALC271X"))
5134 return;
5135 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5136 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5137 snd_hda_sequence_write(codec, verbs);
5138}
5139
Takashi Iwai017f2a12011-07-09 14:42:25 +02005140static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5141 const struct alc_fixup *fix, int action)
5142{
5143 struct alc_spec *spec = codec->spec;
5144
5145 if (action != ALC_FIXUP_ACT_PROBE)
5146 return;
5147
5148 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5149 * fix the sample rate of analog I/O to 44.1kHz
5150 */
5151 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5152 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5153}
5154
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005155static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5156 const struct alc_fixup *fix, int action)
5157{
5158 int coef;
5159
5160 if (action != ALC_FIXUP_ACT_INIT)
5161 return;
5162 /* The digital-mic unit sends PDM (differential signal) instead of
5163 * the standard PCM, thus you can't record a valid mono stream as is.
5164 * Below is a workaround specific to ALC269 to control the dmic
5165 * signal source as mono.
5166 */
5167 coef = alc_read_coef_idx(codec, 0x07);
5168 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5169}
5170
Takashi Iwai24519912011-08-16 15:08:49 +02005171static void alc269_quanta_automute(struct hda_codec *codec)
5172{
David Henningsson42cf0d02011-09-20 12:04:56 +02005173 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005174
5175 snd_hda_codec_write(codec, 0x20, 0,
5176 AC_VERB_SET_COEF_INDEX, 0x0c);
5177 snd_hda_codec_write(codec, 0x20, 0,
5178 AC_VERB_SET_PROC_COEF, 0x680);
5179
5180 snd_hda_codec_write(codec, 0x20, 0,
5181 AC_VERB_SET_COEF_INDEX, 0x0c);
5182 snd_hda_codec_write(codec, 0x20, 0,
5183 AC_VERB_SET_PROC_COEF, 0x480);
5184}
5185
5186static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5187 const struct alc_fixup *fix, int action)
5188{
5189 struct alc_spec *spec = codec->spec;
5190 if (action != ALC_FIXUP_ACT_PROBE)
5191 return;
5192 spec->automute_hook = alc269_quanta_automute;
5193}
5194
Takashi Iwai1d045db2011-07-07 18:23:21 +02005195enum {
5196 ALC269_FIXUP_SONY_VAIO,
5197 ALC275_FIXUP_SONY_VAIO_GPIO2,
5198 ALC269_FIXUP_DELL_M101Z,
5199 ALC269_FIXUP_SKU_IGNORE,
5200 ALC269_FIXUP_ASUS_G73JW,
5201 ALC269_FIXUP_LENOVO_EAPD,
5202 ALC275_FIXUP_SONY_HWEQ,
5203 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005204 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005205 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005206 ALC269_FIXUP_QUANTA_MUTE,
5207 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005208 ALC269_FIXUP_AMIC,
5209 ALC269_FIXUP_DMIC,
5210 ALC269VB_FIXUP_AMIC,
5211 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005212};
5213
5214static const struct alc_fixup alc269_fixups[] = {
5215 [ALC269_FIXUP_SONY_VAIO] = {
5216 .type = ALC_FIXUP_VERBS,
5217 .v.verbs = (const struct hda_verb[]) {
5218 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5219 {}
5220 }
5221 },
5222 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5223 .type = ALC_FIXUP_VERBS,
5224 .v.verbs = (const struct hda_verb[]) {
5225 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5226 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5227 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5228 { }
5229 },
5230 .chained = true,
5231 .chain_id = ALC269_FIXUP_SONY_VAIO
5232 },
5233 [ALC269_FIXUP_DELL_M101Z] = {
5234 .type = ALC_FIXUP_VERBS,
5235 .v.verbs = (const struct hda_verb[]) {
5236 /* Enables internal speaker */
5237 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5238 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5239 {}
5240 }
5241 },
5242 [ALC269_FIXUP_SKU_IGNORE] = {
5243 .type = ALC_FIXUP_SKU,
5244 .v.sku = ALC_FIXUP_SKU_IGNORE,
5245 },
5246 [ALC269_FIXUP_ASUS_G73JW] = {
5247 .type = ALC_FIXUP_PINS,
5248 .v.pins = (const struct alc_pincfg[]) {
5249 { 0x17, 0x99130111 }, /* subwoofer */
5250 { }
5251 }
5252 },
5253 [ALC269_FIXUP_LENOVO_EAPD] = {
5254 .type = ALC_FIXUP_VERBS,
5255 .v.verbs = (const struct hda_verb[]) {
5256 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5257 {}
5258 }
5259 },
5260 [ALC275_FIXUP_SONY_HWEQ] = {
5261 .type = ALC_FIXUP_FUNC,
5262 .v.func = alc269_fixup_hweq,
5263 .chained = true,
5264 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5265 },
5266 [ALC271_FIXUP_DMIC] = {
5267 .type = ALC_FIXUP_FUNC,
5268 .v.func = alc271_fixup_dmic,
5269 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005270 [ALC269_FIXUP_PCM_44K] = {
5271 .type = ALC_FIXUP_FUNC,
5272 .v.func = alc269_fixup_pcm_44k,
5273 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005274 [ALC269_FIXUP_STEREO_DMIC] = {
5275 .type = ALC_FIXUP_FUNC,
5276 .v.func = alc269_fixup_stereo_dmic,
5277 },
Takashi Iwai24519912011-08-16 15:08:49 +02005278 [ALC269_FIXUP_QUANTA_MUTE] = {
5279 .type = ALC_FIXUP_FUNC,
5280 .v.func = alc269_fixup_quanta_mute,
5281 },
5282 [ALC269_FIXUP_LIFEBOOK] = {
5283 .type = ALC_FIXUP_PINS,
5284 .v.pins = (const struct alc_pincfg[]) {
5285 { 0x1a, 0x2101103f }, /* dock line-out */
5286 { 0x1b, 0x23a11040 }, /* dock mic-in */
5287 { }
5288 },
5289 .chained = true,
5290 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5291 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005292 [ALC269_FIXUP_AMIC] = {
5293 .type = ALC_FIXUP_PINS,
5294 .v.pins = (const struct alc_pincfg[]) {
5295 { 0x14, 0x99130110 }, /* speaker */
5296 { 0x15, 0x0121401f }, /* HP out */
5297 { 0x18, 0x01a19c20 }, /* mic */
5298 { 0x19, 0x99a3092f }, /* int-mic */
5299 { }
5300 },
5301 },
5302 [ALC269_FIXUP_DMIC] = {
5303 .type = ALC_FIXUP_PINS,
5304 .v.pins = (const struct alc_pincfg[]) {
5305 { 0x12, 0x99a3092f }, /* int-mic */
5306 { 0x14, 0x99130110 }, /* speaker */
5307 { 0x15, 0x0121401f }, /* HP out */
5308 { 0x18, 0x01a19c20 }, /* mic */
5309 { }
5310 },
5311 },
5312 [ALC269VB_FIXUP_AMIC] = {
5313 .type = ALC_FIXUP_PINS,
5314 .v.pins = (const struct alc_pincfg[]) {
5315 { 0x14, 0x99130110 }, /* speaker */
5316 { 0x18, 0x01a19c20 }, /* mic */
5317 { 0x19, 0x99a3092f }, /* int-mic */
5318 { 0x21, 0x0121401f }, /* HP out */
5319 { }
5320 },
5321 },
5322 [ALC269_FIXUP_DMIC] = {
5323 .type = ALC_FIXUP_PINS,
5324 .v.pins = (const struct alc_pincfg[]) {
5325 { 0x12, 0x99a3092f }, /* int-mic */
5326 { 0x14, 0x99130110 }, /* speaker */
5327 { 0x18, 0x01a19c20 }, /* mic */
5328 { 0x21, 0x0121401f }, /* HP out */
5329 { }
5330 },
5331 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005332};
5333
5334static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005335 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005336 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5337 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5338 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5339 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5340 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005341 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5342 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5343 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5344 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5345 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5346 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005347 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005348 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5349 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5350 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5351 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5352 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005353 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005354 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005355 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005356
5357#if 1
5358 /* Below is a quirk table taken from the old code.
5359 * Basically the device should work as is without the fixup table.
5360 * If BIOS doesn't give a proper info, enable the corresponding
5361 * fixup entry.
5362 */
5363 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5364 ALC269_FIXUP_AMIC),
5365 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5366 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
5367 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5368 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5369 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5370 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5371 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5372 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5373 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5374 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5375 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5376 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5377 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5378 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5379 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5380 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5381 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5382 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5383 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5384 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5385 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5386 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5387 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5388 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5389 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5390 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5391 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5392 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5393 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5394 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5395 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5396 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5397 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5398 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5399 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5400 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5401 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5402 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5403 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5404 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5405#endif
5406 {}
5407};
5408
5409static const struct alc_model_fixup alc269_fixup_models[] = {
5410 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5411 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005412 {}
5413};
5414
5415
5416static int alc269_fill_coef(struct hda_codec *codec)
5417{
5418 int val;
5419
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005420 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005421 alc_write_coef_idx(codec, 0xf, 0x960b);
5422 alc_write_coef_idx(codec, 0xe, 0x8817);
5423 }
5424
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005425 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005426 alc_write_coef_idx(codec, 0xf, 0x960b);
5427 alc_write_coef_idx(codec, 0xe, 0x8814);
5428 }
5429
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005430 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005431 val = alc_read_coef_idx(codec, 0x04);
5432 /* Power up output pin */
5433 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5434 }
5435
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005436 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005437 val = alc_read_coef_idx(codec, 0xd);
5438 if ((val & 0x0c00) >> 10 != 0x1) {
5439 /* Capless ramp up clock control */
5440 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5441 }
5442 val = alc_read_coef_idx(codec, 0x17);
5443 if ((val & 0x01c0) >> 6 != 0x4) {
5444 /* Class D power on reset */
5445 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5446 }
5447 }
5448
5449 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5450 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5451
5452 val = alc_read_coef_idx(codec, 0x4); /* HP */
5453 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5454
5455 return 0;
5456}
5457
5458/*
5459 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005460static int patch_alc269(struct hda_codec *codec)
5461{
5462 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005463 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005464
5465 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5466 if (spec == NULL)
5467 return -ENOMEM;
5468
5469 codec->spec = spec;
5470
5471 spec->mixer_nid = 0x0b;
5472
5473 alc_auto_parse_customize_define(codec);
5474
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005475 err = alc_codec_rename_from_preset(codec);
5476 if (err < 0)
5477 goto error;
5478
Takashi Iwai1d045db2011-07-07 18:23:21 +02005479 if (codec->vendor_id == 0x10ec0269) {
5480 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005481 switch (alc_get_coef0(codec) & 0x00f0) {
5482 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005483 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005484 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005485 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005486 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005487 break;
5488 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005489 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5490 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005491 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005492 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005493 break;
5494 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005495 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005496 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005497 if (err < 0)
5498 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499 alc269_fill_coef(codec);
5500 }
5501
Takashi Iwaia4297b52011-08-23 18:40:12 +02005502 alc_pick_fixup(codec, alc269_fixup_models,
5503 alc269_fixup_tbl, alc269_fixups);
5504 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505
Takashi Iwaia4297b52011-08-23 18:40:12 +02005506 /* automatic parse from the BIOS config */
5507 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005508 if (err < 0)
5509 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005510
Takashi Iwai60a6a842011-07-27 14:01:24 +02005511 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512 alc_auto_fill_adc_caps(codec);
5513 alc_rebuild_imux_for_auto_mic(codec);
5514 alc_remove_invalid_adc_nids(codec);
5515 }
5516
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005517 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005518 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005519
5520 if (!spec->no_analog && has_cdefine_beep(codec)) {
5521 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005522 if (err < 0)
5523 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005524 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005525 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005526
5527 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5528
5529 spec->vmaster_nid = 0x02;
5530
5531 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005532#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005533 codec->patch_ops.resume = alc269_resume;
5534#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005535 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005536 spec->shutup = alc269_shutup;
5537
5538 alc_init_jacks(codec);
5539#ifdef CONFIG_SND_HDA_POWER_SAVE
5540 if (!spec->loopback.amplist)
5541 spec->loopback.amplist = alc269_loopbacks;
5542 if (alc269_mic2_for_mute_led(codec))
5543 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5544#endif
5545
5546 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005547
5548 error:
5549 alc_free(codec);
5550 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005551}
5552
5553/*
5554 * ALC861
5555 */
5556
Takashi Iwai1d045db2011-07-07 18:23:21 +02005557static int alc861_parse_auto_config(struct hda_codec *codec)
5558{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005559 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005560 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5561 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005562}
5563
Takashi Iwai1d045db2011-07-07 18:23:21 +02005564#ifdef CONFIG_SND_HDA_POWER_SAVE
5565static const struct hda_amp_list alc861_loopbacks[] = {
5566 { 0x15, HDA_INPUT, 0 },
5567 { 0x15, HDA_INPUT, 1 },
5568 { 0x15, HDA_INPUT, 2 },
5569 { 0x15, HDA_INPUT, 3 },
5570 { } /* end */
5571};
5572#endif
5573
5574
5575/* Pin config fixes */
5576enum {
5577 PINFIX_FSC_AMILO_PI1505,
5578};
5579
5580static const struct alc_fixup alc861_fixups[] = {
5581 [PINFIX_FSC_AMILO_PI1505] = {
5582 .type = ALC_FIXUP_PINS,
5583 .v.pins = (const struct alc_pincfg[]) {
5584 { 0x0b, 0x0221101f }, /* HP */
5585 { 0x0f, 0x90170310 }, /* speaker */
5586 { }
5587 }
5588 },
5589};
5590
5591static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5592 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5593 {}
5594};
5595
5596/*
5597 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005598static int patch_alc861(struct hda_codec *codec)
5599{
5600 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005601 int err;
5602
5603 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5604 if (spec == NULL)
5605 return -ENOMEM;
5606
5607 codec->spec = spec;
5608
5609 spec->mixer_nid = 0x15;
5610
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005611 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5612 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005613
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005614 /* automatic parse from the BIOS config */
5615 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005616 if (err < 0)
5617 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005618
Takashi Iwai60a6a842011-07-27 14:01:24 +02005619 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005620 alc_auto_fill_adc_caps(codec);
5621 alc_rebuild_imux_for_auto_mic(codec);
5622 alc_remove_invalid_adc_nids(codec);
5623 }
5624
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005625 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005626 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005627
5628 if (!spec->no_analog) {
5629 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005630 if (err < 0)
5631 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005632 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5633 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005634
5635 spec->vmaster_nid = 0x03;
5636
5637 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5638
5639 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005640 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005641#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005642 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643 if (!spec->loopback.amplist)
5644 spec->loopback.amplist = alc861_loopbacks;
5645#endif
5646
5647 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005648
5649 error:
5650 alc_free(codec);
5651 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005652}
5653
5654/*
5655 * ALC861-VD support
5656 *
5657 * Based on ALC882
5658 *
5659 * In addition, an independent DAC
5660 */
5661#ifdef CONFIG_SND_HDA_POWER_SAVE
5662#define alc861vd_loopbacks alc880_loopbacks
5663#endif
5664
Takashi Iwai1d045db2011-07-07 18:23:21 +02005665static int alc861vd_parse_auto_config(struct hda_codec *codec)
5666{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005667 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005668 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5669 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005670}
5671
Takashi Iwai1d045db2011-07-07 18:23:21 +02005672enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005673 ALC660VD_FIX_ASUS_GPIO1,
5674 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005675};
5676
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005677/* exclude VREF80 */
5678static void alc861vd_fixup_dallas(struct hda_codec *codec,
5679 const struct alc_fixup *fix, int action)
5680{
5681 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5682 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5683 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5684 }
5685}
5686
Takashi Iwai1d045db2011-07-07 18:23:21 +02005687static const struct alc_fixup alc861vd_fixups[] = {
5688 [ALC660VD_FIX_ASUS_GPIO1] = {
5689 .type = ALC_FIXUP_VERBS,
5690 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005691 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005692 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5693 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5694 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5695 { }
5696 }
5697 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005698 [ALC861VD_FIX_DALLAS] = {
5699 .type = ALC_FIXUP_FUNC,
5700 .v.func = alc861vd_fixup_dallas,
5701 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005702};
5703
5704static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005705 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005706 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005707 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005708 {}
5709};
5710
5711static const struct hda_verb alc660vd_eapd_verbs[] = {
5712 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5713 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5714 { }
5715};
5716
5717/*
5718 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005719static int patch_alc861vd(struct hda_codec *codec)
5720{
5721 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005722 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005723
5724 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5725 if (spec == NULL)
5726 return -ENOMEM;
5727
5728 codec->spec = spec;
5729
5730 spec->mixer_nid = 0x0b;
5731
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005732 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5733 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005734
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005735 /* automatic parse from the BIOS config */
5736 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005737 if (err < 0)
5738 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005739
Takashi Iwai1d045db2011-07-07 18:23:21 +02005740 if (codec->vendor_id == 0x10ec0660) {
5741 /* always turn on EAPD */
5742 add_verb(spec, alc660vd_eapd_verbs);
5743 }
5744
Takashi Iwai60a6a842011-07-27 14:01:24 +02005745 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005746 alc_auto_fill_adc_caps(codec);
5747 alc_rebuild_imux_for_auto_mic(codec);
5748 alc_remove_invalid_adc_nids(codec);
5749 }
5750
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005751 if (!spec->no_analog && !spec->cap_mixer)
5752 set_capture_mixer(codec);
5753
5754 if (!spec->no_analog) {
5755 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005756 if (err < 0)
5757 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005758 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5759 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005760
5761 spec->vmaster_nid = 0x02;
5762
5763 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5764
5765 codec->patch_ops = alc_patch_ops;
5766
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005767 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005768 spec->shutup = alc_eapd_shutup;
5769#ifdef CONFIG_SND_HDA_POWER_SAVE
5770 if (!spec->loopback.amplist)
5771 spec->loopback.amplist = alc861vd_loopbacks;
5772#endif
5773
5774 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005775
5776 error:
5777 alc_free(codec);
5778 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005779}
5780
5781/*
5782 * ALC662 support
5783 *
5784 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5785 * configuration. Each pin widget can choose any input DACs and a mixer.
5786 * Each ADC is connected from a mixer of all inputs. This makes possible
5787 * 6-channel independent captures.
5788 *
5789 * In addition, an independent DAC for the multi-playback (not used in this
5790 * driver yet).
5791 */
5792#ifdef CONFIG_SND_HDA_POWER_SAVE
5793#define alc662_loopbacks alc880_loopbacks
5794#endif
5795
5796/*
5797 * BIOS auto configuration
5798 */
5799
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005800static int alc662_parse_auto_config(struct hda_codec *codec)
5801{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005802 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005803 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5804 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5805 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005806
Kailang Yang6227cdc2010-02-25 08:36:52 +01005807 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5808 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005809 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005810 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005811 ssids = alc662_ssids;
5812 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005813}
5814
Todd Broch6be79482010-12-07 16:51:05 -08005815static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005816 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005817{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005818 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005819 return;
Todd Broch6be79482010-12-07 16:51:05 -08005820 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5821 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5822 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5823 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5824 (0 << AC_AMPCAP_MUTE_SHIFT)))
5825 printk(KERN_WARNING
5826 "hda_codec: failed to override amp caps for NID 0x2\n");
5827}
5828
David Henningsson6cb3b702010-09-09 08:51:44 +02005829enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005830 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005831 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005832 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005833 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005834 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005835 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005836 ALC662_FIXUP_ASUS_MODE1,
5837 ALC662_FIXUP_ASUS_MODE2,
5838 ALC662_FIXUP_ASUS_MODE3,
5839 ALC662_FIXUP_ASUS_MODE4,
5840 ALC662_FIXUP_ASUS_MODE5,
5841 ALC662_FIXUP_ASUS_MODE6,
5842 ALC662_FIXUP_ASUS_MODE7,
5843 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005844};
5845
5846static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005847 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005848 .type = ALC_FIXUP_PINS,
5849 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005850 { 0x15, 0x99130112 }, /* subwoofer */
5851 { }
5852 }
5853 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005854 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005855 .type = ALC_FIXUP_PINS,
5856 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005857 { 0x17, 0x99130112 }, /* subwoofer */
5858 { }
5859 }
5860 },
Todd Broch6be79482010-12-07 16:51:05 -08005861 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005862 .type = ALC_FIXUP_FUNC,
5863 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005864 },
5865 [ALC662_FIXUP_CZC_P10T] = {
5866 .type = ALC_FIXUP_VERBS,
5867 .v.verbs = (const struct hda_verb[]) {
5868 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5869 {}
5870 }
5871 },
David Henningsson94024cd2011-04-29 14:10:55 +02005872 [ALC662_FIXUP_SKU_IGNORE] = {
5873 .type = ALC_FIXUP_SKU,
5874 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005875 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005876 [ALC662_FIXUP_HP_RP5800] = {
5877 .type = ALC_FIXUP_PINS,
5878 .v.pins = (const struct alc_pincfg[]) {
5879 { 0x14, 0x0221201f }, /* HP out */
5880 { }
5881 },
5882 .chained = true,
5883 .chain_id = ALC662_FIXUP_SKU_IGNORE
5884 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005885 [ALC662_FIXUP_ASUS_MODE1] = {
5886 .type = ALC_FIXUP_PINS,
5887 .v.pins = (const struct alc_pincfg[]) {
5888 { 0x14, 0x99130110 }, /* speaker */
5889 { 0x18, 0x01a19c20 }, /* mic */
5890 { 0x19, 0x99a3092f }, /* int-mic */
5891 { 0x21, 0x0121401f }, /* HP out */
5892 { }
5893 },
5894 .chained = true,
5895 .chain_id = ALC662_FIXUP_SKU_IGNORE
5896 },
5897 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005898 .type = ALC_FIXUP_PINS,
5899 .v.pins = (const struct alc_pincfg[]) {
5900 { 0x14, 0x99130110 }, /* speaker */
5901 { 0x18, 0x01a19820 }, /* mic */
5902 { 0x19, 0x99a3092f }, /* int-mic */
5903 { 0x1b, 0x0121401f }, /* HP out */
5904 { }
5905 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005906 .chained = true,
5907 .chain_id = ALC662_FIXUP_SKU_IGNORE
5908 },
5909 [ALC662_FIXUP_ASUS_MODE3] = {
5910 .type = ALC_FIXUP_PINS,
5911 .v.pins = (const struct alc_pincfg[]) {
5912 { 0x14, 0x99130110 }, /* speaker */
5913 { 0x15, 0x0121441f }, /* HP */
5914 { 0x18, 0x01a19840 }, /* mic */
5915 { 0x19, 0x99a3094f }, /* int-mic */
5916 { 0x21, 0x01211420 }, /* HP2 */
5917 { }
5918 },
5919 .chained = true,
5920 .chain_id = ALC662_FIXUP_SKU_IGNORE
5921 },
5922 [ALC662_FIXUP_ASUS_MODE4] = {
5923 .type = ALC_FIXUP_PINS,
5924 .v.pins = (const struct alc_pincfg[]) {
5925 { 0x14, 0x99130110 }, /* speaker */
5926 { 0x16, 0x99130111 }, /* speaker */
5927 { 0x18, 0x01a19840 }, /* mic */
5928 { 0x19, 0x99a3094f }, /* int-mic */
5929 { 0x21, 0x0121441f }, /* HP */
5930 { }
5931 },
5932 .chained = true,
5933 .chain_id = ALC662_FIXUP_SKU_IGNORE
5934 },
5935 [ALC662_FIXUP_ASUS_MODE5] = {
5936 .type = ALC_FIXUP_PINS,
5937 .v.pins = (const struct alc_pincfg[]) {
5938 { 0x14, 0x99130110 }, /* speaker */
5939 { 0x15, 0x0121441f }, /* HP */
5940 { 0x16, 0x99130111 }, /* speaker */
5941 { 0x18, 0x01a19840 }, /* mic */
5942 { 0x19, 0x99a3094f }, /* int-mic */
5943 { }
5944 },
5945 .chained = true,
5946 .chain_id = ALC662_FIXUP_SKU_IGNORE
5947 },
5948 [ALC662_FIXUP_ASUS_MODE6] = {
5949 .type = ALC_FIXUP_PINS,
5950 .v.pins = (const struct alc_pincfg[]) {
5951 { 0x14, 0x99130110 }, /* speaker */
5952 { 0x15, 0x01211420 }, /* HP2 */
5953 { 0x18, 0x01a19840 }, /* mic */
5954 { 0x19, 0x99a3094f }, /* int-mic */
5955 { 0x1b, 0x0121441f }, /* HP */
5956 { }
5957 },
5958 .chained = true,
5959 .chain_id = ALC662_FIXUP_SKU_IGNORE
5960 },
5961 [ALC662_FIXUP_ASUS_MODE7] = {
5962 .type = ALC_FIXUP_PINS,
5963 .v.pins = (const struct alc_pincfg[]) {
5964 { 0x14, 0x99130110 }, /* speaker */
5965 { 0x17, 0x99130111 }, /* speaker */
5966 { 0x18, 0x01a19840 }, /* mic */
5967 { 0x19, 0x99a3094f }, /* int-mic */
5968 { 0x1b, 0x01214020 }, /* HP */
5969 { 0x21, 0x0121401f }, /* HP */
5970 { }
5971 },
5972 .chained = true,
5973 .chain_id = ALC662_FIXUP_SKU_IGNORE
5974 },
5975 [ALC662_FIXUP_ASUS_MODE8] = {
5976 .type = ALC_FIXUP_PINS,
5977 .v.pins = (const struct alc_pincfg[]) {
5978 { 0x14, 0x99130110 }, /* speaker */
5979 { 0x12, 0x99a30970 }, /* int-mic */
5980 { 0x15, 0x01214020 }, /* HP */
5981 { 0x17, 0x99130111 }, /* speaker */
5982 { 0x18, 0x01a19840 }, /* mic */
5983 { 0x21, 0x0121401f }, /* HP */
5984 { }
5985 },
5986 .chained = true,
5987 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005988 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005989};
5990
Takashi Iwaia9111322011-05-02 11:30:18 +02005991static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02005992 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01005993 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02005994 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04005995 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005996 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02005997 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05005998 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06005999 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006000 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006001 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006002
6003#if 0
6004 /* Below is a quirk table taken from the old code.
6005 * Basically the device should work as is without the fixup table.
6006 * If BIOS doesn't give a proper info, enable the corresponding
6007 * fixup entry.
6008 */
6009 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6010 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6011 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6012 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6013 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6014 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6015 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6016 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6017 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6018 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6019 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6020 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6021 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6022 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6023 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6024 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6025 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6026 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6027 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6028 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6029 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6030 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6031 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6032 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6033 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6034 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6035 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6036 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6037 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6038 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6039 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6040 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6041 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6042 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6043 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6044 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6045 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6046 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6047 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6048 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6049 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6050 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6051 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6052 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6053 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6054 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6055 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6056 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6057 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6058 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6059#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006060 {}
6061};
6062
Todd Broch6be79482010-12-07 16:51:05 -08006063static const struct alc_model_fixup alc662_fixup_models[] = {
6064 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006065 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6066 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6067 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6068 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6069 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6070 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6071 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6072 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006073 {}
6074};
David Henningsson6cb3b702010-09-09 08:51:44 +02006075
6076
Takashi Iwai1d045db2011-07-07 18:23:21 +02006077/*
6078 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006079static int patch_alc662(struct hda_codec *codec)
6080{
6081 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006082 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006083
6084 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6085 if (!spec)
6086 return -ENOMEM;
6087
6088 codec->spec = spec;
6089
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006090 spec->mixer_nid = 0x0b;
6091
Takashi Iwai53c334a2011-08-23 18:27:14 +02006092 /* handle multiple HPs as is */
6093 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6094
Kailang Yangda00c242010-03-19 11:23:45 +01006095 alc_auto_parse_customize_define(codec);
6096
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006097 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6098
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006099 err = alc_codec_rename_from_preset(codec);
6100 if (err < 0)
6101 goto error;
6102
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006103 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006104 codec->bus->pci->subsystem_vendor == 0x1025 &&
6105 spec->cdefine.platform_type == 1) {
6106 if (alc_codec_rename(codec, "ALC272X") < 0)
6107 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006108 }
Kailang Yang274693f2009-12-03 10:07:50 +01006109
Takashi Iwaib9c51062011-08-24 18:08:07 +02006110 alc_pick_fixup(codec, alc662_fixup_models,
6111 alc662_fixup_tbl, alc662_fixups);
6112 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6113 /* automatic parse from the BIOS config */
6114 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006115 if (err < 0)
6116 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006117
Takashi Iwai60a6a842011-07-27 14:01:24 +02006118 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006119 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006120 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006121 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006122 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006123
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006124 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006125 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006126
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006127 if (!spec->no_analog && has_cdefine_beep(codec)) {
6128 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006129 if (err < 0)
6130 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006131 switch (codec->vendor_id) {
6132 case 0x10ec0662:
6133 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6134 break;
6135 case 0x10ec0272:
6136 case 0x10ec0663:
6137 case 0x10ec0665:
6138 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6139 break;
6140 case 0x10ec0273:
6141 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6142 break;
6143 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006144 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006145 spec->vmaster_nid = 0x02;
6146
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006147 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6148
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006149 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006150 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006151 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006152
Kailang Yangbf1b0222010-10-21 08:49:56 +02006153 alc_init_jacks(codec);
6154
Takashi Iwaicb53c622007-08-10 17:21:45 +02006155#ifdef CONFIG_SND_HDA_POWER_SAVE
6156 if (!spec->loopback.amplist)
6157 spec->loopback.amplist = alc662_loopbacks;
6158#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006159
6160 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006161
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006162 error:
6163 alc_free(codec);
6164 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006165}
6166
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006167/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006168 * ALC680 support
6169 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006170
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006171static int alc680_parse_auto_config(struct hda_codec *codec)
6172{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006173 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006174}
6175
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006176/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006177 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006178static int patch_alc680(struct hda_codec *codec)
6179{
6180 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006181 int err;
6182
6183 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6184 if (spec == NULL)
6185 return -ENOMEM;
6186
6187 codec->spec = spec;
6188
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006189 /* ALC680 has no aa-loopback mixer */
6190
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006191 /* automatic parse from the BIOS config */
6192 err = alc680_parse_auto_config(codec);
6193 if (err < 0) {
6194 alc_free(codec);
6195 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006196 }
6197
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006198 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006199 set_capture_mixer(codec);
6200
6201 spec->vmaster_nid = 0x02;
6202
6203 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006204 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006205
6206 return 0;
6207}
6208
6209/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006210 * patch entries
6211 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006212static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006213 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006215 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006216 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006217 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006218 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006219 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006220 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006221 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006222 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006223 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006224 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006225 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6226 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6227 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006228 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02006229 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006230 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6231 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006232 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6233 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006234 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006235 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006236 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006237 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006238 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006239 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006240 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006241 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006242 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006243 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006244 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006245 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006246 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006247 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02006248 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006249 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006250 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006251 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006252 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006253 {} /* terminator */
6254};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006255
6256MODULE_ALIAS("snd-hda-codec-id:10ec*");
6257
6258MODULE_LICENSE("GPL");
6259MODULE_DESCRIPTION("Realtek HD-audio codec");
6260
6261static struct hda_codec_preset_list realtek_list = {
6262 .preset = snd_hda_preset_realtek,
6263 .owner = THIS_MODULE,
6264};
6265
6266static int __init patch_realtek_init(void)
6267{
6268 return snd_hda_add_codec_preset(&realtek_list);
6269}
6270
6271static void __exit patch_realtek_exit(void)
6272{
6273 snd_hda_delete_codec_preset(&realtek_list);
6274}
6275
6276module_init(patch_realtek_init)
6277module_exit(patch_realtek_exit)