blob: 690f2a2a4595898916febc7c2e3d8b14e2f9904c [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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Takashi Iwai1d045db2011-07-07 18:23:21 +020037/* unsol event tags */
38#define ALC_FRONT_EVENT 0x01
39#define ALC_DCVOL_EVENT 0x02
40#define ALC_HP_EVENT 0x04
41#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020042
Kailang Yangdf694da2005-12-05 19:42:22 +010043/* for GPIO Poll */
44#define GPIO_MASK 0x03
45
Takashi Iwai4a79ba32009-04-22 16:31:35 +020046/* extra amp-initialization sequence types */
47enum {
48 ALC_INIT_NONE,
49 ALC_INIT_DEFAULT,
50 ALC_INIT_GPIO1,
51 ALC_INIT_GPIO2,
52 ALC_INIT_GPIO3,
53};
54
Kailang Yangda00c242010-03-19 11:23:45 +010055struct alc_customize_define {
56 unsigned int sku_cfg;
57 unsigned char port_connectivity;
58 unsigned char check_sum;
59 unsigned char customization;
60 unsigned char external_amp;
61 unsigned int enable_pcbeep:1;
62 unsigned int platform_type:1;
63 unsigned int swap:1;
64 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020065 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010066};
67
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010068struct alc_fixup;
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwaid922b512011-04-28 12:18:53 +020076enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020077 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020080};
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082struct alc_spec {
83 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020084 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020086 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010087 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
Takashi Iwai2d9c6482009-10-13 08:06:55 +020089 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020090 * don't forget NULL
91 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020092 */
93 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Takashi Iwaiaa563af2009-07-31 10:05:11 +020095 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020096 const struct hda_pcm_stream *stream_analog_playback;
97 const struct hda_pcm_stream *stream_analog_capture;
98 const struct hda_pcm_stream *stream_analog_alt_playback;
99 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200101 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200102 const struct hda_pcm_stream *stream_digital_playback;
103 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200106 struct hda_multi_out multiout; /* playback set-up
107 * max_channels, dacs must be set
108 * dig_out_nid and hp_nid are optional
109 */
Takashi Iwai63300792008-01-24 15:31:36 +0100110 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100111 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100112 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 /* capture */
115 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200116 const hda_nid_t *adc_nids;
117 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200118 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200119 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwai527e4d72011-10-27 16:33:27 +0200120 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
121 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Takashi Iwai840b64c2010-07-13 22:49:01 +0200123 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200124 hda_nid_t cur_adc;
125 unsigned int cur_adc_stream_tag;
126 unsigned int cur_adc_format;
127
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200129 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 const struct hda_input_mux *input_mux;
131 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200132 hda_nid_t ext_mic_pin;
133 hda_nid_t dock_mic_pin;
134 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100137 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200139 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200140 int const_channel_count;
141 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100144 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200145
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200146 /* dynamic controls, init_verbs and input_mux */
147 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100148 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200149 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200150 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200151 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai49535502009-06-30 15:28:30 +0200152 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
153 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200154 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
155 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
156 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100157
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100158 /* hooks */
159 void (*init_hook)(struct hda_codec *codec);
160 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100161#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500162 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100163#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200164 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200165 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100166
Takashi Iwai834be882006-03-01 14:16:17 +0100167 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200168 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200169 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200170 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200171 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200172 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200173 unsigned int automute_speaker:1; /* automute speaker outputs */
174 unsigned int automute_lo:1; /* automute LO outputs */
175 unsigned int detect_hp:1; /* Headphone detection enabled */
176 unsigned int detect_lo:1; /* Line-out detection enabled */
177 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
178 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200179
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100180 /* other flags */
181 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200182 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100183 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200184 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200185 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100186 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200187
188 /* auto-mute control */
189 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200190 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200191
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200192 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200193 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100194
Takashi Iwai2134ea42008-01-10 16:53:55 +0100195 /* for virtual master */
196 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200197#ifdef CONFIG_SND_HDA_POWER_SAVE
198 struct hda_loopback_check loopback;
199#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200200
201 /* for PLL fix */
202 hda_nid_t pll_nid;
203 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200204 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100205
206 /* fix-up list */
207 int fixup_id;
208 const struct alc_fixup *fixup_list;
209 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200210
211 /* multi-io */
212 int multi_ios;
213 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200214
215 /* bind volumes */
216 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100217};
218
Takashi Iwai1d045db2011-07-07 18:23:21 +0200219#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Takashi Iwai44c02402011-07-08 15:14:19 +0200221static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
222 int dir, unsigned int bits)
223{
224 if (!nid)
225 return false;
226 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
227 if (query_amp_caps(codec, nid, dir) & bits)
228 return true;
229 return false;
230}
231
232#define nid_has_mute(codec, nid, dir) \
233 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
234#define nid_has_volume(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237/*
238 * input MUX handling
239 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200240static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
241 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242{
243 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
244 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200245 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
246 if (mux_idx >= spec->num_mux_defs)
247 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100248 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
249 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200250 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251}
252
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200253static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
254 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
257 struct alc_spec *spec = codec->spec;
258 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
259
260 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
261 return 0;
262}
263
Takashi Iwai21268962011-07-07 15:01:13 +0200264static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265{
Takashi Iwai21268962011-07-07 15:01:13 +0200266 struct alc_spec *spec = codec->spec;
267 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
268
269 if (spec->cur_adc && spec->cur_adc != new_adc) {
270 /* stream is running, let's swap the current ADC */
271 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
272 spec->cur_adc = new_adc;
273 snd_hda_codec_setup_stream(codec, new_adc,
274 spec->cur_adc_stream_tag, 0,
275 spec->cur_adc_format);
276 return true;
277 }
278 return false;
279}
280
Takashi Iwai61071592011-11-23 07:52:15 +0100281static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
282{
283 return spec->capsrc_nids ?
284 spec->capsrc_nids[idx] : spec->adc_nids[idx];
285}
286
Takashi Iwai24de1832011-11-07 17:13:39 +0100287static void call_update_outputs(struct hda_codec *codec);
288
Takashi Iwai21268962011-07-07 15:01:13 +0200289/* select the given imux item; either unmute exclusively or select the route */
290static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
291 unsigned int idx, bool force)
292{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100294 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100295 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100296 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200297 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Takashi Iwaicd896c32008-11-18 12:36:33 +0100299 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
300 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100301 if (!imux->num_items && mux_idx > 0)
302 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100303 if (!imux->num_items)
304 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100305
Takashi Iwai21268962011-07-07 15:01:13 +0200306 if (idx >= imux->num_items)
307 idx = imux->num_items - 1;
308 if (spec->cur_mux[adc_idx] == idx && !force)
309 return 0;
310 spec->cur_mux[adc_idx] = idx;
311
Takashi Iwai24de1832011-11-07 17:13:39 +0100312 /* for shared I/O, change the pin-control accordingly */
313 if (spec->shared_mic_hp) {
314 /* NOTE: this assumes that there are only two inputs, the
315 * first is the real internal mic and the second is HP jack.
316 */
317 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
318 AC_VERB_SET_PIN_WIDGET_CONTROL,
319 spec->cur_mux[adc_idx] ?
320 PIN_VREF80 : PIN_HP);
321 spec->automute_speaker = !spec->cur_mux[adc_idx];
322 call_update_outputs(codec);
323 }
324
Takashi Iwai21268962011-07-07 15:01:13 +0200325 if (spec->dyn_adc_switch) {
326 alc_dyn_adc_pcm_resetup(codec, idx);
327 adc_idx = spec->dyn_adc_idx[idx];
328 }
329
Takashi Iwai61071592011-11-23 07:52:15 +0100330 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200331
332 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100333 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
334 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200335 return 1;
336
Takashi Iwaia22d5432009-07-27 12:54:26 +0200337 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200338 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100339 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100340 int active = imux->items[idx].index;
341 for (i = 0; i < num_conns; i++) {
342 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
343 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100344 HDA_AMP_MUTE, v);
345 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100346 } else {
347 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200348 snd_hda_codec_write_cache(codec, nid, 0,
349 AC_VERB_SET_CONNECT_SEL,
350 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100351 }
Takashi Iwai21268962011-07-07 15:01:13 +0200352 return 1;
353}
354
355static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
356 struct snd_ctl_elem_value *ucontrol)
357{
358 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
359 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
360 return alc_mux_select(codec, adc_idx,
361 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100362}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200363
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100365 * set up the input pin config (depending on the given auto-pin type)
366 */
367static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
368 int auto_pin_type)
369{
370 unsigned int val = PIN_IN;
371
Takashi Iwai86e29592010-09-09 14:50:17 +0200372 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100373 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200374 unsigned int oldval;
375 oldval = snd_hda_codec_read(codec, nid, 0,
376 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100377 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100378 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200379 /* if the default pin setup is vref50, we give it priority */
380 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100381 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200382 else if (pincap & AC_PINCAP_VREF_50)
383 val = PIN_VREF50;
384 else if (pincap & AC_PINCAP_VREF_100)
385 val = PIN_VREF100;
386 else if (pincap & AC_PINCAP_VREF_GRD)
387 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100388 }
389 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
390}
391
392/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200393 * Append the given mixer and verb elements for the later use
394 * The mixer array is referred in build_controls(), and init_verbs are
395 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100396 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200397static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100398{
399 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
400 return;
401 spec->mixers[spec->num_mixers++] = mix;
402}
403
404static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
405{
406 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
407 return;
408 spec->init_verbs[spec->num_init_verbs++] = verb;
409}
410
411/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200412 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100413 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200414/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200415static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200416 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
417 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
418 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
419 { }
420};
421
Takashi Iwaia9111322011-05-02 11:30:18 +0200422static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200423 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
424 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
425 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
426 { }
427};
428
Takashi Iwaia9111322011-05-02 11:30:18 +0200429static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200430 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
431 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
432 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
433 { }
434};
435
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200436/*
437 * Fix hardware PLL issue
438 * On some codecs, the analog PLL gating control must be off while
439 * the default value is 1.
440 */
441static void alc_fix_pll(struct hda_codec *codec)
442{
443 struct alc_spec *spec = codec->spec;
444 unsigned int val;
445
446 if (!spec->pll_nid)
447 return;
448 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
449 spec->pll_coef_idx);
450 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
451 AC_VERB_GET_PROC_COEF, 0);
452 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
453 spec->pll_coef_idx);
454 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
455 val & ~(1 << spec->pll_coef_bit));
456}
457
458static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
459 unsigned int coef_idx, unsigned int coef_bit)
460{
461 struct alc_spec *spec = codec->spec;
462 spec->pll_nid = nid;
463 spec->pll_coef_idx = coef_idx;
464 spec->pll_coef_bit = coef_bit;
465 alc_fix_pll(codec);
466}
467
Takashi Iwai1d045db2011-07-07 18:23:21 +0200468/*
469 * Jack-reporting via input-jack layer
470 */
471
472/* initialization of jacks; currently checks only a few known pins */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200473static int alc_init_jacks(struct hda_codec *codec)
474{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100475#ifdef CONFIG_SND_HDA_INPUT_JACK
Kailang Yang9ad0e492010-09-14 23:22:00 +0200476 struct alc_spec *spec = codec->spec;
477 int err;
478 unsigned int hp_nid = spec->autocfg.hp_pins[0];
Takashi Iwai21268962011-07-07 15:01:13 +0200479 unsigned int mic_nid = spec->ext_mic_pin;
480 unsigned int dock_nid = spec->dock_mic_pin;
Kailang Yang9ad0e492010-09-14 23:22:00 +0200481
Takashi Iwai265a0242010-09-21 11:26:21 +0200482 if (hp_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100483 err = snd_hda_input_jack_add(codec, hp_nid,
484 SND_JACK_HEADPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200485 if (err < 0)
486 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100487 snd_hda_input_jack_report(codec, hp_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200488 }
Kailang Yang9ad0e492010-09-14 23:22:00 +0200489
Takashi Iwai265a0242010-09-21 11:26:21 +0200490 if (mic_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100491 err = snd_hda_input_jack_add(codec, mic_nid,
492 SND_JACK_MICROPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200493 if (err < 0)
494 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100495 snd_hda_input_jack_report(codec, mic_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200496 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200497 if (dock_nid) {
498 err = snd_hda_input_jack_add(codec, dock_nid,
499 SND_JACK_MICROPHONE, NULL);
500 if (err < 0)
501 return err;
502 snd_hda_input_jack_report(codec, dock_nid);
503 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100504#endif /* CONFIG_SND_HDA_INPUT_JACK */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200505 return 0;
506}
Kailang Yang9ad0e492010-09-14 23:22:00 +0200507
Takashi Iwai1d045db2011-07-07 18:23:21 +0200508/*
509 * Jack detections for HP auto-mute and mic-switch
510 */
511
512/* check each pin in the given array; returns true if any of them is plugged */
513static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200514{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200515 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200516
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 for (i = 0; i < num_pins; i++) {
518 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200519 if (!nid)
520 break;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100521 snd_hda_input_jack_report(codec, nid);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200522 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200523 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200524 return present;
525}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200526
Takashi Iwai1d045db2011-07-07 18:23:21 +0200527/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200528static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200529 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200530{
531 struct alc_spec *spec = codec->spec;
532 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200533 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200534 int i;
535
536 for (i = 0; i < num_pins; i++) {
537 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200538 if (!nid)
539 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200540 switch (spec->automute_mode) {
541 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200542 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543 AC_VERB_SET_PIN_WIDGET_CONTROL,
544 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200545 break;
546 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200547 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200548 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200549 break;
550 case ALC_AUTOMUTE_MIXER:
551 nid = spec->automute_mixer_nid[i];
552 if (!nid)
553 break;
554 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200555 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200556 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200557 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200558 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200559 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200560 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200561}
562
David Henningsson42cf0d02011-09-20 12:04:56 +0200563/* Toggle outputs muting */
564static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200565{
566 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200567 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200568
Takashi Iwaic0a20262011-06-10 15:28:15 +0200569 /* Control HP pins/amps depending on master_mute state;
570 * in general, HP pins/amps control should be enabled in all cases,
571 * but currently set only for master_mute, just to be safe
572 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100573 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
574 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200575 spec->autocfg.hp_pins, spec->master_mute, true);
576
David Henningsson42cf0d02011-09-20 12:04:56 +0200577 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200578 on = 0;
579 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200580 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200581 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200582 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200583 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200584
585 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200586 /* if LO is a copy of either HP or Speaker, don't need to handle it */
587 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
588 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200589 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200590 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200591 on = 0;
592 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200593 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200594 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200595 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200596 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200597}
598
David Henningsson42cf0d02011-09-20 12:04:56 +0200599static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200600{
601 struct alc_spec *spec = codec->spec;
602 if (spec->automute_hook)
603 spec->automute_hook(codec);
604 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200605 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200606}
607
Takashi Iwai1d045db2011-07-07 18:23:21 +0200608/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200609static void alc_hp_automute(struct hda_codec *codec)
610{
611 struct alc_spec *spec = codec->spec;
612
David Henningsson42cf0d02011-09-20 12:04:56 +0200613 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200614 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
615 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200616 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200617 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200618 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200619}
620
Takashi Iwai1d045db2011-07-07 18:23:21 +0200621/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200622static void alc_line_automute(struct hda_codec *codec)
623{
624 struct alc_spec *spec = codec->spec;
625
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200626 /* check LO jack only when it's different from HP */
627 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
628 return;
629
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200630 spec->line_jack_present =
631 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
632 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200633 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200634 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200635 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200636}
637
Takashi Iwai8d087c72011-06-28 12:45:47 +0200638#define get_connection_index(codec, mux, nid) \
639 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200640
Takashi Iwai1d045db2011-07-07 18:23:21 +0200641/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200642static void alc_mic_automute(struct hda_codec *codec)
643{
644 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200645 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200646
Takashi Iwai21268962011-07-07 15:01:13 +0200647 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200648 return;
649 if (snd_BUG_ON(!spec->adc_nids))
650 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200651 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200652 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200653
Takashi Iwai21268962011-07-07 15:01:13 +0200654 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
655 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
656 else if (spec->dock_mic_idx >= 0 &&
657 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
658 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
659 else
660 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Takashi Iwai6c819492009-08-10 18:47:44 +0200661
Takashi Iwai21268962011-07-07 15:01:13 +0200662 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
663 if (spec->dock_mic_idx >= 0)
664 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200665}
666
Kailang Yangc9b58002007-10-16 14:30:01 +0200667/* unsolicited event for HP jack sensing */
668static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
669{
670 if (codec->vendor_id == 0x10ec0880)
671 res >>= 28;
672 else
673 res >>= 26;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200674 switch (res) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200675 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200676 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200677 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200678 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200679 alc_line_automute(codec);
680 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200681 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200682 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200683 break;
684 }
Kailang Yang7fb0d782008-10-15 11:12:35 +0200685}
686
Takashi Iwai1d045db2011-07-07 18:23:21 +0200687/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200688static void alc_inithook(struct hda_codec *codec)
689{
Takashi Iwaid922b512011-04-28 12:18:53 +0200690 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200691 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200692 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200693}
694
Kailang Yangf9423e72008-05-27 12:32:25 +0200695/* additional initialization for ALC888 variants */
696static void alc888_coef_init(struct hda_codec *codec)
697{
698 unsigned int tmp;
699
700 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
701 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
702 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100703 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200704 /* alc888S-VC */
705 snd_hda_codec_read(codec, 0x20, 0,
706 AC_VERB_SET_PROC_COEF, 0x830);
707 else
708 /* alc888-VB */
709 snd_hda_codec_read(codec, 0x20, 0,
710 AC_VERB_SET_PROC_COEF, 0x3030);
711}
712
Takashi Iwai1d045db2011-07-07 18:23:21 +0200713/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200714static void alc889_coef_init(struct hda_codec *codec)
715{
716 unsigned int tmp;
717
718 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
719 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
720 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
721 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
722}
723
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100724/* turn on/off EAPD control (only if available) */
725static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
726{
727 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
728 return;
729 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
730 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
731 on ? 2 : 0);
732}
733
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200734/* turn on/off EAPD controls of the codec */
735static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
736{
737 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200738 static hda_nid_t pins[] = {
739 0x0f, 0x10, 0x14, 0x15, 0
740 };
741 hda_nid_t *p;
742 for (p = pins; *p; p++)
743 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200744}
745
Takashi Iwai1c716152011-04-07 10:37:16 +0200746/* generic shutup callback;
747 * just turning off EPAD and a little pause for avoiding pop-noise
748 */
749static void alc_eapd_shutup(struct hda_codec *codec)
750{
751 alc_auto_setup_eapd(codec, false);
752 msleep(200);
753}
754
Takashi Iwai1d045db2011-07-07 18:23:21 +0200755/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200756static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200757{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200758 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200759
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200760 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200761 switch (type) {
762 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200763 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
764 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200765 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200766 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
767 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200768 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200769 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
770 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200771 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200772 switch (codec->vendor_id) {
773 case 0x10ec0260:
774 snd_hda_codec_write(codec, 0x1a, 0,
775 AC_VERB_SET_COEF_INDEX, 7);
776 tmp = snd_hda_codec_read(codec, 0x1a, 0,
777 AC_VERB_GET_PROC_COEF, 0);
778 snd_hda_codec_write(codec, 0x1a, 0,
779 AC_VERB_SET_COEF_INDEX, 7);
780 snd_hda_codec_write(codec, 0x1a, 0,
781 AC_VERB_SET_PROC_COEF,
782 tmp | 0x2010);
783 break;
784 case 0x10ec0262:
785 case 0x10ec0880:
786 case 0x10ec0882:
787 case 0x10ec0883:
788 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100789 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100790 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200791 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200792 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200793 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200794 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200795 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100796#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200797 case 0x10ec0267:
798 case 0x10ec0268:
799 snd_hda_codec_write(codec, 0x20, 0,
800 AC_VERB_SET_COEF_INDEX, 7);
801 tmp = snd_hda_codec_read(codec, 0x20, 0,
802 AC_VERB_GET_PROC_COEF, 0);
803 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200804 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200805 snd_hda_codec_write(codec, 0x20, 0,
806 AC_VERB_SET_PROC_COEF,
807 tmp | 0x3000);
808 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100809#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200810 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200811 break;
812 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200813}
Kailang Yangea1fb292008-08-26 12:58:38 +0200814
Takashi Iwai1d045db2011-07-07 18:23:21 +0200815/*
816 * Auto-Mute mode mixer enum support
817 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200818static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
819 struct snd_ctl_elem_info *uinfo)
820{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200821 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
822 struct alc_spec *spec = codec->spec;
823 static const char * const texts2[] = {
824 "Disabled", "Enabled"
825 };
826 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200827 "Disabled", "Speaker Only", "Line-Out+Speaker"
828 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200829 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200830
831 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
832 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200833 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200834 uinfo->value.enumerated.items = 3;
835 texts = texts3;
836 } else {
837 uinfo->value.enumerated.items = 2;
838 texts = texts2;
839 }
840 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
841 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200842 strcpy(uinfo->value.enumerated.name,
843 texts[uinfo->value.enumerated.item]);
844 return 0;
845}
846
847static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
848 struct snd_ctl_elem_value *ucontrol)
849{
850 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
851 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200852 unsigned int val = 0;
853 if (spec->automute_speaker)
854 val++;
855 if (spec->automute_lo)
856 val++;
857
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200858 ucontrol->value.enumerated.item[0] = val;
859 return 0;
860}
861
862static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
863 struct snd_ctl_elem_value *ucontrol)
864{
865 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
866 struct alc_spec *spec = codec->spec;
867
868 switch (ucontrol->value.enumerated.item[0]) {
869 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200870 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200871 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200872 spec->automute_speaker = 0;
873 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200874 break;
875 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200876 if (spec->automute_speaker_possible) {
877 if (!spec->automute_lo && spec->automute_speaker)
878 return 0;
879 spec->automute_speaker = 1;
880 spec->automute_lo = 0;
881 } else if (spec->automute_lo_possible) {
882 if (spec->automute_lo)
883 return 0;
884 spec->automute_lo = 1;
885 } else
886 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200887 break;
888 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200889 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200890 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200891 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200892 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200893 spec->automute_speaker = 1;
894 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200895 break;
896 default:
897 return -EINVAL;
898 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200899 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200900 return 1;
901}
902
Takashi Iwaia9111322011-05-02 11:30:18 +0200903static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200904 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
905 .name = "Auto-Mute Mode",
906 .info = alc_automute_mode_info,
907 .get = alc_automute_mode_get,
908 .put = alc_automute_mode_put,
909};
910
Takashi Iwai1d045db2011-07-07 18:23:21 +0200911static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
912{
913 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
914 return snd_array_new(&spec->kctls);
915}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200916
917static int alc_add_automute_mode_enum(struct hda_codec *codec)
918{
919 struct alc_spec *spec = codec->spec;
920 struct snd_kcontrol_new *knew;
921
922 knew = alc_kcontrol_new(spec);
923 if (!knew)
924 return -ENOMEM;
925 *knew = alc_automute_mode_enum;
926 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
927 if (!knew->name)
928 return -ENOMEM;
929 return 0;
930}
931
Takashi Iwai1d045db2011-07-07 18:23:21 +0200932/*
933 * Check the availability of HP/line-out auto-mute;
934 * Set up appropriately if really supported
935 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200936static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200937{
938 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200939 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200940 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200941 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200942
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200943 if (cfg->hp_pins[0])
944 present++;
945 if (cfg->line_out_pins[0])
946 present++;
947 if (cfg->speaker_pins[0])
948 present++;
949 if (present < 2) /* need two different output types */
950 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200951
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200952 if (!cfg->speaker_pins[0] &&
953 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200954 memcpy(cfg->speaker_pins, cfg->line_out_pins,
955 sizeof(cfg->speaker_pins));
956 cfg->speaker_outs = cfg->line_outs;
957 }
958
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200959 if (!cfg->hp_pins[0] &&
960 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200961 memcpy(cfg->hp_pins, cfg->line_out_pins,
962 sizeof(cfg->hp_pins));
963 cfg->hp_outs = cfg->line_outs;
964 }
965
David Henningsson42cf0d02011-09-20 12:04:56 +0200966 spec->automute_mode = ALC_AUTOMUTE_PIN;
967
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200968 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200969 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200970 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200971 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200972 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200973 nid);
974 snd_hda_codec_write_cache(codec, nid, 0,
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200975 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +0200976 AC_USRSP_EN | ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200977 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200978 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200979
David Henningsson42cf0d02011-09-20 12:04:56 +0200980 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
981 if (cfg->speaker_outs)
982 for (i = 0; i < cfg->line_outs; i++) {
983 hda_nid_t nid = cfg->line_out_pins[i];
984 if (!is_jack_detectable(codec, nid))
985 continue;
986 snd_printdd("realtek: Enable Line-Out "
987 "auto-muting on NID 0x%x\n", nid);
988 snd_hda_codec_write_cache(codec, nid, 0,
989 AC_VERB_SET_UNSOLICITED_ENABLE,
990 AC_USRSP_EN | ALC_FRONT_EVENT);
991 spec->detect_lo = 1;
992 }
993 spec->automute_lo_possible = spec->detect_hp;
994 }
995
996 spec->automute_speaker_possible = cfg->speaker_outs &&
997 (spec->detect_hp || spec->detect_lo);
998
999 spec->automute_lo = spec->automute_lo_possible;
1000 spec->automute_speaker = spec->automute_speaker_possible;
1001
1002 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001003 /* create a control for automute mode */
1004 alc_add_automute_mode_enum(codec);
1005 spec->unsol_event = alc_sku_unsol_event;
1006 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001007}
1008
Takashi Iwai1d045db2011-07-07 18:23:21 +02001009/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001010static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1011{
1012 int i;
1013 for (i = 0; i < nums; i++)
1014 if (list[i] == nid)
1015 return i;
1016 return -1;
1017}
1018
Takashi Iwai1d045db2011-07-07 18:23:21 +02001019/* check whether dynamic ADC-switching is available */
1020static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1021{
1022 struct alc_spec *spec = codec->spec;
1023 struct hda_input_mux *imux = &spec->private_imux[0];
1024 int i, n, idx;
1025 hda_nid_t cap, pin;
1026
1027 if (imux != spec->input_mux) /* no dynamic imux? */
1028 return false;
1029
1030 for (n = 0; n < spec->num_adc_nids; n++) {
1031 cap = spec->private_capsrc_nids[n];
1032 for (i = 0; i < imux->num_items; i++) {
1033 pin = spec->imux_pins[i];
1034 if (!pin)
1035 return false;
1036 if (get_connection_index(codec, cap, pin) < 0)
1037 break;
1038 }
1039 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001040 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001041 }
1042
1043 for (i = 0; i < imux->num_items; i++) {
1044 pin = spec->imux_pins[i];
1045 for (n = 0; n < spec->num_adc_nids; n++) {
1046 cap = spec->private_capsrc_nids[n];
1047 idx = get_connection_index(codec, cap, pin);
1048 if (idx >= 0) {
1049 imux->items[i].index = idx;
1050 spec->dyn_adc_idx[i] = n;
1051 break;
1052 }
1053 }
1054 }
1055
1056 snd_printdd("realtek: enabling ADC switching\n");
1057 spec->dyn_adc_switch = 1;
1058 return true;
1059}
Takashi Iwai21268962011-07-07 15:01:13 +02001060
1061/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1062static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1063{
1064 struct alc_spec *spec = codec->spec;
1065 struct hda_input_mux *imux;
1066 static char * const texts[3] = {
1067 "Mic", "Internal Mic", "Dock Mic"
1068 };
1069 int i;
1070
1071 if (!spec->auto_mic)
1072 return false;
1073 imux = &spec->private_imux[0];
1074 if (spec->input_mux == imux)
1075 return true;
1076 spec->imux_pins[0] = spec->ext_mic_pin;
1077 spec->imux_pins[1] = spec->int_mic_pin;
1078 spec->imux_pins[2] = spec->dock_mic_pin;
1079 for (i = 0; i < 3; i++) {
1080 strcpy(imux->items[i].label, texts[i]);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001081 if (spec->imux_pins[i]) {
1082 hda_nid_t pin = spec->imux_pins[i];
1083 int c;
1084 for (c = 0; c < spec->num_adc_nids; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001085 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwai6759dc32011-11-23 07:38:59 +01001086 int idx = get_connection_index(codec, cap, pin);
1087 if (idx >= 0) {
1088 imux->items[i].index = idx;
1089 break;
1090 }
1091 }
Takashi Iwai21268962011-07-07 15:01:13 +02001092 imux->num_items = i + 1;
Takashi Iwai6759dc32011-11-23 07:38:59 +01001093 }
Takashi Iwai21268962011-07-07 15:01:13 +02001094 }
1095 spec->num_mux_defs = 1;
1096 spec->input_mux = imux;
1097 return true;
1098}
1099
1100/* check whether all auto-mic pins are valid; setup indices if OK */
1101static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1102{
1103 struct alc_spec *spec = codec->spec;
1104 const struct hda_input_mux *imux;
1105
1106 if (!spec->auto_mic)
1107 return false;
1108 if (spec->auto_mic_valid_imux)
1109 return true; /* already checked */
1110
1111 /* fill up imux indices */
1112 if (!alc_check_dyn_adc_switch(codec)) {
1113 spec->auto_mic = 0;
1114 return false;
1115 }
1116
1117 imux = spec->input_mux;
1118 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1119 spec->imux_pins, imux->num_items);
1120 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1121 spec->imux_pins, imux->num_items);
1122 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1123 spec->imux_pins, imux->num_items);
1124 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1125 spec->auto_mic = 0;
1126 return false; /* no corresponding imux */
1127 }
1128
1129 snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0,
1130 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001131 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001132 if (spec->dock_mic_pin)
1133 snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0,
1134 AC_VERB_SET_UNSOLICITED_ENABLE,
Takashi Iwai1d045db2011-07-07 18:23:21 +02001135 AC_USRSP_EN | ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001136
1137 spec->auto_mic_valid_imux = 1;
1138 spec->auto_mic = 1;
1139 return true;
1140}
1141
Takashi Iwai1d045db2011-07-07 18:23:21 +02001142/*
1143 * Check the availability of auto-mic switch;
1144 * Set up if really supported
1145 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001146static void alc_init_auto_mic(struct hda_codec *codec)
1147{
1148 struct alc_spec *spec = codec->spec;
1149 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001150 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001151 int i;
1152
Takashi Iwai24de1832011-11-07 17:13:39 +01001153 if (spec->shared_mic_hp)
1154 return; /* no auto-mic for the shared I/O */
1155
Takashi Iwai21268962011-07-07 15:01:13 +02001156 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1157
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001158 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001159 for (i = 0; i < cfg->num_inputs; i++) {
1160 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001161 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001162 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001163 switch (snd_hda_get_input_pin_attr(defcfg)) {
1164 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001165 if (fixed)
1166 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001167 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1168 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001169 fixed = nid;
1170 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001171 case INPUT_PIN_ATTR_UNUSED:
1172 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001173 case INPUT_PIN_ATTR_DOCK:
1174 if (dock)
1175 return; /* already occupied */
1176 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1177 return; /* invalid type */
1178 dock = nid;
1179 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001180 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001181 if (ext)
1182 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001183 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1184 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001185 ext = nid;
1186 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001187 }
1188 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001189 if (!ext && dock) {
1190 ext = dock;
1191 dock = 0;
1192 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001193 if (!ext || !fixed)
1194 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001195 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001196 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001197 if (dock && !is_jack_detectable(codec, dock))
1198 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001199
1200 /* check imux indices */
1201 spec->ext_mic_pin = ext;
1202 spec->int_mic_pin = fixed;
1203 spec->dock_mic_pin = dock;
1204
1205 spec->auto_mic = 1;
1206 if (!alc_auto_mic_check_imux(codec))
1207 return;
1208
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001209 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1210 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001211 spec->unsol_event = alc_sku_unsol_event;
1212}
1213
Takashi Iwai1d045db2011-07-07 18:23:21 +02001214/* check the availabilities of auto-mute and auto-mic switches */
1215static void alc_auto_check_switches(struct hda_codec *codec)
1216{
David Henningsson42cf0d02011-09-20 12:04:56 +02001217 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001218 alc_init_auto_mic(codec);
1219}
1220
1221/*
1222 * Realtek SSID verification
1223 */
1224
David Henningsson90622912010-10-14 14:50:18 +02001225/* Could be any non-zero and even value. When used as fixup, tells
1226 * the driver to ignore any present sku defines.
1227 */
1228#define ALC_FIXUP_SKU_IGNORE (2)
1229
Kailang Yangda00c242010-03-19 11:23:45 +01001230static int alc_auto_parse_customize_define(struct hda_codec *codec)
1231{
1232 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001233 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001234 struct alc_spec *spec = codec->spec;
1235
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001236 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1237
David Henningsson90622912010-10-14 14:50:18 +02001238 if (spec->cdefine.fixup) {
1239 ass = spec->cdefine.sku_cfg;
1240 if (ass == ALC_FIXUP_SKU_IGNORE)
1241 return -1;
1242 goto do_sku;
1243 }
1244
Kailang Yangda00c242010-03-19 11:23:45 +01001245 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001246 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001247 goto do_sku;
1248
1249 nid = 0x1d;
1250 if (codec->vendor_id == 0x10ec0260)
1251 nid = 0x17;
1252 ass = snd_hda_codec_get_pincfg(codec, nid);
1253
1254 if (!(ass & 1)) {
1255 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1256 codec->chip_name, ass);
1257 return -1;
1258 }
1259
1260 /* check sum */
1261 tmp = 0;
1262 for (i = 1; i < 16; i++) {
1263 if ((ass >> i) & 1)
1264 tmp++;
1265 }
1266 if (((ass >> 16) & 0xf) != tmp)
1267 return -1;
1268
1269 spec->cdefine.port_connectivity = ass >> 30;
1270 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1271 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1272 spec->cdefine.customization = ass >> 8;
1273do_sku:
1274 spec->cdefine.sku_cfg = ass;
1275 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1276 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1277 spec->cdefine.swap = (ass & 0x2) >> 1;
1278 spec->cdefine.override = ass & 0x1;
1279
1280 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1281 nid, spec->cdefine.sku_cfg);
1282 snd_printd("SKU: port_connectivity=0x%x\n",
1283 spec->cdefine.port_connectivity);
1284 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1285 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1286 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1287 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1288 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1289 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1290 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1291
1292 return 0;
1293}
1294
Takashi Iwai1d045db2011-07-07 18:23:21 +02001295/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001296static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1297{
Takashi Iwai21268962011-07-07 15:01:13 +02001298 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001299}
1300
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001301/* check subsystem ID and set up device-specific initialization;
1302 * return 1 if initialized, 0 if invalid SSID
1303 */
1304/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1305 * 31 ~ 16 : Manufacture ID
1306 * 15 ~ 8 : SKU ID
1307 * 7 ~ 0 : Assembly ID
1308 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1309 */
1310static int alc_subsystem_id(struct hda_codec *codec,
1311 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001312 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001313{
1314 unsigned int ass, tmp, i;
1315 unsigned nid;
1316 struct alc_spec *spec = codec->spec;
1317
David Henningsson90622912010-10-14 14:50:18 +02001318 if (spec->cdefine.fixup) {
1319 ass = spec->cdefine.sku_cfg;
1320 if (ass == ALC_FIXUP_SKU_IGNORE)
1321 return 0;
1322 goto do_sku;
1323 }
1324
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001325 ass = codec->subsystem_id & 0xffff;
1326 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1327 goto do_sku;
1328
1329 /* invalid SSID, check the special NID pin defcfg instead */
1330 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001331 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001332 * 29~21 : reserve
1333 * 20 : PCBEEP input
1334 * 19~16 : Check sum (15:1)
1335 * 15~1 : Custom
1336 * 0 : override
1337 */
1338 nid = 0x1d;
1339 if (codec->vendor_id == 0x10ec0260)
1340 nid = 0x17;
1341 ass = snd_hda_codec_get_pincfg(codec, nid);
1342 snd_printd("realtek: No valid SSID, "
1343 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001344 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001345 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001346 return 0;
1347 if ((ass >> 30) != 1) /* no physical connection */
1348 return 0;
1349
1350 /* check sum */
1351 tmp = 0;
1352 for (i = 1; i < 16; i++) {
1353 if ((ass >> i) & 1)
1354 tmp++;
1355 }
1356 if (((ass >> 16) & 0xf) != tmp)
1357 return 0;
1358do_sku:
1359 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1360 ass & 0xffff, codec->vendor_id);
1361 /*
1362 * 0 : override
1363 * 1 : Swap Jack
1364 * 2 : 0 --> Desktop, 1 --> Laptop
1365 * 3~5 : External Amplifier control
1366 * 7~6 : Reserved
1367 */
1368 tmp = (ass & 0x38) >> 3; /* external Amp control */
1369 switch (tmp) {
1370 case 1:
1371 spec->init_amp = ALC_INIT_GPIO1;
1372 break;
1373 case 3:
1374 spec->init_amp = ALC_INIT_GPIO2;
1375 break;
1376 case 7:
1377 spec->init_amp = ALC_INIT_GPIO3;
1378 break;
1379 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001380 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001381 spec->init_amp = ALC_INIT_DEFAULT;
1382 break;
1383 }
1384
1385 /* is laptop or Desktop and enable the function "Mute internal speaker
1386 * when the external headphone out jack is plugged"
1387 */
1388 if (!(ass & 0x8000))
1389 return 1;
1390 /*
1391 * 10~8 : Jack location
1392 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1393 * 14~13: Resvered
1394 * 15 : 1 --> enable the function "Mute internal speaker
1395 * when the external headphone out jack is plugged"
1396 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001397 if (!spec->autocfg.hp_pins[0] &&
1398 !(spec->autocfg.line_out_pins[0] &&
1399 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001400 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001401 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1402 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001403 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001404 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001405 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001406 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001407 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001408 else if (tmp == 3)
1409 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001410 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001411 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001412 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1413 spec->autocfg.line_outs))
1414 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001415 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001416 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001417 return 1;
1418}
Kailang Yangea1fb292008-08-26 12:58:38 +02001419
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001420/* Check the validity of ALC subsystem-id
1421 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1422static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001423{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001424 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001425 struct alc_spec *spec = codec->spec;
1426 snd_printd("realtek: "
1427 "Enable default setup for auto mode as fallback\n");
1428 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001429 }
Takashi Iwai21268962011-07-07 15:01:13 +02001430}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001431
Takashi Iwai41e41f12005-06-08 14:48:49 +02001432/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001433 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001434 */
1435
1436struct alc_pincfg {
1437 hda_nid_t nid;
1438 u32 val;
1439};
1440
Todd Broche1eb5f12010-12-06 11:19:51 -08001441struct alc_model_fixup {
1442 const int id;
1443 const char *name;
1444};
1445
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001446struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001447 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001448 bool chained;
1449 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001450 union {
1451 unsigned int sku;
1452 const struct alc_pincfg *pins;
1453 const struct hda_verb *verbs;
1454 void (*func)(struct hda_codec *codec,
1455 const struct alc_fixup *fix,
1456 int action);
1457 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001458};
1459
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001460enum {
1461 ALC_FIXUP_INVALID,
1462 ALC_FIXUP_SKU,
1463 ALC_FIXUP_PINS,
1464 ALC_FIXUP_VERBS,
1465 ALC_FIXUP_FUNC,
1466};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001467
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001468enum {
1469 ALC_FIXUP_ACT_PRE_PROBE,
1470 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001471 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001472};
1473
1474static void alc_apply_fixup(struct hda_codec *codec, int action)
1475{
1476 struct alc_spec *spec = codec->spec;
1477 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001478#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001479 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001480#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001481 int depth = 0;
1482
1483 if (!spec->fixup_list)
1484 return;
1485
1486 while (id >= 0) {
1487 const struct alc_fixup *fix = spec->fixup_list + id;
1488 const struct alc_pincfg *cfg;
1489
1490 switch (fix->type) {
1491 case ALC_FIXUP_SKU:
1492 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001493 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001494 snd_printdd(KERN_INFO "hda_codec: %s: "
1495 "Apply sku override for %s\n",
1496 codec->chip_name, modelname);
1497 spec->cdefine.sku_cfg = fix->v.sku;
1498 spec->cdefine.fixup = 1;
1499 break;
1500 case ALC_FIXUP_PINS:
1501 cfg = fix->v.pins;
1502 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1503 break;
1504 snd_printdd(KERN_INFO "hda_codec: %s: "
1505 "Apply pincfg for %s\n",
1506 codec->chip_name, modelname);
1507 for (; cfg->nid; cfg++)
1508 snd_hda_codec_set_pincfg(codec, cfg->nid,
1509 cfg->val);
1510 break;
1511 case ALC_FIXUP_VERBS:
1512 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1513 break;
1514 snd_printdd(KERN_INFO "hda_codec: %s: "
1515 "Apply fix-verbs for %s\n",
1516 codec->chip_name, modelname);
1517 add_verb(codec->spec, fix->v.verbs);
1518 break;
1519 case ALC_FIXUP_FUNC:
1520 if (!fix->v.func)
1521 break;
1522 snd_printdd(KERN_INFO "hda_codec: %s: "
1523 "Apply fix-func for %s\n",
1524 codec->chip_name, modelname);
1525 fix->v.func(codec, fix, action);
1526 break;
1527 default:
1528 snd_printk(KERN_ERR "hda_codec: %s: "
1529 "Invalid fixup type %d\n",
1530 codec->chip_name, fix->type);
1531 break;
1532 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001533 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001534 break;
1535 if (++depth > 10)
1536 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001537 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001538 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001539}
1540
Todd Broche1eb5f12010-12-06 11:19:51 -08001541static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001542 const struct alc_model_fixup *models,
1543 const struct snd_pci_quirk *quirk,
1544 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001545{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001546 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001547 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001548 int id = -1;
1549 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001550
Todd Broche1eb5f12010-12-06 11:19:51 -08001551 if (codec->modelname && models) {
1552 while (models->name) {
1553 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001554 id = models->id;
1555 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001556 break;
1557 }
1558 models++;
1559 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001560 }
1561 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001562 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1563 if (q) {
1564 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001565#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001566 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001567#endif
1568 }
1569 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001570 if (id < 0) {
1571 for (q = quirk; q->subvendor; q++) {
1572 unsigned int vendorid =
1573 q->subdevice | (q->subvendor << 16);
1574 if (vendorid == codec->subsystem_id) {
1575 id = q->value;
1576#ifdef CONFIG_SND_DEBUG_VERBOSE
1577 name = q->name;
1578#endif
1579 break;
1580 }
1581 }
1582 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001583
1584 spec->fixup_id = id;
1585 if (id >= 0) {
1586 spec->fixup_list = fixlist;
1587 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001588 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001589}
1590
Takashi Iwai1d045db2011-07-07 18:23:21 +02001591/*
1592 * COEF access helper functions
1593 */
Kailang Yang274693f2009-12-03 10:07:50 +01001594static int alc_read_coef_idx(struct hda_codec *codec,
1595 unsigned int coef_idx)
1596{
1597 unsigned int val;
1598 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1599 coef_idx);
1600 val = snd_hda_codec_read(codec, 0x20, 0,
1601 AC_VERB_GET_PROC_COEF, 0);
1602 return val;
1603}
1604
Kailang Yang977ddd62010-09-15 10:02:29 +02001605static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1606 unsigned int coef_val)
1607{
1608 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1609 coef_idx);
1610 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1611 coef_val);
1612}
1613
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001614/* a special bypass for COEF 0; read the cached value at the second time */
1615static unsigned int alc_get_coef0(struct hda_codec *codec)
1616{
1617 struct alc_spec *spec = codec->spec;
1618 if (!spec->coef0)
1619 spec->coef0 = alc_read_coef_idx(codec, 0);
1620 return spec->coef0;
1621}
1622
Takashi Iwai1d045db2011-07-07 18:23:21 +02001623/*
1624 * Digital I/O handling
1625 */
1626
Takashi Iwai757899a2010-07-30 10:48:14 +02001627/* set right pin controls for digital I/O */
1628static void alc_auto_init_digital(struct hda_codec *codec)
1629{
1630 struct alc_spec *spec = codec->spec;
1631 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001632 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001633
1634 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1635 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001636 if (!pin)
1637 continue;
1638 snd_hda_codec_write(codec, pin, 0,
1639 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1640 if (!i)
1641 dac = spec->multiout.dig_out_nid;
1642 else
1643 dac = spec->slave_dig_outs[i - 1];
1644 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1645 continue;
1646 snd_hda_codec_write(codec, dac, 0,
1647 AC_VERB_SET_AMP_GAIN_MUTE,
1648 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001649 }
1650 pin = spec->autocfg.dig_in_pin;
1651 if (pin)
1652 snd_hda_codec_write(codec, pin, 0,
1653 AC_VERB_SET_PIN_WIDGET_CONTROL,
1654 PIN_IN);
1655}
1656
1657/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1658static void alc_auto_parse_digital(struct hda_codec *codec)
1659{
1660 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001661 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001662 hda_nid_t dig_nid;
1663
1664 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001665 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001666 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001667 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001668 err = snd_hda_get_connections(codec,
1669 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001670 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001671 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001672 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001673 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001674 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001675 spec->multiout.dig_out_nid = dig_nid;
1676 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1677 } else {
1678 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001679 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001680 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001681 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001682 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001683 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001684 }
1685
1686 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001687 dig_nid = codec->start_nid;
1688 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1689 unsigned int wcaps = get_wcaps(codec, dig_nid);
1690 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1691 continue;
1692 if (!(wcaps & AC_WCAP_DIGITAL))
1693 continue;
1694 if (!(wcaps & AC_WCAP_CONN_LIST))
1695 continue;
1696 err = get_connection_index(codec, dig_nid,
1697 spec->autocfg.dig_in_pin);
1698 if (err >= 0) {
1699 spec->dig_in_nid = dig_nid;
1700 break;
1701 }
1702 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001703 }
1704}
1705
Takashi Iwaif95474e2007-07-10 00:47:43 +02001706/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001707 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001708 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001709static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1710 struct snd_ctl_elem_info *uinfo)
1711{
1712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1713 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001714 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001715 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001716
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001717 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001718 if (spec->vol_in_capsrc)
1719 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1720 else
1721 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1722 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001723 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001724 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001725 return err;
1726}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001728static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1729 unsigned int size, unsigned int __user *tlv)
1730{
1731 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1732 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001733 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001734 int err;
1735
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001736 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001737 if (spec->vol_in_capsrc)
1738 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1739 else
1740 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1741 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001742 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001743 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001744 return err;
1745}
1746
1747typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1748 struct snd_ctl_elem_value *ucontrol);
1749
1750static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1751 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001752 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001753{
1754 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1755 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001756 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001757
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001758 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001759 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001760 for (i = 0; i < spec->num_adc_nids; i++) {
1761 kcontrol->private_value =
1762 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1763 3, 0, HDA_INPUT);
1764 err = func(kcontrol, ucontrol);
1765 if (err < 0)
1766 goto error;
1767 }
1768 } else {
1769 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001770 if (spec->vol_in_capsrc)
1771 kcontrol->private_value =
1772 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1773 3, 0, HDA_OUTPUT);
1774 else
1775 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001776 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1777 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001778 err = func(kcontrol, ucontrol);
1779 }
1780 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001781 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001782 return err;
1783}
1784
1785static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1786 struct snd_ctl_elem_value *ucontrol)
1787{
1788 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001789 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001790}
1791
1792static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1793 struct snd_ctl_elem_value *ucontrol)
1794{
1795 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001796 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001797}
1798
1799/* capture mixer elements */
1800#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1801
1802static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1803 struct snd_ctl_elem_value *ucontrol)
1804{
1805 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001806 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001807}
1808
1809static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1810 struct snd_ctl_elem_value *ucontrol)
1811{
1812 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001813 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001814}
1815
Takashi Iwaia23b6882009-03-23 15:21:36 +01001816#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001817 { \
1818 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1819 .name = "Capture Switch", \
1820 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1821 .count = num, \
1822 .info = alc_cap_sw_info, \
1823 .get = alc_cap_sw_get, \
1824 .put = alc_cap_sw_put, \
1825 }, \
1826 { \
1827 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1828 .name = "Capture Volume", \
1829 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1830 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1831 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1832 .count = num, \
1833 .info = alc_cap_vol_info, \
1834 .get = alc_cap_vol_get, \
1835 .put = alc_cap_vol_put, \
1836 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001837 }
1838
1839#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001840 { \
1841 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1842 /* .name = "Capture Source", */ \
1843 .name = "Input Source", \
1844 .count = num, \
1845 .info = alc_mux_enum_info, \
1846 .get = alc_mux_enum_get, \
1847 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001848 }
1849
1850#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001851static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001852 _DEFINE_CAPMIX(num), \
1853 _DEFINE_CAPSRC(num), \
1854 { } /* end */ \
1855}
1856
1857#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001858static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001859 _DEFINE_CAPMIX(num), \
1860 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001861}
1862
1863/* up to three ADCs */
1864DEFINE_CAPMIX(1);
1865DEFINE_CAPMIX(2);
1866DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001867DEFINE_CAPMIX_NOSRC(1);
1868DEFINE_CAPMIX_NOSRC(2);
1869DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001870
1871/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001872 * virtual master controls
1873 */
1874
1875/*
1876 * slave controls for virtual master
1877 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001878static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001879 "Front Playback Volume",
1880 "Surround Playback Volume",
1881 "Center Playback Volume",
1882 "LFE Playback Volume",
1883 "Side Playback Volume",
1884 "Headphone Playback Volume",
1885 "Speaker Playback Volume",
1886 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001887 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001888 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001889 NULL,
1890};
1891
Takashi Iwaiea734962011-01-17 11:29:34 +01001892static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001893 "Front Playback Switch",
1894 "Surround Playback Switch",
1895 "Center Playback Switch",
1896 "LFE Playback Switch",
1897 "Side Playback Switch",
1898 "Headphone Playback Switch",
1899 "Speaker Playback Switch",
1900 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001901 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001902 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001903 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001904 NULL,
1905};
1906
1907/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001908 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001910
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001911#define NID_MAPPING (-1)
1912
1913#define SUBDEV_SPEAKER_ (0 << 6)
1914#define SUBDEV_HP_ (1 << 6)
1915#define SUBDEV_LINE_ (2 << 6)
1916#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1917#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1918#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1919
Takashi Iwai603c4012008-07-30 15:01:44 +02001920static void alc_free_kctls(struct hda_codec *codec);
1921
Takashi Iwai67d634c2009-11-16 15:35:59 +01001922#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001923/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001924static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001925 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001926 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001927 { } /* end */
1928};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001929#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001930
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931static int alc_build_controls(struct hda_codec *codec)
1932{
1933 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001934 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001935 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001936 int i, j, err;
1937 unsigned int u;
1938 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
1940 for (i = 0; i < spec->num_mixers; i++) {
1941 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1942 if (err < 0)
1943 return err;
1944 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001945 if (spec->cap_mixer) {
1946 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1947 if (err < 0)
1948 return err;
1949 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001951 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001952 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001953 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 if (err < 0)
1955 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001956 if (!spec->no_analog) {
1957 err = snd_hda_create_spdif_share_sw(codec,
1958 &spec->multiout);
1959 if (err < 0)
1960 return err;
1961 spec->multiout.share_spdif = 1;
1962 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 }
1964 if (spec->dig_in_nid) {
1965 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1966 if (err < 0)
1967 return err;
1968 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001969
Takashi Iwai67d634c2009-11-16 15:35:59 +01001970#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001971 /* create beep controls if needed */
1972 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001973 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001974 for (knew = alc_beep_mixer; knew->name; knew++) {
1975 struct snd_kcontrol *kctl;
1976 kctl = snd_ctl_new1(knew, codec);
1977 if (!kctl)
1978 return -ENOMEM;
1979 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001980 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001981 if (err < 0)
1982 return err;
1983 }
1984 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001985#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001986
Takashi Iwai2134ea42008-01-10 16:53:55 +01001987 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001988 if (!spec->no_analog &&
1989 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001990 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001991 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001992 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001993 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001994 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001995 if (err < 0)
1996 return err;
1997 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001998 if (!spec->no_analog &&
1999 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01002000 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
2001 NULL, alc_slave_sws);
2002 if (err < 0)
2003 return err;
2004 }
2005
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002006 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02002007 if (spec->capsrc_nids || spec->adc_nids) {
2008 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
2009 if (!kctl)
2010 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
2011 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002012 err = snd_hda_add_nid(codec, kctl, i,
2013 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02002014 if (err < 0)
2015 return err;
2016 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002017 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02002018 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002019 const char *kname = kctl ? kctl->id.name : NULL;
2020 for (knew = spec->cap_mixer; knew->name; knew++) {
2021 if (kname && strcmp(knew->name, kname) == 0)
2022 continue;
2023 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2024 for (i = 0; kctl && i < kctl->count; i++) {
2025 err = snd_hda_add_nid(codec, kctl, i,
2026 spec->adc_nids[i]);
2027 if (err < 0)
2028 return err;
2029 }
2030 }
2031 }
2032
2033 /* other nid->control mapping */
2034 for (i = 0; i < spec->num_mixers; i++) {
2035 for (knew = spec->mixers[i]; knew->name; knew++) {
2036 if (knew->iface != NID_MAPPING)
2037 continue;
2038 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2039 if (kctl == NULL)
2040 continue;
2041 u = knew->subdevice;
2042 for (j = 0; j < 4; j++, u >>= 8) {
2043 nid = u & 0x3f;
2044 if (nid == 0)
2045 continue;
2046 switch (u & 0xc0) {
2047 case SUBDEV_SPEAKER_:
2048 nid = spec->autocfg.speaker_pins[nid];
2049 break;
2050 case SUBDEV_LINE_:
2051 nid = spec->autocfg.line_out_pins[nid];
2052 break;
2053 case SUBDEV_HP_:
2054 nid = spec->autocfg.hp_pins[nid];
2055 break;
2056 default:
2057 continue;
2058 }
2059 err = snd_hda_add_nid(codec, kctl, 0, nid);
2060 if (err < 0)
2061 return err;
2062 }
2063 u = knew->private_value;
2064 for (j = 0; j < 4; j++, u >>= 8) {
2065 nid = u & 0xff;
2066 if (nid == 0)
2067 continue;
2068 err = snd_hda_add_nid(codec, kctl, 0, nid);
2069 if (err < 0)
2070 return err;
2071 }
2072 }
2073 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002074
2075 alc_free_kctls(codec); /* no longer needed */
2076
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 return 0;
2078}
2079
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002082 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002083 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002084
Takashi Iwai584c0c42011-03-10 12:51:11 +01002085static void alc_init_special_input_src(struct hda_codec *codec);
2086
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087static int alc_init(struct hda_codec *codec)
2088{
2089 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002090 unsigned int i;
2091
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002092 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002093 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002094
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002095 for (i = 0; i < spec->num_init_verbs; i++)
2096 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002097 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002098
2099 if (spec->init_hook)
2100 spec->init_hook(codec);
2101
Takashi Iwai58701122011-01-13 15:41:45 +01002102 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2103
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002104 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 return 0;
2106}
2107
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002108static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2109{
2110 struct alc_spec *spec = codec->spec;
2111
2112 if (spec->unsol_event)
2113 spec->unsol_event(codec, res);
2114}
2115
Takashi Iwaicb53c622007-08-10 17:21:45 +02002116#ifdef CONFIG_SND_HDA_POWER_SAVE
2117static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2118{
2119 struct alc_spec *spec = codec->spec;
2120 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2121}
2122#endif
2123
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124/*
2125 * Analog playback callbacks
2126 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002127static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002129 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130{
2131 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002132 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2133 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002134}
2135
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002136static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 struct hda_codec *codec,
2138 unsigned int stream_tag,
2139 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002140 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141{
2142 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002143 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2144 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145}
2146
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002147static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002149 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
2151 struct alc_spec *spec = codec->spec;
2152 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2153}
2154
2155/*
2156 * Digital out
2157 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002158static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002160 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161{
2162 struct alc_spec *spec = codec->spec;
2163 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2164}
2165
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002166static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002167 struct hda_codec *codec,
2168 unsigned int stream_tag,
2169 unsigned int format,
2170 struct snd_pcm_substream *substream)
2171{
2172 struct alc_spec *spec = codec->spec;
2173 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2174 stream_tag, format, substream);
2175}
2176
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002177static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002178 struct hda_codec *codec,
2179 struct snd_pcm_substream *substream)
2180{
2181 struct alc_spec *spec = codec->spec;
2182 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2183}
2184
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002185static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 struct hda_codec *codec,
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 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2191}
2192
2193/*
2194 * Analog capture
2195 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002196static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197 struct hda_codec *codec,
2198 unsigned int stream_tag,
2199 unsigned int format,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002200 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201{
2202 struct alc_spec *spec = codec->spec;
2203
Takashi Iwai63300792008-01-24 15:31:36 +01002204 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 stream_tag, 0, format);
2206 return 0;
2207}
2208
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002209static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 struct hda_codec *codec,
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002211 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212{
2213 struct alc_spec *spec = codec->spec;
2214
Takashi Iwai888afa12008-03-18 09:57:50 +01002215 snd_hda_codec_cleanup_stream(codec,
2216 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 return 0;
2218}
2219
Takashi Iwai840b64c2010-07-13 22:49:01 +02002220/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002221static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002222 struct hda_codec *codec,
2223 unsigned int stream_tag,
2224 unsigned int format,
2225 struct snd_pcm_substream *substream)
2226{
2227 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002228 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002229 spec->cur_adc_stream_tag = stream_tag;
2230 spec->cur_adc_format = format;
2231 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2232 return 0;
2233}
2234
Takashi Iwai21268962011-07-07 15:01:13 +02002235static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002236 struct hda_codec *codec,
2237 struct snd_pcm_substream *substream)
2238{
2239 struct alc_spec *spec = codec->spec;
2240 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2241 spec->cur_adc = 0;
2242 return 0;
2243}
2244
Takashi Iwai21268962011-07-07 15:01:13 +02002245static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002246 .substreams = 1,
2247 .channels_min = 2,
2248 .channels_max = 2,
2249 .nid = 0, /* fill later */
2250 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002251 .prepare = dyn_adc_capture_pcm_prepare,
2252 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002253 },
2254};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255
2256/*
2257 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002258static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 .substreams = 1,
2260 .channels_min = 2,
2261 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002262 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002264 .open = alc_playback_pcm_open,
2265 .prepare = alc_playback_pcm_prepare,
2266 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 },
2268};
2269
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002270static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002271 .substreams = 1,
2272 .channels_min = 2,
2273 .channels_max = 2,
2274 /* NID is set in alc_build_pcms */
2275};
2276
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002277static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002278 .substreams = 1,
2279 .channels_min = 2,
2280 .channels_max = 2,
2281 /* NID is set in alc_build_pcms */
2282};
2283
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002284static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002285 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 .channels_min = 2,
2287 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002288 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002290 .prepare = alc_alt_capture_pcm_prepare,
2291 .cleanup = alc_alt_capture_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_playback = {
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 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002301 .open = alc_dig_playback_pcm_open,
2302 .close = alc_dig_playback_pcm_close,
2303 .prepare = alc_dig_playback_pcm_prepare,
2304 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 },
2306};
2307
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002308static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 .substreams = 1,
2310 .channels_min = 2,
2311 .channels_max = 2,
2312 /* NID is set in alc_build_pcms */
2313};
2314
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002315/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002316static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002317 .substreams = 0,
2318 .channels_min = 0,
2319 .channels_max = 0,
2320};
2321
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322static int alc_build_pcms(struct hda_codec *codec)
2323{
2324 struct alc_spec *spec = codec->spec;
2325 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002326 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002327 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 int i;
2329
2330 codec->num_pcms = 1;
2331 codec->pcm_info = info;
2332
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002333 if (spec->no_analog)
2334 goto skip_analog;
2335
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002336 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2337 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002339
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002340 if (spec->multiout.dac_nids > 0) {
2341 p = spec->stream_analog_playback;
2342 if (!p)
2343 p = &alc_pcm_analog_playback;
2344 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002345 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2346 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002347 if (spec->adc_nids) {
2348 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002349 if (!p) {
2350 if (spec->dyn_adc_switch)
2351 p = &dyn_adc_pcm_analog_capture;
2352 else
2353 p = &alc_pcm_analog_capture;
2354 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002355 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002356 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2357 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358
Takashi Iwai4a471b72005-12-07 13:56:29 +01002359 if (spec->channel_mode) {
2360 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2361 for (i = 0; i < spec->num_channel_mode; i++) {
2362 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2363 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 }
2366 }
2367
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002368 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002369 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002371 snprintf(spec->stream_name_digital,
2372 sizeof(spec->stream_name_digital),
2373 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002374 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002375 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002376 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002378 if (spec->dig_out_type)
2379 info->pcm_type = spec->dig_out_type;
2380 else
2381 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002382 if (spec->multiout.dig_out_nid) {
2383 p = spec->stream_digital_playback;
2384 if (!p)
2385 p = &alc_pcm_digital_playback;
2386 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2388 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002389 if (spec->dig_in_nid) {
2390 p = spec->stream_digital_capture;
2391 if (!p)
2392 p = &alc_pcm_digital_capture;
2393 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2395 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002396 /* FIXME: do we need this for all Realtek codec models? */
2397 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 }
2399
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002400 if (spec->no_analog)
2401 return 0;
2402
Takashi Iwaie08a0072006-09-07 17:52:14 +02002403 /* If the use of more than one ADC is requested for the current
2404 * model, configure a second analog capture-only PCM.
2405 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002406 have_multi_adcs = (spec->num_adc_nids > 1) &&
2407 !spec->dyn_adc_switch && !spec->auto_mic &&
2408 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002409 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002410 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002411 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002412 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002413 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002414 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002415 p = spec->stream_analog_alt_playback;
2416 if (!p)
2417 p = &alc_pcm_analog_alt_playback;
2418 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002419 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2420 spec->alt_dac_nid;
2421 } else {
2422 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2423 alc_pcm_null_stream;
2424 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2425 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002426 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002427 p = spec->stream_analog_alt_capture;
2428 if (!p)
2429 p = &alc_pcm_analog_alt_capture;
2430 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002431 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2432 spec->adc_nids[1];
2433 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2434 spec->num_adc_nids - 1;
2435 } else {
2436 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2437 alc_pcm_null_stream;
2438 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002439 }
2440 }
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 return 0;
2443}
2444
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002445static inline void alc_shutup(struct hda_codec *codec)
2446{
Takashi Iwai1c716152011-04-07 10:37:16 +02002447 struct alc_spec *spec = codec->spec;
2448
2449 if (spec && spec->shutup)
2450 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002451 snd_hda_shutup_pins(codec);
2452}
2453
Takashi Iwai603c4012008-07-30 15:01:44 +02002454static void alc_free_kctls(struct hda_codec *codec)
2455{
2456 struct alc_spec *spec = codec->spec;
2457
2458 if (spec->kctls.list) {
2459 struct snd_kcontrol_new *kctl = spec->kctls.list;
2460 int i;
2461 for (i = 0; i < spec->kctls.used; i++)
2462 kfree(kctl[i].name);
2463 }
2464 snd_array_free(&spec->kctls);
2465}
2466
Takashi Iwai23c09b02011-08-19 09:05:35 +02002467static void alc_free_bind_ctls(struct hda_codec *codec)
2468{
2469 struct alc_spec *spec = codec->spec;
2470 if (spec->bind_ctls.list) {
2471 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2472 int i;
2473 for (i = 0; i < spec->bind_ctls.used; i++)
2474 kfree(ctl[i]);
2475 }
2476 snd_array_free(&spec->bind_ctls);
2477}
2478
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479static void alc_free(struct hda_codec *codec)
2480{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002481 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002482
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002483 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002484 return;
2485
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002486 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002487 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002488 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002489 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002490 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002491 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492}
2493
Hector Martinf5de24b2009-12-20 22:51:31 +01002494#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002495static void alc_power_eapd(struct hda_codec *codec)
2496{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002497 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002498}
2499
Hector Martinf5de24b2009-12-20 22:51:31 +01002500static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2501{
2502 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002503 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002504 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002505 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002506 return 0;
2507}
2508#endif
2509
Takashi Iwai2a439522011-07-26 09:52:50 +02002510#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002511static int alc_resume(struct hda_codec *codec)
2512{
Takashi Iwai1c716152011-04-07 10:37:16 +02002513 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002514 codec->patch_ops.init(codec);
2515 snd_hda_codec_resume_amp(codec);
2516 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002517 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002518 return 0;
2519}
Takashi Iwaie044c392008-10-27 16:56:24 +01002520#endif
2521
Linus Torvalds1da177e2005-04-16 15:20:36 -07002522/*
2523 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002524static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525 .build_controls = alc_build_controls,
2526 .build_pcms = alc_build_pcms,
2527 .init = alc_init,
2528 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002529 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002530#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002531 .resume = alc_resume,
2532#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002533#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002534 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002535 .check_power_status = alc_check_power_status,
2536#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002537 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538};
2539
Kailang Yangc027ddc2010-03-19 11:33:06 +01002540/* replace the codec chip_name with the given string */
2541static int alc_codec_rename(struct hda_codec *codec, const char *name)
2542{
2543 kfree(codec->chip_name);
2544 codec->chip_name = kstrdup(name, GFP_KERNEL);
2545 if (!codec->chip_name) {
2546 alc_free(codec);
2547 return -ENOMEM;
2548 }
2549 return 0;
2550}
2551
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002552/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002553 * Rename codecs appropriately from COEF value
2554 */
2555struct alc_codec_rename_table {
2556 unsigned int vendor_id;
2557 unsigned short coef_mask;
2558 unsigned short coef_bits;
2559 const char *name;
2560};
2561
2562static struct alc_codec_rename_table rename_tbl[] = {
2563 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2564 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2565 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2566 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2567 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2568 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2569 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2570 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2571 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2572 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2573 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2574 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2575 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2576 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2577 { } /* terminator */
2578};
2579
2580static int alc_codec_rename_from_preset(struct hda_codec *codec)
2581{
2582 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002583
2584 for (p = rename_tbl; p->vendor_id; p++) {
2585 if (p->vendor_id != codec->vendor_id)
2586 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002587 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002588 return alc_codec_rename(codec, p->name);
2589 }
2590 return 0;
2591}
2592
2593/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002594 * Automatic parse of I/O pins from the BIOS configuration
2595 */
2596
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002597enum {
2598 ALC_CTL_WIDGET_VOL,
2599 ALC_CTL_WIDGET_MUTE,
2600 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002601 ALC_CTL_BIND_VOL,
2602 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002603};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002604static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002605 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2606 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002607 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002608 HDA_BIND_VOL(NULL, 0),
2609 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002610};
2611
2612/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002613static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002614 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002615{
Takashi Iwaic8b6bf9b2005-11-17 14:57:47 +01002616 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002617
Takashi Iwaice764ab2011-04-27 16:35:23 +02002618 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002619 if (!knew)
2620 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002621 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002622 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002623 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002624 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002625 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002626 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002627 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002628 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002629 return 0;
2630}
2631
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002632static int add_control_with_pfx(struct alc_spec *spec, int type,
2633 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002634 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002635{
2636 char name[32];
2637 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002638 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002639}
2640
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002641#define add_pb_vol_ctrl(spec, type, pfx, val) \
2642 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2643#define add_pb_sw_ctrl(spec, type, pfx, val) \
2644 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2645#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2646 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2647#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2648 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002649
Takashi Iwai23c09b02011-08-19 09:05:35 +02002650static const char * const channel_name[4] = {
2651 "Front", "Surround", "CLFE", "Side"
2652};
2653
Takashi Iwai6843ca12011-06-24 11:03:58 +02002654static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2655 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002656{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002657 struct auto_pin_cfg *cfg = &spec->autocfg;
2658
Takashi Iwai6843ca12011-06-24 11:03:58 +02002659 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002660 if (cfg->line_outs == 1 && !spec->multi_ios &&
2661 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002662 return "Master";
2663
2664 switch (cfg->line_out_type) {
2665 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002666 if (cfg->line_outs == 1)
2667 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002668 if (cfg->line_outs == 2)
2669 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002670 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002671 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002672 /* for multi-io case, only the primary out */
2673 if (ch && spec->multi_ios)
2674 break;
2675 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002676 return "Headphone";
2677 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002678 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002679 return "PCM";
2680 break;
2681 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002682 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2683 return "PCM";
2684
2685 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002686}
2687
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002688/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002689static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002690 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002691 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002692{
Kailang Yangdf694da2005-12-05 19:42:22 +01002693 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002694
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002695 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002696 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2697 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002698 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002699 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002700 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2701 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002702 return err;
2703 return 0;
2704}
2705
Takashi Iwai05f5f472009-08-25 13:10:18 +02002706static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002707{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002708 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2709 return (pincap & AC_PINCAP_IN) != 0;
2710}
2711
Takashi Iwai1d045db2011-07-07 18:23:21 +02002712/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002713static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002714{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002715 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002716 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002717 hda_nid_t *adc_nids = spec->private_adc_nids;
2718 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2719 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002720 int i, nums = 0;
2721
Takashi Iwai24de1832011-11-07 17:13:39 +01002722 if (spec->shared_mic_hp)
2723 max_nums = 1; /* no multi streams with the shared HP/mic */
2724
Takashi Iwaib7821702011-07-06 15:12:46 +02002725 nid = codec->start_nid;
2726 for (i = 0; i < codec->num_nodes; i++, nid++) {
2727 hda_nid_t src;
2728 const hda_nid_t *list;
2729 unsigned int caps = get_wcaps(codec, nid);
2730 int type = get_wcaps_type(caps);
2731
2732 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2733 continue;
2734 adc_nids[nums] = nid;
2735 cap_nids[nums] = nid;
2736 src = nid;
2737 for (;;) {
2738 int n;
2739 type = get_wcaps_type(get_wcaps(codec, src));
2740 if (type == AC_WID_PIN)
2741 break;
2742 if (type == AC_WID_AUD_SEL) {
2743 cap_nids[nums] = src;
2744 break;
2745 }
2746 n = snd_hda_get_conn_list(codec, src, &list);
2747 if (n > 1) {
2748 cap_nids[nums] = src;
2749 break;
2750 } else if (n != 1)
2751 break;
2752 src = *list;
2753 }
2754 if (++nums >= max_nums)
2755 break;
2756 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002757 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002758 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002759 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002760 return nums;
2761}
2762
Takashi Iwai05f5f472009-08-25 13:10:18 +02002763/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002764static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002765{
2766 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002767 const struct auto_pin_cfg *cfg = &spec->autocfg;
2768 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002769 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002770 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002771 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002772 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002773
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002774 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002775 if (num_adcs < 0)
2776 return 0;
2777
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002778 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002779 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002780 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002781
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002782 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002783 if (!alc_is_input_pin(codec, pin))
2784 continue;
2785
David Henningsson5322bf22011-01-05 11:03:56 +01002786 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002787 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2788 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002789 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002790 type_idx++;
2791 else
2792 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002793 prev_label = label;
2794
Takashi Iwai05f5f472009-08-25 13:10:18 +02002795 if (mixer) {
2796 idx = get_connection_index(codec, mixer, pin);
2797 if (idx >= 0) {
2798 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002799 label, type_idx,
2800 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002801 if (err < 0)
2802 return err;
2803 }
2804 }
2805
Takashi Iwaib7821702011-07-06 15:12:46 +02002806 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002807 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002808 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002809 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002810 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002811 snd_hda_add_imux_item(imux, label, idx, NULL);
2812 break;
2813 }
2814 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002815 }
Takashi Iwai21268962011-07-07 15:01:13 +02002816
2817 spec->num_mux_defs = 1;
2818 spec->input_mux = imux;
2819
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002820 return 0;
2821}
2822
Takashi Iwai24de1832011-11-07 17:13:39 +01002823/* create a shared input with the headphone out */
2824static int alc_auto_create_shared_input(struct hda_codec *codec)
2825{
2826 struct alc_spec *spec = codec->spec;
2827 struct auto_pin_cfg *cfg = &spec->autocfg;
2828 unsigned int defcfg;
2829 hda_nid_t nid;
2830
2831 /* only one internal input pin? */
2832 if (cfg->num_inputs != 1)
2833 return 0;
2834 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2835 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2836 return 0;
2837
2838 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2839 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2840 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2841 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2842 else
2843 return 0; /* both not available */
2844
2845 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2846 return 0; /* no input */
2847
2848 cfg->inputs[1].pin = nid;
2849 cfg->inputs[1].type = AUTO_PIN_MIC;
2850 cfg->num_inputs = 2;
2851 spec->shared_mic_hp = 1;
2852 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2853 return 0;
2854}
2855
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002856static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2857 unsigned int pin_type)
2858{
2859 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2860 pin_type);
2861 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002862 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2863 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002864 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002865}
2866
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002867static int get_pin_type(int line_out_type)
2868{
2869 if (line_out_type == AUTO_PIN_HP_OUT)
2870 return PIN_HP;
2871 else
2872 return PIN_OUT;
2873}
2874
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002875static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002876{
2877 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002878 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002879 int i;
2880
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002881 for (i = 0; i < cfg->num_inputs; i++) {
2882 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002883 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002884 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002885 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002886 snd_hda_codec_write(codec, nid, 0,
2887 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002888 AMP_OUT_MUTE);
2889 }
2890 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002891
2892 /* mute all loopback inputs */
2893 if (spec->mixer_nid) {
2894 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2895 for (i = 0; i < nums; i++)
2896 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2897 AC_VERB_SET_AMP_GAIN_MUTE,
2898 AMP_IN_MUTE(i));
2899 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002900}
2901
Takashi Iwai7085ec12009-10-02 09:03:58 +02002902/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002903static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002904{
Takashi Iwai604401a2011-04-27 15:14:23 +02002905 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002906 int i, num;
2907
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002908 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2909 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002910 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2911 for (i = 0; i < num; i++) {
2912 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2913 return list[i];
2914 }
2915 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002916}
2917
Takashi Iwai604401a2011-04-27 15:14:23 +02002918/* go down to the selector widget before the mixer */
2919static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2920{
2921 hda_nid_t srcs[5];
2922 int num = snd_hda_get_connections(codec, pin, srcs,
2923 ARRAY_SIZE(srcs));
2924 if (num != 1 ||
2925 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2926 return pin;
2927 return srcs[0];
2928}
2929
Takashi Iwai7085ec12009-10-02 09:03:58 +02002930/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002931static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002932 hda_nid_t dac)
2933{
David Henningssoncc1c4522010-11-24 14:17:47 +01002934 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002935 int i, num;
2936
Takashi Iwai604401a2011-04-27 15:14:23 +02002937 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002938 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2939 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002940 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002941 return mix[i];
2942 }
2943 return 0;
2944}
2945
Takashi Iwaice764ab2011-04-27 16:35:23 +02002946/* select the connection from pin to DAC if needed */
2947static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2948 hda_nid_t dac)
2949{
2950 hda_nid_t mix[5];
2951 int i, num;
2952
2953 pin = alc_go_down_to_selector(codec, pin);
2954 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2955 if (num < 2)
2956 return 0;
2957 for (i = 0; i < num; i++) {
2958 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2959 snd_hda_codec_update_cache(codec, pin, 0,
2960 AC_VERB_SET_CONNECT_SEL, i);
2961 return 0;
2962 }
2963 }
2964 return 0;
2965}
2966
Takashi Iwai7085ec12009-10-02 09:03:58 +02002967/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002968static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002969{
2970 struct alc_spec *spec = codec->spec;
2971 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002972 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002973
Takashi Iwai604401a2011-04-27 15:14:23 +02002974 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002975 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002976 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002977 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002978 if (!nid)
2979 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002980 if (found_in_nid_list(nid, spec->multiout.dac_nids,
Takashi Iwai0a34b422011-12-07 17:20:30 +01002981 ARRAY_SIZE(spec->private_dac_nids)))
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002982 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002983 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2984 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2985 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002986 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2987 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2988 continue;
2989 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002990 }
2991 return 0;
2992}
2993
Takashi Iwai07b18f62011-11-10 15:42:54 +01002994/* check whether the DAC is reachable from the pin */
2995static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2996 hda_nid_t pin, hda_nid_t dac)
2997{
2998 hda_nid_t srcs[5];
2999 int i, num;
3000
3001 pin = alc_go_down_to_selector(codec, pin);
3002 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
3003 for (i = 0; i < num; i++) {
3004 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3005 if (nid == dac)
3006 return true;
3007 }
3008 return false;
3009}
3010
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003011static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3012{
3013 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
3014 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
3015 return alc_auto_look_for_dac(codec, pin);
3016 return 0;
3017}
3018
Takashi Iwai0a34b422011-12-07 17:20:30 +01003019/* return 0 if no possible DAC is found, 1 if one or more found */
Takashi Iwaic2674682011-08-24 17:57:44 +02003020static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3021 const hda_nid_t *pins, hda_nid_t *dacs)
3022{
3023 int i;
3024
3025 if (num_outs && !dacs[0]) {
3026 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3027 if (!dacs[0])
3028 return 0;
3029 }
3030
3031 for (i = 1; i < num_outs; i++)
3032 dacs[i] = get_dac_if_single(codec, pins[i]);
3033 for (i = 1; i < num_outs; i++) {
3034 if (!dacs[i])
3035 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3036 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003037 return 1;
Takashi Iwaic2674682011-08-24 17:57:44 +02003038}
3039
3040static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003041 unsigned int location, int offset);
David Henningssonfde48a12011-12-09 18:27:42 +08003042static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3043 hda_nid_t pin, hda_nid_t dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003044
Takashi Iwai7085ec12009-10-02 09:03:58 +02003045/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003046static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003047{
3048 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003049 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003050 unsigned int location, defcfg;
3051 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003052 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003053 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003054
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003055 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003056 /* set num_dacs once to full for alc_auto_look_for_dac() */
3057 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003058 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003059 spec->multiout.extra_out_nid[0] = 0;
3060 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3061 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003062 spec->multi_ios = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003063
3064 /* fill hard-wired DACs first */
3065 if (!redone) {
3066 for (i = 0; i < cfg->line_outs; i++)
3067 spec->private_dac_nids[i] =
3068 get_dac_if_single(codec, cfg->line_out_pins[i]);
3069 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003070 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003071 get_dac_if_single(codec, cfg->hp_pins[0]);
3072 if (cfg->speaker_outs)
3073 spec->multiout.extra_out_nid[0] =
3074 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003075 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003076
3077 for (i = 0; i < cfg->line_outs; i++) {
3078 hda_nid_t pin = cfg->line_out_pins[i];
3079 if (spec->private_dac_nids[i])
3080 continue;
3081 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3082 if (!spec->private_dac_nids[i] && !redone) {
3083 /* if we can't find primary DACs, re-probe without
3084 * checking the hard-wired DACs
3085 */
3086 redone = true;
3087 goto again;
3088 }
3089 }
3090
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003091 /* re-count num_dacs and squash invalid entries */
3092 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003093 for (i = 0; i < cfg->line_outs; i++) {
3094 if (spec->private_dac_nids[i])
3095 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003096 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003097 memmove(spec->private_dac_nids + i,
3098 spec->private_dac_nids + i + 1,
3099 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003100 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3101 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003102 }
3103
Takashi Iwaic2674682011-08-24 17:57:44 +02003104 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3105 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003106 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3107 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003108
Takashi Iwai07b18f62011-11-10 15:42:54 +01003109 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003110 if (num_pins > 0) {
3111 spec->multi_ios = num_pins;
3112 spec->ext_channel_count = 2;
3113 spec->multiout.num_dacs = num_pins + 1;
3114 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003115 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003116
Takashi Iwai716eef02011-10-21 15:07:42 +02003117 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3118 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003119 spec->multiout.hp_out_nid);
Takashi Iwai0a34b422011-12-07 17:20:30 +01003120 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3121 int err = alc_auto_fill_extra_dacs(codec, cfg->speaker_outs,
3122 cfg->speaker_pins,
3123 spec->multiout.extra_out_nid);
3124 /* if no speaker volume is assigned, try again as the primary
3125 * output
3126 */
3127 if (!err && cfg->speaker_outs > 0 &&
3128 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3129 cfg->hp_outs = cfg->line_outs;
3130 memcpy(cfg->hp_pins, cfg->line_out_pins,
3131 sizeof(cfg->hp_pins));
3132 cfg->line_outs = cfg->speaker_outs;
3133 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3134 sizeof(cfg->speaker_pins));
3135 cfg->speaker_outs = 0;
3136 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3137 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
3138 redone = false;
3139 goto again;
3140 }
3141 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003142
Takashi Iwai07b18f62011-11-10 15:42:54 +01003143 if (!spec->multi_ios &&
3144 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3145 cfg->hp_outs) {
3146 /* try multi-ios with HP + inputs */
3147 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3148 location = get_defcfg_location(defcfg);
3149
3150 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3151 if (num_pins > 0) {
3152 spec->multi_ios = num_pins;
3153 spec->ext_channel_count = 2;
3154 spec->multiout.num_dacs = num_pins + 1;
3155 }
3156 }
3157
David Henningssonfde48a12011-12-09 18:27:42 +08003158 if (cfg->line_out_pins[0])
3159 spec->vmaster_nid =
3160 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3161 spec->multiout.dac_nids[0]);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003162 return 0;
3163}
3164
Takashi Iwai527e4d72011-10-27 16:33:27 +02003165static inline unsigned int get_ctl_pos(unsigned int data)
3166{
3167 hda_nid_t nid = get_amp_nid_(data);
3168 unsigned int dir = get_amp_direction_(data);
3169 return (nid << 1) | dir;
3170}
3171
3172#define is_ctl_used(bits, data) \
3173 test_bit(get_ctl_pos(data), bits)
3174#define mark_ctl_usage(bits, data) \
3175 set_bit(get_ctl_pos(data), bits)
3176
Takashi Iwai343a04b2011-07-06 14:28:39 +02003177static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003178 const char *pfx, int cidx,
3179 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003180{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003181 struct alc_spec *spec = codec->spec;
3182 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003183 if (!nid)
3184 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003185 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3186 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3187 return 0;
3188 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003189 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003190 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003191}
3192
Takashi Iwaie29d3772011-11-14 17:13:23 +01003193static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3194 const char *pfx, int cidx,
3195 hda_nid_t nid)
3196{
3197 int chs = 1;
3198 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3199 chs = 3;
3200 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3201}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003202
3203/* create a mute-switch for the given mixer widget;
3204 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3205 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003206static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003207 const char *pfx, int cidx,
3208 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003209{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003210 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003211 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003212 int type;
3213 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003214 if (!nid)
3215 return 0;
3216 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3217 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3218 type = ALC_CTL_WIDGET_MUTE;
3219 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3220 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003221 type = ALC_CTL_WIDGET_MUTE;
3222 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3223 } else {
3224 type = ALC_CTL_BIND_MUTE;
3225 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3226 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003227 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3228 return 0;
3229 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003230 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003231}
3232
Takashi Iwaie29d3772011-11-14 17:13:23 +01003233static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3234 int cidx, hda_nid_t nid)
3235{
3236 int chs = 1;
3237 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3238 chs = 3;
3239 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3240}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003241
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003242static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3243 hda_nid_t pin, hda_nid_t dac)
3244{
3245 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3246 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3247 return pin;
3248 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3249 return mix;
3250 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3251 return dac;
3252 return 0;
3253}
3254
3255static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3256 hda_nid_t pin, hda_nid_t dac)
3257{
3258 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3259 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3260 return dac;
3261 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3262 return mix;
3263 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3264 return pin;
3265 return 0;
3266}
3267
Takashi Iwai7085ec12009-10-02 09:03:58 +02003268/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003269static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003270 const struct auto_pin_cfg *cfg)
3271{
3272 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003273 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003274
Takashi Iwaice764ab2011-04-27 16:35:23 +02003275 noutputs = cfg->line_outs;
3276 if (spec->multi_ios > 0)
3277 noutputs += spec->multi_ios;
3278
3279 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003280 const char *name;
3281 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003282 hda_nid_t dac, pin;
3283 hda_nid_t sw, vol;
3284
3285 dac = spec->multiout.dac_nids[i];
3286 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003287 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003288 if (i >= cfg->line_outs)
3289 pin = spec->multi_io[i - 1].pin;
3290 else
3291 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003292
3293 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3294 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003295 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003296 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003297 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003298 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003299 if (err < 0)
3300 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003301 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003302 if (err < 0)
3303 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003304 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003305 if (err < 0)
3306 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003307 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003308 if (err < 0)
3309 return err;
3310 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003311 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003312 if (err < 0)
3313 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003314 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003315 if (err < 0)
3316 return err;
3317 }
3318 }
3319 return 0;
3320}
3321
Takashi Iwai343a04b2011-07-06 14:28:39 +02003322static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003323 hda_nid_t dac, const char *pfx,
3324 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003325{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003326 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003327 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003328 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003329
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003330 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003331 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003332 /* the corresponding DAC is already occupied */
3333 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3334 return 0; /* no way */
3335 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003336 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3337 if (is_ctl_used(spec->sw_ctls, val))
3338 return 0; /* already created */
3339 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003340 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003341 }
3342
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003343 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3344 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003345 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003346 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003347 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003348 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003349 if (err < 0)
3350 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003351 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003352}
3353
Takashi Iwai23c09b02011-08-19 09:05:35 +02003354static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3355 unsigned int nums,
3356 struct hda_ctl_ops *ops)
3357{
3358 struct alc_spec *spec = codec->spec;
3359 struct hda_bind_ctls **ctlp, *ctl;
3360 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3361 ctlp = snd_array_new(&spec->bind_ctls);
3362 if (!ctlp)
3363 return NULL;
3364 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3365 *ctlp = ctl;
3366 if (ctl)
3367 ctl->ops = ops;
3368 return ctl;
3369}
3370
3371/* add playback controls for speaker and HP outputs */
3372static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3373 const hda_nid_t *pins,
3374 const hda_nid_t *dacs,
3375 const char *pfx)
3376{
3377 struct alc_spec *spec = codec->spec;
3378 struct hda_bind_ctls *ctl;
3379 char name[32];
3380 int i, n, err;
3381
3382 if (!num_pins || !pins[0])
3383 return 0;
3384
Takashi Iwai527e4d72011-10-27 16:33:27 +02003385 if (num_pins == 1) {
3386 hda_nid_t dac = *dacs;
3387 if (!dac)
3388 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003389 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003390 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003391
3392 if (dacs[num_pins - 1]) {
3393 /* OK, we have a multi-output system with individual volumes */
3394 for (i = 0; i < num_pins; i++) {
Takashi Iwai766ddee2011-12-07 16:55:19 +01003395 if (num_pins >= 3) {
3396 snprintf(name, sizeof(name), "%s %s",
3397 pfx, channel_name[i]);
3398 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3399 name, 0);
3400 } else {
3401 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3402 pfx, i);
3403 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003404 if (err < 0)
3405 return err;
3406 }
3407 return 0;
3408 }
3409
3410 /* Let's create a bind-controls */
3411 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3412 if (!ctl)
3413 return -ENOMEM;
3414 n = 0;
3415 for (i = 0; i < num_pins; i++) {
3416 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3417 ctl->values[n++] =
3418 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3419 }
3420 if (n) {
3421 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3422 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3423 if (err < 0)
3424 return err;
3425 }
3426
3427 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3428 if (!ctl)
3429 return -ENOMEM;
3430 n = 0;
3431 for (i = 0; i < num_pins; i++) {
3432 hda_nid_t vol;
3433 if (!pins[i] || !dacs[i])
3434 continue;
3435 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3436 if (vol)
3437 ctl->values[n++] =
3438 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3439 }
3440 if (n) {
3441 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3442 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3443 if (err < 0)
3444 return err;
3445 }
3446 return 0;
3447}
3448
Takashi Iwai343a04b2011-07-06 14:28:39 +02003449static int alc_auto_create_hp_out(struct hda_codec *codec)
3450{
3451 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003452 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3453 spec->autocfg.hp_pins,
3454 spec->multiout.hp_out_nid,
3455 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003456}
3457
3458static int alc_auto_create_speaker_out(struct hda_codec *codec)
3459{
3460 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003461 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3462 spec->autocfg.speaker_pins,
3463 spec->multiout.extra_out_nid,
3464 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003465}
3466
Takashi Iwai343a04b2011-07-06 14:28:39 +02003467static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003468 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003469 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003470{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003471 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003472 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003473 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003474
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003475 alc_set_pin_output(codec, pin, pin_type);
3476 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003477 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003478 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003479 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003480 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003481 mix = srcs[i];
3482 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003483 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003484 if (!mix)
3485 return;
3486
3487 /* need the manual connection? */
3488 if (num > 1)
3489 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3490 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003491 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3492 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003493 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003494 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003495 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003496 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003497 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003498 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3499 if (nid)
3500 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3501 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003502
3503 /* unmute DAC if it's not assigned to a mixer */
3504 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3505 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3506 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3507 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003508}
3509
Takashi Iwai343a04b2011-07-06 14:28:39 +02003510static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003511{
3512 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003513 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003514 int i;
3515
3516 for (i = 0; i <= HDA_SIDE; i++) {
3517 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3518 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003519 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003520 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003521 }
3522}
3523
Takashi Iwai343a04b2011-07-06 14:28:39 +02003524static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003525{
3526 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003527 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003528 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003529
David Henningsson636030e2011-10-12 19:26:03 +02003530 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003531 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3532 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003533 pin = spec->autocfg.hp_pins[i];
3534 if (!pin)
3535 break;
3536 dac = spec->multiout.hp_out_nid[i];
3537 if (!dac) {
3538 if (i > 0 && spec->multiout.hp_out_nid[0])
3539 dac = spec->multiout.hp_out_nid[0];
3540 else
3541 dac = spec->multiout.dac_nids[0];
3542 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003543 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3544 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003545 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003546 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3547 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003548 pin = spec->autocfg.speaker_pins[i];
3549 if (!pin)
3550 break;
3551 dac = spec->multiout.extra_out_nid[i];
3552 if (!dac) {
3553 if (i > 0 && spec->multiout.extra_out_nid[0])
3554 dac = spec->multiout.extra_out_nid[0];
3555 else
3556 dac = spec->multiout.dac_nids[0];
3557 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003558 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3559 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003560}
3561
Takashi Iwaice764ab2011-04-27 16:35:23 +02003562/*
3563 * multi-io helper
3564 */
3565static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003566 unsigned int location,
3567 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003568{
3569 struct alc_spec *spec = codec->spec;
3570 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003571 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003572 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003573
Takashi Iwai07b18f62011-11-10 15:42:54 +01003574 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003575 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3576 for (i = 0; i < cfg->num_inputs; i++) {
3577 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003578 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003579 unsigned int defcfg, caps;
3580 if (cfg->inputs[i].type != type)
3581 continue;
3582 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3583 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3584 continue;
3585 if (location && get_defcfg_location(defcfg) != location)
3586 continue;
3587 caps = snd_hda_query_pin_caps(codec, nid);
3588 if (!(caps & AC_PINCAP_OUT))
3589 continue;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003590 if (offset && offset + num_pins < dacs) {
3591 dac = spec->private_dac_nids[offset + num_pins];
3592 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3593 dac = 0;
3594 }
3595 if (!dac)
3596 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003597 if (!dac)
3598 continue;
3599 spec->multi_io[num_pins].pin = nid;
3600 spec->multi_io[num_pins].dac = dac;
3601 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003602 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003603 }
3604 }
Takashi Iwai07b18f62011-11-10 15:42:54 +01003605 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003606 if (num_pins < 2) {
3607 /* clear up again */
Takashi Iwai07b18f62011-11-10 15:42:54 +01003608 memset(spec->private_dac_nids + dacs, 0,
3609 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003610 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003611 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003612 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003613 return num_pins;
3614}
3615
3616static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3617 struct snd_ctl_elem_info *uinfo)
3618{
3619 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3620 struct alc_spec *spec = codec->spec;
3621
3622 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3623 uinfo->count = 1;
3624 uinfo->value.enumerated.items = spec->multi_ios + 1;
3625 if (uinfo->value.enumerated.item > spec->multi_ios)
3626 uinfo->value.enumerated.item = spec->multi_ios;
3627 sprintf(uinfo->value.enumerated.name, "%dch",
3628 (uinfo->value.enumerated.item + 1) * 2);
3629 return 0;
3630}
3631
3632static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3633 struct snd_ctl_elem_value *ucontrol)
3634{
3635 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3636 struct alc_spec *spec = codec->spec;
3637 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3638 return 0;
3639}
3640
3641static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3642{
3643 struct alc_spec *spec = codec->spec;
3644 hda_nid_t nid = spec->multi_io[idx].pin;
3645
3646 if (!spec->multi_io[idx].ctl_in)
3647 spec->multi_io[idx].ctl_in =
3648 snd_hda_codec_read(codec, nid, 0,
3649 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3650 if (output) {
3651 snd_hda_codec_update_cache(codec, nid, 0,
3652 AC_VERB_SET_PIN_WIDGET_CONTROL,
3653 PIN_OUT);
3654 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3655 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3656 HDA_AMP_MUTE, 0);
3657 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3658 } else {
3659 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3660 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3661 HDA_AMP_MUTE, HDA_AMP_MUTE);
3662 snd_hda_codec_update_cache(codec, nid, 0,
3663 AC_VERB_SET_PIN_WIDGET_CONTROL,
3664 spec->multi_io[idx].ctl_in);
3665 }
3666 return 0;
3667}
3668
3669static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3670 struct snd_ctl_elem_value *ucontrol)
3671{
3672 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3673 struct alc_spec *spec = codec->spec;
3674 int i, ch;
3675
3676 ch = ucontrol->value.enumerated.item[0];
3677 if (ch < 0 || ch > spec->multi_ios)
3678 return -EINVAL;
3679 if (ch == (spec->ext_channel_count - 1) / 2)
3680 return 0;
3681 spec->ext_channel_count = (ch + 1) * 2;
3682 for (i = 0; i < spec->multi_ios; i++)
3683 alc_set_multi_io(codec, i, i < ch);
3684 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003685 if (spec->need_dac_fix && !spec->const_channel_count)
3686 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003687 return 1;
3688}
3689
Takashi Iwaia9111322011-05-02 11:30:18 +02003690static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003691 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3692 .name = "Channel Mode",
3693 .info = alc_auto_ch_mode_info,
3694 .get = alc_auto_ch_mode_get,
3695 .put = alc_auto_ch_mode_put,
3696};
3697
Takashi Iwai23c09b02011-08-19 09:05:35 +02003698static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003699{
3700 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003701
Takashi Iwaic2674682011-08-24 17:57:44 +02003702 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003703 struct snd_kcontrol_new *knew;
3704
3705 knew = alc_kcontrol_new(spec);
3706 if (!knew)
3707 return -ENOMEM;
3708 *knew = alc_auto_channel_mode_enum;
3709 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3710 if (!knew->name)
3711 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003712 }
3713 return 0;
3714}
3715
Takashi Iwai1d045db2011-07-07 18:23:21 +02003716/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3717 * active input pins
3718 */
3719static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3720{
3721 struct alc_spec *spec = codec->spec;
3722 const struct hda_input_mux *imux;
3723 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3724 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3725 int i, n, nums;
3726
3727 imux = spec->input_mux;
3728 if (!imux)
3729 return;
3730 if (spec->dyn_adc_switch)
3731 return;
3732
3733 nums = 0;
3734 for (n = 0; n < spec->num_adc_nids; n++) {
3735 hda_nid_t cap = spec->private_capsrc_nids[n];
3736 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3737 for (i = 0; i < imux->num_items; i++) {
3738 hda_nid_t pin = spec->imux_pins[i];
3739 if (pin) {
3740 if (get_connection_index(codec, cap, pin) < 0)
3741 break;
3742 } else if (num_conns <= imux->items[i].index)
3743 break;
3744 }
3745 if (i >= imux->num_items) {
3746 adc_nids[nums] = spec->private_adc_nids[n];
3747 capsrc_nids[nums++] = cap;
3748 }
3749 }
3750 if (!nums) {
3751 /* check whether ADC-switch is possible */
3752 if (!alc_check_dyn_adc_switch(codec)) {
3753 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3754 " using fallback 0x%x\n",
3755 codec->chip_name, spec->private_adc_nids[0]);
3756 spec->num_adc_nids = 1;
3757 spec->auto_mic = 0;
3758 return;
3759 }
3760 } else if (nums != spec->num_adc_nids) {
3761 memcpy(spec->private_adc_nids, adc_nids,
3762 nums * sizeof(hda_nid_t));
3763 memcpy(spec->private_capsrc_nids, capsrc_nids,
3764 nums * sizeof(hda_nid_t));
3765 spec->num_adc_nids = nums;
3766 }
3767
3768 if (spec->auto_mic)
3769 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3770 else if (spec->input_mux->num_items == 1)
3771 spec->num_adc_nids = 1; /* reduce to a single ADC */
3772}
3773
3774/*
3775 * initialize ADC paths
3776 */
3777static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3778{
3779 struct alc_spec *spec = codec->spec;
3780 hda_nid_t nid;
3781
3782 nid = spec->adc_nids[adc_idx];
3783 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003784 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003785 snd_hda_codec_write(codec, nid, 0,
3786 AC_VERB_SET_AMP_GAIN_MUTE,
3787 AMP_IN_MUTE(0));
3788 return;
3789 }
3790 if (!spec->capsrc_nids)
3791 return;
3792 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003793 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003794 snd_hda_codec_write(codec, nid, 0,
3795 AC_VERB_SET_AMP_GAIN_MUTE,
3796 AMP_OUT_MUTE);
3797}
3798
3799static void alc_auto_init_input_src(struct hda_codec *codec)
3800{
3801 struct alc_spec *spec = codec->spec;
3802 int c, nums;
3803
3804 for (c = 0; c < spec->num_adc_nids; c++)
3805 alc_auto_init_adc(codec, c);
3806 if (spec->dyn_adc_switch)
3807 nums = 1;
3808 else
3809 nums = spec->num_adc_nids;
3810 for (c = 0; c < nums; c++)
3811 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3812}
3813
3814/* add mic boosts if needed */
3815static int alc_auto_add_mic_boost(struct hda_codec *codec)
3816{
3817 struct alc_spec *spec = codec->spec;
3818 struct auto_pin_cfg *cfg = &spec->autocfg;
3819 int i, err;
3820 int type_idx = 0;
3821 hda_nid_t nid;
3822 const char *prev_label = NULL;
3823
3824 for (i = 0; i < cfg->num_inputs; i++) {
3825 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3826 break;
3827 nid = cfg->inputs[i].pin;
3828 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3829 const char *label;
3830 char boost_label[32];
3831
3832 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003833 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3834 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003835 if (prev_label && !strcmp(label, prev_label))
3836 type_idx++;
3837 else
3838 type_idx = 0;
3839 prev_label = label;
3840
3841 snprintf(boost_label, sizeof(boost_label),
3842 "%s Boost Volume", label);
3843 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3844 boost_label, type_idx,
3845 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3846 if (err < 0)
3847 return err;
3848 }
3849 }
3850 return 0;
3851}
3852
3853/* select or unmute the given capsrc route */
3854static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3855 int idx)
3856{
3857 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3858 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3859 HDA_AMP_MUTE, 0);
3860 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3861 snd_hda_codec_write_cache(codec, cap, 0,
3862 AC_VERB_SET_CONNECT_SEL, idx);
3863 }
3864}
3865
3866/* set the default connection to that pin */
3867static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3868{
3869 struct alc_spec *spec = codec->spec;
3870 int i;
3871
3872 if (!pin)
3873 return 0;
3874 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01003875 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003876 int idx;
3877
3878 idx = get_connection_index(codec, cap, pin);
3879 if (idx < 0)
3880 continue;
3881 select_or_unmute_capsrc(codec, cap, idx);
3882 return i; /* return the found index */
3883 }
3884 return -1; /* not found */
3885}
3886
3887/* initialize some special cases for input sources */
3888static void alc_init_special_input_src(struct hda_codec *codec)
3889{
3890 struct alc_spec *spec = codec->spec;
3891 int i;
3892
3893 for (i = 0; i < spec->autocfg.num_inputs; i++)
3894 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3895}
3896
3897/* assign appropriate capture mixers */
3898static void set_capture_mixer(struct hda_codec *codec)
3899{
3900 struct alc_spec *spec = codec->spec;
3901 static const struct snd_kcontrol_new *caps[2][3] = {
3902 { alc_capture_mixer_nosrc1,
3903 alc_capture_mixer_nosrc2,
3904 alc_capture_mixer_nosrc3 },
3905 { alc_capture_mixer1,
3906 alc_capture_mixer2,
3907 alc_capture_mixer3 },
3908 };
3909
3910 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003911 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003912 if (!spec->capsrc_nids)
3913 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003914 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003915 return; /* no volume in capsrc, too */
3916 spec->vol_in_capsrc = 1;
3917 }
3918
3919 if (spec->num_adc_nids > 0) {
3920 int mux = 0;
3921 int num_adcs = 0;
3922
3923 if (spec->input_mux && spec->input_mux->num_items > 1)
3924 mux = 1;
3925 if (spec->auto_mic) {
3926 num_adcs = 1;
3927 mux = 0;
3928 } else if (spec->dyn_adc_switch)
3929 num_adcs = 1;
3930 if (!num_adcs) {
3931 if (spec->num_adc_nids > 3)
3932 spec->num_adc_nids = 3;
3933 else if (!spec->num_adc_nids)
3934 return;
3935 num_adcs = spec->num_adc_nids;
3936 }
3937 spec->cap_mixer = caps[mux][num_adcs - 1];
3938 }
3939}
3940
3941/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003942 * standard auto-parser initializations
3943 */
3944static void alc_auto_init_std(struct hda_codec *codec)
3945{
3946 struct alc_spec *spec = codec->spec;
3947 alc_auto_init_multi_out(codec);
3948 alc_auto_init_extra_out(codec);
3949 alc_auto_init_analog_input(codec);
3950 alc_auto_init_input_src(codec);
3951 alc_auto_init_digital(codec);
3952 if (spec->unsol_event)
3953 alc_inithook(codec);
3954}
3955
3956/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003957 * Digital-beep handlers
3958 */
3959#ifdef CONFIG_SND_HDA_INPUT_BEEP
3960#define set_beep_amp(spec, nid, idx, dir) \
3961 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3962
3963static const struct snd_pci_quirk beep_white_list[] = {
3964 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3965 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3966 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3967 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3968 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3969 {}
3970};
3971
3972static inline int has_cdefine_beep(struct hda_codec *codec)
3973{
3974 struct alc_spec *spec = codec->spec;
3975 const struct snd_pci_quirk *q;
3976 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3977 if (q)
3978 return q->value;
3979 return spec->cdefine.enable_pcbeep;
3980}
3981#else
3982#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3983#define has_cdefine_beep(codec) 0
3984#endif
3985
3986/* parse the BIOS configuration and set up the alc_spec */
3987/* return 1 if successful, 0 if the proper config is not found,
3988 * or a negative error code
3989 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003990static int alc_parse_auto_config(struct hda_codec *codec,
3991 const hda_nid_t *ignore_nids,
3992 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003993{
3994 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003995 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003996 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003997
Takashi Iwai53c334a2011-08-23 18:27:14 +02003998 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3999 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004000 if (err < 0)
4001 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004002 if (!cfg->line_outs) {
4003 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004004 spec->multiout.max_channels = 2;
4005 spec->no_analog = 1;
4006 goto dig_only;
4007 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004008 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004009 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004010
Takashi Iwai06503672011-10-06 08:27:19 +02004011 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4012 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004013 /* use HP as primary out */
4014 cfg->speaker_outs = cfg->line_outs;
4015 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4016 sizeof(cfg->speaker_pins));
4017 cfg->line_outs = cfg->hp_outs;
4018 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4019 cfg->hp_outs = 0;
4020 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4021 cfg->line_out_type = AUTO_PIN_HP_OUT;
4022 }
4023
Takashi Iwai1d045db2011-07-07 18:23:21 +02004024 err = alc_auto_fill_dac_nids(codec);
4025 if (err < 0)
4026 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004027 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004028 if (err < 0)
4029 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004030 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004031 if (err < 0)
4032 return err;
4033 err = alc_auto_create_hp_out(codec);
4034 if (err < 0)
4035 return err;
4036 err = alc_auto_create_speaker_out(codec);
4037 if (err < 0)
4038 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004039 err = alc_auto_create_shared_input(codec);
4040 if (err < 0)
4041 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004042 err = alc_auto_create_input_ctls(codec);
4043 if (err < 0)
4044 return err;
4045
4046 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4047
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004048 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004049 alc_auto_parse_digital(codec);
4050
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004051 if (!spec->no_analog)
4052 alc_remove_invalid_adc_nids(codec);
4053
4054 if (ssid_nids)
4055 alc_ssid_check(codec, ssid_nids);
4056
4057 if (!spec->no_analog) {
4058 alc_auto_check_switches(codec);
4059 err = alc_auto_add_mic_boost(codec);
4060 if (err < 0)
4061 return err;
4062 }
4063
Takashi Iwai1d045db2011-07-07 18:23:21 +02004064 if (spec->kctls.list)
4065 add_mixer(spec, spec->kctls.list);
4066
Takashi Iwai1d045db2011-07-07 18:23:21 +02004067 return 1;
4068}
4069
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004070static int alc880_parse_auto_config(struct hda_codec *codec)
4071{
4072 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4073 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4074 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4075}
4076
Takashi Iwai1d045db2011-07-07 18:23:21 +02004077#ifdef CONFIG_SND_HDA_POWER_SAVE
4078static const struct hda_amp_list alc880_loopbacks[] = {
4079 { 0x0b, HDA_INPUT, 0 },
4080 { 0x0b, HDA_INPUT, 1 },
4081 { 0x0b, HDA_INPUT, 2 },
4082 { 0x0b, HDA_INPUT, 3 },
4083 { 0x0b, HDA_INPUT, 4 },
4084 { } /* end */
4085};
4086#endif
4087
4088/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004089 * ALC880 fix-ups
4090 */
4091enum {
4092 ALC880_FIXUP_GPIO2,
4093 ALC880_FIXUP_MEDION_RIM,
4094};
4095
4096static const struct alc_fixup alc880_fixups[] = {
4097 [ALC880_FIXUP_GPIO2] = {
4098 .type = ALC_FIXUP_VERBS,
4099 .v.verbs = alc_gpio2_init_verbs,
4100 },
4101 [ALC880_FIXUP_MEDION_RIM] = {
4102 .type = ALC_FIXUP_VERBS,
4103 .v.verbs = (const struct hda_verb[]) {
4104 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4105 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4106 { }
4107 },
4108 .chained = true,
4109 .chain_id = ALC880_FIXUP_GPIO2,
4110 },
4111};
4112
4113static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4114 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4115 {}
4116};
4117
4118
4119/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004120 * board setups
4121 */
4122#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4123#define alc_board_config \
4124 snd_hda_check_board_config
4125#define alc_board_codec_sid_config \
4126 snd_hda_check_board_codec_sid_config
4127#include "alc_quirks.c"
4128#else
4129#define alc_board_config(codec, nums, models, tbl) -1
4130#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4131#define setup_preset(codec, x) /* NOP */
4132#endif
4133
4134/*
4135 * OK, here we have finally the patch for ALC880
4136 */
4137#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4138#include "alc880_quirks.c"
4139#endif
4140
4141static int patch_alc880(struct hda_codec *codec)
4142{
4143 struct alc_spec *spec;
4144 int board_config;
4145 int err;
4146
4147 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4148 if (spec == NULL)
4149 return -ENOMEM;
4150
4151 codec->spec = spec;
4152
4153 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004154 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004155
4156 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4157 alc880_models, alc880_cfg_tbl);
4158 if (board_config < 0) {
4159 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4160 codec->chip_name);
4161 board_config = ALC_MODEL_AUTO;
4162 }
4163
4164 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004165 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4166 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4167 }
4168
4169 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004170 /* automatic parse from the BIOS config */
4171 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004172 if (err < 0)
4173 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004174#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4175 else if (!err) {
4176 printk(KERN_INFO
4177 "hda_codec: Cannot set up configuration "
4178 "from BIOS. Using 3-stack mode...\n");
4179 board_config = ALC880_3ST;
4180 }
4181#endif
4182 }
4183
David Henningssonfde48a12011-12-09 18:27:42 +08004184 if (board_config != ALC_MODEL_AUTO) {
4185 spec->vmaster_nid = 0x0c;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004186 setup_preset(codec, &alc880_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004187 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004188
Takashi Iwai60a6a842011-07-27 14:01:24 +02004189 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004190 alc_auto_fill_adc_caps(codec);
4191 alc_rebuild_imux_for_auto_mic(codec);
4192 alc_remove_invalid_adc_nids(codec);
4193 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004194
4195 if (!spec->no_analog && !spec->cap_mixer)
4196 set_capture_mixer(codec);
4197
4198 if (!spec->no_analog) {
4199 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004200 if (err < 0)
4201 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004202 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4203 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004204
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004205 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4206
Takashi Iwai1d045db2011-07-07 18:23:21 +02004207 codec->patch_ops = alc_patch_ops;
4208 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004209 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004210#ifdef CONFIG_SND_HDA_POWER_SAVE
4211 if (!spec->loopback.amplist)
4212 spec->loopback.amplist = alc880_loopbacks;
4213#endif
4214
4215 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004216
4217 error:
4218 alc_free(codec);
4219 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004220}
4221
4222
4223/*
4224 * ALC260 support
4225 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004226static int alc260_parse_auto_config(struct hda_codec *codec)
4227{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004228 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004229 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4230 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004231}
4232
Takashi Iwai1d045db2011-07-07 18:23:21 +02004233#ifdef CONFIG_SND_HDA_POWER_SAVE
4234static const struct hda_amp_list alc260_loopbacks[] = {
4235 { 0x07, HDA_INPUT, 0 },
4236 { 0x07, HDA_INPUT, 1 },
4237 { 0x07, HDA_INPUT, 2 },
4238 { 0x07, HDA_INPUT, 3 },
4239 { 0x07, HDA_INPUT, 4 },
4240 { } /* end */
4241};
4242#endif
4243
4244/*
4245 * Pin config fixes
4246 */
4247enum {
4248 PINFIX_HP_DC5750,
4249};
4250
4251static const struct alc_fixup alc260_fixups[] = {
4252 [PINFIX_HP_DC5750] = {
4253 .type = ALC_FIXUP_PINS,
4254 .v.pins = (const struct alc_pincfg[]) {
4255 { 0x11, 0x90130110 }, /* speaker */
4256 { }
4257 }
4258 },
4259};
4260
4261static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4262 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4263 {}
4264};
4265
4266/*
4267 */
4268#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4269#include "alc260_quirks.c"
4270#endif
4271
4272static int patch_alc260(struct hda_codec *codec)
4273{
4274 struct alc_spec *spec;
4275 int err, board_config;
4276
4277 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4278 if (spec == NULL)
4279 return -ENOMEM;
4280
4281 codec->spec = spec;
4282
4283 spec->mixer_nid = 0x07;
4284
4285 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4286 alc260_models, alc260_cfg_tbl);
4287 if (board_config < 0) {
4288 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4289 codec->chip_name);
4290 board_config = ALC_MODEL_AUTO;
4291 }
4292
4293 if (board_config == ALC_MODEL_AUTO) {
4294 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4295 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4296 }
4297
4298 if (board_config == ALC_MODEL_AUTO) {
4299 /* automatic parse from the BIOS config */
4300 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004301 if (err < 0)
4302 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004303#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4304 else if (!err) {
4305 printk(KERN_INFO
4306 "hda_codec: Cannot set up configuration "
4307 "from BIOS. Using base mode...\n");
4308 board_config = ALC260_BASIC;
4309 }
4310#endif
4311 }
4312
David Henningssonfde48a12011-12-09 18:27:42 +08004313 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004314 setup_preset(codec, &alc260_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004315 spec->vmaster_nid = 0x08;
4316 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004317
Takashi Iwai60a6a842011-07-27 14:01:24 +02004318 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004319 alc_auto_fill_adc_caps(codec);
4320 alc_rebuild_imux_for_auto_mic(codec);
4321 alc_remove_invalid_adc_nids(codec);
4322 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004323
4324 if (!spec->no_analog && !spec->cap_mixer)
4325 set_capture_mixer(codec);
4326
4327 if (!spec->no_analog) {
4328 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004329 if (err < 0)
4330 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004331 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4332 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004333
4334 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4335
Takashi Iwai1d045db2011-07-07 18:23:21 +02004336 codec->patch_ops = alc_patch_ops;
4337 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004338 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004339 spec->shutup = alc_eapd_shutup;
4340#ifdef CONFIG_SND_HDA_POWER_SAVE
4341 if (!spec->loopback.amplist)
4342 spec->loopback.amplist = alc260_loopbacks;
4343#endif
4344
4345 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004346
4347 error:
4348 alc_free(codec);
4349 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004350}
4351
4352
4353/*
4354 * ALC882/883/885/888/889 support
4355 *
4356 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4357 * configuration. Each pin widget can choose any input DACs and a mixer.
4358 * Each ADC is connected from a mixer of all inputs. This makes possible
4359 * 6-channel independent captures.
4360 *
4361 * In addition, an independent DAC for the multi-playback (not used in this
4362 * driver yet).
4363 */
4364#ifdef CONFIG_SND_HDA_POWER_SAVE
4365#define alc882_loopbacks alc880_loopbacks
4366#endif
4367
4368/*
4369 * Pin config fixes
4370 */
4371enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004372 ALC882_FIXUP_ABIT_AW9D_MAX,
4373 ALC882_FIXUP_LENOVO_Y530,
4374 ALC882_FIXUP_PB_M5210,
4375 ALC882_FIXUP_ACER_ASPIRE_7736,
4376 ALC882_FIXUP_ASUS_W90V,
4377 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004378 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004379 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004380 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004381 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004382 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004383 ALC889_FIXUP_COEF,
4384 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004385 ALC882_FIXUP_ACER_ASPIRE_4930G,
4386 ALC882_FIXUP_ACER_ASPIRE_8930G,
4387 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004388 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004389};
4390
Takashi Iwai68ef0562011-11-09 18:24:44 +01004391static void alc889_fixup_coef(struct hda_codec *codec,
4392 const struct alc_fixup *fix, int action)
4393{
4394 if (action != ALC_FIXUP_ACT_INIT)
4395 return;
4396 alc889_coef_init(codec);
4397}
4398
Takashi Iwai56710872011-11-14 17:42:11 +01004399/* toggle speaker-output according to the hp-jack state */
4400static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4401{
4402 unsigned int gpiostate, gpiomask, gpiodir;
4403
4404 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4405 AC_VERB_GET_GPIO_DATA, 0);
4406
4407 if (!muted)
4408 gpiostate |= (1 << pin);
4409 else
4410 gpiostate &= ~(1 << pin);
4411
4412 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4413 AC_VERB_GET_GPIO_MASK, 0);
4414 gpiomask |= (1 << pin);
4415
4416 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4417 AC_VERB_GET_GPIO_DIRECTION, 0);
4418 gpiodir |= (1 << pin);
4419
4420
4421 snd_hda_codec_write(codec, codec->afg, 0,
4422 AC_VERB_SET_GPIO_MASK, gpiomask);
4423 snd_hda_codec_write(codec, codec->afg, 0,
4424 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4425
4426 msleep(1);
4427
4428 snd_hda_codec_write(codec, codec->afg, 0,
4429 AC_VERB_SET_GPIO_DATA, gpiostate);
4430}
4431
4432/* set up GPIO at initialization */
4433static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4434 const struct alc_fixup *fix, int action)
4435{
4436 if (action != ALC_FIXUP_ACT_INIT)
4437 return;
4438 alc882_gpio_mute(codec, 0, 0);
4439 alc882_gpio_mute(codec, 1, 0);
4440}
4441
Takashi Iwai1d045db2011-07-07 18:23:21 +02004442static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004443 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004444 .type = ALC_FIXUP_PINS,
4445 .v.pins = (const struct alc_pincfg[]) {
4446 { 0x15, 0x01080104 }, /* side */
4447 { 0x16, 0x01011012 }, /* rear */
4448 { 0x17, 0x01016011 }, /* clfe */
4449 { }
4450 }
4451 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004452 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004453 .type = ALC_FIXUP_PINS,
4454 .v.pins = (const struct alc_pincfg[]) {
4455 { 0x15, 0x99130112 }, /* rear int speakers */
4456 { 0x16, 0x99130111 }, /* subwoofer */
4457 { }
4458 }
4459 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004460 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004461 .type = ALC_FIXUP_VERBS,
4462 .v.verbs = (const struct hda_verb[]) {
4463 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4464 {}
4465 }
4466 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004467 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004468 .type = ALC_FIXUP_SKU,
4469 .v.sku = ALC_FIXUP_SKU_IGNORE,
4470 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004471 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004472 .type = ALC_FIXUP_PINS,
4473 .v.pins = (const struct alc_pincfg[]) {
4474 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4475 { }
4476 }
4477 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004478 [ALC889_FIXUP_VAIO_TT] = {
4479 .type = ALC_FIXUP_PINS,
4480 .v.pins = (const struct alc_pincfg[]) {
4481 { 0x17, 0x90170111 }, /* hidden surround speaker */
4482 { }
4483 }
4484 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004485 [ALC888_FIXUP_EEE1601] = {
4486 .type = ALC_FIXUP_VERBS,
4487 .v.verbs = (const struct hda_verb[]) {
4488 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4489 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4490 { }
4491 }
Takashi Iwai177943a2011-11-09 12:55:18 +01004492 },
4493 [ALC882_FIXUP_EAPD] = {
4494 .type = ALC_FIXUP_VERBS,
4495 .v.verbs = (const struct hda_verb[]) {
4496 /* change to EAPD mode */
4497 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4498 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4499 { }
4500 }
4501 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004502 [ALC883_FIXUP_EAPD] = {
4503 .type = ALC_FIXUP_VERBS,
4504 .v.verbs = (const struct hda_verb[]) {
4505 /* change to EAPD mode */
4506 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4507 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4508 { }
4509 }
4510 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004511 [ALC883_FIXUP_ACER_EAPD] = {
4512 .type = ALC_FIXUP_VERBS,
4513 .v.verbs = (const struct hda_verb[]) {
4514 /* eanable EAPD on Acer laptops */
4515 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4516 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4517 { }
4518 }
4519 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004520 [ALC882_FIXUP_GPIO3] = {
4521 .type = ALC_FIXUP_VERBS,
4522 .v.verbs = alc_gpio3_init_verbs,
4523 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004524 [ALC882_FIXUP_ASUS_W2JC] = {
4525 .type = ALC_FIXUP_VERBS,
4526 .v.verbs = alc_gpio1_init_verbs,
4527 .chained = true,
4528 .chain_id = ALC882_FIXUP_EAPD,
4529 },
4530 [ALC889_FIXUP_COEF] = {
4531 .type = ALC_FIXUP_FUNC,
4532 .v.func = alc889_fixup_coef,
4533 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004534 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4535 .type = ALC_FIXUP_PINS,
4536 .v.pins = (const struct alc_pincfg[]) {
4537 { 0x16, 0x99130111 }, /* CLFE speaker */
4538 { 0x17, 0x99130112 }, /* surround speaker */
4539 { }
4540 }
4541 },
4542 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4543 .type = ALC_FIXUP_PINS,
4544 .v.pins = (const struct alc_pincfg[]) {
4545 { 0x16, 0x99130111 }, /* CLFE speaker */
4546 { 0x1b, 0x99130112 }, /* surround speaker */
4547 { }
4548 },
4549 .chained = true,
4550 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4551 },
4552 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4553 /* additional init verbs for Acer Aspire 8930G */
4554 .type = ALC_FIXUP_VERBS,
4555 .v.verbs = (const struct hda_verb[]) {
4556 /* Enable all DACs */
4557 /* DAC DISABLE/MUTE 1? */
4558 /* setting bits 1-5 disables DAC nids 0x02-0x06
4559 * apparently. Init=0x38 */
4560 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4561 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4562 /* DAC DISABLE/MUTE 2? */
4563 /* some bit here disables the other DACs.
4564 * Init=0x4900 */
4565 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4566 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4567 /* DMIC fix
4568 * This laptop has a stereo digital microphone.
4569 * The mics are only 1cm apart which makes the stereo
4570 * useless. However, either the mic or the ALC889
4571 * makes the signal become a difference/sum signal
4572 * instead of standard stereo, which is annoying.
4573 * So instead we flip this bit which makes the
4574 * codec replicate the sum signal to both channels,
4575 * turning it into a normal mono mic.
4576 */
4577 /* DMIC_CONTROL? Init value = 0x0001 */
4578 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4579 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4580 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4581 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4582 { }
4583 }
4584 },
Takashi Iwai56710872011-11-14 17:42:11 +01004585 [ALC885_FIXUP_MACPRO_GPIO] = {
4586 .type = ALC_FIXUP_FUNC,
4587 .v.func = alc885_fixup_macpro_gpio,
4588 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004589};
4590
4591static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004592 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4593 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4594 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4595 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4596 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4597 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004598 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4599 ALC882_FIXUP_ACER_ASPIRE_4930G),
4600 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4601 ALC882_FIXUP_ACER_ASPIRE_4930G),
4602 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4603 ALC882_FIXUP_ACER_ASPIRE_8930G),
4604 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4605 ALC882_FIXUP_ACER_ASPIRE_8930G),
4606 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4607 ALC882_FIXUP_ACER_ASPIRE_4930G),
4608 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4609 ALC882_FIXUP_ACER_ASPIRE_4930G),
4610 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4611 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004612 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004613 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01004614 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004615 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004616 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004617 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004618 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01004619
4620 /* All Apple entries are in codec SSIDs */
4621 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4622 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4623 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4624 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4625 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4626
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004627 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004628 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004629 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004630 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4631 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004632 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004633 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004634 {}
4635};
4636
4637/*
4638 * BIOS auto configuration
4639 */
4640/* almost identical with ALC880 parser... */
4641static int alc882_parse_auto_config(struct hda_codec *codec)
4642{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004643 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004644 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4645 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004646}
4647
Takashi Iwai1d045db2011-07-07 18:23:21 +02004648/*
4649 */
4650#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4651#include "alc882_quirks.c"
4652#endif
4653
4654static int patch_alc882(struct hda_codec *codec)
4655{
4656 struct alc_spec *spec;
4657 int err, board_config;
4658
4659 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4660 if (spec == NULL)
4661 return -ENOMEM;
4662
4663 codec->spec = spec;
4664
4665 spec->mixer_nid = 0x0b;
4666
4667 switch (codec->vendor_id) {
4668 case 0x10ec0882:
4669 case 0x10ec0885:
4670 break;
4671 default:
4672 /* ALC883 and variants */
4673 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4674 break;
4675 }
4676
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004677 err = alc_codec_rename_from_preset(codec);
4678 if (err < 0)
4679 goto error;
4680
Takashi Iwaib2539692011-11-14 17:32:17 +01004681 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4682 alc882_models, NULL);
4683 if (board_config < 0)
4684 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004685 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4686
4687 if (board_config < 0) {
4688 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4689 codec->chip_name);
4690 board_config = ALC_MODEL_AUTO;
4691 }
4692
4693 if (board_config == ALC_MODEL_AUTO) {
4694 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4695 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4696 }
4697
4698 alc_auto_parse_customize_define(codec);
4699
4700 if (board_config == ALC_MODEL_AUTO) {
4701 /* automatic parse from the BIOS config */
4702 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004703 if (err < 0)
4704 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004705 }
4706
David Henningssonfde48a12011-12-09 18:27:42 +08004707 if (board_config != ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004708 setup_preset(codec, &alc882_presets[board_config]);
David Henningssonfde48a12011-12-09 18:27:42 +08004709 spec->vmaster_nid = 0x0c;
4710 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004711
Takashi Iwai60a6a842011-07-27 14:01:24 +02004712 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004713 alc_auto_fill_adc_caps(codec);
4714 alc_rebuild_imux_for_auto_mic(codec);
4715 alc_remove_invalid_adc_nids(codec);
4716 }
4717
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004718 if (!spec->no_analog && !spec->cap_mixer)
4719 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004720
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004721 if (!spec->no_analog && has_cdefine_beep(codec)) {
4722 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004723 if (err < 0)
4724 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004725 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004726 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004727
4728 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4729
Takashi Iwai1d045db2011-07-07 18:23:21 +02004730 codec->patch_ops = alc_patch_ops;
4731 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004732 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004733
4734 alc_init_jacks(codec);
4735#ifdef CONFIG_SND_HDA_POWER_SAVE
4736 if (!spec->loopback.amplist)
4737 spec->loopback.amplist = alc882_loopbacks;
4738#endif
4739
4740 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004741
4742 error:
4743 alc_free(codec);
4744 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004745}
4746
4747
4748/*
4749 * ALC262 support
4750 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004751static int alc262_parse_auto_config(struct hda_codec *codec)
4752{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004753 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004754 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4755 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004756}
4757
4758/*
4759 * Pin config fixes
4760 */
4761enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004762 ALC262_FIXUP_FSC_H270,
4763 ALC262_FIXUP_HP_Z200,
4764 ALC262_FIXUP_TYAN,
Takashi Iwai12837c92011-11-07 12:45:24 +01004765 ALC262_FIXUP_TOSHIBA_RX1,
Takashi Iwaic4701502011-11-07 14:20:07 +01004766 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004767 ALC262_FIXUP_BENQ,
4768 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004769};
4770
4771static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004772 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004773 .type = ALC_FIXUP_PINS,
4774 .v.pins = (const struct alc_pincfg[]) {
4775 { 0x14, 0x99130110 }, /* speaker */
4776 { 0x15, 0x0221142f }, /* front HP */
4777 { 0x1b, 0x0121141f }, /* rear HP */
4778 { }
4779 }
4780 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004781 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004782 .type = ALC_FIXUP_PINS,
4783 .v.pins = (const struct alc_pincfg[]) {
4784 { 0x16, 0x99130120 }, /* internal speaker */
4785 { }
4786 }
4787 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004788 [ALC262_FIXUP_TYAN] = {
4789 .type = ALC_FIXUP_PINS,
4790 .v.pins = (const struct alc_pincfg[]) {
4791 { 0x14, 0x1993e1f0 }, /* int AUX */
4792 { }
4793 }
4794 },
Takashi Iwai12837c92011-11-07 12:45:24 +01004795 [ALC262_FIXUP_TOSHIBA_RX1] = {
4796 .type = ALC_FIXUP_PINS,
4797 .v.pins = (const struct alc_pincfg[]) {
4798 { 0x14, 0x90170110 }, /* speaker */
4799 { 0x15, 0x0421101f }, /* HP */
4800 { 0x1a, 0x40f000f0 }, /* N/A */
4801 { 0x1b, 0x40f000f0 }, /* N/A */
4802 { 0x1e, 0x40f000f0 }, /* N/A */
4803 }
4804 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004805 [ALC262_FIXUP_LENOVO_3000] = {
4806 .type = ALC_FIXUP_VERBS,
4807 .v.verbs = (const struct hda_verb[]) {
4808 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004809 {}
4810 },
4811 .chained = true,
4812 .chain_id = ALC262_FIXUP_BENQ,
4813 },
4814 [ALC262_FIXUP_BENQ] = {
4815 .type = ALC_FIXUP_VERBS,
4816 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004817 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4818 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4819 {}
4820 }
4821 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004822 [ALC262_FIXUP_BENQ_T31] = {
4823 .type = ALC_FIXUP_VERBS,
4824 .v.verbs = (const struct hda_verb[]) {
4825 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4826 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4827 {}
4828 }
4829 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004830};
4831
4832static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004833 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004834 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4835 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004836 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
Takashi Iwai12837c92011-11-07 12:45:24 +01004837 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4838 ALC262_FIXUP_TOSHIBA_RX1),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004839 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004840 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004841 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4842 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004843 {}
4844};
4845
4846
4847#ifdef CONFIG_SND_HDA_POWER_SAVE
4848#define alc262_loopbacks alc880_loopbacks
4849#endif
4850
Takashi Iwai1d045db2011-07-07 18:23:21 +02004851/*
4852 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004853static int patch_alc262(struct hda_codec *codec)
4854{
4855 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004856 int err;
4857
4858 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4859 if (spec == NULL)
4860 return -ENOMEM;
4861
4862 codec->spec = spec;
4863
4864 spec->mixer_nid = 0x0b;
4865
4866#if 0
4867 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4868 * under-run
4869 */
4870 {
4871 int tmp;
4872 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4873 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4874 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4875 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4876 }
4877#endif
4878 alc_auto_parse_customize_define(codec);
4879
4880 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4881
Takashi Iwai42399f72011-11-07 17:18:44 +01004882 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4883 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004884
Takashi Iwai42399f72011-11-07 17:18:44 +01004885 /* automatic parse from the BIOS config */
4886 err = alc262_parse_auto_config(codec);
4887 if (err < 0)
4888 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004889
Takashi Iwai60a6a842011-07-27 14:01:24 +02004890 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004891 alc_auto_fill_adc_caps(codec);
4892 alc_rebuild_imux_for_auto_mic(codec);
4893 alc_remove_invalid_adc_nids(codec);
4894 }
4895
4896 if (!spec->no_analog && !spec->cap_mixer)
4897 set_capture_mixer(codec);
4898
Takashi Iwai1d045db2011-07-07 18:23:21 +02004899 if (!spec->no_analog && has_cdefine_beep(codec)) {
4900 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004901 if (err < 0)
4902 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004903 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004904 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004905
4906 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4907
Takashi Iwai1d045db2011-07-07 18:23:21 +02004908 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004909 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004910 spec->shutup = alc_eapd_shutup;
4911
4912 alc_init_jacks(codec);
4913#ifdef CONFIG_SND_HDA_POWER_SAVE
4914 if (!spec->loopback.amplist)
4915 spec->loopback.amplist = alc262_loopbacks;
4916#endif
4917
4918 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004919
4920 error:
4921 alc_free(codec);
4922 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004923}
4924
4925/*
4926 * ALC268
4927 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004928/* bind Beep switches of both NID 0x0f and 0x10 */
4929static const struct hda_bind_ctls alc268_bind_beep_sw = {
4930 .ops = &snd_hda_bind_sw,
4931 .values = {
4932 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4933 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4934 0
4935 },
4936};
4937
4938static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4939 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4940 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4941 { }
4942};
4943
4944/* set PCBEEP vol = 0, mute connections */
4945static const struct hda_verb alc268_beep_init_verbs[] = {
4946 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4947 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4948 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4949 { }
4950};
4951
4952/*
4953 * BIOS auto configuration
4954 */
4955static int alc268_parse_auto_config(struct hda_codec *codec)
4956{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004957 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004958 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004959 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4960 if (err > 0) {
4961 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4962 add_mixer(spec, alc268_beep_mixer);
4963 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004964 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004965 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004966 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004967}
4968
Takashi Iwai1d045db2011-07-07 18:23:21 +02004969/*
4970 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004971static int patch_alc268(struct hda_codec *codec)
4972{
4973 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004974 int i, has_beep, err;
4975
4976 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4977 if (spec == NULL)
4978 return -ENOMEM;
4979
4980 codec->spec = spec;
4981
4982 /* ALC268 has no aa-loopback mixer */
4983
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004984 /* automatic parse from the BIOS config */
4985 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004986 if (err < 0)
4987 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004988
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989 has_beep = 0;
4990 for (i = 0; i < spec->num_mixers; i++) {
4991 if (spec->mixers[i] == alc268_beep_mixer) {
4992 has_beep = 1;
4993 break;
4994 }
4995 }
4996
4997 if (has_beep) {
4998 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004999 if (err < 0)
5000 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005001 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5002 /* override the amp caps for beep generator */
5003 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5004 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5005 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5006 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5007 (0 << AC_AMPCAP_MUTE_SHIFT));
5008 }
5009
Takashi Iwai60a6a842011-07-27 14:01:24 +02005010 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005011 alc_auto_fill_adc_caps(codec);
5012 alc_rebuild_imux_for_auto_mic(codec);
5013 alc_remove_invalid_adc_nids(codec);
5014 }
5015
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005016 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005017 set_capture_mixer(codec);
5018
Takashi Iwai1d045db2011-07-07 18:23:21 +02005019 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005020 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005021 spec->shutup = alc_eapd_shutup;
5022
5023 alc_init_jacks(codec);
5024
5025 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005026
5027 error:
5028 alc_free(codec);
5029 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005030}
5031
5032/*
5033 * ALC269
5034 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005035#ifdef CONFIG_SND_HDA_POWER_SAVE
5036#define alc269_loopbacks alc880_loopbacks
5037#endif
5038
5039static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5040 .substreams = 1,
5041 .channels_min = 2,
5042 .channels_max = 8,
5043 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5044 /* NID is set in alc_build_pcms */
5045 .ops = {
5046 .open = alc_playback_pcm_open,
5047 .prepare = alc_playback_pcm_prepare,
5048 .cleanup = alc_playback_pcm_cleanup
5049 },
5050};
5051
5052static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5053 .substreams = 1,
5054 .channels_min = 2,
5055 .channels_max = 2,
5056 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5057 /* NID is set in alc_build_pcms */
5058};
5059
5060#ifdef CONFIG_SND_HDA_POWER_SAVE
5061static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5062{
5063 switch (codec->subsystem_id) {
5064 case 0x103c1586:
5065 return 1;
5066 }
5067 return 0;
5068}
5069
5070static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5071{
5072 /* update mute-LED according to the speaker mute state */
5073 if (nid == 0x01 || nid == 0x14) {
5074 int pinval;
5075 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5076 HDA_AMP_MUTE)
5077 pinval = 0x24;
5078 else
5079 pinval = 0x20;
5080 /* mic2 vref pin is used for mute LED control */
5081 snd_hda_codec_update_cache(codec, 0x19, 0,
5082 AC_VERB_SET_PIN_WIDGET_CONTROL,
5083 pinval);
5084 }
5085 return alc_check_power_status(codec, nid);
5086}
5087#endif /* CONFIG_SND_HDA_POWER_SAVE */
5088
5089/* different alc269-variants */
5090enum {
5091 ALC269_TYPE_ALC269VA,
5092 ALC269_TYPE_ALC269VB,
5093 ALC269_TYPE_ALC269VC,
5094};
5095
5096/*
5097 * BIOS auto configuration
5098 */
5099static int alc269_parse_auto_config(struct hda_codec *codec)
5100{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005101 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005102 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5103 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5104 struct alc_spec *spec = codec->spec;
5105 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5106 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005107
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005108 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005109}
5110
Takashi Iwai1d045db2011-07-07 18:23:21 +02005111static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5112{
5113 int val = alc_read_coef_idx(codec, 0x04);
5114 if (power_up)
5115 val |= 1 << 11;
5116 else
5117 val &= ~(1 << 11);
5118 alc_write_coef_idx(codec, 0x04, val);
5119}
5120
5121static void alc269_shutup(struct hda_codec *codec)
5122{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005123 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005124 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005125 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005126 alc269_toggle_power_output(codec, 0);
5127 msleep(150);
5128 }
5129}
5130
Takashi Iwai2a439522011-07-26 09:52:50 +02005131#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005132static int alc269_resume(struct hda_codec *codec)
5133{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005134 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005135 alc269_toggle_power_output(codec, 0);
5136 msleep(150);
5137 }
5138
5139 codec->patch_ops.init(codec);
5140
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005141 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005142 alc269_toggle_power_output(codec, 1);
5143 msleep(200);
5144 }
5145
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005146 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005147 alc269_toggle_power_output(codec, 1);
5148
5149 snd_hda_codec_resume_amp(codec);
5150 snd_hda_codec_resume_cache(codec);
5151 hda_call_check_power_status(codec, 0x01);
5152 return 0;
5153}
Takashi Iwai2a439522011-07-26 09:52:50 +02005154#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005155
5156static void alc269_fixup_hweq(struct hda_codec *codec,
5157 const struct alc_fixup *fix, int action)
5158{
5159 int coef;
5160
5161 if (action != ALC_FIXUP_ACT_INIT)
5162 return;
5163 coef = alc_read_coef_idx(codec, 0x1e);
5164 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5165}
5166
5167static void alc271_fixup_dmic(struct hda_codec *codec,
5168 const struct alc_fixup *fix, int action)
5169{
5170 static const struct hda_verb verbs[] = {
5171 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5172 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5173 {}
5174 };
5175 unsigned int cfg;
5176
5177 if (strcmp(codec->chip_name, "ALC271X"))
5178 return;
5179 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5180 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5181 snd_hda_sequence_write(codec, verbs);
5182}
5183
Takashi Iwai017f2a12011-07-09 14:42:25 +02005184static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5185 const struct alc_fixup *fix, int action)
5186{
5187 struct alc_spec *spec = codec->spec;
5188
5189 if (action != ALC_FIXUP_ACT_PROBE)
5190 return;
5191
5192 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5193 * fix the sample rate of analog I/O to 44.1kHz
5194 */
5195 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5196 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5197}
5198
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005199static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5200 const struct alc_fixup *fix, int action)
5201{
5202 int coef;
5203
5204 if (action != ALC_FIXUP_ACT_INIT)
5205 return;
5206 /* The digital-mic unit sends PDM (differential signal) instead of
5207 * the standard PCM, thus you can't record a valid mono stream as is.
5208 * Below is a workaround specific to ALC269 to control the dmic
5209 * signal source as mono.
5210 */
5211 coef = alc_read_coef_idx(codec, 0x07);
5212 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5213}
5214
Takashi Iwai24519912011-08-16 15:08:49 +02005215static void alc269_quanta_automute(struct hda_codec *codec)
5216{
David Henningsson42cf0d02011-09-20 12:04:56 +02005217 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005218
5219 snd_hda_codec_write(codec, 0x20, 0,
5220 AC_VERB_SET_COEF_INDEX, 0x0c);
5221 snd_hda_codec_write(codec, 0x20, 0,
5222 AC_VERB_SET_PROC_COEF, 0x680);
5223
5224 snd_hda_codec_write(codec, 0x20, 0,
5225 AC_VERB_SET_COEF_INDEX, 0x0c);
5226 snd_hda_codec_write(codec, 0x20, 0,
5227 AC_VERB_SET_PROC_COEF, 0x480);
5228}
5229
5230static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5231 const struct alc_fixup *fix, int action)
5232{
5233 struct alc_spec *spec = codec->spec;
5234 if (action != ALC_FIXUP_ACT_PROBE)
5235 return;
5236 spec->automute_hook = alc269_quanta_automute;
5237}
5238
Takashi Iwai1d045db2011-07-07 18:23:21 +02005239enum {
5240 ALC269_FIXUP_SONY_VAIO,
5241 ALC275_FIXUP_SONY_VAIO_GPIO2,
5242 ALC269_FIXUP_DELL_M101Z,
5243 ALC269_FIXUP_SKU_IGNORE,
5244 ALC269_FIXUP_ASUS_G73JW,
5245 ALC269_FIXUP_LENOVO_EAPD,
5246 ALC275_FIXUP_SONY_HWEQ,
5247 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005248 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005249 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005250 ALC269_FIXUP_QUANTA_MUTE,
5251 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005252 ALC269_FIXUP_AMIC,
5253 ALC269_FIXUP_DMIC,
5254 ALC269VB_FIXUP_AMIC,
5255 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005256};
5257
5258static const struct alc_fixup alc269_fixups[] = {
5259 [ALC269_FIXUP_SONY_VAIO] = {
5260 .type = ALC_FIXUP_VERBS,
5261 .v.verbs = (const struct hda_verb[]) {
5262 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5263 {}
5264 }
5265 },
5266 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5267 .type = ALC_FIXUP_VERBS,
5268 .v.verbs = (const struct hda_verb[]) {
5269 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5270 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5271 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5272 { }
5273 },
5274 .chained = true,
5275 .chain_id = ALC269_FIXUP_SONY_VAIO
5276 },
5277 [ALC269_FIXUP_DELL_M101Z] = {
5278 .type = ALC_FIXUP_VERBS,
5279 .v.verbs = (const struct hda_verb[]) {
5280 /* Enables internal speaker */
5281 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5282 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5283 {}
5284 }
5285 },
5286 [ALC269_FIXUP_SKU_IGNORE] = {
5287 .type = ALC_FIXUP_SKU,
5288 .v.sku = ALC_FIXUP_SKU_IGNORE,
5289 },
5290 [ALC269_FIXUP_ASUS_G73JW] = {
5291 .type = ALC_FIXUP_PINS,
5292 .v.pins = (const struct alc_pincfg[]) {
5293 { 0x17, 0x99130111 }, /* subwoofer */
5294 { }
5295 }
5296 },
5297 [ALC269_FIXUP_LENOVO_EAPD] = {
5298 .type = ALC_FIXUP_VERBS,
5299 .v.verbs = (const struct hda_verb[]) {
5300 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5301 {}
5302 }
5303 },
5304 [ALC275_FIXUP_SONY_HWEQ] = {
5305 .type = ALC_FIXUP_FUNC,
5306 .v.func = alc269_fixup_hweq,
5307 .chained = true,
5308 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5309 },
5310 [ALC271_FIXUP_DMIC] = {
5311 .type = ALC_FIXUP_FUNC,
5312 .v.func = alc271_fixup_dmic,
5313 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005314 [ALC269_FIXUP_PCM_44K] = {
5315 .type = ALC_FIXUP_FUNC,
5316 .v.func = alc269_fixup_pcm_44k,
5317 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005318 [ALC269_FIXUP_STEREO_DMIC] = {
5319 .type = ALC_FIXUP_FUNC,
5320 .v.func = alc269_fixup_stereo_dmic,
5321 },
Takashi Iwai24519912011-08-16 15:08:49 +02005322 [ALC269_FIXUP_QUANTA_MUTE] = {
5323 .type = ALC_FIXUP_FUNC,
5324 .v.func = alc269_fixup_quanta_mute,
5325 },
5326 [ALC269_FIXUP_LIFEBOOK] = {
5327 .type = ALC_FIXUP_PINS,
5328 .v.pins = (const struct alc_pincfg[]) {
5329 { 0x1a, 0x2101103f }, /* dock line-out */
5330 { 0x1b, 0x23a11040 }, /* dock mic-in */
5331 { }
5332 },
5333 .chained = true,
5334 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5335 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005336 [ALC269_FIXUP_AMIC] = {
5337 .type = ALC_FIXUP_PINS,
5338 .v.pins = (const struct alc_pincfg[]) {
5339 { 0x14, 0x99130110 }, /* speaker */
5340 { 0x15, 0x0121401f }, /* HP out */
5341 { 0x18, 0x01a19c20 }, /* mic */
5342 { 0x19, 0x99a3092f }, /* int-mic */
5343 { }
5344 },
5345 },
5346 [ALC269_FIXUP_DMIC] = {
5347 .type = ALC_FIXUP_PINS,
5348 .v.pins = (const struct alc_pincfg[]) {
5349 { 0x12, 0x99a3092f }, /* int-mic */
5350 { 0x14, 0x99130110 }, /* speaker */
5351 { 0x15, 0x0121401f }, /* HP out */
5352 { 0x18, 0x01a19c20 }, /* mic */
5353 { }
5354 },
5355 },
5356 [ALC269VB_FIXUP_AMIC] = {
5357 .type = ALC_FIXUP_PINS,
5358 .v.pins = (const struct alc_pincfg[]) {
5359 { 0x14, 0x99130110 }, /* speaker */
5360 { 0x18, 0x01a19c20 }, /* mic */
5361 { 0x19, 0x99a3092f }, /* int-mic */
5362 { 0x21, 0x0121401f }, /* HP out */
5363 { }
5364 },
5365 },
5366 [ALC269_FIXUP_DMIC] = {
5367 .type = ALC_FIXUP_PINS,
5368 .v.pins = (const struct alc_pincfg[]) {
5369 { 0x12, 0x99a3092f }, /* int-mic */
5370 { 0x14, 0x99130110 }, /* speaker */
5371 { 0x18, 0x01a19c20 }, /* mic */
5372 { 0x21, 0x0121401f }, /* HP out */
5373 { }
5374 },
5375 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005376};
5377
5378static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005379 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005380 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5381 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5382 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5383 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5384 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005385 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5386 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5387 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5388 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5389 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5390 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005391 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005392 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5393 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5394 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5395 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5396 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005397 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005398 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005399 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005400
5401#if 1
5402 /* Below is a quirk table taken from the old code.
5403 * Basically the device should work as is without the fixup table.
5404 * If BIOS doesn't give a proper info, enable the corresponding
5405 * fixup entry.
5406 */
5407 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5408 ALC269_FIXUP_AMIC),
5409 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5410 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
5411 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5412 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5413 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5414 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5415 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5416 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5417 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5418 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5419 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5420 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5421 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5422 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5423 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5424 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5425 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5426 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5427 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5428 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5429 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5430 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5431 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5432 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5433 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5434 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5435 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5436 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5437 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5438 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5439 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5440 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5441 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5442 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5443 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5444 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5445 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5446 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5447 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5448 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5449#endif
5450 {}
5451};
5452
5453static const struct alc_model_fixup alc269_fixup_models[] = {
5454 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5455 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005456 {}
5457};
5458
5459
5460static int alc269_fill_coef(struct hda_codec *codec)
5461{
5462 int val;
5463
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005464 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005465 alc_write_coef_idx(codec, 0xf, 0x960b);
5466 alc_write_coef_idx(codec, 0xe, 0x8817);
5467 }
5468
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005469 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005470 alc_write_coef_idx(codec, 0xf, 0x960b);
5471 alc_write_coef_idx(codec, 0xe, 0x8814);
5472 }
5473
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005474 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005475 val = alc_read_coef_idx(codec, 0x04);
5476 /* Power up output pin */
5477 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5478 }
5479
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005480 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481 val = alc_read_coef_idx(codec, 0xd);
5482 if ((val & 0x0c00) >> 10 != 0x1) {
5483 /* Capless ramp up clock control */
5484 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5485 }
5486 val = alc_read_coef_idx(codec, 0x17);
5487 if ((val & 0x01c0) >> 6 != 0x4) {
5488 /* Class D power on reset */
5489 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5490 }
5491 }
5492
5493 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5494 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5495
5496 val = alc_read_coef_idx(codec, 0x4); /* HP */
5497 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5498
5499 return 0;
5500}
5501
5502/*
5503 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005504static int patch_alc269(struct hda_codec *codec)
5505{
5506 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005507 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005508
5509 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5510 if (spec == NULL)
5511 return -ENOMEM;
5512
5513 codec->spec = spec;
5514
5515 spec->mixer_nid = 0x0b;
5516
5517 alc_auto_parse_customize_define(codec);
5518
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005519 err = alc_codec_rename_from_preset(codec);
5520 if (err < 0)
5521 goto error;
5522
Takashi Iwai1d045db2011-07-07 18:23:21 +02005523 if (codec->vendor_id == 0x10ec0269) {
5524 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005525 switch (alc_get_coef0(codec) & 0x00f0) {
5526 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005527 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005528 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005529 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005530 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005531 break;
5532 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005533 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5534 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005535 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005536 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005537 break;
5538 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005539 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005540 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005541 if (err < 0)
5542 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005543 alc269_fill_coef(codec);
5544 }
5545
Takashi Iwaia4297b52011-08-23 18:40:12 +02005546 alc_pick_fixup(codec, alc269_fixup_models,
5547 alc269_fixup_tbl, alc269_fixups);
5548 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005549
Takashi Iwaia4297b52011-08-23 18:40:12 +02005550 /* automatic parse from the BIOS config */
5551 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005552 if (err < 0)
5553 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005554
Takashi Iwai60a6a842011-07-27 14:01:24 +02005555 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005556 alc_auto_fill_adc_caps(codec);
5557 alc_rebuild_imux_for_auto_mic(codec);
5558 alc_remove_invalid_adc_nids(codec);
5559 }
5560
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005561 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005562 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005563
5564 if (!spec->no_analog && has_cdefine_beep(codec)) {
5565 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005566 if (err < 0)
5567 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005568 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005569 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005570
5571 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5572
Takashi Iwai1d045db2011-07-07 18:23:21 +02005573 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005574#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005575 codec->patch_ops.resume = alc269_resume;
5576#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005577 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005578 spec->shutup = alc269_shutup;
5579
5580 alc_init_jacks(codec);
5581#ifdef CONFIG_SND_HDA_POWER_SAVE
5582 if (!spec->loopback.amplist)
5583 spec->loopback.amplist = alc269_loopbacks;
5584 if (alc269_mic2_for_mute_led(codec))
5585 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5586#endif
5587
5588 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005589
5590 error:
5591 alc_free(codec);
5592 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005593}
5594
5595/*
5596 * ALC861
5597 */
5598
Takashi Iwai1d045db2011-07-07 18:23:21 +02005599static int alc861_parse_auto_config(struct hda_codec *codec)
5600{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005601 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005602 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5603 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604}
5605
Takashi Iwai1d045db2011-07-07 18:23:21 +02005606#ifdef CONFIG_SND_HDA_POWER_SAVE
5607static const struct hda_amp_list alc861_loopbacks[] = {
5608 { 0x15, HDA_INPUT, 0 },
5609 { 0x15, HDA_INPUT, 1 },
5610 { 0x15, HDA_INPUT, 2 },
5611 { 0x15, HDA_INPUT, 3 },
5612 { } /* end */
5613};
5614#endif
5615
5616
5617/* Pin config fixes */
5618enum {
5619 PINFIX_FSC_AMILO_PI1505,
5620};
5621
5622static const struct alc_fixup alc861_fixups[] = {
5623 [PINFIX_FSC_AMILO_PI1505] = {
5624 .type = ALC_FIXUP_PINS,
5625 .v.pins = (const struct alc_pincfg[]) {
5626 { 0x0b, 0x0221101f }, /* HP */
5627 { 0x0f, 0x90170310 }, /* speaker */
5628 { }
5629 }
5630 },
5631};
5632
5633static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5634 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5635 {}
5636};
5637
5638/*
5639 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005640static int patch_alc861(struct hda_codec *codec)
5641{
5642 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005643 int err;
5644
5645 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5646 if (spec == NULL)
5647 return -ENOMEM;
5648
5649 codec->spec = spec;
5650
5651 spec->mixer_nid = 0x15;
5652
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005653 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5654 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005655
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005656 /* automatic parse from the BIOS config */
5657 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005658 if (err < 0)
5659 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005660
Takashi Iwai60a6a842011-07-27 14:01:24 +02005661 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005662 alc_auto_fill_adc_caps(codec);
5663 alc_rebuild_imux_for_auto_mic(codec);
5664 alc_remove_invalid_adc_nids(codec);
5665 }
5666
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005667 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005668 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005669
5670 if (!spec->no_analog) {
5671 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005672 if (err < 0)
5673 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005674 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5675 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005676
Takashi Iwai1d045db2011-07-07 18:23:21 +02005677 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5678
5679 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005680 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005681#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005682 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005683 if (!spec->loopback.amplist)
5684 spec->loopback.amplist = alc861_loopbacks;
5685#endif
5686
5687 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005688
5689 error:
5690 alc_free(codec);
5691 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005692}
5693
5694/*
5695 * ALC861-VD support
5696 *
5697 * Based on ALC882
5698 *
5699 * In addition, an independent DAC
5700 */
5701#ifdef CONFIG_SND_HDA_POWER_SAVE
5702#define alc861vd_loopbacks alc880_loopbacks
5703#endif
5704
Takashi Iwai1d045db2011-07-07 18:23:21 +02005705static int alc861vd_parse_auto_config(struct hda_codec *codec)
5706{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005707 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005708 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5709 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005710}
5711
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005713 ALC660VD_FIX_ASUS_GPIO1,
5714 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005715};
5716
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005717/* exclude VREF80 */
5718static void alc861vd_fixup_dallas(struct hda_codec *codec,
5719 const struct alc_fixup *fix, int action)
5720{
5721 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5722 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5723 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5724 }
5725}
5726
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727static const struct alc_fixup alc861vd_fixups[] = {
5728 [ALC660VD_FIX_ASUS_GPIO1] = {
5729 .type = ALC_FIXUP_VERBS,
5730 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005731 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005732 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5733 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5734 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5735 { }
5736 }
5737 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005738 [ALC861VD_FIX_DALLAS] = {
5739 .type = ALC_FIXUP_FUNC,
5740 .v.func = alc861vd_fixup_dallas,
5741 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005742};
5743
5744static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005745 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005746 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005747 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748 {}
5749};
5750
5751static const struct hda_verb alc660vd_eapd_verbs[] = {
5752 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5753 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5754 { }
5755};
5756
5757/*
5758 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005759static int patch_alc861vd(struct hda_codec *codec)
5760{
5761 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005762 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005763
5764 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5765 if (spec == NULL)
5766 return -ENOMEM;
5767
5768 codec->spec = spec;
5769
5770 spec->mixer_nid = 0x0b;
5771
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005772 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5773 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005774
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005775 /* automatic parse from the BIOS config */
5776 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005777 if (err < 0)
5778 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005779
Takashi Iwai1d045db2011-07-07 18:23:21 +02005780 if (codec->vendor_id == 0x10ec0660) {
5781 /* always turn on EAPD */
5782 add_verb(spec, alc660vd_eapd_verbs);
5783 }
5784
Takashi Iwai60a6a842011-07-27 14:01:24 +02005785 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786 alc_auto_fill_adc_caps(codec);
5787 alc_rebuild_imux_for_auto_mic(codec);
5788 alc_remove_invalid_adc_nids(codec);
5789 }
5790
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005791 if (!spec->no_analog && !spec->cap_mixer)
5792 set_capture_mixer(codec);
5793
5794 if (!spec->no_analog) {
5795 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005796 if (err < 0)
5797 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005798 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5799 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005800
Takashi Iwai1d045db2011-07-07 18:23:21 +02005801 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5802
5803 codec->patch_ops = alc_patch_ops;
5804
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005805 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005806 spec->shutup = alc_eapd_shutup;
5807#ifdef CONFIG_SND_HDA_POWER_SAVE
5808 if (!spec->loopback.amplist)
5809 spec->loopback.amplist = alc861vd_loopbacks;
5810#endif
5811
5812 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005813
5814 error:
5815 alc_free(codec);
5816 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005817}
5818
5819/*
5820 * ALC662 support
5821 *
5822 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5823 * configuration. Each pin widget can choose any input DACs and a mixer.
5824 * Each ADC is connected from a mixer of all inputs. This makes possible
5825 * 6-channel independent captures.
5826 *
5827 * In addition, an independent DAC for the multi-playback (not used in this
5828 * driver yet).
5829 */
5830#ifdef CONFIG_SND_HDA_POWER_SAVE
5831#define alc662_loopbacks alc880_loopbacks
5832#endif
5833
5834/*
5835 * BIOS auto configuration
5836 */
5837
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005838static int alc662_parse_auto_config(struct hda_codec *codec)
5839{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005840 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005841 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5842 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5843 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005844
Kailang Yang6227cdc2010-02-25 08:36:52 +01005845 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5846 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005847 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005848 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005849 ssids = alc662_ssids;
5850 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005851}
5852
Todd Broch6be79482010-12-07 16:51:05 -08005853static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005854 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005855{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005856 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005857 return;
Todd Broch6be79482010-12-07 16:51:05 -08005858 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5859 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5860 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5861 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5862 (0 << AC_AMPCAP_MUTE_SHIFT)))
5863 printk(KERN_WARNING
5864 "hda_codec: failed to override amp caps for NID 0x2\n");
5865}
5866
David Henningsson6cb3b702010-09-09 08:51:44 +02005867enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005868 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005869 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005870 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005871 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005872 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005873 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005874 ALC662_FIXUP_ASUS_MODE1,
5875 ALC662_FIXUP_ASUS_MODE2,
5876 ALC662_FIXUP_ASUS_MODE3,
5877 ALC662_FIXUP_ASUS_MODE4,
5878 ALC662_FIXUP_ASUS_MODE5,
5879 ALC662_FIXUP_ASUS_MODE6,
5880 ALC662_FIXUP_ASUS_MODE7,
5881 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005882};
5883
5884static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005885 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005886 .type = ALC_FIXUP_PINS,
5887 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005888 { 0x15, 0x99130112 }, /* subwoofer */
5889 { }
5890 }
5891 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005892 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005893 .type = ALC_FIXUP_PINS,
5894 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005895 { 0x17, 0x99130112 }, /* subwoofer */
5896 { }
5897 }
5898 },
Todd Broch6be79482010-12-07 16:51:05 -08005899 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005900 .type = ALC_FIXUP_FUNC,
5901 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005902 },
5903 [ALC662_FIXUP_CZC_P10T] = {
5904 .type = ALC_FIXUP_VERBS,
5905 .v.verbs = (const struct hda_verb[]) {
5906 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5907 {}
5908 }
5909 },
David Henningsson94024cd2011-04-29 14:10:55 +02005910 [ALC662_FIXUP_SKU_IGNORE] = {
5911 .type = ALC_FIXUP_SKU,
5912 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005913 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005914 [ALC662_FIXUP_HP_RP5800] = {
5915 .type = ALC_FIXUP_PINS,
5916 .v.pins = (const struct alc_pincfg[]) {
5917 { 0x14, 0x0221201f }, /* HP out */
5918 { }
5919 },
5920 .chained = true,
5921 .chain_id = ALC662_FIXUP_SKU_IGNORE
5922 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005923 [ALC662_FIXUP_ASUS_MODE1] = {
5924 .type = ALC_FIXUP_PINS,
5925 .v.pins = (const struct alc_pincfg[]) {
5926 { 0x14, 0x99130110 }, /* speaker */
5927 { 0x18, 0x01a19c20 }, /* mic */
5928 { 0x19, 0x99a3092f }, /* int-mic */
5929 { 0x21, 0x0121401f }, /* HP out */
5930 { }
5931 },
5932 .chained = true,
5933 .chain_id = ALC662_FIXUP_SKU_IGNORE
5934 },
5935 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005936 .type = ALC_FIXUP_PINS,
5937 .v.pins = (const struct alc_pincfg[]) {
5938 { 0x14, 0x99130110 }, /* speaker */
5939 { 0x18, 0x01a19820 }, /* mic */
5940 { 0x19, 0x99a3092f }, /* int-mic */
5941 { 0x1b, 0x0121401f }, /* HP out */
5942 { }
5943 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005944 .chained = true,
5945 .chain_id = ALC662_FIXUP_SKU_IGNORE
5946 },
5947 [ALC662_FIXUP_ASUS_MODE3] = {
5948 .type = ALC_FIXUP_PINS,
5949 .v.pins = (const struct alc_pincfg[]) {
5950 { 0x14, 0x99130110 }, /* speaker */
5951 { 0x15, 0x0121441f }, /* HP */
5952 { 0x18, 0x01a19840 }, /* mic */
5953 { 0x19, 0x99a3094f }, /* int-mic */
5954 { 0x21, 0x01211420 }, /* HP2 */
5955 { }
5956 },
5957 .chained = true,
5958 .chain_id = ALC662_FIXUP_SKU_IGNORE
5959 },
5960 [ALC662_FIXUP_ASUS_MODE4] = {
5961 .type = ALC_FIXUP_PINS,
5962 .v.pins = (const struct alc_pincfg[]) {
5963 { 0x14, 0x99130110 }, /* speaker */
5964 { 0x16, 0x99130111 }, /* speaker */
5965 { 0x18, 0x01a19840 }, /* mic */
5966 { 0x19, 0x99a3094f }, /* int-mic */
5967 { 0x21, 0x0121441f }, /* HP */
5968 { }
5969 },
5970 .chained = true,
5971 .chain_id = ALC662_FIXUP_SKU_IGNORE
5972 },
5973 [ALC662_FIXUP_ASUS_MODE5] = {
5974 .type = ALC_FIXUP_PINS,
5975 .v.pins = (const struct alc_pincfg[]) {
5976 { 0x14, 0x99130110 }, /* speaker */
5977 { 0x15, 0x0121441f }, /* HP */
5978 { 0x16, 0x99130111 }, /* speaker */
5979 { 0x18, 0x01a19840 }, /* mic */
5980 { 0x19, 0x99a3094f }, /* int-mic */
5981 { }
5982 },
5983 .chained = true,
5984 .chain_id = ALC662_FIXUP_SKU_IGNORE
5985 },
5986 [ALC662_FIXUP_ASUS_MODE6] = {
5987 .type = ALC_FIXUP_PINS,
5988 .v.pins = (const struct alc_pincfg[]) {
5989 { 0x14, 0x99130110 }, /* speaker */
5990 { 0x15, 0x01211420 }, /* HP2 */
5991 { 0x18, 0x01a19840 }, /* mic */
5992 { 0x19, 0x99a3094f }, /* int-mic */
5993 { 0x1b, 0x0121441f }, /* HP */
5994 { }
5995 },
5996 .chained = true,
5997 .chain_id = ALC662_FIXUP_SKU_IGNORE
5998 },
5999 [ALC662_FIXUP_ASUS_MODE7] = {
6000 .type = ALC_FIXUP_PINS,
6001 .v.pins = (const struct alc_pincfg[]) {
6002 { 0x14, 0x99130110 }, /* speaker */
6003 { 0x17, 0x99130111 }, /* speaker */
6004 { 0x18, 0x01a19840 }, /* mic */
6005 { 0x19, 0x99a3094f }, /* int-mic */
6006 { 0x1b, 0x01214020 }, /* HP */
6007 { 0x21, 0x0121401f }, /* HP */
6008 { }
6009 },
6010 .chained = true,
6011 .chain_id = ALC662_FIXUP_SKU_IGNORE
6012 },
6013 [ALC662_FIXUP_ASUS_MODE8] = {
6014 .type = ALC_FIXUP_PINS,
6015 .v.pins = (const struct alc_pincfg[]) {
6016 { 0x14, 0x99130110 }, /* speaker */
6017 { 0x12, 0x99a30970 }, /* int-mic */
6018 { 0x15, 0x01214020 }, /* HP */
6019 { 0x17, 0x99130111 }, /* speaker */
6020 { 0x18, 0x01a19840 }, /* mic */
6021 { 0x21, 0x0121401f }, /* HP */
6022 { }
6023 },
6024 .chained = true,
6025 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006026 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006027};
6028
Takashi Iwaia9111322011-05-02 11:30:18 +02006029static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006030 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006031 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006032 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006033 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006034 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006035 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006036 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006037 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006038 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006039 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006040
6041#if 0
6042 /* Below is a quirk table taken from the old code.
6043 * Basically the device should work as is without the fixup table.
6044 * If BIOS doesn't give a proper info, enable the corresponding
6045 * fixup entry.
6046 */
6047 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6048 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6049 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6050 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6051 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6052 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6053 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6054 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6055 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6056 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6057 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6058 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6059 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6060 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6061 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6062 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6063 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6064 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6065 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6066 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6067 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6068 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6069 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6070 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6071 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6072 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6073 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6074 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6075 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6076 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6077 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6078 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6079 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6080 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6081 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6082 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6083 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6084 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6085 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6086 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6087 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6088 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6089 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6090 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6091 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6092 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6093 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6094 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6095 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6096 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6097#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006098 {}
6099};
6100
Todd Broch6be79482010-12-07 16:51:05 -08006101static const struct alc_model_fixup alc662_fixup_models[] = {
6102 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006103 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6104 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6105 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6106 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6107 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6108 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6109 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6110 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006111 {}
6112};
David Henningsson6cb3b702010-09-09 08:51:44 +02006113
6114
Takashi Iwai1d045db2011-07-07 18:23:21 +02006115/*
6116 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006117static int patch_alc662(struct hda_codec *codec)
6118{
6119 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006120 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006121
6122 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6123 if (!spec)
6124 return -ENOMEM;
6125
6126 codec->spec = spec;
6127
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006128 spec->mixer_nid = 0x0b;
6129
Takashi Iwai53c334a2011-08-23 18:27:14 +02006130 /* handle multiple HPs as is */
6131 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6132
Kailang Yangda00c242010-03-19 11:23:45 +01006133 alc_auto_parse_customize_define(codec);
6134
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006135 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6136
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006137 err = alc_codec_rename_from_preset(codec);
6138 if (err < 0)
6139 goto error;
6140
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006141 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006142 codec->bus->pci->subsystem_vendor == 0x1025 &&
6143 spec->cdefine.platform_type == 1) {
6144 if (alc_codec_rename(codec, "ALC272X") < 0)
6145 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006146 }
Kailang Yang274693f2009-12-03 10:07:50 +01006147
Takashi Iwaib9c51062011-08-24 18:08:07 +02006148 alc_pick_fixup(codec, alc662_fixup_models,
6149 alc662_fixup_tbl, alc662_fixups);
6150 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6151 /* automatic parse from the BIOS config */
6152 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006153 if (err < 0)
6154 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006155
Takashi Iwai60a6a842011-07-27 14:01:24 +02006156 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006157 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006158 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006159 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006160 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006161
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006162 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006163 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006164
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006165 if (!spec->no_analog && has_cdefine_beep(codec)) {
6166 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006167 if (err < 0)
6168 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006169 switch (codec->vendor_id) {
6170 case 0x10ec0662:
6171 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6172 break;
6173 case 0x10ec0272:
6174 case 0x10ec0663:
6175 case 0x10ec0665:
6176 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6177 break;
6178 case 0x10ec0273:
6179 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6180 break;
6181 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006182 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006183
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006184 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6185
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006186 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006187 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006188 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006189
Kailang Yangbf1b0222010-10-21 08:49:56 +02006190 alc_init_jacks(codec);
6191
Takashi Iwaicb53c622007-08-10 17:21:45 +02006192#ifdef CONFIG_SND_HDA_POWER_SAVE
6193 if (!spec->loopback.amplist)
6194 spec->loopback.amplist = alc662_loopbacks;
6195#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006196
6197 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006198
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006199 error:
6200 alc_free(codec);
6201 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006202}
6203
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006204/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006205 * ALC680 support
6206 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006207
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006208static int alc680_parse_auto_config(struct hda_codec *codec)
6209{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006210 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006211}
6212
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006213/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006214 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006215static int patch_alc680(struct hda_codec *codec)
6216{
6217 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006218 int err;
6219
6220 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6221 if (spec == NULL)
6222 return -ENOMEM;
6223
6224 codec->spec = spec;
6225
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006226 /* ALC680 has no aa-loopback mixer */
6227
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006228 /* automatic parse from the BIOS config */
6229 err = alc680_parse_auto_config(codec);
6230 if (err < 0) {
6231 alc_free(codec);
6232 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006233 }
6234
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006235 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006236 set_capture_mixer(codec);
6237
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006238 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006239 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006240
6241 return 0;
6242}
6243
6244/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245 * patch entries
6246 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006247static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006248 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006249 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006250 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006251 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006252 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006253 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006254 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006255 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006256 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006257 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006258 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006259 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006260 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6261 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6262 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006263 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai49535502009-06-30 15:28:30 +02006264 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006265 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6266 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006267 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6268 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006269 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006270 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006271 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006272 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006273 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006274 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006275 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006276 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006277 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006278 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai49535502009-06-30 15:28:30 +02006279 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006280 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006281 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006282 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai49535502009-06-30 15:28:30 +02006283 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006284 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai49535502009-06-30 15:28:30 +02006285 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006286 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006287 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006288 {} /* terminator */
6289};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006290
6291MODULE_ALIAS("snd-hda-codec-id:10ec*");
6292
6293MODULE_LICENSE("GPL");
6294MODULE_DESCRIPTION("Realtek HD-audio codec");
6295
6296static struct hda_codec_preset_list realtek_list = {
6297 .preset = snd_hda_preset_realtek,
6298 .owner = THIS_MODULE,
6299};
6300
6301static int __init patch_realtek_init(void)
6302{
6303 return snd_hda_add_codec_preset(&realtek_list);
6304}
6305
6306static void __exit patch_realtek_exit(void)
6307{
6308 snd_hda_delete_codec_preset(&realtek_list);
6309}
6310
6311module_init(patch_realtek_init)
6312module_exit(patch_realtek_exit)