blob: 9a90cdac78f48db70844a662133256c6dd2e1585 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e42006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090035#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020036#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Takashi Iwai1d045db2011-07-07 18:23:21 +020038/* unsol event tags */
39#define ALC_FRONT_EVENT 0x01
40#define ALC_DCVOL_EVENT 0x02
41#define ALC_HP_EVENT 0x04
42#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020043
Kailang Yangdf694da2005-12-05 19:42:22 +010044/* for GPIO Poll */
45#define GPIO_MASK 0x03
46
Takashi Iwai4a79ba32009-04-22 16:31:35 +020047/* extra amp-initialization sequence types */
48enum {
49 ALC_INIT_NONE,
50 ALC_INIT_DEFAULT,
51 ALC_INIT_GPIO1,
52 ALC_INIT_GPIO2,
53 ALC_INIT_GPIO3,
54};
55
Kailang Yangda00c242010-03-19 11:23:45 +010056struct alc_customize_define {
57 unsigned int sku_cfg;
58 unsigned char port_connectivity;
59 unsigned char check_sum;
60 unsigned char customization;
61 unsigned char external_amp;
62 unsigned int enable_pcbeep:1;
63 unsigned int platform_type:1;
64 unsigned int swap:1;
65 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020066 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010067};
68
Takashi Iwaib5bfbc62011-01-13 14:22:32 +010069struct alc_fixup;
70
Takashi Iwaice764ab2011-04-27 16:35:23 +020071struct alc_multi_io {
72 hda_nid_t pin; /* multi-io widget pin NID */
73 hda_nid_t dac; /* DAC to be connected */
74 unsigned int ctl_in; /* cached input-pin control value */
75};
76
Takashi Iwaid922b512011-04-28 12:18:53 +020077enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020078 ALC_AUTOMUTE_PIN, /* change the pin control */
79 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
80 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020081};
82
Linus Torvalds1da177e2005-04-16 15:20:36 -070083struct alc_spec {
84 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020085 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010088 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Takashi Iwai2d9c6482009-10-13 08:06:55 +020090 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020091 * don't forget NULL
92 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020093 */
94 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095
Takashi Iwaiaa563af2009-07-31 10:05:11 +020096 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020097 const struct hda_pcm_stream *stream_analog_playback;
98 const struct hda_pcm_stream *stream_analog_capture;
99 const struct hda_pcm_stream *stream_analog_alt_playback;
100 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200102 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200103 const struct hda_pcm_stream *stream_digital_playback;
104 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
106 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200107 struct hda_multi_out multiout; /* playback set-up
108 * max_channels, dacs must be set
109 * dig_out_nid and hp_nid are optional
110 */
Takashi Iwai63300792008-01-24 15:31:36 +0100111 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100112 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100113 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 /* capture */
116 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200117 const hda_nid_t *adc_nids;
118 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200119 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200120 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwai527e4d72011-10-27 16:33:27 +0200121 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
122 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Takashi Iwai840b64c2010-07-13 22:49:01 +0200124 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200125 hda_nid_t cur_adc;
126 unsigned int cur_adc_stream_tag;
127 unsigned int cur_adc_format;
128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200130 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 const struct hda_input_mux *input_mux;
132 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200133 hda_nid_t ext_mic_pin;
134 hda_nid_t dock_mic_pin;
135 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100138 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200140 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200141 int const_channel_count;
142 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100145 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200146
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200147 /* dynamic controls, init_verbs and input_mux */
148 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100149 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200150 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200151 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200152 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200153 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
154 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200155 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
156 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
157 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100158
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100159 /* hooks */
160 void (*init_hook)(struct hda_codec *codec);
161 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100162#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500163 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200165 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200166 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100167
Takashi Iwai834be882006-03-01 14:16:17 +0100168 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200169 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200170 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200171 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200172 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200173 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200174 unsigned int automute_speaker:1; /* automute speaker outputs */
175 unsigned int automute_lo:1; /* automute LO outputs */
176 unsigned int detect_hp:1; /* Headphone detection enabled */
177 unsigned int detect_lo:1; /* Line-out detection enabled */
178 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
179 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200180
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100181 /* other flags */
182 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200183 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100184 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200185 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200186 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100187 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai3a938972011-10-28 01:16:55 +0200188 unsigned int use_jack_tbl:1; /* 1 for model=auto */
Takashi Iwaid922b512011-04-28 12:18:53 +0200189
190 /* auto-mute control */
191 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200192 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200193
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200194 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200195 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100196
Takashi Iwai2134ea42008-01-10 16:53:55 +0100197 /* for virtual master */
198 hda_nid_t vmaster_nid;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200199#ifdef CONFIG_SND_HDA_POWER_SAVE
200 struct hda_loopback_check loopback;
201#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200202
203 /* for PLL fix */
204 hda_nid_t pll_nid;
205 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200206 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100207
208 /* fix-up list */
209 int fixup_id;
210 const struct alc_fixup *fixup_list;
211 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200212
213 /* multi-io */
214 int multi_ios;
215 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200216
217 /* bind volumes */
218 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100219};
220
Takashi Iwai1d045db2011-07-07 18:23:21 +0200221#define ALC_MODEL_AUTO 0 /* common for all chips */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Takashi Iwai44c02402011-07-08 15:14:19 +0200223static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
224 int dir, unsigned int bits)
225{
226 if (!nid)
227 return false;
228 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
229 if (query_amp_caps(codec, nid, dir) & bits)
230 return true;
231 return false;
232}
233
234#define nid_has_mute(codec, nid, dir) \
235 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
236#define nid_has_volume(codec, nid, dir) \
237 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
238
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239/*
240 * input MUX handling
241 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200242static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
243 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
245 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
246 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200247 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
248 if (mux_idx >= spec->num_mux_defs)
249 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100250 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
251 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200252 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253}
254
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200255static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
256 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257{
258 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
259 struct alc_spec *spec = codec->spec;
260 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
261
262 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
263 return 0;
264}
265
Takashi Iwai21268962011-07-07 15:01:13 +0200266static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
Takashi Iwai21268962011-07-07 15:01:13 +0200268 struct alc_spec *spec = codec->spec;
269 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
270
271 if (spec->cur_adc && spec->cur_adc != new_adc) {
272 /* stream is running, let's swap the current ADC */
273 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
274 spec->cur_adc = new_adc;
275 snd_hda_codec_setup_stream(codec, new_adc,
276 spec->cur_adc_stream_tag, 0,
277 spec->cur_adc_format);
278 return true;
279 }
280 return false;
281}
282
Takashi Iwai24de1832011-11-07 17:13:39 +0100283static void call_update_outputs(struct hda_codec *codec);
284
Takashi Iwai21268962011-07-07 15:01:13 +0200285/* select the given imux item; either unmute exclusively or select the route */
286static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
287 unsigned int idx, bool force)
288{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100290 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100291 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100292 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200293 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Takashi Iwaicd896c32008-11-18 12:36:33 +0100295 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
296 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100297 if (!imux->num_items && mux_idx > 0)
298 imux = &spec->input_mux[0];
Takashi Iwaicd896c32008-11-18 12:36:33 +0100299
Takashi Iwai21268962011-07-07 15:01:13 +0200300 if (idx >= imux->num_items)
301 idx = imux->num_items - 1;
302 if (spec->cur_mux[adc_idx] == idx && !force)
303 return 0;
304 spec->cur_mux[adc_idx] = idx;
305
Takashi Iwai24de1832011-11-07 17:13:39 +0100306 /* for shared I/O, change the pin-control accordingly */
307 if (spec->shared_mic_hp) {
308 /* NOTE: this assumes that there are only two inputs, the
309 * first is the real internal mic and the second is HP jack.
310 */
311 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
312 AC_VERB_SET_PIN_WIDGET_CONTROL,
313 spec->cur_mux[adc_idx] ?
314 PIN_VREF80 : PIN_HP);
315 spec->automute_speaker = !spec->cur_mux[adc_idx];
316 call_update_outputs(codec);
317 }
318
Takashi Iwai21268962011-07-07 15:01:13 +0200319 if (spec->dyn_adc_switch) {
320 alc_dyn_adc_pcm_resetup(codec, idx);
321 adc_idx = spec->dyn_adc_idx[idx];
322 }
323
324 nid = spec->capsrc_nids ?
325 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
326
327 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100328 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
329 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200330 return 1;
331
Takashi Iwaia22d5432009-07-27 12:54:26 +0200332 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200333 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100334 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100335 int active = imux->items[idx].index;
336 for (i = 0; i < num_conns; i++) {
337 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
338 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100339 HDA_AMP_MUTE, v);
340 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100341 } else {
342 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200343 snd_hda_codec_write_cache(codec, nid, 0,
344 AC_VERB_SET_CONNECT_SEL,
345 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100346 }
Takashi Iwai21268962011-07-07 15:01:13 +0200347 return 1;
348}
349
350static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
351 struct snd_ctl_elem_value *ucontrol)
352{
353 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
354 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
355 return alc_mux_select(codec, adc_idx,
356 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100357}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200358
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100360 * set up the input pin config (depending on the given auto-pin type)
361 */
362static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
363 int auto_pin_type)
364{
365 unsigned int val = PIN_IN;
366
Takashi Iwai86e29592010-09-09 14:50:17 +0200367 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100368 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200369 unsigned int oldval;
370 oldval = snd_hda_codec_read(codec, nid, 0,
371 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100372 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100373 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200374 /* if the default pin setup is vref50, we give it priority */
375 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100376 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200377 else if (pincap & AC_PINCAP_VREF_50)
378 val = PIN_VREF50;
379 else if (pincap & AC_PINCAP_VREF_100)
380 val = PIN_VREF100;
381 else if (pincap & AC_PINCAP_VREF_GRD)
382 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100383 }
384 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
385}
386
387/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200388 * Append the given mixer and verb elements for the later use
389 * The mixer array is referred in build_controls(), and init_verbs are
390 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100391 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200392static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100393{
394 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
395 return;
396 spec->mixers[spec->num_mixers++] = mix;
397}
398
399static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
400{
401 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
402 return;
403 spec->init_verbs[spec->num_init_verbs++] = verb;
404}
405
406/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200407 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100408 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200409/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200410static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200411 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
412 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
413 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
414 { }
415};
416
Takashi Iwaia9111322011-05-02 11:30:18 +0200417static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200418 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
419 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
420 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
421 { }
422};
423
Takashi Iwaia9111322011-05-02 11:30:18 +0200424static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200425 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
426 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
427 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
428 { }
429};
430
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200431/*
432 * Fix hardware PLL issue
433 * On some codecs, the analog PLL gating control must be off while
434 * the default value is 1.
435 */
436static void alc_fix_pll(struct hda_codec *codec)
437{
438 struct alc_spec *spec = codec->spec;
439 unsigned int val;
440
441 if (!spec->pll_nid)
442 return;
443 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
444 spec->pll_coef_idx);
445 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
446 AC_VERB_GET_PROC_COEF, 0);
447 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
448 spec->pll_coef_idx);
449 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
450 val & ~(1 << spec->pll_coef_bit));
451}
452
453static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
454 unsigned int coef_idx, unsigned int coef_bit)
455{
456 struct alc_spec *spec = codec->spec;
457 spec->pll_nid = nid;
458 spec->pll_coef_idx = coef_idx;
459 spec->pll_coef_bit = coef_bit;
460 alc_fix_pll(codec);
461}
462
Takashi Iwai1d045db2011-07-07 18:23:21 +0200463/*
464 * Jack-reporting via input-jack layer
465 */
466
467/* initialization of jacks; currently checks only a few known pins */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200468static int alc_init_jacks(struct hda_codec *codec)
469{
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100470#ifdef CONFIG_SND_HDA_INPUT_JACK
Kailang Yang9ad0e492010-09-14 23:22:00 +0200471 struct alc_spec *spec = codec->spec;
472 int err;
473 unsigned int hp_nid = spec->autocfg.hp_pins[0];
Takashi Iwai21268962011-07-07 15:01:13 +0200474 unsigned int mic_nid = spec->ext_mic_pin;
475 unsigned int dock_nid = spec->dock_mic_pin;
Kailang Yang9ad0e492010-09-14 23:22:00 +0200476
Takashi Iwai265a0242010-09-21 11:26:21 +0200477 if (hp_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100478 err = snd_hda_input_jack_add(codec, hp_nid,
479 SND_JACK_HEADPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200480 if (err < 0)
481 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100482 snd_hda_input_jack_report(codec, hp_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200483 }
Kailang Yang9ad0e492010-09-14 23:22:00 +0200484
Takashi Iwai265a0242010-09-21 11:26:21 +0200485 if (mic_nid) {
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100486 err = snd_hda_input_jack_add(codec, mic_nid,
487 SND_JACK_MICROPHONE, NULL);
Takashi Iwai265a0242010-09-21 11:26:21 +0200488 if (err < 0)
489 return err;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100490 snd_hda_input_jack_report(codec, mic_nid);
Takashi Iwai265a0242010-09-21 11:26:21 +0200491 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +0200492 if (dock_nid) {
493 err = snd_hda_input_jack_add(codec, dock_nid,
494 SND_JACK_MICROPHONE, NULL);
495 if (err < 0)
496 return err;
497 snd_hda_input_jack_report(codec, dock_nid);
498 }
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100499#endif /* CONFIG_SND_HDA_INPUT_JACK */
Kailang Yang9ad0e492010-09-14 23:22:00 +0200500 return 0;
501}
Kailang Yang9ad0e492010-09-14 23:22:00 +0200502
Takashi Iwai1d045db2011-07-07 18:23:21 +0200503/*
504 * Jack detections for HP auto-mute and mic-switch
505 */
506
507/* check each pin in the given array; returns true if any of them is plugged */
508static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200509{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200510 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200511
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200512 for (i = 0; i < num_pins; i++) {
513 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200514 if (!nid)
515 break;
Takashi Iwaicd372fb2011-03-03 14:40:14 +0100516 snd_hda_input_jack_report(codec, nid);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200518 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200519 return present;
520}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200521
Takashi Iwai1d045db2011-07-07 18:23:21 +0200522/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200523static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200524 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200525{
526 struct alc_spec *spec = codec->spec;
527 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200528 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529 int i;
530
531 for (i = 0; i < num_pins; i++) {
532 hda_nid_t nid = pins[i];
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200533 if (!nid)
534 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200535 switch (spec->automute_mode) {
536 case ALC_AUTOMUTE_PIN:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200537 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200538 AC_VERB_SET_PIN_WIDGET_CONTROL,
539 pin_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200540 break;
541 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200542 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200544 break;
545 case ALC_AUTOMUTE_MIXER:
546 nid = spec->automute_mixer_nid[i];
547 if (!nid)
548 break;
549 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200550 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200551 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200552 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200553 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200554 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200555 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200556}
557
David Henningsson42cf0d02011-09-20 12:04:56 +0200558/* Toggle outputs muting */
559static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200560{
561 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200562 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200563
Takashi Iwaic0a20262011-06-10 15:28:15 +0200564 /* Control HP pins/amps depending on master_mute state;
565 * in general, HP pins/amps control should be enabled in all cases,
566 * but currently set only for master_mute, just to be safe
567 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100568 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
569 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200570 spec->autocfg.hp_pins, spec->master_mute, true);
571
David Henningsson42cf0d02011-09-20 12:04:56 +0200572 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200573 on = 0;
574 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200575 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200576 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200578 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200579
580 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200581 /* if LO is a copy of either HP or Speaker, don't need to handle it */
582 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
583 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200584 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200585 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200586 on = 0;
587 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200588 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200589 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200590 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200591 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200592}
593
David Henningsson42cf0d02011-09-20 12:04:56 +0200594static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200595{
596 struct alc_spec *spec = codec->spec;
597 if (spec->automute_hook)
598 spec->automute_hook(codec);
599 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200600 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200601}
602
Takashi Iwai1d045db2011-07-07 18:23:21 +0200603/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200604static void alc_hp_automute(struct hda_codec *codec)
605{
606 struct alc_spec *spec = codec->spec;
607
David Henningsson42cf0d02011-09-20 12:04:56 +0200608 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200609 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
610 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200611 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200612 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200613 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200614}
615
Takashi Iwai1d045db2011-07-07 18:23:21 +0200616/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200617static void alc_line_automute(struct hda_codec *codec)
618{
619 struct alc_spec *spec = codec->spec;
620
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200621 /* check LO jack only when it's different from HP */
622 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
623 return;
624
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200625 spec->line_jack_present =
626 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
627 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200628 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200629 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200630 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200631}
632
Takashi Iwai8d087c72011-06-28 12:45:47 +0200633#define get_connection_index(codec, mux, nid) \
634 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200635
Takashi Iwai1d045db2011-07-07 18:23:21 +0200636/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200637static void alc_mic_automute(struct hda_codec *codec)
638{
639 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200640 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200641
Takashi Iwai21268962011-07-07 15:01:13 +0200642 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200643 return;
644 if (snd_BUG_ON(!spec->adc_nids))
645 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200646 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200647 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200648
Takashi Iwai21268962011-07-07 15:01:13 +0200649 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
650 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
651 else if (spec->dock_mic_idx >= 0 &&
652 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
653 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
654 else
655 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Takashi Iwai6c819492009-08-10 18:47:44 +0200656
Takashi Iwai21268962011-07-07 15:01:13 +0200657 snd_hda_input_jack_report(codec, pins[spec->ext_mic_idx]);
658 if (spec->dock_mic_idx >= 0)
659 snd_hda_input_jack_report(codec, pins[spec->dock_mic_idx]);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200660}
661
Kailang Yangc9b58002007-10-16 14:30:01 +0200662/* unsolicited event for HP jack sensing */
663static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
664{
Takashi Iwai3a938972011-10-28 01:16:55 +0200665 struct alc_spec *spec = codec->spec;
Kailang Yangc9b58002007-10-16 14:30:01 +0200666 if (codec->vendor_id == 0x10ec0880)
667 res >>= 28;
668 else
669 res >>= 26;
Takashi Iwai3a938972011-10-28 01:16:55 +0200670 if (spec->use_jack_tbl)
671 res = snd_hda_jack_get_action(codec, res);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200672 switch (res) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200673 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200674 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200675 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200676 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200677 alc_line_automute(codec);
678 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200679 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200680 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200681 break;
682 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200683 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200684}
685
Takashi Iwai1d045db2011-07-07 18:23:21 +0200686/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200687static void alc_inithook(struct hda_codec *codec)
688{
Takashi Iwaid922b512011-04-28 12:18:53 +0200689 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200690 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200691 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200692}
693
Kailang Yangf9423e72008-05-27 12:32:25 +0200694/* additional initialization for ALC888 variants */
695static void alc888_coef_init(struct hda_codec *codec)
696{
697 unsigned int tmp;
698
699 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
700 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
701 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100702 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200703 /* alc888S-VC */
704 snd_hda_codec_read(codec, 0x20, 0,
705 AC_VERB_SET_PROC_COEF, 0x830);
706 else
707 /* alc888-VB */
708 snd_hda_codec_read(codec, 0x20, 0,
709 AC_VERB_SET_PROC_COEF, 0x3030);
710}
711
Takashi Iwai1d045db2011-07-07 18:23:21 +0200712/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200713static void alc889_coef_init(struct hda_codec *codec)
714{
715 unsigned int tmp;
716
717 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
718 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
719 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
720 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
721}
722
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100723/* turn on/off EAPD control (only if available) */
724static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
725{
726 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
727 return;
728 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
729 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
730 on ? 2 : 0);
731}
732
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200733/* turn on/off EAPD controls of the codec */
734static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
735{
736 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200737 static hda_nid_t pins[] = {
738 0x0f, 0x10, 0x14, 0x15, 0
739 };
740 hda_nid_t *p;
741 for (p = pins; *p; p++)
742 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200743}
744
Takashi Iwai1c716152011-04-07 10:37:16 +0200745/* generic shutup callback;
746 * just turning off EPAD and a little pause for avoiding pop-noise
747 */
748static void alc_eapd_shutup(struct hda_codec *codec)
749{
750 alc_auto_setup_eapd(codec, false);
751 msleep(200);
752}
753
Takashi Iwai1d045db2011-07-07 18:23:21 +0200754/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200755static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200756{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200757 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200758
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200759 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200760 switch (type) {
761 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200762 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
763 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200764 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200765 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
766 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200767 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200768 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
769 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200771 switch (codec->vendor_id) {
772 case 0x10ec0260:
773 snd_hda_codec_write(codec, 0x1a, 0,
774 AC_VERB_SET_COEF_INDEX, 7);
775 tmp = snd_hda_codec_read(codec, 0x1a, 0,
776 AC_VERB_GET_PROC_COEF, 0);
777 snd_hda_codec_write(codec, 0x1a, 0,
778 AC_VERB_SET_COEF_INDEX, 7);
779 snd_hda_codec_write(codec, 0x1a, 0,
780 AC_VERB_SET_PROC_COEF,
781 tmp | 0x2010);
782 break;
783 case 0x10ec0262:
784 case 0x10ec0880:
785 case 0x10ec0882:
786 case 0x10ec0883:
787 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100788 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100789 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200790 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200791 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200792 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200793 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200794 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100795#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200796 case 0x10ec0267:
797 case 0x10ec0268:
798 snd_hda_codec_write(codec, 0x20, 0,
799 AC_VERB_SET_COEF_INDEX, 7);
800 tmp = snd_hda_codec_read(codec, 0x20, 0,
801 AC_VERB_GET_PROC_COEF, 0);
802 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200803 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200804 snd_hda_codec_write(codec, 0x20, 0,
805 AC_VERB_SET_PROC_COEF,
806 tmp | 0x3000);
807 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100808#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200809 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200810 break;
811 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200812}
Kailang Yangea1fb292008-08-26 12:58:38 +0200813
Takashi Iwai1d045db2011-07-07 18:23:21 +0200814/*
815 * Auto-Mute mode mixer enum support
816 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200817static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
818 struct snd_ctl_elem_info *uinfo)
819{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200820 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
821 struct alc_spec *spec = codec->spec;
822 static const char * const texts2[] = {
823 "Disabled", "Enabled"
824 };
825 static const char * const texts3[] = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200826 "Disabled", "Speaker Only", "Line-Out+Speaker"
827 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200828 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200829
830 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
831 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200832 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200833 uinfo->value.enumerated.items = 3;
834 texts = texts3;
835 } else {
836 uinfo->value.enumerated.items = 2;
837 texts = texts2;
838 }
839 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
840 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200841 strcpy(uinfo->value.enumerated.name,
842 texts[uinfo->value.enumerated.item]);
843 return 0;
844}
845
846static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
847 struct snd_ctl_elem_value *ucontrol)
848{
849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
850 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200851 unsigned int val = 0;
852 if (spec->automute_speaker)
853 val++;
854 if (spec->automute_lo)
855 val++;
856
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200857 ucontrol->value.enumerated.item[0] = val;
858 return 0;
859}
860
861static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
862 struct snd_ctl_elem_value *ucontrol)
863{
864 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
865 struct alc_spec *spec = codec->spec;
866
867 switch (ucontrol->value.enumerated.item[0]) {
868 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200869 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200870 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200871 spec->automute_speaker = 0;
872 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200873 break;
874 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200875 if (spec->automute_speaker_possible) {
876 if (!spec->automute_lo && spec->automute_speaker)
877 return 0;
878 spec->automute_speaker = 1;
879 spec->automute_lo = 0;
880 } else if (spec->automute_lo_possible) {
881 if (spec->automute_lo)
882 return 0;
883 spec->automute_lo = 1;
884 } else
885 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200886 break;
887 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200888 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200889 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200890 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200891 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200892 spec->automute_speaker = 1;
893 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200894 break;
895 default:
896 return -EINVAL;
897 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200898 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899 return 1;
900}
901
Takashi Iwaia9111322011-05-02 11:30:18 +0200902static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200903 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
904 .name = "Auto-Mute Mode",
905 .info = alc_automute_mode_info,
906 .get = alc_automute_mode_get,
907 .put = alc_automute_mode_put,
908};
909
Takashi Iwai1d045db2011-07-07 18:23:21 +0200910static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
911{
912 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
913 return snd_array_new(&spec->kctls);
914}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200915
916static int alc_add_automute_mode_enum(struct hda_codec *codec)
917{
918 struct alc_spec *spec = codec->spec;
919 struct snd_kcontrol_new *knew;
920
921 knew = alc_kcontrol_new(spec);
922 if (!knew)
923 return -ENOMEM;
924 *knew = alc_automute_mode_enum;
925 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
926 if (!knew->name)
927 return -ENOMEM;
928 return 0;
929}
930
Takashi Iwai1d045db2011-07-07 18:23:21 +0200931/*
932 * Check the availability of HP/line-out auto-mute;
933 * Set up appropriately if really supported
934 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200935static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200936{
937 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200938 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200939 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200940 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200941
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200942 if (cfg->hp_pins[0])
943 present++;
944 if (cfg->line_out_pins[0])
945 present++;
946 if (cfg->speaker_pins[0])
947 present++;
948 if (present < 2) /* need two different output types */
949 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200950
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200951 if (!cfg->speaker_pins[0] &&
952 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200953 memcpy(cfg->speaker_pins, cfg->line_out_pins,
954 sizeof(cfg->speaker_pins));
955 cfg->speaker_outs = cfg->line_outs;
956 }
957
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200958 if (!cfg->hp_pins[0] &&
959 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200960 memcpy(cfg->hp_pins, cfg->line_out_pins,
961 sizeof(cfg->hp_pins));
962 cfg->hp_outs = cfg->line_outs;
963 }
964
David Henningsson42cf0d02011-09-20 12:04:56 +0200965 spec->automute_mode = ALC_AUTOMUTE_PIN;
966
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200967 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200968 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200969 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200970 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200971 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200972 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200973 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200974 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200975 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200976
David Henningsson42cf0d02011-09-20 12:04:56 +0200977 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
978 if (cfg->speaker_outs)
979 for (i = 0; i < cfg->line_outs; i++) {
980 hda_nid_t nid = cfg->line_out_pins[i];
981 if (!is_jack_detectable(codec, nid))
982 continue;
983 snd_printdd("realtek: Enable Line-Out "
984 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200985 snd_hda_jack_detect_enable(codec, nid,
986 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200987 spec->detect_lo = 1;
988 }
989 spec->automute_lo_possible = spec->detect_hp;
990 }
991
992 spec->automute_speaker_possible = cfg->speaker_outs &&
993 (spec->detect_hp || spec->detect_lo);
994
995 spec->automute_lo = spec->automute_lo_possible;
996 spec->automute_speaker = spec->automute_speaker_possible;
997
998 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200999 /* create a control for automute mode */
1000 alc_add_automute_mode_enum(codec);
1001 spec->unsol_event = alc_sku_unsol_event;
1002 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001003}
1004
Takashi Iwai1d045db2011-07-07 18:23:21 +02001005/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001006static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1007{
1008 int i;
1009 for (i = 0; i < nums; i++)
1010 if (list[i] == nid)
1011 return i;
1012 return -1;
1013}
1014
Takashi Iwai1d045db2011-07-07 18:23:21 +02001015/* check whether dynamic ADC-switching is available */
1016static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1017{
1018 struct alc_spec *spec = codec->spec;
1019 struct hda_input_mux *imux = &spec->private_imux[0];
1020 int i, n, idx;
1021 hda_nid_t cap, pin;
1022
1023 if (imux != spec->input_mux) /* no dynamic imux? */
1024 return false;
1025
1026 for (n = 0; n < spec->num_adc_nids; n++) {
1027 cap = spec->private_capsrc_nids[n];
1028 for (i = 0; i < imux->num_items; i++) {
1029 pin = spec->imux_pins[i];
1030 if (!pin)
1031 return false;
1032 if (get_connection_index(codec, cap, pin) < 0)
1033 break;
1034 }
1035 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001036 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001037 }
1038
1039 for (i = 0; i < imux->num_items; i++) {
1040 pin = spec->imux_pins[i];
1041 for (n = 0; n < spec->num_adc_nids; n++) {
1042 cap = spec->private_capsrc_nids[n];
1043 idx = get_connection_index(codec, cap, pin);
1044 if (idx >= 0) {
1045 imux->items[i].index = idx;
1046 spec->dyn_adc_idx[i] = n;
1047 break;
1048 }
1049 }
1050 }
1051
1052 snd_printdd("realtek: enabling ADC switching\n");
1053 spec->dyn_adc_switch = 1;
1054 return true;
1055}
Takashi Iwai21268962011-07-07 15:01:13 +02001056
1057/* rebuild imux for matching with the given auto-mic pins (if not yet) */
1058static bool alc_rebuild_imux_for_auto_mic(struct hda_codec *codec)
1059{
1060 struct alc_spec *spec = codec->spec;
1061 struct hda_input_mux *imux;
1062 static char * const texts[3] = {
1063 "Mic", "Internal Mic", "Dock Mic"
1064 };
1065 int i;
1066
1067 if (!spec->auto_mic)
1068 return false;
1069 imux = &spec->private_imux[0];
1070 if (spec->input_mux == imux)
1071 return true;
1072 spec->imux_pins[0] = spec->ext_mic_pin;
1073 spec->imux_pins[1] = spec->int_mic_pin;
1074 spec->imux_pins[2] = spec->dock_mic_pin;
1075 for (i = 0; i < 3; i++) {
1076 strcpy(imux->items[i].label, texts[i]);
1077 if (spec->imux_pins[i])
1078 imux->num_items = i + 1;
1079 }
1080 spec->num_mux_defs = 1;
1081 spec->input_mux = imux;
1082 return true;
1083}
1084
1085/* check whether all auto-mic pins are valid; setup indices if OK */
1086static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1087{
1088 struct alc_spec *spec = codec->spec;
1089 const struct hda_input_mux *imux;
1090
1091 if (!spec->auto_mic)
1092 return false;
1093 if (spec->auto_mic_valid_imux)
1094 return true; /* already checked */
1095
1096 /* fill up imux indices */
1097 if (!alc_check_dyn_adc_switch(codec)) {
1098 spec->auto_mic = 0;
1099 return false;
1100 }
1101
1102 imux = spec->input_mux;
1103 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1104 spec->imux_pins, imux->num_items);
1105 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1106 spec->imux_pins, imux->num_items);
1107 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1108 spec->imux_pins, imux->num_items);
1109 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1110 spec->auto_mic = 0;
1111 return false; /* no corresponding imux */
1112 }
1113
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001114 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001115 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001116 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1117 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001118
1119 spec->auto_mic_valid_imux = 1;
1120 spec->auto_mic = 1;
1121 return true;
1122}
1123
Takashi Iwai1d045db2011-07-07 18:23:21 +02001124/*
1125 * Check the availability of auto-mic switch;
1126 * Set up if really supported
1127 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001128static void alc_init_auto_mic(struct hda_codec *codec)
1129{
1130 struct alc_spec *spec = codec->spec;
1131 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001132 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001133 int i;
1134
Takashi Iwai24de1832011-11-07 17:13:39 +01001135 if (spec->shared_mic_hp)
1136 return; /* no auto-mic for the shared I/O */
1137
Takashi Iwai21268962011-07-07 15:01:13 +02001138 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1139
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001140 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001141 for (i = 0; i < cfg->num_inputs; i++) {
1142 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001143 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001144 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001145 switch (snd_hda_get_input_pin_attr(defcfg)) {
1146 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001147 if (fixed)
1148 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001149 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1150 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001151 fixed = nid;
1152 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001153 case INPUT_PIN_ATTR_UNUSED:
1154 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001155 case INPUT_PIN_ATTR_DOCK:
1156 if (dock)
1157 return; /* already occupied */
1158 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1159 return; /* invalid type */
1160 dock = nid;
1161 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001162 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001163 if (ext)
1164 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001165 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1166 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001167 ext = nid;
1168 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001169 }
1170 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001171 if (!ext && dock) {
1172 ext = dock;
1173 dock = 0;
1174 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001175 if (!ext || !fixed)
1176 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001177 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001178 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001179 if (dock && !is_jack_detectable(codec, dock))
1180 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001181
1182 /* check imux indices */
1183 spec->ext_mic_pin = ext;
1184 spec->int_mic_pin = fixed;
1185 spec->dock_mic_pin = dock;
1186
1187 spec->auto_mic = 1;
1188 if (!alc_auto_mic_check_imux(codec))
1189 return;
1190
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001191 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1192 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001193 spec->unsol_event = alc_sku_unsol_event;
1194}
1195
Takashi Iwai1d045db2011-07-07 18:23:21 +02001196/* check the availabilities of auto-mute and auto-mic switches */
1197static void alc_auto_check_switches(struct hda_codec *codec)
1198{
David Henningsson42cf0d02011-09-20 12:04:56 +02001199 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001200 alc_init_auto_mic(codec);
1201}
1202
1203/*
1204 * Realtek SSID verification
1205 */
1206
David Henningsson90622912010-10-14 14:50:18 +02001207/* Could be any non-zero and even value. When used as fixup, tells
1208 * the driver to ignore any present sku defines.
1209 */
1210#define ALC_FIXUP_SKU_IGNORE (2)
1211
Kailang Yangda00c242010-03-19 11:23:45 +01001212static int alc_auto_parse_customize_define(struct hda_codec *codec)
1213{
1214 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001215 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001216 struct alc_spec *spec = codec->spec;
1217
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001218 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1219
David Henningsson90622912010-10-14 14:50:18 +02001220 if (spec->cdefine.fixup) {
1221 ass = spec->cdefine.sku_cfg;
1222 if (ass == ALC_FIXUP_SKU_IGNORE)
1223 return -1;
1224 goto do_sku;
1225 }
1226
Kailang Yangda00c242010-03-19 11:23:45 +01001227 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001228 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001229 goto do_sku;
1230
1231 nid = 0x1d;
1232 if (codec->vendor_id == 0x10ec0260)
1233 nid = 0x17;
1234 ass = snd_hda_codec_get_pincfg(codec, nid);
1235
1236 if (!(ass & 1)) {
1237 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1238 codec->chip_name, ass);
1239 return -1;
1240 }
1241
1242 /* check sum */
1243 tmp = 0;
1244 for (i = 1; i < 16; i++) {
1245 if ((ass >> i) & 1)
1246 tmp++;
1247 }
1248 if (((ass >> 16) & 0xf) != tmp)
1249 return -1;
1250
1251 spec->cdefine.port_connectivity = ass >> 30;
1252 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1253 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1254 spec->cdefine.customization = ass >> 8;
1255do_sku:
1256 spec->cdefine.sku_cfg = ass;
1257 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1258 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1259 spec->cdefine.swap = (ass & 0x2) >> 1;
1260 spec->cdefine.override = ass & 0x1;
1261
1262 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1263 nid, spec->cdefine.sku_cfg);
1264 snd_printd("SKU: port_connectivity=0x%x\n",
1265 spec->cdefine.port_connectivity);
1266 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1267 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1268 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1269 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1270 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1271 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1272 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1273
1274 return 0;
1275}
1276
Takashi Iwai1d045db2011-07-07 18:23:21 +02001277/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001278static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1279{
Takashi Iwai21268962011-07-07 15:01:13 +02001280 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001281}
1282
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001283/* check subsystem ID and set up device-specific initialization;
1284 * return 1 if initialized, 0 if invalid SSID
1285 */
1286/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1287 * 31 ~ 16 : Manufacture ID
1288 * 15 ~ 8 : SKU ID
1289 * 7 ~ 0 : Assembly ID
1290 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1291 */
1292static int alc_subsystem_id(struct hda_codec *codec,
1293 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001294 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001295{
1296 unsigned int ass, tmp, i;
1297 unsigned nid;
1298 struct alc_spec *spec = codec->spec;
1299
David Henningsson90622912010-10-14 14:50:18 +02001300 if (spec->cdefine.fixup) {
1301 ass = spec->cdefine.sku_cfg;
1302 if (ass == ALC_FIXUP_SKU_IGNORE)
1303 return 0;
1304 goto do_sku;
1305 }
1306
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001307 ass = codec->subsystem_id & 0xffff;
1308 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1309 goto do_sku;
1310
1311 /* invalid SSID, check the special NID pin defcfg instead */
1312 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001313 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001314 * 29~21 : reserve
1315 * 20 : PCBEEP input
1316 * 19~16 : Check sum (15:1)
1317 * 15~1 : Custom
1318 * 0 : override
1319 */
1320 nid = 0x1d;
1321 if (codec->vendor_id == 0x10ec0260)
1322 nid = 0x17;
1323 ass = snd_hda_codec_get_pincfg(codec, nid);
1324 snd_printd("realtek: No valid SSID, "
1325 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001326 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001327 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001328 return 0;
1329 if ((ass >> 30) != 1) /* no physical connection */
1330 return 0;
1331
1332 /* check sum */
1333 tmp = 0;
1334 for (i = 1; i < 16; i++) {
1335 if ((ass >> i) & 1)
1336 tmp++;
1337 }
1338 if (((ass >> 16) & 0xf) != tmp)
1339 return 0;
1340do_sku:
1341 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1342 ass & 0xffff, codec->vendor_id);
1343 /*
1344 * 0 : override
1345 * 1 : Swap Jack
1346 * 2 : 0 --> Desktop, 1 --> Laptop
1347 * 3~5 : External Amplifier control
1348 * 7~6 : Reserved
1349 */
1350 tmp = (ass & 0x38) >> 3; /* external Amp control */
1351 switch (tmp) {
1352 case 1:
1353 spec->init_amp = ALC_INIT_GPIO1;
1354 break;
1355 case 3:
1356 spec->init_amp = ALC_INIT_GPIO2;
1357 break;
1358 case 7:
1359 spec->init_amp = ALC_INIT_GPIO3;
1360 break;
1361 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001362 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001363 spec->init_amp = ALC_INIT_DEFAULT;
1364 break;
1365 }
1366
1367 /* is laptop or Desktop and enable the function "Mute internal speaker
1368 * when the external headphone out jack is plugged"
1369 */
1370 if (!(ass & 0x8000))
1371 return 1;
1372 /*
1373 * 10~8 : Jack location
1374 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1375 * 14~13: Resvered
1376 * 15 : 1 --> enable the function "Mute internal speaker
1377 * when the external headphone out jack is plugged"
1378 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001379 if (!spec->autocfg.hp_pins[0] &&
1380 !(spec->autocfg.line_out_pins[0] &&
1381 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001382 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001383 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1384 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001385 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001386 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001387 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001388 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001389 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001390 else if (tmp == 3)
1391 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001392 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001393 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001394 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1395 spec->autocfg.line_outs))
1396 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001397 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001398 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001399 return 1;
1400}
Kailang Yangea1fb292008-08-26 12:58:38 +02001401
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001402/* Check the validity of ALC subsystem-id
1403 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1404static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001405{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001406 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001407 struct alc_spec *spec = codec->spec;
1408 snd_printd("realtek: "
1409 "Enable default setup for auto mode as fallback\n");
1410 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001411 }
Takashi Iwai21268962011-07-07 15:01:13 +02001412}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001413
Takashi Iwai41e41f12005-06-08 14:48:49 +02001414/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001415 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001416 */
1417
1418struct alc_pincfg {
1419 hda_nid_t nid;
1420 u32 val;
1421};
1422
Todd Broche1eb5f12010-12-06 11:19:51 -08001423struct alc_model_fixup {
1424 const int id;
1425 const char *name;
1426};
1427
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001428struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001429 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001430 bool chained;
1431 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001432 union {
1433 unsigned int sku;
1434 const struct alc_pincfg *pins;
1435 const struct hda_verb *verbs;
1436 void (*func)(struct hda_codec *codec,
1437 const struct alc_fixup *fix,
1438 int action);
1439 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001440};
1441
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001442enum {
1443 ALC_FIXUP_INVALID,
1444 ALC_FIXUP_SKU,
1445 ALC_FIXUP_PINS,
1446 ALC_FIXUP_VERBS,
1447 ALC_FIXUP_FUNC,
1448};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001449
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001450enum {
1451 ALC_FIXUP_ACT_PRE_PROBE,
1452 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001453 ALC_FIXUP_ACT_INIT,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001454};
1455
1456static void alc_apply_fixup(struct hda_codec *codec, int action)
1457{
1458 struct alc_spec *spec = codec->spec;
1459 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001460#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001461 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001462#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001463 int depth = 0;
1464
1465 if (!spec->fixup_list)
1466 return;
1467
1468 while (id >= 0) {
1469 const struct alc_fixup *fix = spec->fixup_list + id;
1470 const struct alc_pincfg *cfg;
1471
1472 switch (fix->type) {
1473 case ALC_FIXUP_SKU:
1474 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001475 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001476 snd_printdd(KERN_INFO "hda_codec: %s: "
1477 "Apply sku override for %s\n",
1478 codec->chip_name, modelname);
1479 spec->cdefine.sku_cfg = fix->v.sku;
1480 spec->cdefine.fixup = 1;
1481 break;
1482 case ALC_FIXUP_PINS:
1483 cfg = fix->v.pins;
1484 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1485 break;
1486 snd_printdd(KERN_INFO "hda_codec: %s: "
1487 "Apply pincfg for %s\n",
1488 codec->chip_name, modelname);
1489 for (; cfg->nid; cfg++)
1490 snd_hda_codec_set_pincfg(codec, cfg->nid,
1491 cfg->val);
1492 break;
1493 case ALC_FIXUP_VERBS:
1494 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1495 break;
1496 snd_printdd(KERN_INFO "hda_codec: %s: "
1497 "Apply fix-verbs for %s\n",
1498 codec->chip_name, modelname);
1499 add_verb(codec->spec, fix->v.verbs);
1500 break;
1501 case ALC_FIXUP_FUNC:
1502 if (!fix->v.func)
1503 break;
1504 snd_printdd(KERN_INFO "hda_codec: %s: "
1505 "Apply fix-func for %s\n",
1506 codec->chip_name, modelname);
1507 fix->v.func(codec, fix, action);
1508 break;
1509 default:
1510 snd_printk(KERN_ERR "hda_codec: %s: "
1511 "Invalid fixup type %d\n",
1512 codec->chip_name, fix->type);
1513 break;
1514 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001515 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001516 break;
1517 if (++depth > 10)
1518 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001519 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001520 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001521}
1522
Todd Broche1eb5f12010-12-06 11:19:51 -08001523static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001524 const struct alc_model_fixup *models,
1525 const struct snd_pci_quirk *quirk,
1526 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001527{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001528 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001529 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001530 int id = -1;
1531 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001532
Todd Broche1eb5f12010-12-06 11:19:51 -08001533 if (codec->modelname && models) {
1534 while (models->name) {
1535 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001536 id = models->id;
1537 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001538 break;
1539 }
1540 models++;
1541 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001542 }
1543 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001544 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1545 if (q) {
1546 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001547#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001548 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001549#endif
1550 }
1551 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001552 if (id < 0) {
1553 for (q = quirk; q->subvendor; q++) {
1554 unsigned int vendorid =
1555 q->subdevice | (q->subvendor << 16);
1556 if (vendorid == codec->subsystem_id) {
1557 id = q->value;
1558#ifdef CONFIG_SND_DEBUG_VERBOSE
1559 name = q->name;
1560#endif
1561 break;
1562 }
1563 }
1564 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001565
1566 spec->fixup_id = id;
1567 if (id >= 0) {
1568 spec->fixup_list = fixlist;
1569 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001570 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001571}
1572
Takashi Iwai1d045db2011-07-07 18:23:21 +02001573/*
1574 * COEF access helper functions
1575 */
Kailang Yang274693f2009-12-03 10:07:50 +01001576static int alc_read_coef_idx(struct hda_codec *codec,
1577 unsigned int coef_idx)
1578{
1579 unsigned int val;
1580 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1581 coef_idx);
1582 val = snd_hda_codec_read(codec, 0x20, 0,
1583 AC_VERB_GET_PROC_COEF, 0);
1584 return val;
1585}
1586
Kailang Yang977ddd62010-09-15 10:02:29 +02001587static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1588 unsigned int coef_val)
1589{
1590 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1591 coef_idx);
1592 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1593 coef_val);
1594}
1595
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001596/* a special bypass for COEF 0; read the cached value at the second time */
1597static unsigned int alc_get_coef0(struct hda_codec *codec)
1598{
1599 struct alc_spec *spec = codec->spec;
1600 if (!spec->coef0)
1601 spec->coef0 = alc_read_coef_idx(codec, 0);
1602 return spec->coef0;
1603}
1604
Takashi Iwai1d045db2011-07-07 18:23:21 +02001605/*
1606 * Digital I/O handling
1607 */
1608
Takashi Iwai757899a2010-07-30 10:48:14 +02001609/* set right pin controls for digital I/O */
1610static void alc_auto_init_digital(struct hda_codec *codec)
1611{
1612 struct alc_spec *spec = codec->spec;
1613 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001614 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001615
1616 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1617 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001618 if (!pin)
1619 continue;
1620 snd_hda_codec_write(codec, pin, 0,
1621 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1622 if (!i)
1623 dac = spec->multiout.dig_out_nid;
1624 else
1625 dac = spec->slave_dig_outs[i - 1];
1626 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1627 continue;
1628 snd_hda_codec_write(codec, dac, 0,
1629 AC_VERB_SET_AMP_GAIN_MUTE,
1630 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001631 }
1632 pin = spec->autocfg.dig_in_pin;
1633 if (pin)
1634 snd_hda_codec_write(codec, pin, 0,
1635 AC_VERB_SET_PIN_WIDGET_CONTROL,
1636 PIN_IN);
1637}
1638
1639/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1640static void alc_auto_parse_digital(struct hda_codec *codec)
1641{
1642 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001643 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001644 hda_nid_t dig_nid;
1645
1646 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001647 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001648 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001649 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001650 err = snd_hda_get_connections(codec,
1651 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001652 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001653 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001654 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001655 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001656 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001657 spec->multiout.dig_out_nid = dig_nid;
1658 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1659 } else {
1660 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001661 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001662 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001663 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001664 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001665 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001666 }
1667
1668 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001669 dig_nid = codec->start_nid;
1670 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1671 unsigned int wcaps = get_wcaps(codec, dig_nid);
1672 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1673 continue;
1674 if (!(wcaps & AC_WCAP_DIGITAL))
1675 continue;
1676 if (!(wcaps & AC_WCAP_CONN_LIST))
1677 continue;
1678 err = get_connection_index(codec, dig_nid,
1679 spec->autocfg.dig_in_pin);
1680 if (err >= 0) {
1681 spec->dig_in_nid = dig_nid;
1682 break;
1683 }
1684 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001685 }
1686}
1687
Takashi Iwaif95474e2007-07-10 00:47:43 +02001688/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001689 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001690 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001691static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1692 struct snd_ctl_elem_info *uinfo)
1693{
1694 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1695 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001696 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001697 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001698
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001699 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001700 if (spec->vol_in_capsrc)
1701 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1702 else
1703 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1704 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001705 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001706 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001707 return err;
1708}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001710static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1711 unsigned int size, unsigned int __user *tlv)
1712{
1713 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1714 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001715 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001716 int err;
1717
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001718 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001719 if (spec->vol_in_capsrc)
1720 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1721 else
1722 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1723 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001724 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001725 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001726 return err;
1727}
1728
1729typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1730 struct snd_ctl_elem_value *ucontrol);
1731
1732static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1733 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001734 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001735{
1736 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1737 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001738 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001739
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001740 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001741 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001742 for (i = 0; i < spec->num_adc_nids; i++) {
1743 kcontrol->private_value =
1744 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1745 3, 0, HDA_INPUT);
1746 err = func(kcontrol, ucontrol);
1747 if (err < 0)
1748 goto error;
1749 }
1750 } else {
1751 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001752 if (spec->vol_in_capsrc)
1753 kcontrol->private_value =
1754 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1755 3, 0, HDA_OUTPUT);
1756 else
1757 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001758 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1759 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001760 err = func(kcontrol, ucontrol);
1761 }
1762 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001763 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001764 return err;
1765}
1766
1767static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1768 struct snd_ctl_elem_value *ucontrol)
1769{
1770 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001771 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001772}
1773
1774static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1775 struct snd_ctl_elem_value *ucontrol)
1776{
1777 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001778 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001779}
1780
1781/* capture mixer elements */
1782#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1783
1784static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1785 struct snd_ctl_elem_value *ucontrol)
1786{
1787 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001788 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001789}
1790
1791static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1792 struct snd_ctl_elem_value *ucontrol)
1793{
1794 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001795 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001796}
1797
Takashi Iwaia23b6882009-03-23 15:21:36 +01001798#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001799 { \
1800 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1801 .name = "Capture Switch", \
1802 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1803 .count = num, \
1804 .info = alc_cap_sw_info, \
1805 .get = alc_cap_sw_get, \
1806 .put = alc_cap_sw_put, \
1807 }, \
1808 { \
1809 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1810 .name = "Capture Volume", \
1811 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1812 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1813 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1814 .count = num, \
1815 .info = alc_cap_vol_info, \
1816 .get = alc_cap_vol_get, \
1817 .put = alc_cap_vol_put, \
1818 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001819 }
1820
1821#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001822 { \
1823 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1824 /* .name = "Capture Source", */ \
1825 .name = "Input Source", \
1826 .count = num, \
1827 .info = alc_mux_enum_info, \
1828 .get = alc_mux_enum_get, \
1829 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001830 }
1831
1832#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001833static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001834 _DEFINE_CAPMIX(num), \
1835 _DEFINE_CAPSRC(num), \
1836 { } /* end */ \
1837}
1838
1839#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001840static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001841 _DEFINE_CAPMIX(num), \
1842 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001843}
1844
1845/* up to three ADCs */
1846DEFINE_CAPMIX(1);
1847DEFINE_CAPMIX(2);
1848DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001849DEFINE_CAPMIX_NOSRC(1);
1850DEFINE_CAPMIX_NOSRC(2);
1851DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001852
1853/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001854 * virtual master controls
1855 */
1856
1857/*
1858 * slave controls for virtual master
1859 */
Takashi Iwaiea734962011-01-17 11:29:34 +01001860static const char * const alc_slave_vols[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001861 "Front Playback Volume",
1862 "Surround Playback Volume",
1863 "Center Playback Volume",
1864 "LFE Playback Volume",
1865 "Side Playback Volume",
1866 "Headphone Playback Volume",
1867 "Speaker Playback Volume",
1868 "Mono Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001869 "Line-Out Playback Volume",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001870 "PCM Playback Volume",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001871 NULL,
1872};
1873
Takashi Iwaiea734962011-01-17 11:29:34 +01001874static const char * const alc_slave_sws[] = {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001875 "Front Playback Switch",
1876 "Surround Playback Switch",
1877 "Center Playback Switch",
1878 "LFE Playback Switch",
1879 "Side Playback Switch",
1880 "Headphone Playback Switch",
1881 "Speaker Playback Switch",
1882 "Mono Playback Switch",
Takashi Iwaiedb54a52008-01-29 12:47:02 +01001883 "IEC958 Playback Switch",
Takashi Iwai23033b22009-12-08 12:36:52 +01001884 "Line-Out Playback Switch",
Takashi Iwai3fe45ae2011-08-18 15:13:17 +02001885 "PCM Playback Switch",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001886 NULL,
1887};
1888
1889/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001890 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001892
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001893#define NID_MAPPING (-1)
1894
1895#define SUBDEV_SPEAKER_ (0 << 6)
1896#define SUBDEV_HP_ (1 << 6)
1897#define SUBDEV_LINE_ (2 << 6)
1898#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1899#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1900#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1901
Takashi Iwai603c4012008-07-30 15:01:44 +02001902static void alc_free_kctls(struct hda_codec *codec);
1903
Takashi Iwai67d634c2009-11-16 15:35:59 +01001904#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001905/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001906static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001907 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001908 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001909 { } /* end */
1910};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001911#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001912
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913static int alc_build_controls(struct hda_codec *codec)
1914{
1915 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001916 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001917 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001918 int i, j, err;
1919 unsigned int u;
1920 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921
1922 for (i = 0; i < spec->num_mixers; i++) {
1923 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1924 if (err < 0)
1925 return err;
1926 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001927 if (spec->cap_mixer) {
1928 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1929 if (err < 0)
1930 return err;
1931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001933 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001934 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001935 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 if (err < 0)
1937 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001938 if (!spec->no_analog) {
1939 err = snd_hda_create_spdif_share_sw(codec,
1940 &spec->multiout);
1941 if (err < 0)
1942 return err;
1943 spec->multiout.share_spdif = 1;
1944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 }
1946 if (spec->dig_in_nid) {
1947 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1948 if (err < 0)
1949 return err;
1950 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001951
Takashi Iwai67d634c2009-11-16 15:35:59 +01001952#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001953 /* create beep controls if needed */
1954 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001955 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001956 for (knew = alc_beep_mixer; knew->name; knew++) {
1957 struct snd_kcontrol *kctl;
1958 kctl = snd_ctl_new1(knew, codec);
1959 if (!kctl)
1960 return -ENOMEM;
1961 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001962 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001963 if (err < 0)
1964 return err;
1965 }
1966 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001967#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001968
Takashi Iwai2134ea42008-01-10 16:53:55 +01001969 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001970 if (!spec->no_analog &&
1971 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001972 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001973 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001974 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001975 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001976 vmaster_tlv, alc_slave_vols);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001977 if (err < 0)
1978 return err;
1979 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001980 if (!spec->no_analog &&
1981 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai2134ea42008-01-10 16:53:55 +01001982 err = snd_hda_add_vmaster(codec, "Master Playback Switch",
1983 NULL, alc_slave_sws);
1984 if (err < 0)
1985 return err;
1986 }
1987
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001988 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001989 if (spec->capsrc_nids || spec->adc_nids) {
1990 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1991 if (!kctl)
1992 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1993 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02001994 const hda_nid_t *nids = spec->capsrc_nids;
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001995 if (!nids)
1996 nids = spec->adc_nids;
1997 err = snd_hda_add_nid(codec, kctl, i, nids[i]);
1998 if (err < 0)
1999 return err;
2000 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002001 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02002002 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01002003 const char *kname = kctl ? kctl->id.name : NULL;
2004 for (knew = spec->cap_mixer; knew->name; knew++) {
2005 if (kname && strcmp(knew->name, kname) == 0)
2006 continue;
2007 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2008 for (i = 0; kctl && i < kctl->count; i++) {
2009 err = snd_hda_add_nid(codec, kctl, i,
2010 spec->adc_nids[i]);
2011 if (err < 0)
2012 return err;
2013 }
2014 }
2015 }
2016
2017 /* other nid->control mapping */
2018 for (i = 0; i < spec->num_mixers; i++) {
2019 for (knew = spec->mixers[i]; knew->name; knew++) {
2020 if (knew->iface != NID_MAPPING)
2021 continue;
2022 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2023 if (kctl == NULL)
2024 continue;
2025 u = knew->subdevice;
2026 for (j = 0; j < 4; j++, u >>= 8) {
2027 nid = u & 0x3f;
2028 if (nid == 0)
2029 continue;
2030 switch (u & 0xc0) {
2031 case SUBDEV_SPEAKER_:
2032 nid = spec->autocfg.speaker_pins[nid];
2033 break;
2034 case SUBDEV_LINE_:
2035 nid = spec->autocfg.line_out_pins[nid];
2036 break;
2037 case SUBDEV_HP_:
2038 nid = spec->autocfg.hp_pins[nid];
2039 break;
2040 default:
2041 continue;
2042 }
2043 err = snd_hda_add_nid(codec, kctl, 0, nid);
2044 if (err < 0)
2045 return err;
2046 }
2047 u = knew->private_value;
2048 for (j = 0; j < 4; j++, u >>= 8) {
2049 nid = u & 0xff;
2050 if (nid == 0)
2051 continue;
2052 err = snd_hda_add_nid(codec, kctl, 0, nid);
2053 if (err < 0)
2054 return err;
2055 }
2056 }
2057 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002058
2059 alc_free_kctls(codec); /* no longer needed */
2060
Takashi Iwai01a61e12011-10-28 00:03:22 +02002061 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
2062 if (err < 0)
2063 return err;
2064
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 return 0;
2066}
2067
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002068
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002070 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002071 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002072
Takashi Iwai584c0c42011-03-10 12:51:11 +01002073static void alc_init_special_input_src(struct hda_codec *codec);
2074
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075static int alc_init(struct hda_codec *codec)
2076{
2077 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002078 unsigned int i;
2079
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002080 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002081 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002082
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002083 for (i = 0; i < spec->num_init_verbs; i++)
2084 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002085 alc_init_special_input_src(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002086
2087 if (spec->init_hook)
2088 spec->init_hook(codec);
2089
Takashi Iwai58701122011-01-13 15:41:45 +01002090 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2091
Takashi Iwai01a61e12011-10-28 00:03:22 +02002092 snd_hda_jack_report_sync(codec);
2093
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002094 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 return 0;
2096}
2097
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002098static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2099{
2100 struct alc_spec *spec = codec->spec;
2101
2102 if (spec->unsol_event)
2103 spec->unsol_event(codec, res);
2104}
2105
Takashi Iwaicb53c622007-08-10 17:21:45 +02002106#ifdef CONFIG_SND_HDA_POWER_SAVE
2107static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2108{
2109 struct alc_spec *spec = codec->spec;
2110 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2111}
2112#endif
2113
Linus Torvalds1da177e2005-04-16 15:20:36 -07002114/*
2115 * Analog playback callbacks
2116 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002117static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002119 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
2121 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002122 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2123 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124}
2125
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002126static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 struct hda_codec *codec,
2128 unsigned int stream_tag,
2129 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002130 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131{
2132 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002133 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2134 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135}
2136
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002137static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002139 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140{
2141 struct alc_spec *spec = codec->spec;
2142 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2143}
2144
2145/*
2146 * Digital out
2147 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002148static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002149 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002150 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151{
2152 struct alc_spec *spec = codec->spec;
2153 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2154}
2155
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002156static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002157 struct hda_codec *codec,
2158 unsigned int stream_tag,
2159 unsigned int format,
2160 struct snd_pcm_substream *substream)
2161{
2162 struct alc_spec *spec = codec->spec;
2163 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2164 stream_tag, format, substream);
2165}
2166
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002167static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002168 struct hda_codec *codec,
2169 struct snd_pcm_substream *substream)
2170{
2171 struct alc_spec *spec = codec->spec;
2172 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2173}
2174
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002175static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002177 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178{
2179 struct alc_spec *spec = codec->spec;
2180 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2181}
2182
2183/*
2184 * Analog capture
2185 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002186static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 struct hda_codec *codec,
2188 unsigned int stream_tag,
2189 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002190 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191{
2192 struct alc_spec *spec = codec->spec;
2193
Takashi Iwai63300792008-01-24 15:31:36 +01002194 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 stream_tag, 0, format);
2196 return 0;
2197}
2198
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002199static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002201 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202{
2203 struct alc_spec *spec = codec->spec;
2204
Takashi Iwai888afa12008-03-18 09:57:50 +01002205 snd_hda_codec_cleanup_stream(codec,
2206 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 return 0;
2208}
2209
Takashi Iwai840b64c2010-07-13 22:49:01 +02002210/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002211static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002212 struct hda_codec *codec,
2213 unsigned int stream_tag,
2214 unsigned int format,
2215 struct snd_pcm_substream *substream)
2216{
2217 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002218 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002219 spec->cur_adc_stream_tag = stream_tag;
2220 spec->cur_adc_format = format;
2221 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2222 return 0;
2223}
2224
Takashi Iwai21268962011-07-07 15:01:13 +02002225static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002226 struct hda_codec *codec,
2227 struct snd_pcm_substream *substream)
2228{
2229 struct alc_spec *spec = codec->spec;
2230 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2231 spec->cur_adc = 0;
2232 return 0;
2233}
2234
Takashi Iwai21268962011-07-07 15:01:13 +02002235static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002236 .substreams = 1,
2237 .channels_min = 2,
2238 .channels_max = 2,
2239 .nid = 0, /* fill later */
2240 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002241 .prepare = dyn_adc_capture_pcm_prepare,
2242 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002243 },
2244};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
2246/*
2247 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002248static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 .substreams = 1,
2250 .channels_min = 2,
2251 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002252 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002254 .open = alc_playback_pcm_open,
2255 .prepare = alc_playback_pcm_prepare,
2256 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 },
2258};
2259
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002260static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002261 .substreams = 1,
2262 .channels_min = 2,
2263 .channels_max = 2,
2264 /* NID is set in alc_build_pcms */
2265};
2266
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002267static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002268 .substreams = 1,
2269 .channels_min = 2,
2270 .channels_max = 2,
2271 /* NID is set in alc_build_pcms */
2272};
2273
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002274static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002275 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 .channels_min = 2,
2277 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002278 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002280 .prepare = alc_alt_capture_pcm_prepare,
2281 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 },
2283};
2284
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002285static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 .substreams = 1,
2287 .channels_min = 2,
2288 .channels_max = 2,
2289 /* NID is set in alc_build_pcms */
2290 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002291 .open = alc_dig_playback_pcm_open,
2292 .close = alc_dig_playback_pcm_close,
2293 .prepare = alc_dig_playback_pcm_prepare,
2294 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 },
2296};
2297
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002298static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 .substreams = 1,
2300 .channels_min = 2,
2301 .channels_max = 2,
2302 /* NID is set in alc_build_pcms */
2303};
2304
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002305/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002306static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002307 .substreams = 0,
2308 .channels_min = 0,
2309 .channels_max = 0,
2310};
2311
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312static int alc_build_pcms(struct hda_codec *codec)
2313{
2314 struct alc_spec *spec = codec->spec;
2315 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002316 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002317 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 int i;
2319
2320 codec->num_pcms = 1;
2321 codec->pcm_info = info;
2322
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002323 if (spec->no_analog)
2324 goto skip_analog;
2325
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002326 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2327 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002329
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002330 if (spec->multiout.dac_nids > 0) {
2331 p = spec->stream_analog_playback;
2332 if (!p)
2333 p = &alc_pcm_analog_playback;
2334 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002335 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2336 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002337 if (spec->adc_nids) {
2338 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002339 if (!p) {
2340 if (spec->dyn_adc_switch)
2341 p = &dyn_adc_pcm_analog_capture;
2342 else
2343 p = &alc_pcm_analog_capture;
2344 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002345 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002346 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2347 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348
Takashi Iwai4a471b72005-12-07 13:56:29 +01002349 if (spec->channel_mode) {
2350 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2351 for (i = 0; i < spec->num_channel_mode; i++) {
2352 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2353 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 }
2356 }
2357
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002358 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002359 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002361 snprintf(spec->stream_name_digital,
2362 sizeof(spec->stream_name_digital),
2363 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002364 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002365 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002366 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002368 if (spec->dig_out_type)
2369 info->pcm_type = spec->dig_out_type;
2370 else
2371 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002372 if (spec->multiout.dig_out_nid) {
2373 p = spec->stream_digital_playback;
2374 if (!p)
2375 p = &alc_pcm_digital_playback;
2376 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2378 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002379 if (spec->dig_in_nid) {
2380 p = spec->stream_digital_capture;
2381 if (!p)
2382 p = &alc_pcm_digital_capture;
2383 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2385 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002386 /* FIXME: do we need this for all Realtek codec models? */
2387 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 }
2389
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002390 if (spec->no_analog)
2391 return 0;
2392
Takashi Iwaie08a0072006-09-07 17:52:14 +02002393 /* If the use of more than one ADC is requested for the current
2394 * model, configure a second analog capture-only PCM.
2395 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002396 have_multi_adcs = (spec->num_adc_nids > 1) &&
2397 !spec->dyn_adc_switch && !spec->auto_mic &&
2398 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002399 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002400 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002401 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002402 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002403 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002404 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002405 p = spec->stream_analog_alt_playback;
2406 if (!p)
2407 p = &alc_pcm_analog_alt_playback;
2408 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002409 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2410 spec->alt_dac_nid;
2411 } else {
2412 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2413 alc_pcm_null_stream;
2414 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2415 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002416 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002417 p = spec->stream_analog_alt_capture;
2418 if (!p)
2419 p = &alc_pcm_analog_alt_capture;
2420 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002421 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2422 spec->adc_nids[1];
2423 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2424 spec->num_adc_nids - 1;
2425 } else {
2426 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2427 alc_pcm_null_stream;
2428 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002429 }
2430 }
2431
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 return 0;
2433}
2434
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002435static inline void alc_shutup(struct hda_codec *codec)
2436{
Takashi Iwai1c716152011-04-07 10:37:16 +02002437 struct alc_spec *spec = codec->spec;
2438
2439 if (spec && spec->shutup)
2440 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002441 snd_hda_shutup_pins(codec);
2442}
2443
Takashi Iwai603c4012008-07-30 15:01:44 +02002444static void alc_free_kctls(struct hda_codec *codec)
2445{
2446 struct alc_spec *spec = codec->spec;
2447
2448 if (spec->kctls.list) {
2449 struct snd_kcontrol_new *kctl = spec->kctls.list;
2450 int i;
2451 for (i = 0; i < spec->kctls.used; i++)
2452 kfree(kctl[i].name);
2453 }
2454 snd_array_free(&spec->kctls);
2455}
2456
Takashi Iwai23c09b02011-08-19 09:05:35 +02002457static void alc_free_bind_ctls(struct hda_codec *codec)
2458{
2459 struct alc_spec *spec = codec->spec;
2460 if (spec->bind_ctls.list) {
2461 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2462 int i;
2463 for (i = 0; i < spec->bind_ctls.used; i++)
2464 kfree(ctl[i]);
2465 }
2466 snd_array_free(&spec->bind_ctls);
2467}
2468
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469static void alc_free(struct hda_codec *codec)
2470{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002471 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002472
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002473 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002474 return;
2475
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002476 alc_shutup(codec);
Takashi Iwaicd372fb2011-03-03 14:40:14 +01002477 snd_hda_input_jack_free(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002478 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002479 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002480 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002481 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482}
2483
Hector Martinf5de24b2009-12-20 22:51:31 +01002484#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002485static void alc_power_eapd(struct hda_codec *codec)
2486{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002487 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002488}
2489
Hector Martinf5de24b2009-12-20 22:51:31 +01002490static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2491{
2492 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002493 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002494 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002495 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002496 return 0;
2497}
2498#endif
2499
Takashi Iwai2a439522011-07-26 09:52:50 +02002500#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002501static int alc_resume(struct hda_codec *codec)
2502{
Takashi Iwai1c716152011-04-07 10:37:16 +02002503 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002504 codec->patch_ops.init(codec);
2505 snd_hda_codec_resume_amp(codec);
2506 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002507 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002508 return 0;
2509}
Takashi Iwaie044c392008-10-27 16:56:24 +01002510#endif
2511
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512/*
2513 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002514static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 .build_controls = alc_build_controls,
2516 .build_pcms = alc_build_pcms,
2517 .init = alc_init,
2518 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002519 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002520#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002521 .resume = alc_resume,
2522#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002523#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002524 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002525 .check_power_status = alc_check_power_status,
2526#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002527 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528};
2529
Kailang Yangc027ddc2010-03-19 11:33:06 +01002530/* replace the codec chip_name with the given string */
2531static int alc_codec_rename(struct hda_codec *codec, const char *name)
2532{
2533 kfree(codec->chip_name);
2534 codec->chip_name = kstrdup(name, GFP_KERNEL);
2535 if (!codec->chip_name) {
2536 alc_free(codec);
2537 return -ENOMEM;
2538 }
2539 return 0;
2540}
2541
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002542/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002543 * Rename codecs appropriately from COEF value
2544 */
2545struct alc_codec_rename_table {
2546 unsigned int vendor_id;
2547 unsigned short coef_mask;
2548 unsigned short coef_bits;
2549 const char *name;
2550};
2551
2552static struct alc_codec_rename_table rename_tbl[] = {
2553 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2554 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2555 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2556 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2557 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2558 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2559 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2560 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2561 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2562 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2563 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2564 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2565 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2566 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2567 { } /* terminator */
2568};
2569
2570static int alc_codec_rename_from_preset(struct hda_codec *codec)
2571{
2572 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002573
2574 for (p = rename_tbl; p->vendor_id; p++) {
2575 if (p->vendor_id != codec->vendor_id)
2576 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002577 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002578 return alc_codec_rename(codec, p->name);
2579 }
2580 return 0;
2581}
2582
2583/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002584 * Automatic parse of I/O pins from the BIOS configuration
2585 */
2586
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002587enum {
2588 ALC_CTL_WIDGET_VOL,
2589 ALC_CTL_WIDGET_MUTE,
2590 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002591 ALC_CTL_BIND_VOL,
2592 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002593};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002594static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002595 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2596 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002597 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002598 HDA_BIND_VOL(NULL, 0),
2599 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002600};
2601
2602/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002603static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002604 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002605{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002606 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002607
Takashi Iwaice764ab2011-04-27 16:35:23 +02002608 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002609 if (!knew)
2610 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002611 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002612 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002613 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002614 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002615 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002616 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002617 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002618 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002619 return 0;
2620}
2621
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002622static int add_control_with_pfx(struct alc_spec *spec, int type,
2623 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002624 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002625{
2626 char name[32];
2627 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002628 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002629}
2630
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002631#define add_pb_vol_ctrl(spec, type, pfx, val) \
2632 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2633#define add_pb_sw_ctrl(spec, type, pfx, val) \
2634 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2635#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2636 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2637#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2638 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002639
Takashi Iwai23c09b02011-08-19 09:05:35 +02002640static const char * const channel_name[4] = {
2641 "Front", "Surround", "CLFE", "Side"
2642};
2643
Takashi Iwai6843ca12011-06-24 11:03:58 +02002644static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2645 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002646{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002647 struct auto_pin_cfg *cfg = &spec->autocfg;
2648
Takashi Iwai6843ca12011-06-24 11:03:58 +02002649 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002650 if (cfg->line_outs == 1 && !spec->multi_ios &&
2651 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002652 return "Master";
2653
2654 switch (cfg->line_out_type) {
2655 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002656 if (cfg->line_outs == 1)
2657 return "Speaker";
2658 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002659 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002660 /* for multi-io case, only the primary out */
2661 if (ch && spec->multi_ios)
2662 break;
2663 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002664 return "Headphone";
2665 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002666 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002667 return "PCM";
2668 break;
2669 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002670 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2671 return "PCM";
2672
2673 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002674}
2675
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002676/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002677static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002678 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002679 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002680{
Kailang Yangdf694da2005-12-05 19:42:22 +01002681 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002682
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002683 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002684 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2685 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002686 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002687 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002688 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2689 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002690 return err;
2691 return 0;
2692}
2693
Takashi Iwai05f5f472009-08-25 13:10:18 +02002694static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002695{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002696 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2697 return (pincap & AC_PINCAP_IN) != 0;
2698}
2699
Takashi Iwai1d045db2011-07-07 18:23:21 +02002700/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002701static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002702{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002703 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002704 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002705 hda_nid_t *adc_nids = spec->private_adc_nids;
2706 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2707 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002708 int i, nums = 0;
2709
Takashi Iwai24de1832011-11-07 17:13:39 +01002710 if (spec->shared_mic_hp)
2711 max_nums = 1; /* no multi streams with the shared HP/mic */
2712
Takashi Iwaib7821702011-07-06 15:12:46 +02002713 nid = codec->start_nid;
2714 for (i = 0; i < codec->num_nodes; i++, nid++) {
2715 hda_nid_t src;
2716 const hda_nid_t *list;
2717 unsigned int caps = get_wcaps(codec, nid);
2718 int type = get_wcaps_type(caps);
2719
2720 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2721 continue;
2722 adc_nids[nums] = nid;
2723 cap_nids[nums] = nid;
2724 src = nid;
2725 for (;;) {
2726 int n;
2727 type = get_wcaps_type(get_wcaps(codec, src));
2728 if (type == AC_WID_PIN)
2729 break;
2730 if (type == AC_WID_AUD_SEL) {
2731 cap_nids[nums] = src;
2732 break;
2733 }
2734 n = snd_hda_get_conn_list(codec, src, &list);
2735 if (n > 1) {
2736 cap_nids[nums] = src;
2737 break;
2738 } else if (n != 1)
2739 break;
2740 src = *list;
2741 }
2742 if (++nums >= max_nums)
2743 break;
2744 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002745 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002746 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002747 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002748 return nums;
2749}
2750
Takashi Iwai05f5f472009-08-25 13:10:18 +02002751/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002752static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002753{
2754 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002755 const struct auto_pin_cfg *cfg = &spec->autocfg;
2756 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002757 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002758 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002759 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002760 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002761
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002762 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002763 if (num_adcs < 0)
2764 return 0;
2765
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002766 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002767 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002768 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002769
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002770 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002771 if (!alc_is_input_pin(codec, pin))
2772 continue;
2773
David Henningsson5322bf22011-01-05 11:03:56 +01002774 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002775 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2776 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002777 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002778 type_idx++;
2779 else
2780 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002781 prev_label = label;
2782
Takashi Iwai05f5f472009-08-25 13:10:18 +02002783 if (mixer) {
2784 idx = get_connection_index(codec, mixer, pin);
2785 if (idx >= 0) {
2786 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002787 label, type_idx,
2788 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002789 if (err < 0)
2790 return err;
2791 }
2792 }
2793
Takashi Iwaib7821702011-07-06 15:12:46 +02002794 for (c = 0; c < num_adcs; c++) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002795 hda_nid_t cap = spec->capsrc_nids ?
2796 spec->capsrc_nids[c] : spec->adc_nids[c];
2797 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002798 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002799 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002800 snd_hda_add_imux_item(imux, label, idx, NULL);
2801 break;
2802 }
2803 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002804 }
Takashi Iwai21268962011-07-07 15:01:13 +02002805
2806 spec->num_mux_defs = 1;
2807 spec->input_mux = imux;
2808
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002809 return 0;
2810}
2811
Takashi Iwai24de1832011-11-07 17:13:39 +01002812/* create a shared input with the headphone out */
2813static int alc_auto_create_shared_input(struct hda_codec *codec)
2814{
2815 struct alc_spec *spec = codec->spec;
2816 struct auto_pin_cfg *cfg = &spec->autocfg;
2817 unsigned int defcfg;
2818 hda_nid_t nid;
2819
2820 /* only one internal input pin? */
2821 if (cfg->num_inputs != 1)
2822 return 0;
2823 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2824 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2825 return 0;
2826
2827 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2828 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2829 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2830 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2831 else
2832 return 0; /* both not available */
2833
2834 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2835 return 0; /* no input */
2836
2837 cfg->inputs[1].pin = nid;
2838 cfg->inputs[1].type = AUTO_PIN_MIC;
2839 cfg->num_inputs = 2;
2840 spec->shared_mic_hp = 1;
2841 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2842 return 0;
2843}
2844
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002845static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2846 unsigned int pin_type)
2847{
2848 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2849 pin_type);
2850 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002851 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2852 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002853 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002854}
2855
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002856static int get_pin_type(int line_out_type)
2857{
2858 if (line_out_type == AUTO_PIN_HP_OUT)
2859 return PIN_HP;
2860 else
2861 return PIN_OUT;
2862}
2863
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002864static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002865{
2866 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002867 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002868 int i;
2869
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002870 for (i = 0; i < cfg->num_inputs; i++) {
2871 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002872 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002873 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002874 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002875 snd_hda_codec_write(codec, nid, 0,
2876 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002877 AMP_OUT_MUTE);
2878 }
2879 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002880
2881 /* mute all loopback inputs */
2882 if (spec->mixer_nid) {
2883 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2884 for (i = 0; i < nums; i++)
2885 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2886 AC_VERB_SET_AMP_GAIN_MUTE,
2887 AMP_IN_MUTE(i));
2888 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002889}
2890
Takashi Iwai7085ec12009-10-02 09:03:58 +02002891/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002892static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002893{
Takashi Iwai604401a2011-04-27 15:14:23 +02002894 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002895 int i, num;
2896
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002897 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2898 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002899 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2900 for (i = 0; i < num; i++) {
2901 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2902 return list[i];
2903 }
2904 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002905}
2906
Takashi Iwai604401a2011-04-27 15:14:23 +02002907/* go down to the selector widget before the mixer */
2908static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2909{
2910 hda_nid_t srcs[5];
2911 int num = snd_hda_get_connections(codec, pin, srcs,
2912 ARRAY_SIZE(srcs));
2913 if (num != 1 ||
2914 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2915 return pin;
2916 return srcs[0];
2917}
2918
Takashi Iwai7085ec12009-10-02 09:03:58 +02002919/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002920static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002921 hda_nid_t dac)
2922{
David Henningssoncc1c4522010-11-24 14:17:47 +01002923 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002924 int i, num;
2925
Takashi Iwai604401a2011-04-27 15:14:23 +02002926 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002927 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2928 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002929 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002930 return mix[i];
2931 }
2932 return 0;
2933}
2934
Takashi Iwaice764ab2011-04-27 16:35:23 +02002935/* select the connection from pin to DAC if needed */
2936static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2937 hda_nid_t dac)
2938{
2939 hda_nid_t mix[5];
2940 int i, num;
2941
2942 pin = alc_go_down_to_selector(codec, pin);
2943 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2944 if (num < 2)
2945 return 0;
2946 for (i = 0; i < num; i++) {
2947 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2948 snd_hda_codec_update_cache(codec, pin, 0,
2949 AC_VERB_SET_CONNECT_SEL, i);
2950 return 0;
2951 }
2952 }
2953 return 0;
2954}
2955
Takashi Iwai7085ec12009-10-02 09:03:58 +02002956/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002957static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002958{
2959 struct alc_spec *spec = codec->spec;
2960 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002961 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002962
Takashi Iwai604401a2011-04-27 15:14:23 +02002963 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002964 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002965 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002966 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002967 if (!nid)
2968 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002969 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2970 spec->multiout.num_dacs))
2971 continue;
Takashi Iwaic2674682011-08-24 17:57:44 +02002972 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2973 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2974 continue;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002975 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2976 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2977 continue;
2978 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002979 }
2980 return 0;
2981}
2982
Takashi Iwai07b18f62011-11-10 15:42:54 +01002983/* check whether the DAC is reachable from the pin */
2984static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2985 hda_nid_t pin, hda_nid_t dac)
2986{
2987 hda_nid_t srcs[5];
2988 int i, num;
2989
2990 pin = alc_go_down_to_selector(codec, pin);
2991 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2992 for (i = 0; i < num; i++) {
2993 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2994 if (nid == dac)
2995 return true;
2996 }
2997 return false;
2998}
2999
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003000static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3001{
3002 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
3003 if (snd_hda_get_conn_list(codec, sel, NULL) == 1)
3004 return alc_auto_look_for_dac(codec, pin);
3005 return 0;
3006}
3007
Takashi Iwaic2674682011-08-24 17:57:44 +02003008static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
3009 const hda_nid_t *pins, hda_nid_t *dacs)
3010{
3011 int i;
3012
3013 if (num_outs && !dacs[0]) {
3014 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
3015 if (!dacs[0])
3016 return 0;
3017 }
3018
3019 for (i = 1; i < num_outs; i++)
3020 dacs[i] = get_dac_if_single(codec, pins[i]);
3021 for (i = 1; i < num_outs; i++) {
3022 if (!dacs[i])
3023 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
3024 }
3025 return 0;
3026}
3027
3028static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003029 unsigned int location, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003030
Takashi Iwai7085ec12009-10-02 09:03:58 +02003031/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003032static int alc_auto_fill_dac_nids(struct hda_codec *codec)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003033{
3034 struct alc_spec *spec = codec->spec;
Takashi Iwaicb053a82011-06-27 11:32:07 +02003035 const struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003036 unsigned int location, defcfg;
3037 int num_pins;
Takashi Iwai350434e2011-06-30 21:29:12 +02003038 bool redone = false;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003039 int i;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003040
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003041 again:
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003042 /* set num_dacs once to full for alc_auto_look_for_dac() */
3043 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003044 spec->multiout.hp_out_nid[0] = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003045 spec->multiout.extra_out_nid[0] = 0;
3046 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3047 spec->multiout.dac_nids = spec->private_dac_nids;
3048
3049 /* fill hard-wired DACs first */
3050 if (!redone) {
3051 for (i = 0; i < cfg->line_outs; i++)
3052 spec->private_dac_nids[i] =
3053 get_dac_if_single(codec, cfg->line_out_pins[i]);
3054 if (cfg->hp_outs)
Takashi Iwaie23832a2011-08-23 18:16:56 +02003055 spec->multiout.hp_out_nid[0] =
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003056 get_dac_if_single(codec, cfg->hp_pins[0]);
3057 if (cfg->speaker_outs)
3058 spec->multiout.extra_out_nid[0] =
3059 get_dac_if_single(codec, cfg->speaker_pins[0]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003060 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003061
3062 for (i = 0; i < cfg->line_outs; i++) {
3063 hda_nid_t pin = cfg->line_out_pins[i];
3064 if (spec->private_dac_nids[i])
3065 continue;
3066 spec->private_dac_nids[i] = alc_auto_look_for_dac(codec, pin);
3067 if (!spec->private_dac_nids[i] && !redone) {
3068 /* if we can't find primary DACs, re-probe without
3069 * checking the hard-wired DACs
3070 */
3071 redone = true;
3072 goto again;
3073 }
3074 }
3075
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003076 /* re-count num_dacs and squash invalid entries */
3077 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003078 for (i = 0; i < cfg->line_outs; i++) {
3079 if (spec->private_dac_nids[i])
3080 spec->multiout.num_dacs++;
3081 else
3082 memmove(spec->private_dac_nids + i,
3083 spec->private_dac_nids + i + 1,
3084 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
3085 }
3086
Takashi Iwaic2674682011-08-24 17:57:44 +02003087 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3088 /* try to fill multi-io first */
Takashi Iwaic2674682011-08-24 17:57:44 +02003089 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3090 location = get_defcfg_location(defcfg);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003091
Takashi Iwai07b18f62011-11-10 15:42:54 +01003092 num_pins = alc_auto_fill_multi_ios(codec, location, 0);
Takashi Iwaic2674682011-08-24 17:57:44 +02003093 if (num_pins > 0) {
3094 spec->multi_ios = num_pins;
3095 spec->ext_channel_count = 2;
3096 spec->multiout.num_dacs = num_pins + 1;
3097 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003098 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003099
Takashi Iwai716eef02011-10-21 15:07:42 +02003100 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3101 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003102 spec->multiout.hp_out_nid);
Takashi Iwai716eef02011-10-21 15:07:42 +02003103 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3104 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
Takashi Iwaic2674682011-08-24 17:57:44 +02003105 spec->multiout.extra_out_nid);
3106
Takashi Iwai07b18f62011-11-10 15:42:54 +01003107 if (!spec->multi_ios &&
3108 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3109 cfg->hp_outs) {
3110 /* try multi-ios with HP + inputs */
3111 defcfg = snd_hda_codec_get_pincfg(codec, cfg->hp_pins[0]);
3112 location = get_defcfg_location(defcfg);
3113
3114 num_pins = alc_auto_fill_multi_ios(codec, location, 1);
3115 if (num_pins > 0) {
3116 spec->multi_ios = num_pins;
3117 spec->ext_channel_count = 2;
3118 spec->multiout.num_dacs = num_pins + 1;
3119 }
3120 }
3121
Takashi Iwai23c09b02011-08-19 09:05:35 +02003122 return 0;
3123}
3124
Takashi Iwai527e4d72011-10-27 16:33:27 +02003125static inline unsigned int get_ctl_pos(unsigned int data)
3126{
3127 hda_nid_t nid = get_amp_nid_(data);
3128 unsigned int dir = get_amp_direction_(data);
3129 return (nid << 1) | dir;
3130}
3131
3132#define is_ctl_used(bits, data) \
3133 test_bit(get_ctl_pos(data), bits)
3134#define mark_ctl_usage(bits, data) \
3135 set_bit(get_ctl_pos(data), bits)
3136
Takashi Iwai343a04b2011-07-06 14:28:39 +02003137static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003138 const char *pfx, int cidx,
3139 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003140{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003141 struct alc_spec *spec = codec->spec;
3142 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003143 if (!nid)
3144 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003145 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3146 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3147 return 0;
3148 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003149 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003150 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003151}
3152
Takashi Iwaie29d3772011-11-14 17:13:23 +01003153static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3154 const char *pfx, int cidx,
3155 hda_nid_t nid)
3156{
3157 int chs = 1;
3158 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3159 chs = 3;
3160 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3161}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003162
3163/* create a mute-switch for the given mixer widget;
3164 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3165 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003166static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003167 const char *pfx, int cidx,
3168 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003169{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003170 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003171 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003172 int type;
3173 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003174 if (!nid)
3175 return 0;
3176 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3177 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3178 type = ALC_CTL_WIDGET_MUTE;
3179 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3180 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003181 type = ALC_CTL_WIDGET_MUTE;
3182 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3183 } else {
3184 type = ALC_CTL_BIND_MUTE;
3185 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3186 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003187 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3188 return 0;
3189 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003190 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003191}
3192
Takashi Iwaie29d3772011-11-14 17:13:23 +01003193static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3194 int cidx, hda_nid_t nid)
3195{
3196 int chs = 1;
3197 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3198 chs = 3;
3199 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3200}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003201
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003202static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3203 hda_nid_t pin, hda_nid_t dac)
3204{
3205 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3206 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3207 return pin;
3208 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3209 return mix;
3210 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3211 return dac;
3212 return 0;
3213}
3214
3215static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3216 hda_nid_t pin, hda_nid_t dac)
3217{
3218 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3219 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3220 return dac;
3221 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3222 return mix;
3223 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3224 return pin;
3225 return 0;
3226}
3227
Takashi Iwai7085ec12009-10-02 09:03:58 +02003228/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003229static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003230 const struct auto_pin_cfg *cfg)
3231{
3232 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003233 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003234
Takashi Iwaice764ab2011-04-27 16:35:23 +02003235 noutputs = cfg->line_outs;
3236 if (spec->multi_ios > 0)
3237 noutputs += spec->multi_ios;
3238
3239 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003240 const char *name;
3241 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003242 hda_nid_t dac, pin;
3243 hda_nid_t sw, vol;
3244
3245 dac = spec->multiout.dac_nids[i];
3246 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003247 continue;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003248 if (i >= cfg->line_outs)
3249 pin = spec->multi_io[i - 1].pin;
3250 else
3251 pin = cfg->line_out_pins[i];
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003252
3253 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3254 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai6843ca12011-06-24 11:03:58 +02003255 name = alc_get_line_out_pfx(spec, i, true, &index);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003256 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003257 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003258 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003259 if (err < 0)
3260 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003261 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003262 if (err < 0)
3263 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003264 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003265 if (err < 0)
3266 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003267 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003268 if (err < 0)
3269 return err;
3270 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003271 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003272 if (err < 0)
3273 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003274 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003275 if (err < 0)
3276 return err;
3277 }
3278 }
3279 return 0;
3280}
3281
Takashi Iwai343a04b2011-07-06 14:28:39 +02003282static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai23c09b02011-08-19 09:05:35 +02003283 hda_nid_t dac, const char *pfx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003284{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003285 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003286 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003287 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003288
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003289 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003290 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003291 /* the corresponding DAC is already occupied */
3292 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3293 return 0; /* no way */
3294 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003295 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3296 if (is_ctl_used(spec->sw_ctls, val))
3297 return 0; /* already created */
3298 mark_ctl_usage(spec->sw_ctls, val);
3299 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003300 }
3301
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003302 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3303 vol = alc_look_for_out_vol_nid(codec, pin, dac);
3304 err = alc_auto_add_stereo_vol(codec, pfx, 0, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003305 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003306 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003307 err = alc_auto_add_stereo_sw(codec, pfx, 0, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003308 if (err < 0)
3309 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003310 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003311}
3312
Takashi Iwai23c09b02011-08-19 09:05:35 +02003313static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3314 unsigned int nums,
3315 struct hda_ctl_ops *ops)
3316{
3317 struct alc_spec *spec = codec->spec;
3318 struct hda_bind_ctls **ctlp, *ctl;
3319 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3320 ctlp = snd_array_new(&spec->bind_ctls);
3321 if (!ctlp)
3322 return NULL;
3323 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3324 *ctlp = ctl;
3325 if (ctl)
3326 ctl->ops = ops;
3327 return ctl;
3328}
3329
3330/* add playback controls for speaker and HP outputs */
3331static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3332 const hda_nid_t *pins,
3333 const hda_nid_t *dacs,
3334 const char *pfx)
3335{
3336 struct alc_spec *spec = codec->spec;
3337 struct hda_bind_ctls *ctl;
3338 char name[32];
3339 int i, n, err;
3340
3341 if (!num_pins || !pins[0])
3342 return 0;
3343
Takashi Iwai527e4d72011-10-27 16:33:27 +02003344 if (num_pins == 1) {
3345 hda_nid_t dac = *dacs;
3346 if (!dac)
3347 dac = spec->multiout.dac_nids[0];
3348 return alc_auto_create_extra_out(codec, *pins, dac, pfx);
3349 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003350
3351 if (dacs[num_pins - 1]) {
3352 /* OK, we have a multi-output system with individual volumes */
3353 for (i = 0; i < num_pins; i++) {
3354 snprintf(name, sizeof(name), "%s %s",
3355 pfx, channel_name[i]);
3356 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3357 name);
3358 if (err < 0)
3359 return err;
3360 }
3361 return 0;
3362 }
3363
3364 /* Let's create a bind-controls */
3365 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3366 if (!ctl)
3367 return -ENOMEM;
3368 n = 0;
3369 for (i = 0; i < num_pins; i++) {
3370 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3371 ctl->values[n++] =
3372 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3373 }
3374 if (n) {
3375 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3376 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3377 if (err < 0)
3378 return err;
3379 }
3380
3381 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3382 if (!ctl)
3383 return -ENOMEM;
3384 n = 0;
3385 for (i = 0; i < num_pins; i++) {
3386 hda_nid_t vol;
3387 if (!pins[i] || !dacs[i])
3388 continue;
3389 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3390 if (vol)
3391 ctl->values[n++] =
3392 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3393 }
3394 if (n) {
3395 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3396 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3397 if (err < 0)
3398 return err;
3399 }
3400 return 0;
3401}
3402
Takashi Iwai343a04b2011-07-06 14:28:39 +02003403static int alc_auto_create_hp_out(struct hda_codec *codec)
3404{
3405 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003406 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3407 spec->autocfg.hp_pins,
3408 spec->multiout.hp_out_nid,
3409 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003410}
3411
3412static int alc_auto_create_speaker_out(struct hda_codec *codec)
3413{
3414 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003415 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3416 spec->autocfg.speaker_pins,
3417 spec->multiout.extra_out_nid,
3418 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003419}
3420
Takashi Iwai343a04b2011-07-06 14:28:39 +02003421static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003422 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003423 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003424{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003425 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003426 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003427 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003428
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003429 alc_set_pin_output(codec, pin, pin_type);
3430 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003431 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003432 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003433 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003434 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003435 mix = srcs[i];
3436 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003437 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003438 if (!mix)
3439 return;
3440
3441 /* need the manual connection? */
3442 if (num > 1)
3443 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3444 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003445 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3446 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003447 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003448 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003449 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003450 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003451 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003452 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3453 if (nid)
3454 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3455 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003456
3457 /* unmute DAC if it's not assigned to a mixer */
3458 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3459 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3460 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3461 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003462}
3463
Takashi Iwai343a04b2011-07-06 14:28:39 +02003464static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003465{
3466 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003467 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003468 int i;
3469
3470 for (i = 0; i <= HDA_SIDE; i++) {
3471 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3472 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003473 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003474 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003475 }
3476}
3477
Takashi Iwai343a04b2011-07-06 14:28:39 +02003478static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003479{
3480 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003481 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003482 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003483
David Henningsson636030e2011-10-12 19:26:03 +02003484 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003485 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3486 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003487 pin = spec->autocfg.hp_pins[i];
3488 if (!pin)
3489 break;
3490 dac = spec->multiout.hp_out_nid[i];
3491 if (!dac) {
3492 if (i > 0 && spec->multiout.hp_out_nid[0])
3493 dac = spec->multiout.hp_out_nid[0];
3494 else
3495 dac = spec->multiout.dac_nids[0];
3496 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003497 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3498 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003499 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003500 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3501 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003502 pin = spec->autocfg.speaker_pins[i];
3503 if (!pin)
3504 break;
3505 dac = spec->multiout.extra_out_nid[i];
3506 if (!dac) {
3507 if (i > 0 && spec->multiout.extra_out_nid[0])
3508 dac = spec->multiout.extra_out_nid[0];
3509 else
3510 dac = spec->multiout.dac_nids[0];
3511 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003512 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3513 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003514}
3515
Takashi Iwaice764ab2011-04-27 16:35:23 +02003516/*
3517 * multi-io helper
3518 */
3519static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai07b18f62011-11-10 15:42:54 +01003520 unsigned int location,
3521 int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003522{
3523 struct alc_spec *spec = codec->spec;
3524 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaic2674682011-08-24 17:57:44 +02003525 hda_nid_t prime_dac = spec->private_dac_nids[0];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003526 int type, i, dacs, num_pins = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003527
Takashi Iwai07b18f62011-11-10 15:42:54 +01003528 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003529 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3530 for (i = 0; i < cfg->num_inputs; i++) {
3531 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003532 hda_nid_t dac = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003533 unsigned int defcfg, caps;
3534 if (cfg->inputs[i].type != type)
3535 continue;
3536 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3537 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3538 continue;
3539 if (location && get_defcfg_location(defcfg) != location)
3540 continue;
3541 caps = snd_hda_query_pin_caps(codec, nid);
3542 if (!(caps & AC_PINCAP_OUT))
3543 continue;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003544 if (offset && offset + num_pins < dacs) {
3545 dac = spec->private_dac_nids[offset + num_pins];
3546 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3547 dac = 0;
3548 }
3549 if (!dac)
3550 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003551 if (!dac)
3552 continue;
3553 spec->multi_io[num_pins].pin = nid;
3554 spec->multi_io[num_pins].dac = dac;
3555 num_pins++;
Takashi Iwaidda14412011-05-02 11:29:30 +02003556 spec->private_dac_nids[spec->multiout.num_dacs++] = dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003557 }
3558 }
Takashi Iwai07b18f62011-11-10 15:42:54 +01003559 spec->multiout.num_dacs = dacs;
Takashi Iwaic2674682011-08-24 17:57:44 +02003560 if (num_pins < 2) {
3561 /* clear up again */
Takashi Iwai07b18f62011-11-10 15:42:54 +01003562 memset(spec->private_dac_nids + dacs, 0,
3563 sizeof(hda_nid_t) * (AUTO_CFG_MAX_OUTS - dacs));
Takashi Iwaic2674682011-08-24 17:57:44 +02003564 spec->private_dac_nids[0] = prime_dac;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003565 return 0;
Takashi Iwaic2674682011-08-24 17:57:44 +02003566 }
Takashi Iwaice764ab2011-04-27 16:35:23 +02003567 return num_pins;
3568}
3569
3570static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3571 struct snd_ctl_elem_info *uinfo)
3572{
3573 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3574 struct alc_spec *spec = codec->spec;
3575
3576 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3577 uinfo->count = 1;
3578 uinfo->value.enumerated.items = spec->multi_ios + 1;
3579 if (uinfo->value.enumerated.item > spec->multi_ios)
3580 uinfo->value.enumerated.item = spec->multi_ios;
3581 sprintf(uinfo->value.enumerated.name, "%dch",
3582 (uinfo->value.enumerated.item + 1) * 2);
3583 return 0;
3584}
3585
3586static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3587 struct snd_ctl_elem_value *ucontrol)
3588{
3589 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3590 struct alc_spec *spec = codec->spec;
3591 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3592 return 0;
3593}
3594
3595static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3596{
3597 struct alc_spec *spec = codec->spec;
3598 hda_nid_t nid = spec->multi_io[idx].pin;
3599
3600 if (!spec->multi_io[idx].ctl_in)
3601 spec->multi_io[idx].ctl_in =
3602 snd_hda_codec_read(codec, nid, 0,
3603 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3604 if (output) {
3605 snd_hda_codec_update_cache(codec, nid, 0,
3606 AC_VERB_SET_PIN_WIDGET_CONTROL,
3607 PIN_OUT);
3608 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3609 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3610 HDA_AMP_MUTE, 0);
3611 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3612 } else {
3613 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3614 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3615 HDA_AMP_MUTE, HDA_AMP_MUTE);
3616 snd_hda_codec_update_cache(codec, nid, 0,
3617 AC_VERB_SET_PIN_WIDGET_CONTROL,
3618 spec->multi_io[idx].ctl_in);
3619 }
3620 return 0;
3621}
3622
3623static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3624 struct snd_ctl_elem_value *ucontrol)
3625{
3626 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3627 struct alc_spec *spec = codec->spec;
3628 int i, ch;
3629
3630 ch = ucontrol->value.enumerated.item[0];
3631 if (ch < 0 || ch > spec->multi_ios)
3632 return -EINVAL;
3633 if (ch == (spec->ext_channel_count - 1) / 2)
3634 return 0;
3635 spec->ext_channel_count = (ch + 1) * 2;
3636 for (i = 0; i < spec->multi_ios; i++)
3637 alc_set_multi_io(codec, i, i < ch);
3638 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003639 if (spec->need_dac_fix && !spec->const_channel_count)
3640 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003641 return 1;
3642}
3643
Takashi Iwaia9111322011-05-02 11:30:18 +02003644static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003645 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3646 .name = "Channel Mode",
3647 .info = alc_auto_ch_mode_info,
3648 .get = alc_auto_ch_mode_get,
3649 .put = alc_auto_ch_mode_put,
3650};
3651
Takashi Iwai23c09b02011-08-19 09:05:35 +02003652static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003653{
3654 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003655
Takashi Iwaic2674682011-08-24 17:57:44 +02003656 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003657 struct snd_kcontrol_new *knew;
3658
3659 knew = alc_kcontrol_new(spec);
3660 if (!knew)
3661 return -ENOMEM;
3662 *knew = alc_auto_channel_mode_enum;
3663 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3664 if (!knew->name)
3665 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003666 }
3667 return 0;
3668}
3669
Takashi Iwai1d045db2011-07-07 18:23:21 +02003670/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3671 * active input pins
3672 */
3673static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3674{
3675 struct alc_spec *spec = codec->spec;
3676 const struct hda_input_mux *imux;
3677 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3678 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3679 int i, n, nums;
3680
3681 imux = spec->input_mux;
3682 if (!imux)
3683 return;
3684 if (spec->dyn_adc_switch)
3685 return;
3686
3687 nums = 0;
3688 for (n = 0; n < spec->num_adc_nids; n++) {
3689 hda_nid_t cap = spec->private_capsrc_nids[n];
3690 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
3691 for (i = 0; i < imux->num_items; i++) {
3692 hda_nid_t pin = spec->imux_pins[i];
3693 if (pin) {
3694 if (get_connection_index(codec, cap, pin) < 0)
3695 break;
3696 } else if (num_conns <= imux->items[i].index)
3697 break;
3698 }
3699 if (i >= imux->num_items) {
3700 adc_nids[nums] = spec->private_adc_nids[n];
3701 capsrc_nids[nums++] = cap;
3702 }
3703 }
3704 if (!nums) {
3705 /* check whether ADC-switch is possible */
3706 if (!alc_check_dyn_adc_switch(codec)) {
3707 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3708 " using fallback 0x%x\n",
3709 codec->chip_name, spec->private_adc_nids[0]);
3710 spec->num_adc_nids = 1;
3711 spec->auto_mic = 0;
3712 return;
3713 }
3714 } else if (nums != spec->num_adc_nids) {
3715 memcpy(spec->private_adc_nids, adc_nids,
3716 nums * sizeof(hda_nid_t));
3717 memcpy(spec->private_capsrc_nids, capsrc_nids,
3718 nums * sizeof(hda_nid_t));
3719 spec->num_adc_nids = nums;
3720 }
3721
3722 if (spec->auto_mic)
3723 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
3724 else if (spec->input_mux->num_items == 1)
3725 spec->num_adc_nids = 1; /* reduce to a single ADC */
3726}
3727
3728/*
3729 * initialize ADC paths
3730 */
3731static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3732{
3733 struct alc_spec *spec = codec->spec;
3734 hda_nid_t nid;
3735
3736 nid = spec->adc_nids[adc_idx];
3737 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003738 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003739 snd_hda_codec_write(codec, nid, 0,
3740 AC_VERB_SET_AMP_GAIN_MUTE,
3741 AMP_IN_MUTE(0));
3742 return;
3743 }
3744 if (!spec->capsrc_nids)
3745 return;
3746 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003747 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003748 snd_hda_codec_write(codec, nid, 0,
3749 AC_VERB_SET_AMP_GAIN_MUTE,
3750 AMP_OUT_MUTE);
3751}
3752
3753static void alc_auto_init_input_src(struct hda_codec *codec)
3754{
3755 struct alc_spec *spec = codec->spec;
3756 int c, nums;
3757
3758 for (c = 0; c < spec->num_adc_nids; c++)
3759 alc_auto_init_adc(codec, c);
3760 if (spec->dyn_adc_switch)
3761 nums = 1;
3762 else
3763 nums = spec->num_adc_nids;
3764 for (c = 0; c < nums; c++)
3765 alc_mux_select(codec, 0, spec->cur_mux[c], true);
3766}
3767
3768/* add mic boosts if needed */
3769static int alc_auto_add_mic_boost(struct hda_codec *codec)
3770{
3771 struct alc_spec *spec = codec->spec;
3772 struct auto_pin_cfg *cfg = &spec->autocfg;
3773 int i, err;
3774 int type_idx = 0;
3775 hda_nid_t nid;
3776 const char *prev_label = NULL;
3777
3778 for (i = 0; i < cfg->num_inputs; i++) {
3779 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3780 break;
3781 nid = cfg->inputs[i].pin;
3782 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
3783 const char *label;
3784 char boost_label[32];
3785
3786 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01003787 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
3788 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02003789 if (prev_label && !strcmp(label, prev_label))
3790 type_idx++;
3791 else
3792 type_idx = 0;
3793 prev_label = label;
3794
3795 snprintf(boost_label, sizeof(boost_label),
3796 "%s Boost Volume", label);
3797 err = add_control(spec, ALC_CTL_WIDGET_VOL,
3798 boost_label, type_idx,
3799 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
3800 if (err < 0)
3801 return err;
3802 }
3803 }
3804 return 0;
3805}
3806
3807/* select or unmute the given capsrc route */
3808static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
3809 int idx)
3810{
3811 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
3812 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
3813 HDA_AMP_MUTE, 0);
3814 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
3815 snd_hda_codec_write_cache(codec, cap, 0,
3816 AC_VERB_SET_CONNECT_SEL, idx);
3817 }
3818}
3819
3820/* set the default connection to that pin */
3821static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
3822{
3823 struct alc_spec *spec = codec->spec;
3824 int i;
3825
3826 if (!pin)
3827 return 0;
3828 for (i = 0; i < spec->num_adc_nids; i++) {
3829 hda_nid_t cap = spec->capsrc_nids ?
3830 spec->capsrc_nids[i] : spec->adc_nids[i];
3831 int idx;
3832
3833 idx = get_connection_index(codec, cap, pin);
3834 if (idx < 0)
3835 continue;
3836 select_or_unmute_capsrc(codec, cap, idx);
3837 return i; /* return the found index */
3838 }
3839 return -1; /* not found */
3840}
3841
3842/* initialize some special cases for input sources */
3843static void alc_init_special_input_src(struct hda_codec *codec)
3844{
3845 struct alc_spec *spec = codec->spec;
3846 int i;
3847
3848 for (i = 0; i < spec->autocfg.num_inputs; i++)
3849 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
3850}
3851
3852/* assign appropriate capture mixers */
3853static void set_capture_mixer(struct hda_codec *codec)
3854{
3855 struct alc_spec *spec = codec->spec;
3856 static const struct snd_kcontrol_new *caps[2][3] = {
3857 { alc_capture_mixer_nosrc1,
3858 alc_capture_mixer_nosrc2,
3859 alc_capture_mixer_nosrc3 },
3860 { alc_capture_mixer1,
3861 alc_capture_mixer2,
3862 alc_capture_mixer3 },
3863 };
3864
3865 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02003866 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003867 if (!spec->capsrc_nids)
3868 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02003869 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003870 return; /* no volume in capsrc, too */
3871 spec->vol_in_capsrc = 1;
3872 }
3873
3874 if (spec->num_adc_nids > 0) {
3875 int mux = 0;
3876 int num_adcs = 0;
3877
3878 if (spec->input_mux && spec->input_mux->num_items > 1)
3879 mux = 1;
3880 if (spec->auto_mic) {
3881 num_adcs = 1;
3882 mux = 0;
3883 } else if (spec->dyn_adc_switch)
3884 num_adcs = 1;
3885 if (!num_adcs) {
3886 if (spec->num_adc_nids > 3)
3887 spec->num_adc_nids = 3;
3888 else if (!spec->num_adc_nids)
3889 return;
3890 num_adcs = spec->num_adc_nids;
3891 }
3892 spec->cap_mixer = caps[mux][num_adcs - 1];
3893 }
3894}
3895
3896/*
Takashi Iwaie4770622011-07-08 11:11:35 +02003897 * standard auto-parser initializations
3898 */
3899static void alc_auto_init_std(struct hda_codec *codec)
3900{
3901 struct alc_spec *spec = codec->spec;
Takashi Iwai3a938972011-10-28 01:16:55 +02003902 spec->use_jack_tbl = 1;
Takashi Iwaie4770622011-07-08 11:11:35 +02003903 alc_auto_init_multi_out(codec);
3904 alc_auto_init_extra_out(codec);
3905 alc_auto_init_analog_input(codec);
3906 alc_auto_init_input_src(codec);
3907 alc_auto_init_digital(codec);
3908 if (spec->unsol_event)
3909 alc_inithook(codec);
3910}
3911
3912/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02003913 * Digital-beep handlers
3914 */
3915#ifdef CONFIG_SND_HDA_INPUT_BEEP
3916#define set_beep_amp(spec, nid, idx, dir) \
3917 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
3918
3919static const struct snd_pci_quirk beep_white_list[] = {
3920 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
3921 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
3922 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
3923 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
3924 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
3925 {}
3926};
3927
3928static inline int has_cdefine_beep(struct hda_codec *codec)
3929{
3930 struct alc_spec *spec = codec->spec;
3931 const struct snd_pci_quirk *q;
3932 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
3933 if (q)
3934 return q->value;
3935 return spec->cdefine.enable_pcbeep;
3936}
3937#else
3938#define set_beep_amp(spec, nid, idx, dir) /* NOP */
3939#define has_cdefine_beep(codec) 0
3940#endif
3941
3942/* parse the BIOS configuration and set up the alc_spec */
3943/* return 1 if successful, 0 if the proper config is not found,
3944 * or a negative error code
3945 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003946static int alc_parse_auto_config(struct hda_codec *codec,
3947 const hda_nid_t *ignore_nids,
3948 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003949{
3950 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003951 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003952 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003953
Takashi Iwai53c334a2011-08-23 18:27:14 +02003954 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3955 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003956 if (err < 0)
3957 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003958 if (!cfg->line_outs) {
3959 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003960 spec->multiout.max_channels = 2;
3961 spec->no_analog = 1;
3962 goto dig_only;
3963 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003964 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003965 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003966
Takashi Iwai06503672011-10-06 08:27:19 +02003967 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3968 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02003969 /* use HP as primary out */
3970 cfg->speaker_outs = cfg->line_outs;
3971 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3972 sizeof(cfg->speaker_pins));
3973 cfg->line_outs = cfg->hp_outs;
3974 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3975 cfg->hp_outs = 0;
3976 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3977 cfg->line_out_type = AUTO_PIN_HP_OUT;
3978 }
3979
Takashi Iwai1d045db2011-07-07 18:23:21 +02003980 err = alc_auto_fill_dac_nids(codec);
3981 if (err < 0)
3982 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003983 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02003984 if (err < 0)
3985 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003986 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003987 if (err < 0)
3988 return err;
3989 err = alc_auto_create_hp_out(codec);
3990 if (err < 0)
3991 return err;
3992 err = alc_auto_create_speaker_out(codec);
3993 if (err < 0)
3994 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01003995 err = alc_auto_create_shared_input(codec);
3996 if (err < 0)
3997 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02003998 err = alc_auto_create_input_ctls(codec);
3999 if (err < 0)
4000 return err;
4001
4002 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4003
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004004 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004005 alc_auto_parse_digital(codec);
4006
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004007 if (!spec->no_analog)
4008 alc_remove_invalid_adc_nids(codec);
4009
4010 if (ssid_nids)
4011 alc_ssid_check(codec, ssid_nids);
4012
4013 if (!spec->no_analog) {
4014 alc_auto_check_switches(codec);
4015 err = alc_auto_add_mic_boost(codec);
4016 if (err < 0)
4017 return err;
4018 }
4019
Takashi Iwai1d045db2011-07-07 18:23:21 +02004020 if (spec->kctls.list)
4021 add_mixer(spec, spec->kctls.list);
4022
Takashi Iwai1d045db2011-07-07 18:23:21 +02004023 return 1;
4024}
4025
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004026static int alc880_parse_auto_config(struct hda_codec *codec)
4027{
4028 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4029 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4030 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4031}
4032
Takashi Iwai1d045db2011-07-07 18:23:21 +02004033#ifdef CONFIG_SND_HDA_POWER_SAVE
4034static const struct hda_amp_list alc880_loopbacks[] = {
4035 { 0x0b, HDA_INPUT, 0 },
4036 { 0x0b, HDA_INPUT, 1 },
4037 { 0x0b, HDA_INPUT, 2 },
4038 { 0x0b, HDA_INPUT, 3 },
4039 { 0x0b, HDA_INPUT, 4 },
4040 { } /* end */
4041};
4042#endif
4043
4044/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004045 * ALC880 fix-ups
4046 */
4047enum {
4048 ALC880_FIXUP_GPIO2,
4049 ALC880_FIXUP_MEDION_RIM,
4050};
4051
4052static const struct alc_fixup alc880_fixups[] = {
4053 [ALC880_FIXUP_GPIO2] = {
4054 .type = ALC_FIXUP_VERBS,
4055 .v.verbs = alc_gpio2_init_verbs,
4056 },
4057 [ALC880_FIXUP_MEDION_RIM] = {
4058 .type = ALC_FIXUP_VERBS,
4059 .v.verbs = (const struct hda_verb[]) {
4060 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4061 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4062 { }
4063 },
4064 .chained = true,
4065 .chain_id = ALC880_FIXUP_GPIO2,
4066 },
4067};
4068
4069static const struct snd_pci_quirk alc880_fixup_tbl[] = {
4070 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
4071 {}
4072};
4073
4074
4075/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004076 * board setups
4077 */
4078#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4079#define alc_board_config \
4080 snd_hda_check_board_config
4081#define alc_board_codec_sid_config \
4082 snd_hda_check_board_codec_sid_config
4083#include "alc_quirks.c"
4084#else
4085#define alc_board_config(codec, nums, models, tbl) -1
4086#define alc_board_codec_sid_config(codec, nums, models, tbl) -1
4087#define setup_preset(codec, x) /* NOP */
4088#endif
4089
4090/*
4091 * OK, here we have finally the patch for ALC880
4092 */
4093#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4094#include "alc880_quirks.c"
4095#endif
4096
4097static int patch_alc880(struct hda_codec *codec)
4098{
4099 struct alc_spec *spec;
4100 int board_config;
4101 int err;
4102
4103 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4104 if (spec == NULL)
4105 return -ENOMEM;
4106
4107 codec->spec = spec;
4108
4109 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004110 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004111
4112 board_config = alc_board_config(codec, ALC880_MODEL_LAST,
4113 alc880_models, alc880_cfg_tbl);
4114 if (board_config < 0) {
4115 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4116 codec->chip_name);
4117 board_config = ALC_MODEL_AUTO;
4118 }
4119
4120 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004121 alc_pick_fixup(codec, NULL, alc880_fixup_tbl, alc880_fixups);
4122 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4123 }
4124
4125 if (board_config == ALC_MODEL_AUTO) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004126 /* automatic parse from the BIOS config */
4127 err = alc880_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004128 if (err < 0)
4129 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004130#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4131 else if (!err) {
4132 printk(KERN_INFO
4133 "hda_codec: Cannot set up configuration "
4134 "from BIOS. Using 3-stack mode...\n");
4135 board_config = ALC880_3ST;
4136 }
4137#endif
4138 }
4139
Takashi Iwai1d045db2011-07-07 18:23:21 +02004140 if (board_config != ALC_MODEL_AUTO)
4141 setup_preset(codec, &alc880_presets[board_config]);
4142
Takashi Iwai60a6a842011-07-27 14:01:24 +02004143 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004144 alc_auto_fill_adc_caps(codec);
4145 alc_rebuild_imux_for_auto_mic(codec);
4146 alc_remove_invalid_adc_nids(codec);
4147 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004148
4149 if (!spec->no_analog && !spec->cap_mixer)
4150 set_capture_mixer(codec);
4151
4152 if (!spec->no_analog) {
4153 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004154 if (err < 0)
4155 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004156 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4157 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004158
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004159 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4160
Takashi Iwai1d045db2011-07-07 18:23:21 +02004161 spec->vmaster_nid = 0x0c;
4162
4163 codec->patch_ops = alc_patch_ops;
4164 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004165 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004166#ifdef CONFIG_SND_HDA_POWER_SAVE
4167 if (!spec->loopback.amplist)
4168 spec->loopback.amplist = alc880_loopbacks;
4169#endif
4170
4171 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004172
4173 error:
4174 alc_free(codec);
4175 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004176}
4177
4178
4179/*
4180 * ALC260 support
4181 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004182static int alc260_parse_auto_config(struct hda_codec *codec)
4183{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004184 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004185 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4186 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004187}
4188
Takashi Iwai1d045db2011-07-07 18:23:21 +02004189#ifdef CONFIG_SND_HDA_POWER_SAVE
4190static const struct hda_amp_list alc260_loopbacks[] = {
4191 { 0x07, HDA_INPUT, 0 },
4192 { 0x07, HDA_INPUT, 1 },
4193 { 0x07, HDA_INPUT, 2 },
4194 { 0x07, HDA_INPUT, 3 },
4195 { 0x07, HDA_INPUT, 4 },
4196 { } /* end */
4197};
4198#endif
4199
4200/*
4201 * Pin config fixes
4202 */
4203enum {
4204 PINFIX_HP_DC5750,
4205};
4206
4207static const struct alc_fixup alc260_fixups[] = {
4208 [PINFIX_HP_DC5750] = {
4209 .type = ALC_FIXUP_PINS,
4210 .v.pins = (const struct alc_pincfg[]) {
4211 { 0x11, 0x90130110 }, /* speaker */
4212 { }
4213 }
4214 },
4215};
4216
4217static const struct snd_pci_quirk alc260_fixup_tbl[] = {
4218 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", PINFIX_HP_DC5750),
4219 {}
4220};
4221
4222/*
4223 */
4224#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4225#include "alc260_quirks.c"
4226#endif
4227
4228static int patch_alc260(struct hda_codec *codec)
4229{
4230 struct alc_spec *spec;
4231 int err, board_config;
4232
4233 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4234 if (spec == NULL)
4235 return -ENOMEM;
4236
4237 codec->spec = spec;
4238
4239 spec->mixer_nid = 0x07;
4240
4241 board_config = alc_board_config(codec, ALC260_MODEL_LAST,
4242 alc260_models, alc260_cfg_tbl);
4243 if (board_config < 0) {
4244 snd_printd(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4245 codec->chip_name);
4246 board_config = ALC_MODEL_AUTO;
4247 }
4248
4249 if (board_config == ALC_MODEL_AUTO) {
4250 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4251 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4252 }
4253
4254 if (board_config == ALC_MODEL_AUTO) {
4255 /* automatic parse from the BIOS config */
4256 err = alc260_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004257 if (err < 0)
4258 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004259#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4260 else if (!err) {
4261 printk(KERN_INFO
4262 "hda_codec: Cannot set up configuration "
4263 "from BIOS. Using base mode...\n");
4264 board_config = ALC260_BASIC;
4265 }
4266#endif
4267 }
4268
Takashi Iwai1d045db2011-07-07 18:23:21 +02004269 if (board_config != ALC_MODEL_AUTO)
4270 setup_preset(codec, &alc260_presets[board_config]);
4271
Takashi Iwai60a6a842011-07-27 14:01:24 +02004272 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004273 alc_auto_fill_adc_caps(codec);
4274 alc_rebuild_imux_for_auto_mic(codec);
4275 alc_remove_invalid_adc_nids(codec);
4276 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004277
4278 if (!spec->no_analog && !spec->cap_mixer)
4279 set_capture_mixer(codec);
4280
4281 if (!spec->no_analog) {
4282 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004283 if (err < 0)
4284 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004285 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4286 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004287
4288 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4289
4290 spec->vmaster_nid = 0x08;
4291
4292 codec->patch_ops = alc_patch_ops;
4293 if (board_config == ALC_MODEL_AUTO)
Takashi Iwai8452a982011-07-08 16:19:48 +02004294 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004295 spec->shutup = alc_eapd_shutup;
4296#ifdef CONFIG_SND_HDA_POWER_SAVE
4297 if (!spec->loopback.amplist)
4298 spec->loopback.amplist = alc260_loopbacks;
4299#endif
4300
4301 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004302
4303 error:
4304 alc_free(codec);
4305 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004306}
4307
4308
4309/*
4310 * ALC882/883/885/888/889 support
4311 *
4312 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4313 * configuration. Each pin widget can choose any input DACs and a mixer.
4314 * Each ADC is connected from a mixer of all inputs. This makes possible
4315 * 6-channel independent captures.
4316 *
4317 * In addition, an independent DAC for the multi-playback (not used in this
4318 * driver yet).
4319 */
4320#ifdef CONFIG_SND_HDA_POWER_SAVE
4321#define alc882_loopbacks alc880_loopbacks
4322#endif
4323
4324/*
4325 * Pin config fixes
4326 */
4327enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004328 ALC882_FIXUP_ABIT_AW9D_MAX,
4329 ALC882_FIXUP_LENOVO_Y530,
4330 ALC882_FIXUP_PB_M5210,
4331 ALC882_FIXUP_ACER_ASPIRE_7736,
4332 ALC882_FIXUP_ASUS_W90V,
4333 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004334 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004335 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004336 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004337 ALC883_FIXUP_ACER_EAPD,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004338 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004339 ALC889_FIXUP_COEF,
4340 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004341 ALC882_FIXUP_ACER_ASPIRE_4930G,
4342 ALC882_FIXUP_ACER_ASPIRE_8930G,
4343 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004344 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004345};
4346
Takashi Iwai68ef0562011-11-09 18:24:44 +01004347static void alc889_fixup_coef(struct hda_codec *codec,
4348 const struct alc_fixup *fix, int action)
4349{
4350 if (action != ALC_FIXUP_ACT_INIT)
4351 return;
4352 alc889_coef_init(codec);
4353}
4354
Takashi Iwai56710872011-11-14 17:42:11 +01004355/* toggle speaker-output according to the hp-jack state */
4356static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4357{
4358 unsigned int gpiostate, gpiomask, gpiodir;
4359
4360 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4361 AC_VERB_GET_GPIO_DATA, 0);
4362
4363 if (!muted)
4364 gpiostate |= (1 << pin);
4365 else
4366 gpiostate &= ~(1 << pin);
4367
4368 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4369 AC_VERB_GET_GPIO_MASK, 0);
4370 gpiomask |= (1 << pin);
4371
4372 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4373 AC_VERB_GET_GPIO_DIRECTION, 0);
4374 gpiodir |= (1 << pin);
4375
4376
4377 snd_hda_codec_write(codec, codec->afg, 0,
4378 AC_VERB_SET_GPIO_MASK, gpiomask);
4379 snd_hda_codec_write(codec, codec->afg, 0,
4380 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4381
4382 msleep(1);
4383
4384 snd_hda_codec_write(codec, codec->afg, 0,
4385 AC_VERB_SET_GPIO_DATA, gpiostate);
4386}
4387
4388/* set up GPIO at initialization */
4389static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4390 const struct alc_fixup *fix, int action)
4391{
4392 if (action != ALC_FIXUP_ACT_INIT)
4393 return;
4394 alc882_gpio_mute(codec, 0, 0);
4395 alc882_gpio_mute(codec, 1, 0);
4396}
4397
Takashi Iwai1d045db2011-07-07 18:23:21 +02004398static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004399 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004400 .type = ALC_FIXUP_PINS,
4401 .v.pins = (const struct alc_pincfg[]) {
4402 { 0x15, 0x01080104 }, /* side */
4403 { 0x16, 0x01011012 }, /* rear */
4404 { 0x17, 0x01016011 }, /* clfe */
4405 { }
4406 }
4407 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004408 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004409 .type = ALC_FIXUP_PINS,
4410 .v.pins = (const struct alc_pincfg[]) {
4411 { 0x15, 0x99130112 }, /* rear int speakers */
4412 { 0x16, 0x99130111 }, /* subwoofer */
4413 { }
4414 }
4415 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004416 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004417 .type = ALC_FIXUP_VERBS,
4418 .v.verbs = (const struct hda_verb[]) {
4419 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
4420 {}
4421 }
4422 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004423 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004424 .type = ALC_FIXUP_SKU,
4425 .v.sku = ALC_FIXUP_SKU_IGNORE,
4426 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004427 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02004428 .type = ALC_FIXUP_PINS,
4429 .v.pins = (const struct alc_pincfg[]) {
4430 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4431 { }
4432 }
4433 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004434 [ALC889_FIXUP_VAIO_TT] = {
4435 .type = ALC_FIXUP_PINS,
4436 .v.pins = (const struct alc_pincfg[]) {
4437 { 0x17, 0x90170111 }, /* hidden surround speaker */
4438 { }
4439 }
4440 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004441 [ALC888_FIXUP_EEE1601] = {
4442 .type = ALC_FIXUP_VERBS,
4443 .v.verbs = (const struct hda_verb[]) {
4444 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4445 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
4446 { }
4447 }
Takashi Iwai177943a2011-11-09 12:55:18 +01004448 },
4449 [ALC882_FIXUP_EAPD] = {
4450 .type = ALC_FIXUP_VERBS,
4451 .v.verbs = (const struct hda_verb[]) {
4452 /* change to EAPD mode */
4453 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4454 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4455 { }
4456 }
4457 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004458 [ALC883_FIXUP_EAPD] = {
4459 .type = ALC_FIXUP_VERBS,
4460 .v.verbs = (const struct hda_verb[]) {
4461 /* change to EAPD mode */
4462 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4463 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4464 { }
4465 }
4466 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004467 [ALC883_FIXUP_ACER_EAPD] = {
4468 .type = ALC_FIXUP_VERBS,
4469 .v.verbs = (const struct hda_verb[]) {
4470 /* eanable EAPD on Acer laptops */
4471 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4472 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4473 { }
4474 }
4475 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01004476 [ALC882_FIXUP_GPIO3] = {
4477 .type = ALC_FIXUP_VERBS,
4478 .v.verbs = alc_gpio3_init_verbs,
4479 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01004480 [ALC882_FIXUP_ASUS_W2JC] = {
4481 .type = ALC_FIXUP_VERBS,
4482 .v.verbs = alc_gpio1_init_verbs,
4483 .chained = true,
4484 .chain_id = ALC882_FIXUP_EAPD,
4485 },
4486 [ALC889_FIXUP_COEF] = {
4487 .type = ALC_FIXUP_FUNC,
4488 .v.func = alc889_fixup_coef,
4489 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004490 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
4491 .type = ALC_FIXUP_PINS,
4492 .v.pins = (const struct alc_pincfg[]) {
4493 { 0x16, 0x99130111 }, /* CLFE speaker */
4494 { 0x17, 0x99130112 }, /* surround speaker */
4495 { }
4496 }
4497 },
4498 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
4499 .type = ALC_FIXUP_PINS,
4500 .v.pins = (const struct alc_pincfg[]) {
4501 { 0x16, 0x99130111 }, /* CLFE speaker */
4502 { 0x1b, 0x99130112 }, /* surround speaker */
4503 { }
4504 },
4505 .chained = true,
4506 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
4507 },
4508 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
4509 /* additional init verbs for Acer Aspire 8930G */
4510 .type = ALC_FIXUP_VERBS,
4511 .v.verbs = (const struct hda_verb[]) {
4512 /* Enable all DACs */
4513 /* DAC DISABLE/MUTE 1? */
4514 /* setting bits 1-5 disables DAC nids 0x02-0x06
4515 * apparently. Init=0x38 */
4516 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
4517 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4518 /* DAC DISABLE/MUTE 2? */
4519 /* some bit here disables the other DACs.
4520 * Init=0x4900 */
4521 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
4522 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
4523 /* DMIC fix
4524 * This laptop has a stereo digital microphone.
4525 * The mics are only 1cm apart which makes the stereo
4526 * useless. However, either the mic or the ALC889
4527 * makes the signal become a difference/sum signal
4528 * instead of standard stereo, which is annoying.
4529 * So instead we flip this bit which makes the
4530 * codec replicate the sum signal to both channels,
4531 * turning it into a normal mono mic.
4532 */
4533 /* DMIC_CONTROL? Init value = 0x0001 */
4534 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
4535 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
4536 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4537 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4538 { }
4539 }
4540 },
Takashi Iwai56710872011-11-14 17:42:11 +01004541 [ALC885_FIXUP_MACPRO_GPIO] = {
4542 .type = ALC_FIXUP_FUNC,
4543 .v.func = alc885_fixup_macpro_gpio,
4544 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004545};
4546
4547static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004548 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
4549 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4550 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
4551 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
4552 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
4553 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004554 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
4555 ALC882_FIXUP_ACER_ASPIRE_4930G),
4556 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
4557 ALC882_FIXUP_ACER_ASPIRE_4930G),
4558 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
4559 ALC882_FIXUP_ACER_ASPIRE_8930G),
4560 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
4561 ALC882_FIXUP_ACER_ASPIRE_8930G),
4562 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
4563 ALC882_FIXUP_ACER_ASPIRE_4930G),
4564 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
4565 ALC882_FIXUP_ACER_ASPIRE_4930G),
4566 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
4567 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004568 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004569 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01004570 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004571 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004572 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004573 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004574 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01004575
4576 /* All Apple entries are in codec SSIDs */
4577 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
4578 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
4579 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
4580 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
4581 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
4582
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004583 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01004584 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004585 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004586 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
4587 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01004588 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01004589 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004590 {}
4591};
4592
4593/*
4594 * BIOS auto configuration
4595 */
4596/* almost identical with ALC880 parser... */
4597static int alc882_parse_auto_config(struct hda_codec *codec)
4598{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004599 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004600 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4601 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004602}
4603
Takashi Iwai1d045db2011-07-07 18:23:21 +02004604/*
4605 */
4606#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4607#include "alc882_quirks.c"
4608#endif
4609
4610static int patch_alc882(struct hda_codec *codec)
4611{
4612 struct alc_spec *spec;
4613 int err, board_config;
4614
4615 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4616 if (spec == NULL)
4617 return -ENOMEM;
4618
4619 codec->spec = spec;
4620
4621 spec->mixer_nid = 0x0b;
4622
4623 switch (codec->vendor_id) {
4624 case 0x10ec0882:
4625 case 0x10ec0885:
4626 break;
4627 default:
4628 /* ALC883 and variants */
4629 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4630 break;
4631 }
4632
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004633 err = alc_codec_rename_from_preset(codec);
4634 if (err < 0)
4635 goto error;
4636
Takashi Iwaib2539692011-11-14 17:32:17 +01004637 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
4638 alc882_models, NULL);
4639 if (board_config < 0)
4640 board_config = alc_board_codec_sid_config(codec,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004641 ALC882_MODEL_LAST, alc882_models, alc882_ssid_cfg_tbl);
4642
4643 if (board_config < 0) {
4644 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4645 codec->chip_name);
4646 board_config = ALC_MODEL_AUTO;
4647 }
4648
4649 if (board_config == ALC_MODEL_AUTO) {
4650 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
4651 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4652 }
4653
4654 alc_auto_parse_customize_define(codec);
4655
4656 if (board_config == ALC_MODEL_AUTO) {
4657 /* automatic parse from the BIOS config */
4658 err = alc882_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004659 if (err < 0)
4660 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004661 }
4662
Takashi Iwai1d045db2011-07-07 18:23:21 +02004663 if (board_config != ALC_MODEL_AUTO)
4664 setup_preset(codec, &alc882_presets[board_config]);
4665
Takashi Iwai60a6a842011-07-27 14:01:24 +02004666 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004667 alc_auto_fill_adc_caps(codec);
4668 alc_rebuild_imux_for_auto_mic(codec);
4669 alc_remove_invalid_adc_nids(codec);
4670 }
4671
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004672 if (!spec->no_analog && !spec->cap_mixer)
4673 set_capture_mixer(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004674
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004675 if (!spec->no_analog && has_cdefine_beep(codec)) {
4676 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004677 if (err < 0)
4678 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004679 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004680 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004681
4682 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4683
4684 spec->vmaster_nid = 0x0c;
4685
4686 codec->patch_ops = alc_patch_ops;
4687 if (board_config == ALC_MODEL_AUTO)
Takashi Iwaie4770622011-07-08 11:11:35 +02004688 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004689
4690 alc_init_jacks(codec);
4691#ifdef CONFIG_SND_HDA_POWER_SAVE
4692 if (!spec->loopback.amplist)
4693 spec->loopback.amplist = alc882_loopbacks;
4694#endif
4695
4696 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004697
4698 error:
4699 alc_free(codec);
4700 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004701}
4702
4703
4704/*
4705 * ALC262 support
4706 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004707static int alc262_parse_auto_config(struct hda_codec *codec)
4708{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004709 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004710 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4711 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004712}
4713
4714/*
4715 * Pin config fixes
4716 */
4717enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004718 ALC262_FIXUP_FSC_H270,
4719 ALC262_FIXUP_HP_Z200,
4720 ALC262_FIXUP_TYAN,
Takashi Iwai12837c982011-11-07 12:45:24 +01004721 ALC262_FIXUP_TOSHIBA_RX1,
Takashi Iwaic4701502011-11-07 14:20:07 +01004722 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01004723 ALC262_FIXUP_BENQ,
4724 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004725};
4726
4727static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004728 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004729 .type = ALC_FIXUP_PINS,
4730 .v.pins = (const struct alc_pincfg[]) {
4731 { 0x14, 0x99130110 }, /* speaker */
4732 { 0x15, 0x0221142f }, /* front HP */
4733 { 0x1b, 0x0121141f }, /* rear HP */
4734 { }
4735 }
4736 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004737 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004738 .type = ALC_FIXUP_PINS,
4739 .v.pins = (const struct alc_pincfg[]) {
4740 { 0x16, 0x99130120 }, /* internal speaker */
4741 { }
4742 }
4743 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004744 [ALC262_FIXUP_TYAN] = {
4745 .type = ALC_FIXUP_PINS,
4746 .v.pins = (const struct alc_pincfg[]) {
4747 { 0x14, 0x1993e1f0 }, /* int AUX */
4748 { }
4749 }
4750 },
Takashi Iwai12837c982011-11-07 12:45:24 +01004751 [ALC262_FIXUP_TOSHIBA_RX1] = {
4752 .type = ALC_FIXUP_PINS,
4753 .v.pins = (const struct alc_pincfg[]) {
4754 { 0x14, 0x90170110 }, /* speaker */
4755 { 0x15, 0x0421101f }, /* HP */
4756 { 0x1a, 0x40f000f0 }, /* N/A */
4757 { 0x1b, 0x40f000f0 }, /* N/A */
4758 { 0x1e, 0x40f000f0 }, /* N/A */
4759 }
4760 },
Takashi Iwaic4701502011-11-07 14:20:07 +01004761 [ALC262_FIXUP_LENOVO_3000] = {
4762 .type = ALC_FIXUP_VERBS,
4763 .v.verbs = (const struct hda_verb[]) {
4764 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004765 {}
4766 },
4767 .chained = true,
4768 .chain_id = ALC262_FIXUP_BENQ,
4769 },
4770 [ALC262_FIXUP_BENQ] = {
4771 .type = ALC_FIXUP_VERBS,
4772 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01004773 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4774 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4775 {}
4776 }
4777 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01004778 [ALC262_FIXUP_BENQ_T31] = {
4779 .type = ALC_FIXUP_VERBS,
4780 .v.verbs = (const struct hda_verb[]) {
4781 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4782 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4783 {}
4784 }
4785 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004786};
4787
4788static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004789 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01004790 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
4791 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004792 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
Takashi Iwai12837c982011-11-07 12:45:24 +01004793 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
4794 ALC262_FIXUP_TOSHIBA_RX1),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01004795 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01004796 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01004797 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
4798 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004799 {}
4800};
4801
4802
4803#ifdef CONFIG_SND_HDA_POWER_SAVE
4804#define alc262_loopbacks alc880_loopbacks
4805#endif
4806
Takashi Iwai1d045db2011-07-07 18:23:21 +02004807/*
4808 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004809static int patch_alc262(struct hda_codec *codec)
4810{
4811 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004812 int err;
4813
4814 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4815 if (spec == NULL)
4816 return -ENOMEM;
4817
4818 codec->spec = spec;
4819
4820 spec->mixer_nid = 0x0b;
4821
4822#if 0
4823 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
4824 * under-run
4825 */
4826 {
4827 int tmp;
4828 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4829 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
4830 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
4831 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
4832 }
4833#endif
4834 alc_auto_parse_customize_define(codec);
4835
4836 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
4837
Takashi Iwai42399f72011-11-07 17:18:44 +01004838 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
4839 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004840
Takashi Iwai42399f72011-11-07 17:18:44 +01004841 /* automatic parse from the BIOS config */
4842 err = alc262_parse_auto_config(codec);
4843 if (err < 0)
4844 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004845
Takashi Iwai60a6a842011-07-27 14:01:24 +02004846 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004847 alc_auto_fill_adc_caps(codec);
4848 alc_rebuild_imux_for_auto_mic(codec);
4849 alc_remove_invalid_adc_nids(codec);
4850 }
4851
4852 if (!spec->no_analog && !spec->cap_mixer)
4853 set_capture_mixer(codec);
4854
Takashi Iwai1d045db2011-07-07 18:23:21 +02004855 if (!spec->no_analog && has_cdefine_beep(codec)) {
4856 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004857 if (err < 0)
4858 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004859 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004860 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004861
4862 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4863
4864 spec->vmaster_nid = 0x0c;
4865
4866 codec->patch_ops = alc_patch_ops;
Takashi Iwai42399f72011-11-07 17:18:44 +01004867 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004868 spec->shutup = alc_eapd_shutup;
4869
4870 alc_init_jacks(codec);
4871#ifdef CONFIG_SND_HDA_POWER_SAVE
4872 if (!spec->loopback.amplist)
4873 spec->loopback.amplist = alc262_loopbacks;
4874#endif
4875
4876 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004877
4878 error:
4879 alc_free(codec);
4880 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881}
4882
4883/*
4884 * ALC268
4885 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004886/* bind Beep switches of both NID 0x0f and 0x10 */
4887static const struct hda_bind_ctls alc268_bind_beep_sw = {
4888 .ops = &snd_hda_bind_sw,
4889 .values = {
4890 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
4891 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
4892 0
4893 },
4894};
4895
4896static const struct snd_kcontrol_new alc268_beep_mixer[] = {
4897 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
4898 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
4899 { }
4900};
4901
4902/* set PCBEEP vol = 0, mute connections */
4903static const struct hda_verb alc268_beep_init_verbs[] = {
4904 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
4905 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4906 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
4907 { }
4908};
4909
4910/*
4911 * BIOS auto configuration
4912 */
4913static int alc268_parse_auto_config(struct hda_codec *codec)
4914{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004915 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02004916 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004917 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
4918 if (err > 0) {
4919 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
4920 add_mixer(spec, alc268_beep_mixer);
4921 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004922 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004923 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004924 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004925}
4926
Takashi Iwai1d045db2011-07-07 18:23:21 +02004927/*
4928 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004929static int patch_alc268(struct hda_codec *codec)
4930{
4931 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004932 int i, has_beep, err;
4933
4934 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4935 if (spec == NULL)
4936 return -ENOMEM;
4937
4938 codec->spec = spec;
4939
4940 /* ALC268 has no aa-loopback mixer */
4941
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004942 /* automatic parse from the BIOS config */
4943 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004944 if (err < 0)
4945 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004946
Takashi Iwai1d045db2011-07-07 18:23:21 +02004947 has_beep = 0;
4948 for (i = 0; i < spec->num_mixers; i++) {
4949 if (spec->mixers[i] == alc268_beep_mixer) {
4950 has_beep = 1;
4951 break;
4952 }
4953 }
4954
4955 if (has_beep) {
4956 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004957 if (err < 0)
4958 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004959 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4960 /* override the amp caps for beep generator */
4961 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
4962 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
4963 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
4964 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
4965 (0 << AC_AMPCAP_MUTE_SHIFT));
4966 }
4967
Takashi Iwai60a6a842011-07-27 14:01:24 +02004968 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004969 alc_auto_fill_adc_caps(codec);
4970 alc_rebuild_imux_for_auto_mic(codec);
4971 alc_remove_invalid_adc_nids(codec);
4972 }
4973
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004974 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004975 set_capture_mixer(codec);
4976
4977 spec->vmaster_nid = 0x02;
4978
4979 codec->patch_ops = alc_patch_ops;
Takashi Iwai6ebb8052011-08-16 15:15:40 +02004980 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004981 spec->shutup = alc_eapd_shutup;
4982
4983 alc_init_jacks(codec);
4984
4985 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004986
4987 error:
4988 alc_free(codec);
4989 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004990}
4991
4992/*
4993 * ALC269
4994 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004995#ifdef CONFIG_SND_HDA_POWER_SAVE
4996#define alc269_loopbacks alc880_loopbacks
4997#endif
4998
4999static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5000 .substreams = 1,
5001 .channels_min = 2,
5002 .channels_max = 8,
5003 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5004 /* NID is set in alc_build_pcms */
5005 .ops = {
5006 .open = alc_playback_pcm_open,
5007 .prepare = alc_playback_pcm_prepare,
5008 .cleanup = alc_playback_pcm_cleanup
5009 },
5010};
5011
5012static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5013 .substreams = 1,
5014 .channels_min = 2,
5015 .channels_max = 2,
5016 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5017 /* NID is set in alc_build_pcms */
5018};
5019
5020#ifdef CONFIG_SND_HDA_POWER_SAVE
5021static int alc269_mic2_for_mute_led(struct hda_codec *codec)
5022{
5023 switch (codec->subsystem_id) {
5024 case 0x103c1586:
5025 return 1;
5026 }
5027 return 0;
5028}
5029
5030static int alc269_mic2_mute_check_ps(struct hda_codec *codec, hda_nid_t nid)
5031{
5032 /* update mute-LED according to the speaker mute state */
5033 if (nid == 0x01 || nid == 0x14) {
5034 int pinval;
5035 if (snd_hda_codec_amp_read(codec, 0x14, 0, HDA_OUTPUT, 0) &
5036 HDA_AMP_MUTE)
5037 pinval = 0x24;
5038 else
5039 pinval = 0x20;
5040 /* mic2 vref pin is used for mute LED control */
5041 snd_hda_codec_update_cache(codec, 0x19, 0,
5042 AC_VERB_SET_PIN_WIDGET_CONTROL,
5043 pinval);
5044 }
5045 return alc_check_power_status(codec, nid);
5046}
5047#endif /* CONFIG_SND_HDA_POWER_SAVE */
5048
5049/* different alc269-variants */
5050enum {
5051 ALC269_TYPE_ALC269VA,
5052 ALC269_TYPE_ALC269VB,
5053 ALC269_TYPE_ALC269VC,
5054};
5055
5056/*
5057 * BIOS auto configuration
5058 */
5059static int alc269_parse_auto_config(struct hda_codec *codec)
5060{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005061 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005062 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5063 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5064 struct alc_spec *spec = codec->spec;
5065 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5066 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005067
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005068 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005069}
5070
Takashi Iwai1d045db2011-07-07 18:23:21 +02005071static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5072{
5073 int val = alc_read_coef_idx(codec, 0x04);
5074 if (power_up)
5075 val |= 1 << 11;
5076 else
5077 val &= ~(1 << 11);
5078 alc_write_coef_idx(codec, 0x04, val);
5079}
5080
5081static void alc269_shutup(struct hda_codec *codec)
5082{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005083 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005084 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005085 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005086 alc269_toggle_power_output(codec, 0);
5087 msleep(150);
5088 }
5089}
5090
Takashi Iwai2a439522011-07-26 09:52:50 +02005091#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005092static int alc269_resume(struct hda_codec *codec)
5093{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005094 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005095 alc269_toggle_power_output(codec, 0);
5096 msleep(150);
5097 }
5098
5099 codec->patch_ops.init(codec);
5100
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005101 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005102 alc269_toggle_power_output(codec, 1);
5103 msleep(200);
5104 }
5105
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005106 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005107 alc269_toggle_power_output(codec, 1);
5108
5109 snd_hda_codec_resume_amp(codec);
5110 snd_hda_codec_resume_cache(codec);
5111 hda_call_check_power_status(codec, 0x01);
5112 return 0;
5113}
Takashi Iwai2a439522011-07-26 09:52:50 +02005114#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005115
5116static void alc269_fixup_hweq(struct hda_codec *codec,
5117 const struct alc_fixup *fix, int action)
5118{
5119 int coef;
5120
5121 if (action != ALC_FIXUP_ACT_INIT)
5122 return;
5123 coef = alc_read_coef_idx(codec, 0x1e);
5124 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5125}
5126
5127static void alc271_fixup_dmic(struct hda_codec *codec,
5128 const struct alc_fixup *fix, int action)
5129{
5130 static const struct hda_verb verbs[] = {
5131 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5132 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5133 {}
5134 };
5135 unsigned int cfg;
5136
5137 if (strcmp(codec->chip_name, "ALC271X"))
5138 return;
5139 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5140 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5141 snd_hda_sequence_write(codec, verbs);
5142}
5143
Takashi Iwai017f2a12011-07-09 14:42:25 +02005144static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5145 const struct alc_fixup *fix, int action)
5146{
5147 struct alc_spec *spec = codec->spec;
5148
5149 if (action != ALC_FIXUP_ACT_PROBE)
5150 return;
5151
5152 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5153 * fix the sample rate of analog I/O to 44.1kHz
5154 */
5155 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5156 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5157}
5158
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005159static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5160 const struct alc_fixup *fix, int action)
5161{
5162 int coef;
5163
5164 if (action != ALC_FIXUP_ACT_INIT)
5165 return;
5166 /* The digital-mic unit sends PDM (differential signal) instead of
5167 * the standard PCM, thus you can't record a valid mono stream as is.
5168 * Below is a workaround specific to ALC269 to control the dmic
5169 * signal source as mono.
5170 */
5171 coef = alc_read_coef_idx(codec, 0x07);
5172 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5173}
5174
Takashi Iwai24519912011-08-16 15:08:49 +02005175static void alc269_quanta_automute(struct hda_codec *codec)
5176{
David Henningsson42cf0d02011-09-20 12:04:56 +02005177 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005178
5179 snd_hda_codec_write(codec, 0x20, 0,
5180 AC_VERB_SET_COEF_INDEX, 0x0c);
5181 snd_hda_codec_write(codec, 0x20, 0,
5182 AC_VERB_SET_PROC_COEF, 0x680);
5183
5184 snd_hda_codec_write(codec, 0x20, 0,
5185 AC_VERB_SET_COEF_INDEX, 0x0c);
5186 snd_hda_codec_write(codec, 0x20, 0,
5187 AC_VERB_SET_PROC_COEF, 0x480);
5188}
5189
5190static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5191 const struct alc_fixup *fix, int action)
5192{
5193 struct alc_spec *spec = codec->spec;
5194 if (action != ALC_FIXUP_ACT_PROBE)
5195 return;
5196 spec->automute_hook = alc269_quanta_automute;
5197}
5198
Takashi Iwai1d045db2011-07-07 18:23:21 +02005199enum {
5200 ALC269_FIXUP_SONY_VAIO,
5201 ALC275_FIXUP_SONY_VAIO_GPIO2,
5202 ALC269_FIXUP_DELL_M101Z,
5203 ALC269_FIXUP_SKU_IGNORE,
5204 ALC269_FIXUP_ASUS_G73JW,
5205 ALC269_FIXUP_LENOVO_EAPD,
5206 ALC275_FIXUP_SONY_HWEQ,
5207 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005208 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005209 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005210 ALC269_FIXUP_QUANTA_MUTE,
5211 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005212 ALC269_FIXUP_AMIC,
5213 ALC269_FIXUP_DMIC,
5214 ALC269VB_FIXUP_AMIC,
5215 ALC269VB_FIXUP_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005216};
5217
5218static const struct alc_fixup alc269_fixups[] = {
5219 [ALC269_FIXUP_SONY_VAIO] = {
5220 .type = ALC_FIXUP_VERBS,
5221 .v.verbs = (const struct hda_verb[]) {
5222 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5223 {}
5224 }
5225 },
5226 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5227 .type = ALC_FIXUP_VERBS,
5228 .v.verbs = (const struct hda_verb[]) {
5229 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5230 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5231 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5232 { }
5233 },
5234 .chained = true,
5235 .chain_id = ALC269_FIXUP_SONY_VAIO
5236 },
5237 [ALC269_FIXUP_DELL_M101Z] = {
5238 .type = ALC_FIXUP_VERBS,
5239 .v.verbs = (const struct hda_verb[]) {
5240 /* Enables internal speaker */
5241 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5242 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5243 {}
5244 }
5245 },
5246 [ALC269_FIXUP_SKU_IGNORE] = {
5247 .type = ALC_FIXUP_SKU,
5248 .v.sku = ALC_FIXUP_SKU_IGNORE,
5249 },
5250 [ALC269_FIXUP_ASUS_G73JW] = {
5251 .type = ALC_FIXUP_PINS,
5252 .v.pins = (const struct alc_pincfg[]) {
5253 { 0x17, 0x99130111 }, /* subwoofer */
5254 { }
5255 }
5256 },
5257 [ALC269_FIXUP_LENOVO_EAPD] = {
5258 .type = ALC_FIXUP_VERBS,
5259 .v.verbs = (const struct hda_verb[]) {
5260 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5261 {}
5262 }
5263 },
5264 [ALC275_FIXUP_SONY_HWEQ] = {
5265 .type = ALC_FIXUP_FUNC,
5266 .v.func = alc269_fixup_hweq,
5267 .chained = true,
5268 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5269 },
5270 [ALC271_FIXUP_DMIC] = {
5271 .type = ALC_FIXUP_FUNC,
5272 .v.func = alc271_fixup_dmic,
5273 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005274 [ALC269_FIXUP_PCM_44K] = {
5275 .type = ALC_FIXUP_FUNC,
5276 .v.func = alc269_fixup_pcm_44k,
5277 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005278 [ALC269_FIXUP_STEREO_DMIC] = {
5279 .type = ALC_FIXUP_FUNC,
5280 .v.func = alc269_fixup_stereo_dmic,
5281 },
Takashi Iwai24519912011-08-16 15:08:49 +02005282 [ALC269_FIXUP_QUANTA_MUTE] = {
5283 .type = ALC_FIXUP_FUNC,
5284 .v.func = alc269_fixup_quanta_mute,
5285 },
5286 [ALC269_FIXUP_LIFEBOOK] = {
5287 .type = ALC_FIXUP_PINS,
5288 .v.pins = (const struct alc_pincfg[]) {
5289 { 0x1a, 0x2101103f }, /* dock line-out */
5290 { 0x1b, 0x23a11040 }, /* dock mic-in */
5291 { }
5292 },
5293 .chained = true,
5294 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5295 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005296 [ALC269_FIXUP_AMIC] = {
5297 .type = ALC_FIXUP_PINS,
5298 .v.pins = (const struct alc_pincfg[]) {
5299 { 0x14, 0x99130110 }, /* speaker */
5300 { 0x15, 0x0121401f }, /* HP out */
5301 { 0x18, 0x01a19c20 }, /* mic */
5302 { 0x19, 0x99a3092f }, /* int-mic */
5303 { }
5304 },
5305 },
5306 [ALC269_FIXUP_DMIC] = {
5307 .type = ALC_FIXUP_PINS,
5308 .v.pins = (const struct alc_pincfg[]) {
5309 { 0x12, 0x99a3092f }, /* int-mic */
5310 { 0x14, 0x99130110 }, /* speaker */
5311 { 0x15, 0x0121401f }, /* HP out */
5312 { 0x18, 0x01a19c20 }, /* mic */
5313 { }
5314 },
5315 },
5316 [ALC269VB_FIXUP_AMIC] = {
5317 .type = ALC_FIXUP_PINS,
5318 .v.pins = (const struct alc_pincfg[]) {
5319 { 0x14, 0x99130110 }, /* speaker */
5320 { 0x18, 0x01a19c20 }, /* mic */
5321 { 0x19, 0x99a3092f }, /* int-mic */
5322 { 0x21, 0x0121401f }, /* HP out */
5323 { }
5324 },
5325 },
5326 [ALC269_FIXUP_DMIC] = {
5327 .type = ALC_FIXUP_PINS,
5328 .v.pins = (const struct alc_pincfg[]) {
5329 { 0x12, 0x99a3092f }, /* int-mic */
5330 { 0x14, 0x99130110 }, /* speaker */
5331 { 0x18, 0x01a19c20 }, /* mic */
5332 { 0x21, 0x0121401f }, /* HP out */
5333 { }
5334 },
5335 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005336};
5337
5338static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai017f2a12011-07-09 14:42:25 +02005339 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005340 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5341 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5342 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5343 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5344 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005345 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5346 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5347 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5348 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5349 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5350 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005351 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005352 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5353 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5354 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5355 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5356 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005357 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005358 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005359 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005360
5361#if 1
5362 /* Below is a quirk table taken from the old code.
5363 * Basically the device should work as is without the fixup table.
5364 * If BIOS doesn't give a proper info, enable the corresponding
5365 * fixup entry.
5366 */
5367 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5368 ALC269_FIXUP_AMIC),
5369 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
5370 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
5371 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5372 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5373 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5374 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5375 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5376 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5377 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5378 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5379 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5380 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5381 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5382 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5383 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5384 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5385 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5386 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5387 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5388 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5389 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5390 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5391 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5392 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5393 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5394 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5395 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5396 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5397 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5398 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5399 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5400 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5401 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5402 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5403 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5404 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5405 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5406 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
5407 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
5408 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5409#endif
5410 {}
5411};
5412
5413static const struct alc_model_fixup alc269_fixup_models[] = {
5414 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5415 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02005416 {}
5417};
5418
5419
5420static int alc269_fill_coef(struct hda_codec *codec)
5421{
5422 int val;
5423
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005424 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005425 alc_write_coef_idx(codec, 0xf, 0x960b);
5426 alc_write_coef_idx(codec, 0xe, 0x8817);
5427 }
5428
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005429 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005430 alc_write_coef_idx(codec, 0xf, 0x960b);
5431 alc_write_coef_idx(codec, 0xe, 0x8814);
5432 }
5433
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005434 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005435 val = alc_read_coef_idx(codec, 0x04);
5436 /* Power up output pin */
5437 alc_write_coef_idx(codec, 0x04, val | (1<<11));
5438 }
5439
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005440 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005441 val = alc_read_coef_idx(codec, 0xd);
5442 if ((val & 0x0c00) >> 10 != 0x1) {
5443 /* Capless ramp up clock control */
5444 alc_write_coef_idx(codec, 0xd, val | (1<<10));
5445 }
5446 val = alc_read_coef_idx(codec, 0x17);
5447 if ((val & 0x01c0) >> 6 != 0x4) {
5448 /* Class D power on reset */
5449 alc_write_coef_idx(codec, 0x17, val | (1<<7));
5450 }
5451 }
5452
5453 val = alc_read_coef_idx(codec, 0xd); /* Class D */
5454 alc_write_coef_idx(codec, 0xd, val | (1<<14));
5455
5456 val = alc_read_coef_idx(codec, 0x4); /* HP */
5457 alc_write_coef_idx(codec, 0x4, val | (1<<11));
5458
5459 return 0;
5460}
5461
5462/*
5463 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005464static int patch_alc269(struct hda_codec *codec)
5465{
5466 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005467 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005468
5469 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5470 if (spec == NULL)
5471 return -ENOMEM;
5472
5473 codec->spec = spec;
5474
5475 spec->mixer_nid = 0x0b;
5476
5477 alc_auto_parse_customize_define(codec);
5478
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005479 err = alc_codec_rename_from_preset(codec);
5480 if (err < 0)
5481 goto error;
5482
Takashi Iwai1d045db2011-07-07 18:23:21 +02005483 if (codec->vendor_id == 0x10ec0269) {
5484 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005485 switch (alc_get_coef0(codec) & 0x00f0) {
5486 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005487 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005488 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005489 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005490 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005491 break;
5492 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005493 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
5494 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02005495 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02005496 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005497 break;
5498 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005500 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005501 if (err < 0)
5502 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005503 alc269_fill_coef(codec);
5504 }
5505
Takashi Iwaia4297b52011-08-23 18:40:12 +02005506 alc_pick_fixup(codec, alc269_fixup_models,
5507 alc269_fixup_tbl, alc269_fixups);
5508 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005509
Takashi Iwaia4297b52011-08-23 18:40:12 +02005510 /* automatic parse from the BIOS config */
5511 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005512 if (err < 0)
5513 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005514
Takashi Iwai60a6a842011-07-27 14:01:24 +02005515 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005516 alc_auto_fill_adc_caps(codec);
5517 alc_rebuild_imux_for_auto_mic(codec);
5518 alc_remove_invalid_adc_nids(codec);
5519 }
5520
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005521 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005522 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005523
5524 if (!spec->no_analog && has_cdefine_beep(codec)) {
5525 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005526 if (err < 0)
5527 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005528 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005529 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005530
5531 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5532
5533 spec->vmaster_nid = 0x02;
5534
5535 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02005536#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005537 codec->patch_ops.resume = alc269_resume;
5538#endif
Takashi Iwaia4297b52011-08-23 18:40:12 +02005539 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005540 spec->shutup = alc269_shutup;
5541
5542 alc_init_jacks(codec);
5543#ifdef CONFIG_SND_HDA_POWER_SAVE
5544 if (!spec->loopback.amplist)
5545 spec->loopback.amplist = alc269_loopbacks;
5546 if (alc269_mic2_for_mute_led(codec))
5547 codec->patch_ops.check_power_status = alc269_mic2_mute_check_ps;
5548#endif
5549
5550 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005551
5552 error:
5553 alc_free(codec);
5554 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005555}
5556
5557/*
5558 * ALC861
5559 */
5560
Takashi Iwai1d045db2011-07-07 18:23:21 +02005561static int alc861_parse_auto_config(struct hda_codec *codec)
5562{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005563 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005564 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
5565 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005566}
5567
Takashi Iwai1d045db2011-07-07 18:23:21 +02005568#ifdef CONFIG_SND_HDA_POWER_SAVE
5569static const struct hda_amp_list alc861_loopbacks[] = {
5570 { 0x15, HDA_INPUT, 0 },
5571 { 0x15, HDA_INPUT, 1 },
5572 { 0x15, HDA_INPUT, 2 },
5573 { 0x15, HDA_INPUT, 3 },
5574 { } /* end */
5575};
5576#endif
5577
5578
5579/* Pin config fixes */
5580enum {
5581 PINFIX_FSC_AMILO_PI1505,
5582};
5583
5584static const struct alc_fixup alc861_fixups[] = {
5585 [PINFIX_FSC_AMILO_PI1505] = {
5586 .type = ALC_FIXUP_PINS,
5587 .v.pins = (const struct alc_pincfg[]) {
5588 { 0x0b, 0x0221101f }, /* HP */
5589 { 0x0f, 0x90170310 }, /* speaker */
5590 { }
5591 }
5592 },
5593};
5594
5595static const struct snd_pci_quirk alc861_fixup_tbl[] = {
5596 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", PINFIX_FSC_AMILO_PI1505),
5597 {}
5598};
5599
5600/*
5601 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005602static int patch_alc861(struct hda_codec *codec)
5603{
5604 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005605 int err;
5606
5607 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5608 if (spec == NULL)
5609 return -ENOMEM;
5610
5611 codec->spec = spec;
5612
5613 spec->mixer_nid = 0x15;
5614
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005615 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
5616 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005617
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005618 /* automatic parse from the BIOS config */
5619 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005620 if (err < 0)
5621 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005622
Takashi Iwai60a6a842011-07-27 14:01:24 +02005623 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005624 alc_auto_fill_adc_caps(codec);
5625 alc_rebuild_imux_for_auto_mic(codec);
5626 alc_remove_invalid_adc_nids(codec);
5627 }
5628
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005629 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005630 set_capture_mixer(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005631
5632 if (!spec->no_analog) {
5633 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005634 if (err < 0)
5635 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005636 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
5637 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005638
5639 spec->vmaster_nid = 0x03;
5640
5641 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5642
5643 codec->patch_ops = alc_patch_ops;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005644 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005645#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005646 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005647 if (!spec->loopback.amplist)
5648 spec->loopback.amplist = alc861_loopbacks;
5649#endif
5650
5651 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005652
5653 error:
5654 alc_free(codec);
5655 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656}
5657
5658/*
5659 * ALC861-VD support
5660 *
5661 * Based on ALC882
5662 *
5663 * In addition, an independent DAC
5664 */
5665#ifdef CONFIG_SND_HDA_POWER_SAVE
5666#define alc861vd_loopbacks alc880_loopbacks
5667#endif
5668
Takashi Iwai1d045db2011-07-07 18:23:21 +02005669static int alc861vd_parse_auto_config(struct hda_codec *codec)
5670{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005671 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005672 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5673 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005674}
5675
Takashi Iwai1d045db2011-07-07 18:23:21 +02005676enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005677 ALC660VD_FIX_ASUS_GPIO1,
5678 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005679};
5680
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005681/* exclude VREF80 */
5682static void alc861vd_fixup_dallas(struct hda_codec *codec,
5683 const struct alc_fixup *fix, int action)
5684{
5685 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5686 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5687 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5688 }
5689}
5690
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691static const struct alc_fixup alc861vd_fixups[] = {
5692 [ALC660VD_FIX_ASUS_GPIO1] = {
5693 .type = ALC_FIXUP_VERBS,
5694 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005695 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005696 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
5697 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
5698 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
5699 { }
5700 }
5701 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005702 [ALC861VD_FIX_DALLAS] = {
5703 .type = ALC_FIXUP_FUNC,
5704 .v.func = alc861vd_fixup_dallas,
5705 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005706};
5707
5708static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005709 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005710 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02005711 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712 {}
5713};
5714
5715static const struct hda_verb alc660vd_eapd_verbs[] = {
5716 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
5717 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
5718 { }
5719};
5720
5721/*
5722 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005723static int patch_alc861vd(struct hda_codec *codec)
5724{
5725 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005726 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727
5728 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5729 if (spec == NULL)
5730 return -ENOMEM;
5731
5732 codec->spec = spec;
5733
5734 spec->mixer_nid = 0x0b;
5735
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005736 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
5737 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005738
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005739 /* automatic parse from the BIOS config */
5740 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005741 if (err < 0)
5742 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743
Takashi Iwai1d045db2011-07-07 18:23:21 +02005744 if (codec->vendor_id == 0x10ec0660) {
5745 /* always turn on EAPD */
5746 add_verb(spec, alc660vd_eapd_verbs);
5747 }
5748
Takashi Iwai60a6a842011-07-27 14:01:24 +02005749 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750 alc_auto_fill_adc_caps(codec);
5751 alc_rebuild_imux_for_auto_mic(codec);
5752 alc_remove_invalid_adc_nids(codec);
5753 }
5754
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005755 if (!spec->no_analog && !spec->cap_mixer)
5756 set_capture_mixer(codec);
5757
5758 if (!spec->no_analog) {
5759 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005760 if (err < 0)
5761 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005762 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5763 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005764
5765 spec->vmaster_nid = 0x02;
5766
5767 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5768
5769 codec->patch_ops = alc_patch_ops;
5770
Takashi Iwaicb4e4822011-08-23 17:34:25 +02005771 spec->init_hook = alc_auto_init_std;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005772 spec->shutup = alc_eapd_shutup;
5773#ifdef CONFIG_SND_HDA_POWER_SAVE
5774 if (!spec->loopback.amplist)
5775 spec->loopback.amplist = alc861vd_loopbacks;
5776#endif
5777
5778 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005779
5780 error:
5781 alc_free(codec);
5782 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005783}
5784
5785/*
5786 * ALC662 support
5787 *
5788 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
5789 * configuration. Each pin widget can choose any input DACs and a mixer.
5790 * Each ADC is connected from a mixer of all inputs. This makes possible
5791 * 6-channel independent captures.
5792 *
5793 * In addition, an independent DAC for the multi-playback (not used in this
5794 * driver yet).
5795 */
5796#ifdef CONFIG_SND_HDA_POWER_SAVE
5797#define alc662_loopbacks alc880_loopbacks
5798#endif
5799
5800/*
5801 * BIOS auto configuration
5802 */
5803
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005804static int alc662_parse_auto_config(struct hda_codec *codec)
5805{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02005806 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005807 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
5808 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5809 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02005810
Kailang Yang6227cdc2010-02-25 08:36:52 +01005811 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
5812 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005813 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01005814 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005815 ssids = alc662_ssids;
5816 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02005817}
5818
Todd Broch6be79482010-12-07 16:51:05 -08005819static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005820 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005821{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005822 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01005823 return;
Todd Broch6be79482010-12-07 16:51:05 -08005824 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
5825 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
5826 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
5827 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5828 (0 << AC_AMPCAP_MUTE_SHIFT)))
5829 printk(KERN_WARNING
5830 "hda_codec: failed to override amp caps for NID 0x2\n");
5831}
5832
David Henningsson6cb3b702010-09-09 08:51:44 +02005833enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04005834 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02005835 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08005836 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005837 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02005838 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005839 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02005840 ALC662_FIXUP_ASUS_MODE1,
5841 ALC662_FIXUP_ASUS_MODE2,
5842 ALC662_FIXUP_ASUS_MODE3,
5843 ALC662_FIXUP_ASUS_MODE4,
5844 ALC662_FIXUP_ASUS_MODE5,
5845 ALC662_FIXUP_ASUS_MODE6,
5846 ALC662_FIXUP_ASUS_MODE7,
5847 ALC662_FIXUP_ASUS_MODE8,
David Henningsson6cb3b702010-09-09 08:51:44 +02005848};
5849
5850static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04005851 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005852 .type = ALC_FIXUP_PINS,
5853 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04005854 { 0x15, 0x99130112 }, /* subwoofer */
5855 { }
5856 }
5857 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005858 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005859 .type = ALC_FIXUP_PINS,
5860 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02005861 { 0x17, 0x99130112 }, /* subwoofer */
5862 { }
5863 }
5864 },
Todd Broch6be79482010-12-07 16:51:05 -08005865 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01005866 .type = ALC_FIXUP_FUNC,
5867 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01005868 },
5869 [ALC662_FIXUP_CZC_P10T] = {
5870 .type = ALC_FIXUP_VERBS,
5871 .v.verbs = (const struct hda_verb[]) {
5872 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5873 {}
5874 }
5875 },
David Henningsson94024cd2011-04-29 14:10:55 +02005876 [ALC662_FIXUP_SKU_IGNORE] = {
5877 .type = ALC_FIXUP_SKU,
5878 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02005879 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02005880 [ALC662_FIXUP_HP_RP5800] = {
5881 .type = ALC_FIXUP_PINS,
5882 .v.pins = (const struct alc_pincfg[]) {
5883 { 0x14, 0x0221201f }, /* HP out */
5884 { }
5885 },
5886 .chained = true,
5887 .chain_id = ALC662_FIXUP_SKU_IGNORE
5888 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005889 [ALC662_FIXUP_ASUS_MODE1] = {
5890 .type = ALC_FIXUP_PINS,
5891 .v.pins = (const struct alc_pincfg[]) {
5892 { 0x14, 0x99130110 }, /* speaker */
5893 { 0x18, 0x01a19c20 }, /* mic */
5894 { 0x19, 0x99a3092f }, /* int-mic */
5895 { 0x21, 0x0121401f }, /* HP out */
5896 { }
5897 },
5898 .chained = true,
5899 .chain_id = ALC662_FIXUP_SKU_IGNORE
5900 },
5901 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005902 .type = ALC_FIXUP_PINS,
5903 .v.pins = (const struct alc_pincfg[]) {
5904 { 0x14, 0x99130110 }, /* speaker */
5905 { 0x18, 0x01a19820 }, /* mic */
5906 { 0x19, 0x99a3092f }, /* int-mic */
5907 { 0x1b, 0x0121401f }, /* HP out */
5908 { }
5909 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02005910 .chained = true,
5911 .chain_id = ALC662_FIXUP_SKU_IGNORE
5912 },
5913 [ALC662_FIXUP_ASUS_MODE3] = {
5914 .type = ALC_FIXUP_PINS,
5915 .v.pins = (const struct alc_pincfg[]) {
5916 { 0x14, 0x99130110 }, /* speaker */
5917 { 0x15, 0x0121441f }, /* HP */
5918 { 0x18, 0x01a19840 }, /* mic */
5919 { 0x19, 0x99a3094f }, /* int-mic */
5920 { 0x21, 0x01211420 }, /* HP2 */
5921 { }
5922 },
5923 .chained = true,
5924 .chain_id = ALC662_FIXUP_SKU_IGNORE
5925 },
5926 [ALC662_FIXUP_ASUS_MODE4] = {
5927 .type = ALC_FIXUP_PINS,
5928 .v.pins = (const struct alc_pincfg[]) {
5929 { 0x14, 0x99130110 }, /* speaker */
5930 { 0x16, 0x99130111 }, /* speaker */
5931 { 0x18, 0x01a19840 }, /* mic */
5932 { 0x19, 0x99a3094f }, /* int-mic */
5933 { 0x21, 0x0121441f }, /* HP */
5934 { }
5935 },
5936 .chained = true,
5937 .chain_id = ALC662_FIXUP_SKU_IGNORE
5938 },
5939 [ALC662_FIXUP_ASUS_MODE5] = {
5940 .type = ALC_FIXUP_PINS,
5941 .v.pins = (const struct alc_pincfg[]) {
5942 { 0x14, 0x99130110 }, /* speaker */
5943 { 0x15, 0x0121441f }, /* HP */
5944 { 0x16, 0x99130111 }, /* speaker */
5945 { 0x18, 0x01a19840 }, /* mic */
5946 { 0x19, 0x99a3094f }, /* int-mic */
5947 { }
5948 },
5949 .chained = true,
5950 .chain_id = ALC662_FIXUP_SKU_IGNORE
5951 },
5952 [ALC662_FIXUP_ASUS_MODE6] = {
5953 .type = ALC_FIXUP_PINS,
5954 .v.pins = (const struct alc_pincfg[]) {
5955 { 0x14, 0x99130110 }, /* speaker */
5956 { 0x15, 0x01211420 }, /* HP2 */
5957 { 0x18, 0x01a19840 }, /* mic */
5958 { 0x19, 0x99a3094f }, /* int-mic */
5959 { 0x1b, 0x0121441f }, /* HP */
5960 { }
5961 },
5962 .chained = true,
5963 .chain_id = ALC662_FIXUP_SKU_IGNORE
5964 },
5965 [ALC662_FIXUP_ASUS_MODE7] = {
5966 .type = ALC_FIXUP_PINS,
5967 .v.pins = (const struct alc_pincfg[]) {
5968 { 0x14, 0x99130110 }, /* speaker */
5969 { 0x17, 0x99130111 }, /* speaker */
5970 { 0x18, 0x01a19840 }, /* mic */
5971 { 0x19, 0x99a3094f }, /* int-mic */
5972 { 0x1b, 0x01214020 }, /* HP */
5973 { 0x21, 0x0121401f }, /* HP */
5974 { }
5975 },
5976 .chained = true,
5977 .chain_id = ALC662_FIXUP_SKU_IGNORE
5978 },
5979 [ALC662_FIXUP_ASUS_MODE8] = {
5980 .type = ALC_FIXUP_PINS,
5981 .v.pins = (const struct alc_pincfg[]) {
5982 { 0x14, 0x99130110 }, /* speaker */
5983 { 0x12, 0x99a30970 }, /* int-mic */
5984 { 0x15, 0x01214020 }, /* HP */
5985 { 0x17, 0x99130111 }, /* speaker */
5986 { 0x18, 0x01a19840 }, /* mic */
5987 { 0x21, 0x0121401f }, /* HP */
5988 { }
5989 },
5990 .chained = true,
5991 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02005992 },
David Henningsson6cb3b702010-09-09 08:51:44 +02005993};
5994
Takashi Iwaia9111322011-05-02 11:30:18 +02005995static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02005996 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01005997 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02005998 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04005999 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006000 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006001 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006002 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006003 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006004 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006005 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006006
6007#if 0
6008 /* Below is a quirk table taken from the old code.
6009 * Basically the device should work as is without the fixup table.
6010 * If BIOS doesn't give a proper info, enable the corresponding
6011 * fixup entry.
6012 */
6013 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6014 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6015 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6016 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6017 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6018 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6019 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6020 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6021 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6022 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6023 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6024 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6025 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6026 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6027 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6028 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6029 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6030 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6031 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6032 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6033 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6034 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6035 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6036 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6037 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6038 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6039 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6040 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6041 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6042 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6043 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6044 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6045 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6046 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6047 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6048 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6049 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6050 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6051 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6052 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6053 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6054 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6055 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6056 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6057 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6058 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6059 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6060 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6061 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6062 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6063#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006064 {}
6065};
6066
Todd Broch6be79482010-12-07 16:51:05 -08006067static const struct alc_model_fixup alc662_fixup_models[] = {
6068 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006069 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6070 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6071 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6072 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6073 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6074 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6075 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6076 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006077 {}
6078};
David Henningsson6cb3b702010-09-09 08:51:44 +02006079
6080
Takashi Iwai1d045db2011-07-07 18:23:21 +02006081/*
6082 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006083static int patch_alc662(struct hda_codec *codec)
6084{
6085 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006086 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006087
6088 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6089 if (!spec)
6090 return -ENOMEM;
6091
6092 codec->spec = spec;
6093
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006094 spec->mixer_nid = 0x0b;
6095
Takashi Iwai53c334a2011-08-23 18:27:14 +02006096 /* handle multiple HPs as is */
6097 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6098
Kailang Yangda00c242010-03-19 11:23:45 +01006099 alc_auto_parse_customize_define(codec);
6100
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006101 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6102
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006103 err = alc_codec_rename_from_preset(codec);
6104 if (err < 0)
6105 goto error;
6106
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006107 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006108 codec->bus->pci->subsystem_vendor == 0x1025 &&
6109 spec->cdefine.platform_type == 1) {
6110 if (alc_codec_rename(codec, "ALC272X") < 0)
6111 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006112 }
Kailang Yang274693f2009-12-03 10:07:50 +01006113
Takashi Iwaib9c51062011-08-24 18:08:07 +02006114 alc_pick_fixup(codec, alc662_fixup_models,
6115 alc662_fixup_tbl, alc662_fixups);
6116 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6117 /* automatic parse from the BIOS config */
6118 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006119 if (err < 0)
6120 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006121
Takashi Iwai60a6a842011-07-27 14:01:24 +02006122 if (!spec->no_analog && !spec->adc_nids) {
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006123 alc_auto_fill_adc_caps(codec);
Takashi Iwai21268962011-07-07 15:01:13 +02006124 alc_rebuild_imux_for_auto_mic(codec);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02006125 alc_remove_invalid_adc_nids(codec);
Takashi Iwaidd704692009-08-11 08:45:11 +02006126 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006127
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006128 if (!spec->no_analog && !spec->cap_mixer)
Takashi Iwaib59bdf32009-08-11 09:47:30 +02006129 set_capture_mixer(codec);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01006130
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006131 if (!spec->no_analog && has_cdefine_beep(codec)) {
6132 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006133 if (err < 0)
6134 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006135 switch (codec->vendor_id) {
6136 case 0x10ec0662:
6137 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6138 break;
6139 case 0x10ec0272:
6140 case 0x10ec0663:
6141 case 0x10ec0665:
6142 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6143 break;
6144 case 0x10ec0273:
6145 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6146 break;
6147 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006148 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006149 spec->vmaster_nid = 0x02;
6150
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006151 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6152
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006153 codec->patch_ops = alc_patch_ops;
Takashi Iwaib9c51062011-08-24 18:08:07 +02006154 spec->init_hook = alc_auto_init_std;
Takashi Iwai1c716152011-04-07 10:37:16 +02006155 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006156
Kailang Yangbf1b0222010-10-21 08:49:56 +02006157 alc_init_jacks(codec);
6158
Takashi Iwaicb53c622007-08-10 17:21:45 +02006159#ifdef CONFIG_SND_HDA_POWER_SAVE
6160 if (!spec->loopback.amplist)
6161 spec->loopback.amplist = alc662_loopbacks;
6162#endif
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006163
6164 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006165
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006166 error:
6167 alc_free(codec);
6168 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006169}
6170
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006171/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006172 * ALC680 support
6173 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006174
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006175static int alc680_parse_auto_config(struct hda_codec *codec)
6176{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006177 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006178}
6179
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006180/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006181 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006182static int patch_alc680(struct hda_codec *codec)
6183{
6184 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006185 int err;
6186
6187 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6188 if (spec == NULL)
6189 return -ENOMEM;
6190
6191 codec->spec = spec;
6192
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006193 /* ALC680 has no aa-loopback mixer */
6194
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006195 /* automatic parse from the BIOS config */
6196 err = alc680_parse_auto_config(codec);
6197 if (err < 0) {
6198 alc_free(codec);
6199 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006200 }
6201
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006202 if (!spec->no_analog && !spec->cap_mixer)
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006203 set_capture_mixer(codec);
6204
6205 spec->vmaster_nid = 0x02;
6206
6207 codec->patch_ops = alc_patch_ops;
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006208 spec->init_hook = alc_auto_init_std;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006209
6210 return 0;
6211}
6212
6213/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006214 * patch entries
6215 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006216static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006217 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006218 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006219 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006220 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006221 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006222 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006223 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006224 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006225 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006226 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006227 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006228 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006229 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6230 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6231 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006232 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006233 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006234 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6235 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006236 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6237 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006238 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006239 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006240 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006241 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006242 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006243 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006244 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006245 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006246 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006247 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006248 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006249 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006250 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006251 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006252 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006253 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006254 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006255 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006256 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006257 {} /* terminator */
6258};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006259
6260MODULE_ALIAS("snd-hda-codec-id:10ec*");
6261
6262MODULE_LICENSE("GPL");
6263MODULE_DESCRIPTION("Realtek HD-audio codec");
6264
6265static struct hda_codec_preset_list realtek_list = {
6266 .preset = snd_hda_preset_realtek,
6267 .owner = THIS_MODULE,
6268};
6269
6270static int __init patch_realtek_init(void)
6271{
6272 return snd_hda_add_codec_preset(&realtek_list);
6273}
6274
6275static void __exit patch_realtek_exit(void)
6276{
6277 snd_hda_delete_codec_preset(&realtek_list);
6278}
6279
6280module_init(patch_realtek_init)
6281module_exit(patch_realtek_exit)