blob: 9917e55d6f11f8bbe9c0e8c7827febaf6c6ba6f7 [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
Takashi Iwaic14c95f2012-02-16 16:38:07 +010083#define MAX_VOL_NIDS 0x40
84
Linus Torvalds1da177e2005-04-16 15:20:36 -070085struct alc_spec {
86 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +020087 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +020089 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +010090 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Takashi Iwai2d9c6482009-10-13 08:06:55 +020092 const struct hda_verb *init_verbs[10]; /* initialization verbs
Takashi Iwai9c7f8522006-06-28 15:08:22 +020093 * don't forget NULL
94 * termination!
Takashi Iwaie9edcee2005-06-13 14:16:38 +020095 */
96 unsigned int num_init_verbs;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Takashi Iwaiaa563af2009-07-31 10:05:11 +020098 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +020099 const struct hda_pcm_stream *stream_analog_playback;
100 const struct hda_pcm_stream *stream_analog_capture;
101 const struct hda_pcm_stream *stream_analog_alt_playback;
102 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200104 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200105 const struct hda_pcm_stream *stream_digital_playback;
106 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200109 struct hda_multi_out multiout; /* playback set-up
110 * max_channels, dacs must be set
111 * dig_out_nid and hp_nid are optional
112 */
Takashi Iwai63300792008-01-24 15:31:36 +0100113 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100114 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100115 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 /* capture */
118 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200119 const hda_nid_t *adc_nids;
120 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200121 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200122 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwaic14c95f2012-02-16 16:38:07 +0100123 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
124 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Takashi Iwai840b64c2010-07-13 22:49:01 +0200126 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200127 hda_nid_t cur_adc;
128 unsigned int cur_adc_stream_tag;
129 unsigned int cur_adc_format;
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200132 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 const struct hda_input_mux *input_mux;
134 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200135 hda_nid_t ext_mic_pin;
136 hda_nid_t dock_mic_pin;
137 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100140 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200142 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200143 int const_channel_count;
144 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100147 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200148
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200149 /* dynamic controls, init_verbs and input_mux */
150 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100151 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200152 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200153 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200154 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200155 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
156 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200157 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
158 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
159 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai834be882006-03-01 14:16:17 +0100160
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100161 /* hooks */
162 void (*init_hook)(struct hda_codec *codec);
163 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100164#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500165 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100166#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200167 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200168 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100169
Takashi Iwai834be882006-03-01 14:16:17 +0100170 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200171 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200172 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200173 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200174 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200175 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200176 unsigned int automute_speaker:1; /* automute speaker outputs */
177 unsigned int automute_lo:1; /* automute LO outputs */
178 unsigned int detect_hp:1; /* Headphone detection enabled */
179 unsigned int detect_lo:1; /* Line-out detection enabled */
180 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
181 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100182 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200183
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100184 /* other flags */
185 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200186 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100187 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200188 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200189 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100190 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200191
192 /* auto-mute control */
193 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200194 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200195
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200196 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200197 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100198
Takashi Iwai2134ea42008-01-10 16:53:55 +0100199 /* for virtual master */
200 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100201 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200202#ifdef CONFIG_SND_HDA_POWER_SAVE
203 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100204 int num_loopbacks;
205 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200206#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200207
208 /* for PLL fix */
209 hda_nid_t pll_nid;
210 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200211 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100212
213 /* fix-up list */
214 int fixup_id;
215 const struct alc_fixup *fixup_list;
216 const char *fixup_name;
Takashi Iwaice764ab2011-04-27 16:35:23 +0200217
218 /* multi-io */
219 int multi_ios;
220 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200221
222 /* bind volumes */
223 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100224};
225
Takashi Iwai44c02402011-07-08 15:14:19 +0200226static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
227 int dir, unsigned int bits)
228{
229 if (!nid)
230 return false;
231 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
232 if (query_amp_caps(codec, nid, dir) & bits)
233 return true;
234 return false;
235}
236
237#define nid_has_mute(codec, nid, dir) \
238 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
239#define nid_has_volume(codec, nid, dir) \
240 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
241
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242/*
243 * input MUX handling
244 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200245static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
246 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247{
248 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
249 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200250 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
251 if (mux_idx >= spec->num_mux_defs)
252 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100253 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
254 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200255 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256}
257
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200258static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
259 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260{
261 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
262 struct alc_spec *spec = codec->spec;
263 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
264
265 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
266 return 0;
267}
268
Takashi Iwai21268962011-07-07 15:01:13 +0200269static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270{
Takashi Iwai21268962011-07-07 15:01:13 +0200271 struct alc_spec *spec = codec->spec;
272 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
273
274 if (spec->cur_adc && spec->cur_adc != new_adc) {
275 /* stream is running, let's swap the current ADC */
276 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
277 spec->cur_adc = new_adc;
278 snd_hda_codec_setup_stream(codec, new_adc,
279 spec->cur_adc_stream_tag, 0,
280 spec->cur_adc_format);
281 return true;
282 }
283 return false;
284}
285
Takashi Iwai61071592011-11-23 07:52:15 +0100286static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
287{
288 return spec->capsrc_nids ?
289 spec->capsrc_nids[idx] : spec->adc_nids[idx];
290}
291
Takashi Iwai24de1832011-11-07 17:13:39 +0100292static void call_update_outputs(struct hda_codec *codec);
293
Takashi Iwai21268962011-07-07 15:01:13 +0200294/* select the given imux item; either unmute exclusively or select the route */
295static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
296 unsigned int idx, bool force)
297{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100299 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100300 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100301 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200302 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303
Takashi Iwai5803a322012-02-21 11:59:45 +0100304 if (!spec->input_mux)
305 return 0;
306
Takashi Iwaicd896c32008-11-18 12:36:33 +0100307 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
308 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100309 if (!imux->num_items && mux_idx > 0)
310 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100311 if (!imux->num_items)
312 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100313
Takashi Iwai21268962011-07-07 15:01:13 +0200314 if (idx >= imux->num_items)
315 idx = imux->num_items - 1;
316 if (spec->cur_mux[adc_idx] == idx && !force)
317 return 0;
318 spec->cur_mux[adc_idx] = idx;
319
Takashi Iwai24de1832011-11-07 17:13:39 +0100320 /* for shared I/O, change the pin-control accordingly */
321 if (spec->shared_mic_hp) {
322 /* NOTE: this assumes that there are only two inputs, the
323 * first is the real internal mic and the second is HP jack.
324 */
325 snd_hda_codec_write(codec, spec->autocfg.inputs[1].pin, 0,
326 AC_VERB_SET_PIN_WIDGET_CONTROL,
327 spec->cur_mux[adc_idx] ?
328 PIN_VREF80 : PIN_HP);
329 spec->automute_speaker = !spec->cur_mux[adc_idx];
330 call_update_outputs(codec);
331 }
332
Takashi Iwai21268962011-07-07 15:01:13 +0200333 if (spec->dyn_adc_switch) {
334 alc_dyn_adc_pcm_resetup(codec, idx);
335 adc_idx = spec->dyn_adc_idx[idx];
336 }
337
Takashi Iwai61071592011-11-23 07:52:15 +0100338 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200339
340 /* no selection? */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100341 num_conns = snd_hda_get_conn_list(codec, nid, NULL);
342 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200343 return 1;
344
Takashi Iwaia22d5432009-07-27 12:54:26 +0200345 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200346 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100347 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100348 int active = imux->items[idx].index;
349 for (i = 0; i < num_conns; i++) {
350 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
351 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100352 HDA_AMP_MUTE, v);
353 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100354 } else {
355 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200356 snd_hda_codec_write_cache(codec, nid, 0,
357 AC_VERB_SET_CONNECT_SEL,
358 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100359 }
Takashi Iwai21268962011-07-07 15:01:13 +0200360 return 1;
361}
362
363static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
364 struct snd_ctl_elem_value *ucontrol)
365{
366 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
367 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
368 return alc_mux_select(codec, adc_idx,
369 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100370}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100373 * set up the input pin config (depending on the given auto-pin type)
374 */
375static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
376 int auto_pin_type)
377{
378 unsigned int val = PIN_IN;
379
Takashi Iwai86e29592010-09-09 14:50:17 +0200380 if (auto_pin_type == AUTO_PIN_MIC) {
Takashi Iwai23f0c042009-02-26 13:03:58 +0100381 unsigned int pincap;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200382 unsigned int oldval;
383 oldval = snd_hda_codec_read(codec, nid, 0,
384 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
Takashi Iwai1327a322009-03-23 13:07:47 +0100385 pincap = snd_hda_query_pin_caps(codec, nid);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100386 pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
Takashi Iwai954a29c2010-07-30 10:55:44 +0200387 /* if the default pin setup is vref50, we give it priority */
388 if ((pincap & AC_PINCAP_VREF_80) && oldval != PIN_VREF50)
Takashi Iwai23f0c042009-02-26 13:03:58 +0100389 val = PIN_VREF80;
Takashi Iwai461c6c32009-05-25 08:06:02 +0200390 else if (pincap & AC_PINCAP_VREF_50)
391 val = PIN_VREF50;
392 else if (pincap & AC_PINCAP_VREF_100)
393 val = PIN_VREF100;
394 else if (pincap & AC_PINCAP_VREF_GRD)
395 val = PIN_VREFGRD;
Takashi Iwai23f0c042009-02-26 13:03:58 +0100396 }
397 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, val);
398}
399
400/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200401 * Append the given mixer and verb elements for the later use
402 * The mixer array is referred in build_controls(), and init_verbs are
403 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100404 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200405static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100406{
407 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
408 return;
409 spec->mixers[spec->num_mixers++] = mix;
410}
411
412static void add_verb(struct alc_spec *spec, const struct hda_verb *verb)
413{
414 if (snd_BUG_ON(spec->num_init_verbs >= ARRAY_SIZE(spec->init_verbs)))
415 return;
416 spec->init_verbs[spec->num_init_verbs++] = verb;
417}
418
419/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200420 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100421 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200422/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200423static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200424 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
425 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
426 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
427 { }
428};
429
Takashi Iwaia9111322011-05-02 11:30:18 +0200430static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200431 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
432 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
433 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
434 { }
435};
436
Takashi Iwaia9111322011-05-02 11:30:18 +0200437static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200438 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
439 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
440 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
441 { }
442};
443
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200444/*
445 * Fix hardware PLL issue
446 * On some codecs, the analog PLL gating control must be off while
447 * the default value is 1.
448 */
449static void alc_fix_pll(struct hda_codec *codec)
450{
451 struct alc_spec *spec = codec->spec;
452 unsigned int val;
453
454 if (!spec->pll_nid)
455 return;
456 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
457 spec->pll_coef_idx);
458 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
459 AC_VERB_GET_PROC_COEF, 0);
460 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
461 spec->pll_coef_idx);
462 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
463 val & ~(1 << spec->pll_coef_bit));
464}
465
466static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
467 unsigned int coef_idx, unsigned int coef_bit)
468{
469 struct alc_spec *spec = codec->spec;
470 spec->pll_nid = nid;
471 spec->pll_coef_idx = coef_idx;
472 spec->pll_coef_bit = coef_bit;
473 alc_fix_pll(codec);
474}
475
Takashi Iwai1d045db2011-07-07 18:23:21 +0200476/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200477 * Jack detections for HP auto-mute and mic-switch
478 */
479
480/* check each pin in the given array; returns true if any of them is plugged */
481static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200482{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200483 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200484
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200485 for (i = 0; i < num_pins; i++) {
486 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200487 if (!nid)
488 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200489 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200490 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200491 return present;
492}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200493
Takashi Iwai1d045db2011-07-07 18:23:21 +0200494/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200496 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200497{
498 struct alc_spec *spec = codec->spec;
499 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200500 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 int i;
502
503 for (i = 0; i < num_pins; i++) {
504 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100505 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200506 if (!nid)
507 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200508 switch (spec->automute_mode) {
509 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100510 /* don't reset VREF value in case it's controlling
511 * the amp (see alc861_fixup_asus_amp_vref_0f())
512 */
513 if (spec->keep_vref_in_automute) {
514 val = snd_hda_codec_read(codec, nid, 0,
515 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
516 val &= ~PIN_HP;
517 } else
518 val = 0;
519 val |= pin_bits;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200520 snd_hda_codec_write(codec, nid, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200521 AC_VERB_SET_PIN_WIDGET_CONTROL,
Takashi Iwai31150f22012-01-30 10:54:08 +0100522 val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200523 break;
524 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200525 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200527 break;
528 case ALC_AUTOMUTE_MIXER:
529 nid = spec->automute_mixer_nid[i];
530 if (!nid)
531 break;
532 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200533 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200534 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200535 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200536 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200537 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200538 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200539}
540
David Henningsson42cf0d02011-09-20 12:04:56 +0200541/* Toggle outputs muting */
542static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543{
544 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200545 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200546
Takashi Iwaic0a20262011-06-10 15:28:15 +0200547 /* Control HP pins/amps depending on master_mute state;
548 * in general, HP pins/amps control should be enabled in all cases,
549 * but currently set only for master_mute, just to be safe
550 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100551 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
552 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200553 spec->autocfg.hp_pins, spec->master_mute, true);
554
David Henningsson42cf0d02011-09-20 12:04:56 +0200555 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200556 on = 0;
557 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200558 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200559 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200560 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200561 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200562
563 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200564 /* if LO is a copy of either HP or Speaker, don't need to handle it */
565 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
566 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200567 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200568 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200569 on = 0;
570 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200571 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200572 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200573 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200574 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200575}
576
David Henningsson42cf0d02011-09-20 12:04:56 +0200577static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200578{
579 struct alc_spec *spec = codec->spec;
580 if (spec->automute_hook)
581 spec->automute_hook(codec);
582 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200583 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200584}
585
Takashi Iwai1d045db2011-07-07 18:23:21 +0200586/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200587static void alc_hp_automute(struct hda_codec *codec)
588{
589 struct alc_spec *spec = codec->spec;
590
David Henningsson42cf0d02011-09-20 12:04:56 +0200591 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200592 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
593 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200594 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200595 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200596 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200597}
598
Takashi Iwai1d045db2011-07-07 18:23:21 +0200599/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200600static void alc_line_automute(struct hda_codec *codec)
601{
602 struct alc_spec *spec = codec->spec;
603
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200604 /* check LO jack only when it's different from HP */
605 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
606 return;
607
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200608 spec->line_jack_present =
609 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
610 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200611 if (!spec->automute_speaker || !spec->detect_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 Iwai8d087c72011-06-28 12:45:47 +0200616#define get_connection_index(codec, mux, nid) \
617 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200618
Takashi Iwai1d045db2011-07-07 18:23:21 +0200619/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200620static void alc_mic_automute(struct hda_codec *codec)
621{
622 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200623 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200624
Takashi Iwai21268962011-07-07 15:01:13 +0200625 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200626 return;
627 if (snd_BUG_ON(!spec->adc_nids))
628 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200629 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200630 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200631
Takashi Iwai21268962011-07-07 15:01:13 +0200632 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
633 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
634 else if (spec->dock_mic_idx >= 0 &&
635 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
636 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
637 else
638 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200639}
640
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100641/* handle the specified unsol action (ALC_XXX_EVENT) */
642static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200643{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100644 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200645 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200646 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200647 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200648 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200649 alc_line_automute(codec);
650 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200651 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200652 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200653 break;
654 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200655 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200656}
657
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100658/* update the master volume per volume-knob's unsol event */
659static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
660{
661 unsigned int val;
662 struct snd_kcontrol *kctl;
663 struct snd_ctl_elem_value *uctl;
664
665 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
666 if (!kctl)
667 return;
668 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
669 if (!uctl)
670 return;
671 val = snd_hda_codec_read(codec, nid, 0,
672 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
673 val &= HDA_AMP_VOLMASK;
674 uctl->value.integer.value[0] = val;
675 uctl->value.integer.value[1] = val;
676 kctl->put(kctl, uctl);
677 kfree(uctl);
678}
679
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100680/* unsolicited event for HP jack sensing */
681static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
682{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100683 int action;
684
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100685 if (codec->vendor_id == 0x10ec0880)
686 res >>= 28;
687 else
688 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100689 action = snd_hda_jack_get_action(codec, res);
David Henningssone21af482012-03-05 11:38:46 +0100690 if (action == ALC_DCVOL_EVENT) {
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100691 /* Execute the dc-vol event here as it requires the NID
692 * but we don't pass NID to alc_exec_unsol_event().
693 * Once when we convert all static quirks to the auto-parser,
694 * this can be integerated into there.
695 */
696 struct hda_jack_tbl *jack;
697 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
698 if (jack)
699 alc_update_knob_master(codec, jack->nid);
700 return;
701 }
702 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100703}
704
Takashi Iwai1d045db2011-07-07 18:23:21 +0200705/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200706static void alc_inithook(struct hda_codec *codec)
707{
Takashi Iwaid922b512011-04-28 12:18:53 +0200708 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200709 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200710 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200711}
712
Kailang Yangf9423e72008-05-27 12:32:25 +0200713/* additional initialization for ALC888 variants */
714static void alc888_coef_init(struct hda_codec *codec)
715{
716 unsigned int tmp;
717
718 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
719 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
720 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100721 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200722 /* alc888S-VC */
723 snd_hda_codec_read(codec, 0x20, 0,
724 AC_VERB_SET_PROC_COEF, 0x830);
725 else
726 /* alc888-VB */
727 snd_hda_codec_read(codec, 0x20, 0,
728 AC_VERB_SET_PROC_COEF, 0x3030);
729}
730
Takashi Iwai1d045db2011-07-07 18:23:21 +0200731/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200732static void alc889_coef_init(struct hda_codec *codec)
733{
734 unsigned int tmp;
735
736 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
737 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
738 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
739 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
740}
741
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100742/* turn on/off EAPD control (only if available) */
743static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
744{
745 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
746 return;
747 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
748 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
749 on ? 2 : 0);
750}
751
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200752/* turn on/off EAPD controls of the codec */
753static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
754{
755 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200756 static hda_nid_t pins[] = {
757 0x0f, 0x10, 0x14, 0x15, 0
758 };
759 hda_nid_t *p;
760 for (p = pins; *p; p++)
761 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200762}
763
Takashi Iwai1c716152011-04-07 10:37:16 +0200764/* generic shutup callback;
765 * just turning off EPAD and a little pause for avoiding pop-noise
766 */
767static void alc_eapd_shutup(struct hda_codec *codec)
768{
769 alc_auto_setup_eapd(codec, false);
770 msleep(200);
771}
772
Takashi Iwai1d045db2011-07-07 18:23:21 +0200773/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200774static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200775{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200776 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200777
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200778 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200779 switch (type) {
780 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200781 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
782 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200783 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200784 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
785 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200786 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200787 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
788 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200789 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200790 switch (codec->vendor_id) {
791 case 0x10ec0260:
792 snd_hda_codec_write(codec, 0x1a, 0,
793 AC_VERB_SET_COEF_INDEX, 7);
794 tmp = snd_hda_codec_read(codec, 0x1a, 0,
795 AC_VERB_GET_PROC_COEF, 0);
796 snd_hda_codec_write(codec, 0x1a, 0,
797 AC_VERB_SET_COEF_INDEX, 7);
798 snd_hda_codec_write(codec, 0x1a, 0,
799 AC_VERB_SET_PROC_COEF,
800 tmp | 0x2010);
801 break;
802 case 0x10ec0262:
803 case 0x10ec0880:
804 case 0x10ec0882:
805 case 0x10ec0883:
806 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100807 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100808 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200809 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200810 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200811 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200812 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200813 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100814#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200815 case 0x10ec0267:
816 case 0x10ec0268:
817 snd_hda_codec_write(codec, 0x20, 0,
818 AC_VERB_SET_COEF_INDEX, 7);
819 tmp = snd_hda_codec_read(codec, 0x20, 0,
820 AC_VERB_GET_PROC_COEF, 0);
821 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200822 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200823 snd_hda_codec_write(codec, 0x20, 0,
824 AC_VERB_SET_PROC_COEF,
825 tmp | 0x3000);
826 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100827#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200828 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200829 break;
830 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200831}
Kailang Yangea1fb292008-08-26 12:58:38 +0200832
Takashi Iwai1d045db2011-07-07 18:23:21 +0200833/*
834 * Auto-Mute mode mixer enum support
835 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200836static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
837 struct snd_ctl_elem_info *uinfo)
838{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200839 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
840 struct alc_spec *spec = codec->spec;
841 static const char * const texts2[] = {
842 "Disabled", "Enabled"
843 };
844 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100845 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200846 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200847 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200848
849 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
850 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200851 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200852 uinfo->value.enumerated.items = 3;
853 texts = texts3;
854 } else {
855 uinfo->value.enumerated.items = 2;
856 texts = texts2;
857 }
858 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
859 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200860 strcpy(uinfo->value.enumerated.name,
861 texts[uinfo->value.enumerated.item]);
862 return 0;
863}
864
865static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
866 struct snd_ctl_elem_value *ucontrol)
867{
868 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
869 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200870 unsigned int val = 0;
871 if (spec->automute_speaker)
872 val++;
873 if (spec->automute_lo)
874 val++;
875
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200876 ucontrol->value.enumerated.item[0] = val;
877 return 0;
878}
879
880static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
881 struct snd_ctl_elem_value *ucontrol)
882{
883 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
884 struct alc_spec *spec = codec->spec;
885
886 switch (ucontrol->value.enumerated.item[0]) {
887 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200888 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200889 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200890 spec->automute_speaker = 0;
891 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200892 break;
893 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200894 if (spec->automute_speaker_possible) {
895 if (!spec->automute_lo && spec->automute_speaker)
896 return 0;
897 spec->automute_speaker = 1;
898 spec->automute_lo = 0;
899 } else if (spec->automute_lo_possible) {
900 if (spec->automute_lo)
901 return 0;
902 spec->automute_lo = 1;
903 } else
904 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200905 break;
906 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200907 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200908 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200909 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200910 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200911 spec->automute_speaker = 1;
912 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200913 break;
914 default:
915 return -EINVAL;
916 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200917 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200918 return 1;
919}
920
Takashi Iwaia9111322011-05-02 11:30:18 +0200921static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200922 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
923 .name = "Auto-Mute Mode",
924 .info = alc_automute_mode_info,
925 .get = alc_automute_mode_get,
926 .put = alc_automute_mode_put,
927};
928
Takashi Iwai1d045db2011-07-07 18:23:21 +0200929static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
930{
931 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
932 return snd_array_new(&spec->kctls);
933}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200934
935static int alc_add_automute_mode_enum(struct hda_codec *codec)
936{
937 struct alc_spec *spec = codec->spec;
938 struct snd_kcontrol_new *knew;
939
940 knew = alc_kcontrol_new(spec);
941 if (!knew)
942 return -ENOMEM;
943 *knew = alc_automute_mode_enum;
944 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
945 if (!knew->name)
946 return -ENOMEM;
947 return 0;
948}
949
Takashi Iwai1d045db2011-07-07 18:23:21 +0200950/*
951 * Check the availability of HP/line-out auto-mute;
952 * Set up appropriately if really supported
953 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200954static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200955{
956 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200957 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200958 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200959 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200960
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200961 if (cfg->hp_pins[0])
962 present++;
963 if (cfg->line_out_pins[0])
964 present++;
965 if (cfg->speaker_pins[0])
966 present++;
967 if (present < 2) /* need two different output types */
968 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200969
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200970 if (!cfg->speaker_pins[0] &&
971 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200972 memcpy(cfg->speaker_pins, cfg->line_out_pins,
973 sizeof(cfg->speaker_pins));
974 cfg->speaker_outs = cfg->line_outs;
975 }
976
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200977 if (!cfg->hp_pins[0] &&
978 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200979 memcpy(cfg->hp_pins, cfg->line_out_pins,
980 sizeof(cfg->hp_pins));
981 cfg->hp_outs = cfg->line_outs;
982 }
983
David Henningsson42cf0d02011-09-20 12:04:56 +0200984 spec->automute_mode = ALC_AUTOMUTE_PIN;
985
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200986 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200987 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200988 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200989 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200990 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200991 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200992 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200993 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200994 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200995
David Henningsson42cf0d02011-09-20 12:04:56 +0200996 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
997 if (cfg->speaker_outs)
998 for (i = 0; i < cfg->line_outs; i++) {
999 hda_nid_t nid = cfg->line_out_pins[i];
1000 if (!is_jack_detectable(codec, nid))
1001 continue;
1002 snd_printdd("realtek: Enable Line-Out "
1003 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001004 snd_hda_jack_detect_enable(codec, nid,
1005 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001006 spec->detect_lo = 1;
1007 }
1008 spec->automute_lo_possible = spec->detect_hp;
1009 }
1010
1011 spec->automute_speaker_possible = cfg->speaker_outs &&
1012 (spec->detect_hp || spec->detect_lo);
1013
1014 spec->automute_lo = spec->automute_lo_possible;
1015 spec->automute_speaker = spec->automute_speaker_possible;
1016
1017 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001018 /* create a control for automute mode */
1019 alc_add_automute_mode_enum(codec);
1020 spec->unsol_event = alc_sku_unsol_event;
1021 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001022}
1023
Takashi Iwai1d045db2011-07-07 18:23:21 +02001024/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001025static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1026{
1027 int i;
1028 for (i = 0; i < nums; i++)
1029 if (list[i] == nid)
1030 return i;
1031 return -1;
1032}
1033
Takashi Iwai1d045db2011-07-07 18:23:21 +02001034/* check whether dynamic ADC-switching is available */
1035static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1036{
1037 struct alc_spec *spec = codec->spec;
1038 struct hda_input_mux *imux = &spec->private_imux[0];
1039 int i, n, idx;
1040 hda_nid_t cap, pin;
1041
1042 if (imux != spec->input_mux) /* no dynamic imux? */
1043 return false;
1044
1045 for (n = 0; n < spec->num_adc_nids; n++) {
1046 cap = spec->private_capsrc_nids[n];
1047 for (i = 0; i < imux->num_items; i++) {
1048 pin = spec->imux_pins[i];
1049 if (!pin)
1050 return false;
1051 if (get_connection_index(codec, cap, pin) < 0)
1052 break;
1053 }
1054 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001055 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001056 }
1057
1058 for (i = 0; i < imux->num_items; i++) {
1059 pin = spec->imux_pins[i];
1060 for (n = 0; n < spec->num_adc_nids; n++) {
1061 cap = spec->private_capsrc_nids[n];
1062 idx = get_connection_index(codec, cap, pin);
1063 if (idx >= 0) {
1064 imux->items[i].index = idx;
1065 spec->dyn_adc_idx[i] = n;
1066 break;
1067 }
1068 }
1069 }
1070
1071 snd_printdd("realtek: enabling ADC switching\n");
1072 spec->dyn_adc_switch = 1;
1073 return true;
1074}
Takashi Iwai21268962011-07-07 15:01:13 +02001075
Takashi Iwai21268962011-07-07 15:01:13 +02001076/* check whether all auto-mic pins are valid; setup indices if OK */
1077static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1078{
1079 struct alc_spec *spec = codec->spec;
1080 const struct hda_input_mux *imux;
1081
1082 if (!spec->auto_mic)
1083 return false;
1084 if (spec->auto_mic_valid_imux)
1085 return true; /* already checked */
1086
1087 /* fill up imux indices */
1088 if (!alc_check_dyn_adc_switch(codec)) {
1089 spec->auto_mic = 0;
1090 return false;
1091 }
1092
1093 imux = spec->input_mux;
1094 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1095 spec->imux_pins, imux->num_items);
1096 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1097 spec->imux_pins, imux->num_items);
1098 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1099 spec->imux_pins, imux->num_items);
1100 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1101 spec->auto_mic = 0;
1102 return false; /* no corresponding imux */
1103 }
1104
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001105 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001106 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001107 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1108 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001109
1110 spec->auto_mic_valid_imux = 1;
1111 spec->auto_mic = 1;
1112 return true;
1113}
1114
Takashi Iwai1d045db2011-07-07 18:23:21 +02001115/*
1116 * Check the availability of auto-mic switch;
1117 * Set up if really supported
1118 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001119static void alc_init_auto_mic(struct hda_codec *codec)
1120{
1121 struct alc_spec *spec = codec->spec;
1122 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001123 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001124 int i;
1125
Takashi Iwai24de1832011-11-07 17:13:39 +01001126 if (spec->shared_mic_hp)
1127 return; /* no auto-mic for the shared I/O */
1128
Takashi Iwai21268962011-07-07 15:01:13 +02001129 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1130
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001131 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001132 for (i = 0; i < cfg->num_inputs; i++) {
1133 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001134 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001135 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001136 switch (snd_hda_get_input_pin_attr(defcfg)) {
1137 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001138 if (fixed)
1139 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001140 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1141 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001142 fixed = nid;
1143 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001144 case INPUT_PIN_ATTR_UNUSED:
1145 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001146 case INPUT_PIN_ATTR_DOCK:
1147 if (dock)
1148 return; /* already occupied */
1149 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1150 return; /* invalid type */
1151 dock = nid;
1152 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001153 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001154 if (ext)
1155 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001156 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1157 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001158 ext = nid;
1159 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001160 }
1161 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001162 if (!ext && dock) {
1163 ext = dock;
1164 dock = 0;
1165 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001166 if (!ext || !fixed)
1167 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001168 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001169 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001170 if (dock && !is_jack_detectable(codec, dock))
1171 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001172
1173 /* check imux indices */
1174 spec->ext_mic_pin = ext;
1175 spec->int_mic_pin = fixed;
1176 spec->dock_mic_pin = dock;
1177
1178 spec->auto_mic = 1;
1179 if (!alc_auto_mic_check_imux(codec))
1180 return;
1181
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001182 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1183 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001184 spec->unsol_event = alc_sku_unsol_event;
1185}
1186
Takashi Iwai1d045db2011-07-07 18:23:21 +02001187/* check the availabilities of auto-mute and auto-mic switches */
1188static void alc_auto_check_switches(struct hda_codec *codec)
1189{
David Henningsson42cf0d02011-09-20 12:04:56 +02001190 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001191 alc_init_auto_mic(codec);
1192}
1193
1194/*
1195 * Realtek SSID verification
1196 */
1197
David Henningsson90622912010-10-14 14:50:18 +02001198/* Could be any non-zero and even value. When used as fixup, tells
1199 * the driver to ignore any present sku defines.
1200 */
1201#define ALC_FIXUP_SKU_IGNORE (2)
1202
Kailang Yangda00c242010-03-19 11:23:45 +01001203static int alc_auto_parse_customize_define(struct hda_codec *codec)
1204{
1205 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001206 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001207 struct alc_spec *spec = codec->spec;
1208
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001209 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1210
David Henningsson90622912010-10-14 14:50:18 +02001211 if (spec->cdefine.fixup) {
1212 ass = spec->cdefine.sku_cfg;
1213 if (ass == ALC_FIXUP_SKU_IGNORE)
1214 return -1;
1215 goto do_sku;
1216 }
1217
Kailang Yangda00c242010-03-19 11:23:45 +01001218 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001219 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001220 goto do_sku;
1221
1222 nid = 0x1d;
1223 if (codec->vendor_id == 0x10ec0260)
1224 nid = 0x17;
1225 ass = snd_hda_codec_get_pincfg(codec, nid);
1226
1227 if (!(ass & 1)) {
1228 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1229 codec->chip_name, ass);
1230 return -1;
1231 }
1232
1233 /* check sum */
1234 tmp = 0;
1235 for (i = 1; i < 16; i++) {
1236 if ((ass >> i) & 1)
1237 tmp++;
1238 }
1239 if (((ass >> 16) & 0xf) != tmp)
1240 return -1;
1241
1242 spec->cdefine.port_connectivity = ass >> 30;
1243 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1244 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1245 spec->cdefine.customization = ass >> 8;
1246do_sku:
1247 spec->cdefine.sku_cfg = ass;
1248 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1249 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1250 spec->cdefine.swap = (ass & 0x2) >> 1;
1251 spec->cdefine.override = ass & 0x1;
1252
1253 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1254 nid, spec->cdefine.sku_cfg);
1255 snd_printd("SKU: port_connectivity=0x%x\n",
1256 spec->cdefine.port_connectivity);
1257 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1258 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1259 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1260 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1261 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1262 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1263 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1264
1265 return 0;
1266}
1267
Takashi Iwai1d045db2011-07-07 18:23:21 +02001268/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001269static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1270{
Takashi Iwai21268962011-07-07 15:01:13 +02001271 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001272}
1273
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001274/* check subsystem ID and set up device-specific initialization;
1275 * return 1 if initialized, 0 if invalid SSID
1276 */
1277/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1278 * 31 ~ 16 : Manufacture ID
1279 * 15 ~ 8 : SKU ID
1280 * 7 ~ 0 : Assembly ID
1281 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1282 */
1283static int alc_subsystem_id(struct hda_codec *codec,
1284 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001285 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001286{
1287 unsigned int ass, tmp, i;
1288 unsigned nid;
1289 struct alc_spec *spec = codec->spec;
1290
David Henningsson90622912010-10-14 14:50:18 +02001291 if (spec->cdefine.fixup) {
1292 ass = spec->cdefine.sku_cfg;
1293 if (ass == ALC_FIXUP_SKU_IGNORE)
1294 return 0;
1295 goto do_sku;
1296 }
1297
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001298 ass = codec->subsystem_id & 0xffff;
1299 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1300 goto do_sku;
1301
1302 /* invalid SSID, check the special NID pin defcfg instead */
1303 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001304 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001305 * 29~21 : reserve
1306 * 20 : PCBEEP input
1307 * 19~16 : Check sum (15:1)
1308 * 15~1 : Custom
1309 * 0 : override
1310 */
1311 nid = 0x1d;
1312 if (codec->vendor_id == 0x10ec0260)
1313 nid = 0x17;
1314 ass = snd_hda_codec_get_pincfg(codec, nid);
1315 snd_printd("realtek: No valid SSID, "
1316 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001317 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001318 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001319 return 0;
1320 if ((ass >> 30) != 1) /* no physical connection */
1321 return 0;
1322
1323 /* check sum */
1324 tmp = 0;
1325 for (i = 1; i < 16; i++) {
1326 if ((ass >> i) & 1)
1327 tmp++;
1328 }
1329 if (((ass >> 16) & 0xf) != tmp)
1330 return 0;
1331do_sku:
1332 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1333 ass & 0xffff, codec->vendor_id);
1334 /*
1335 * 0 : override
1336 * 1 : Swap Jack
1337 * 2 : 0 --> Desktop, 1 --> Laptop
1338 * 3~5 : External Amplifier control
1339 * 7~6 : Reserved
1340 */
1341 tmp = (ass & 0x38) >> 3; /* external Amp control */
1342 switch (tmp) {
1343 case 1:
1344 spec->init_amp = ALC_INIT_GPIO1;
1345 break;
1346 case 3:
1347 spec->init_amp = ALC_INIT_GPIO2;
1348 break;
1349 case 7:
1350 spec->init_amp = ALC_INIT_GPIO3;
1351 break;
1352 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001353 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001354 spec->init_amp = ALC_INIT_DEFAULT;
1355 break;
1356 }
1357
1358 /* is laptop or Desktop and enable the function "Mute internal speaker
1359 * when the external headphone out jack is plugged"
1360 */
1361 if (!(ass & 0x8000))
1362 return 1;
1363 /*
1364 * 10~8 : Jack location
1365 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1366 * 14~13: Resvered
1367 * 15 : 1 --> enable the function "Mute internal speaker
1368 * when the external headphone out jack is plugged"
1369 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001370 if (!spec->autocfg.hp_pins[0] &&
1371 !(spec->autocfg.line_out_pins[0] &&
1372 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001373 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001374 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1375 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001376 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001377 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001378 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001379 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001380 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001381 else if (tmp == 3)
1382 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001383 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001384 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001385 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1386 spec->autocfg.line_outs))
1387 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001388 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001389 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001390 return 1;
1391}
Kailang Yangea1fb292008-08-26 12:58:38 +02001392
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001393/* Check the validity of ALC subsystem-id
1394 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1395static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001396{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001397 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001398 struct alc_spec *spec = codec->spec;
1399 snd_printd("realtek: "
1400 "Enable default setup for auto mode as fallback\n");
1401 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001402 }
Takashi Iwai21268962011-07-07 15:01:13 +02001403}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001404
Takashi Iwai41e41f12005-06-08 14:48:49 +02001405/*
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001406 * Fix-up pin default configurations and add default verbs
Takashi Iwaif95474e2007-07-10 00:47:43 +02001407 */
1408
1409struct alc_pincfg {
1410 hda_nid_t nid;
1411 u32 val;
1412};
1413
Todd Broche1eb5f12010-12-06 11:19:51 -08001414struct alc_model_fixup {
1415 const int id;
1416 const char *name;
1417};
1418
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001419struct alc_fixup {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001420 int type;
Takashi Iwai361fe6e2011-01-14 09:55:32 +01001421 bool chained;
1422 int chain_id;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001423 union {
1424 unsigned int sku;
1425 const struct alc_pincfg *pins;
1426 const struct hda_verb *verbs;
1427 void (*func)(struct hda_codec *codec,
1428 const struct alc_fixup *fix,
1429 int action);
1430 } v;
Takashi Iwaif8f25ba2009-10-06 08:31:29 +02001431};
1432
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001433enum {
1434 ALC_FIXUP_INVALID,
1435 ALC_FIXUP_SKU,
1436 ALC_FIXUP_PINS,
1437 ALC_FIXUP_VERBS,
1438 ALC_FIXUP_FUNC,
1439};
Takashi Iwaif95474e2007-07-10 00:47:43 +02001440
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001441enum {
1442 ALC_FIXUP_ACT_PRE_PROBE,
1443 ALC_FIXUP_ACT_PROBE,
Takashi Iwai58701122011-01-13 15:41:45 +01001444 ALC_FIXUP_ACT_INIT,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001445 ALC_FIXUP_ACT_BUILD,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001446};
1447
1448static void alc_apply_fixup(struct hda_codec *codec, int action)
1449{
1450 struct alc_spec *spec = codec->spec;
1451 int id = spec->fixup_id;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001452#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001453 const char *modelname = spec->fixup_name;
Takashi Iwaiaa1d0c52011-01-19 17:27:58 +01001454#endif
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001455 int depth = 0;
1456
1457 if (!spec->fixup_list)
1458 return;
1459
1460 while (id >= 0) {
1461 const struct alc_fixup *fix = spec->fixup_list + id;
1462 const struct alc_pincfg *cfg;
1463
1464 switch (fix->type) {
1465 case ALC_FIXUP_SKU:
1466 if (action != ALC_FIXUP_ACT_PRE_PROBE || !fix->v.sku)
Jesper Juhle53de8f2011-11-13 23:11:50 +01001467 break;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001468 snd_printdd(KERN_INFO "hda_codec: %s: "
1469 "Apply sku override for %s\n",
1470 codec->chip_name, modelname);
1471 spec->cdefine.sku_cfg = fix->v.sku;
1472 spec->cdefine.fixup = 1;
1473 break;
1474 case ALC_FIXUP_PINS:
1475 cfg = fix->v.pins;
1476 if (action != ALC_FIXUP_ACT_PRE_PROBE || !cfg)
1477 break;
1478 snd_printdd(KERN_INFO "hda_codec: %s: "
1479 "Apply pincfg for %s\n",
1480 codec->chip_name, modelname);
1481 for (; cfg->nid; cfg++)
1482 snd_hda_codec_set_pincfg(codec, cfg->nid,
1483 cfg->val);
1484 break;
1485 case ALC_FIXUP_VERBS:
1486 if (action != ALC_FIXUP_ACT_PROBE || !fix->v.verbs)
1487 break;
1488 snd_printdd(KERN_INFO "hda_codec: %s: "
1489 "Apply fix-verbs for %s\n",
1490 codec->chip_name, modelname);
1491 add_verb(codec->spec, fix->v.verbs);
1492 break;
1493 case ALC_FIXUP_FUNC:
1494 if (!fix->v.func)
1495 break;
1496 snd_printdd(KERN_INFO "hda_codec: %s: "
1497 "Apply fix-func for %s\n",
1498 codec->chip_name, modelname);
1499 fix->v.func(codec, fix, action);
1500 break;
1501 default:
1502 snd_printk(KERN_ERR "hda_codec: %s: "
1503 "Invalid fixup type %d\n",
1504 codec->chip_name, fix->type);
1505 break;
1506 }
Takashi Iwai24af2b12011-05-02 13:55:36 +02001507 if (!fix->chained)
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001508 break;
1509 if (++depth > 10)
1510 break;
Takashi Iwai24af2b12011-05-02 13:55:36 +02001511 id = fix->chain_id;
Takashi Iwai9d578832010-11-22 13:29:19 +01001512 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001513}
1514
Todd Broche1eb5f12010-12-06 11:19:51 -08001515static void alc_pick_fixup(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001516 const struct alc_model_fixup *models,
1517 const struct snd_pci_quirk *quirk,
1518 const struct alc_fixup *fixlist)
Todd Broche1eb5f12010-12-06 11:19:51 -08001519{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001520 struct alc_spec *spec = codec->spec;
Takashi Iwai596830e2011-11-09 15:06:45 +01001521 const struct snd_pci_quirk *q;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001522 int id = -1;
1523 const char *name = NULL;
Todd Broche1eb5f12010-12-06 11:19:51 -08001524
Takashi Iwai9155f822012-02-20 18:41:02 +01001525 /* when model=nofixup is given, don't pick up any fixups */
1526 if (codec->modelname && !strcmp(codec->modelname, "nofixup")) {
1527 spec->fixup_list = NULL;
1528 spec->fixup_id = -1;
1529 return;
1530 }
1531
Todd Broche1eb5f12010-12-06 11:19:51 -08001532 if (codec->modelname && models) {
1533 while (models->name) {
1534 if (!strcmp(codec->modelname, models->name)) {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001535 id = models->id;
1536 name = models->name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001537 break;
1538 }
1539 models++;
1540 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001541 }
1542 if (id < 0) {
Takashi Iwai596830e2011-11-09 15:06:45 +01001543 q = snd_pci_quirk_lookup(codec->bus->pci, quirk);
1544 if (q) {
1545 id = q->value;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001546#ifdef CONFIG_SND_DEBUG_VERBOSE
Takashi Iwai596830e2011-11-09 15:06:45 +01001547 name = q->name;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001548#endif
1549 }
1550 }
Takashi Iwai596830e2011-11-09 15:06:45 +01001551 if (id < 0) {
1552 for (q = quirk; q->subvendor; q++) {
1553 unsigned int vendorid =
1554 q->subdevice | (q->subvendor << 16);
1555 if (vendorid == codec->subsystem_id) {
1556 id = q->value;
1557#ifdef CONFIG_SND_DEBUG_VERBOSE
1558 name = q->name;
1559#endif
1560 break;
1561 }
1562 }
1563 }
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01001564
1565 spec->fixup_id = id;
1566 if (id >= 0) {
1567 spec->fixup_list = fixlist;
1568 spec->fixup_name = name;
Todd Broche1eb5f12010-12-06 11:19:51 -08001569 }
Takashi Iwaif95474e2007-07-10 00:47:43 +02001570}
1571
Takashi Iwai1d045db2011-07-07 18:23:21 +02001572/*
1573 * COEF access helper functions
1574 */
Kailang Yang274693f2009-12-03 10:07:50 +01001575static int alc_read_coef_idx(struct hda_codec *codec,
1576 unsigned int coef_idx)
1577{
1578 unsigned int val;
1579 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1580 coef_idx);
1581 val = snd_hda_codec_read(codec, 0x20, 0,
1582 AC_VERB_GET_PROC_COEF, 0);
1583 return val;
1584}
1585
Kailang Yang977ddd62010-09-15 10:02:29 +02001586static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1587 unsigned int coef_val)
1588{
1589 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1590 coef_idx);
1591 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1592 coef_val);
1593}
1594
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001595/* a special bypass for COEF 0; read the cached value at the second time */
1596static unsigned int alc_get_coef0(struct hda_codec *codec)
1597{
1598 struct alc_spec *spec = codec->spec;
1599 if (!spec->coef0)
1600 spec->coef0 = alc_read_coef_idx(codec, 0);
1601 return spec->coef0;
1602}
1603
Takashi Iwai1d045db2011-07-07 18:23:21 +02001604/*
1605 * Digital I/O handling
1606 */
1607
Takashi Iwai757899a2010-07-30 10:48:14 +02001608/* set right pin controls for digital I/O */
1609static void alc_auto_init_digital(struct hda_codec *codec)
1610{
1611 struct alc_spec *spec = codec->spec;
1612 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001613 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001614
1615 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1616 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001617 if (!pin)
1618 continue;
1619 snd_hda_codec_write(codec, pin, 0,
1620 AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
1621 if (!i)
1622 dac = spec->multiout.dig_out_nid;
1623 else
1624 dac = spec->slave_dig_outs[i - 1];
1625 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1626 continue;
1627 snd_hda_codec_write(codec, dac, 0,
1628 AC_VERB_SET_AMP_GAIN_MUTE,
1629 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001630 }
1631 pin = spec->autocfg.dig_in_pin;
1632 if (pin)
1633 snd_hda_codec_write(codec, pin, 0,
1634 AC_VERB_SET_PIN_WIDGET_CONTROL,
1635 PIN_IN);
1636}
1637
1638/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1639static void alc_auto_parse_digital(struct hda_codec *codec)
1640{
1641 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001642 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001643 hda_nid_t dig_nid;
1644
1645 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001646 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001647 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001648 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001649 err = snd_hda_get_connections(codec,
1650 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001651 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001652 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001653 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001654 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001655 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001656 spec->multiout.dig_out_nid = dig_nid;
1657 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1658 } else {
1659 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001660 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001661 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001662 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001663 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001664 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001665 }
1666
1667 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001668 dig_nid = codec->start_nid;
1669 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1670 unsigned int wcaps = get_wcaps(codec, dig_nid);
1671 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1672 continue;
1673 if (!(wcaps & AC_WCAP_DIGITAL))
1674 continue;
1675 if (!(wcaps & AC_WCAP_CONN_LIST))
1676 continue;
1677 err = get_connection_index(codec, dig_nid,
1678 spec->autocfg.dig_in_pin);
1679 if (err >= 0) {
1680 spec->dig_in_nid = dig_nid;
1681 break;
1682 }
1683 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001684 }
1685}
1686
Takashi Iwaif95474e2007-07-10 00:47:43 +02001687/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001688 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001689 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001690static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1691 struct snd_ctl_elem_info *uinfo)
1692{
1693 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1694 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001695 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001696 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001697
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001698 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001699 if (spec->vol_in_capsrc)
1700 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1701 else
1702 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1703 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001704 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001705 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001706 return err;
1707}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001709static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1710 unsigned int size, unsigned int __user *tlv)
1711{
1712 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1713 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001714 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001715 int err;
1716
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001717 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001718 if (spec->vol_in_capsrc)
1719 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1720 else
1721 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1722 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001723 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001724 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001725 return err;
1726}
1727
1728typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1729 struct snd_ctl_elem_value *ucontrol);
1730
1731static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1732 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001733 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001734{
1735 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1736 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001737 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001738
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001739 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001740 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001741 for (i = 0; i < spec->num_adc_nids; i++) {
1742 kcontrol->private_value =
1743 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1744 3, 0, HDA_INPUT);
1745 err = func(kcontrol, ucontrol);
1746 if (err < 0)
1747 goto error;
1748 }
1749 } else {
1750 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001751 if (spec->vol_in_capsrc)
1752 kcontrol->private_value =
1753 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1754 3, 0, HDA_OUTPUT);
1755 else
1756 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001757 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1758 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001759 err = func(kcontrol, ucontrol);
1760 }
1761 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001762 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001763 return err;
1764}
1765
1766static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1767 struct snd_ctl_elem_value *ucontrol)
1768{
1769 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001770 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001771}
1772
1773static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1774 struct snd_ctl_elem_value *ucontrol)
1775{
1776 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001777 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001778}
1779
1780/* capture mixer elements */
1781#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1782
1783static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1784 struct snd_ctl_elem_value *ucontrol)
1785{
1786 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001787 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001788}
1789
1790static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1791 struct snd_ctl_elem_value *ucontrol)
1792{
1793 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001794 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001795}
1796
Takashi Iwaia23b6882009-03-23 15:21:36 +01001797#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001798 { \
1799 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1800 .name = "Capture Switch", \
1801 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1802 .count = num, \
1803 .info = alc_cap_sw_info, \
1804 .get = alc_cap_sw_get, \
1805 .put = alc_cap_sw_put, \
1806 }, \
1807 { \
1808 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1809 .name = "Capture Volume", \
1810 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1811 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1812 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1813 .count = num, \
1814 .info = alc_cap_vol_info, \
1815 .get = alc_cap_vol_get, \
1816 .put = alc_cap_vol_put, \
1817 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001818 }
1819
1820#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001821 { \
1822 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1823 /* .name = "Capture Source", */ \
1824 .name = "Input Source", \
1825 .count = num, \
1826 .info = alc_mux_enum_info, \
1827 .get = alc_mux_enum_get, \
1828 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001829 }
1830
1831#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001832static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001833 _DEFINE_CAPMIX(num), \
1834 _DEFINE_CAPSRC(num), \
1835 { } /* end */ \
1836}
1837
1838#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001839static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001840 _DEFINE_CAPMIX(num), \
1841 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001842}
1843
1844/* up to three ADCs */
1845DEFINE_CAPMIX(1);
1846DEFINE_CAPMIX(2);
1847DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001848DEFINE_CAPMIX_NOSRC(1);
1849DEFINE_CAPMIX_NOSRC(2);
1850DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001851
1852/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001853 * virtual master controls
1854 */
1855
1856/*
1857 * slave controls for virtual master
1858 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001859static const char * const alc_slave_pfxs[] = {
1860 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001861 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001862 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001863 NULL,
1864};
1865
1866/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001867 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001869
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001870#define NID_MAPPING (-1)
1871
1872#define SUBDEV_SPEAKER_ (0 << 6)
1873#define SUBDEV_HP_ (1 << 6)
1874#define SUBDEV_LINE_ (2 << 6)
1875#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1876#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1877#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1878
Takashi Iwai603c4012008-07-30 15:01:44 +02001879static void alc_free_kctls(struct hda_codec *codec);
1880
Takashi Iwai67d634c2009-11-16 15:35:59 +01001881#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001882/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001883static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001884 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001885 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001886 { } /* end */
1887};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001888#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001889
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001890static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891{
1892 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001893 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001894 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001895 int i, j, err;
1896 unsigned int u;
1897 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001898
1899 for (i = 0; i < spec->num_mixers; i++) {
1900 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1901 if (err < 0)
1902 return err;
1903 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001904 if (spec->cap_mixer) {
1905 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1906 if (err < 0)
1907 return err;
1908 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001910 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001911 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001912 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 if (err < 0)
1914 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001915 if (!spec->no_analog) {
1916 err = snd_hda_create_spdif_share_sw(codec,
1917 &spec->multiout);
1918 if (err < 0)
1919 return err;
1920 spec->multiout.share_spdif = 1;
1921 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922 }
1923 if (spec->dig_in_nid) {
1924 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1925 if (err < 0)
1926 return err;
1927 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001928
Takashi Iwai67d634c2009-11-16 15:35:59 +01001929#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001930 /* create beep controls if needed */
1931 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001932 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001933 for (knew = alc_beep_mixer; knew->name; knew++) {
1934 struct snd_kcontrol *kctl;
1935 kctl = snd_ctl_new1(knew, codec);
1936 if (!kctl)
1937 return -ENOMEM;
1938 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001939 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001940 if (err < 0)
1941 return err;
1942 }
1943 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001944#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001945
Takashi Iwai2134ea42008-01-10 16:53:55 +01001946 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001947 if (!spec->no_analog &&
1948 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001949 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001950 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001951 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001952 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001953 vmaster_tlv, alc_slave_pfxs,
1954 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001955 if (err < 0)
1956 return err;
1957 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001958 if (!spec->no_analog &&
1959 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001960 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1961 NULL, alc_slave_pfxs,
1962 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001963 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001964 if (err < 0)
1965 return err;
1966 }
1967
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001968 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001969 if (spec->capsrc_nids || spec->adc_nids) {
1970 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1971 if (!kctl)
1972 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1973 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001974 err = snd_hda_add_nid(codec, kctl, i,
1975 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001976 if (err < 0)
1977 return err;
1978 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001979 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001980 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001981 const char *kname = kctl ? kctl->id.name : NULL;
1982 for (knew = spec->cap_mixer; knew->name; knew++) {
1983 if (kname && strcmp(knew->name, kname) == 0)
1984 continue;
1985 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1986 for (i = 0; kctl && i < kctl->count; i++) {
1987 err = snd_hda_add_nid(codec, kctl, i,
1988 spec->adc_nids[i]);
1989 if (err < 0)
1990 return err;
1991 }
1992 }
1993 }
1994
1995 /* other nid->control mapping */
1996 for (i = 0; i < spec->num_mixers; i++) {
1997 for (knew = spec->mixers[i]; knew->name; knew++) {
1998 if (knew->iface != NID_MAPPING)
1999 continue;
2000 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
2001 if (kctl == NULL)
2002 continue;
2003 u = knew->subdevice;
2004 for (j = 0; j < 4; j++, u >>= 8) {
2005 nid = u & 0x3f;
2006 if (nid == 0)
2007 continue;
2008 switch (u & 0xc0) {
2009 case SUBDEV_SPEAKER_:
2010 nid = spec->autocfg.speaker_pins[nid];
2011 break;
2012 case SUBDEV_LINE_:
2013 nid = spec->autocfg.line_out_pins[nid];
2014 break;
2015 case SUBDEV_HP_:
2016 nid = spec->autocfg.hp_pins[nid];
2017 break;
2018 default:
2019 continue;
2020 }
2021 err = snd_hda_add_nid(codec, kctl, 0, nid);
2022 if (err < 0)
2023 return err;
2024 }
2025 u = knew->private_value;
2026 for (j = 0; j < 4; j++, u >>= 8) {
2027 nid = u & 0xff;
2028 if (nid == 0)
2029 continue;
2030 err = snd_hda_add_nid(codec, kctl, 0, nid);
2031 if (err < 0)
2032 return err;
2033 }
2034 }
2035 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01002036
2037 alc_free_kctls(codec); /* no longer needed */
2038
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002039 return 0;
2040}
2041
2042static int alc_build_controls(struct hda_codec *codec)
2043{
2044 struct alc_spec *spec = codec->spec;
2045 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002046 if (err < 0)
2047 return err;
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002048 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
2049 if (err < 0)
2050 return err;
2051 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2052 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053}
2054
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002055
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002057 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002058 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002059
Takashi Iwai584c0c42011-03-10 12:51:11 +01002060static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002061static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002062
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063static int alc_init(struct hda_codec *codec)
2064{
2065 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002066 unsigned int i;
2067
Takashi Iwai546bb672012-03-07 08:37:19 +01002068 if (spec->init_hook)
2069 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002070
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002071 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002072 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002073
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002074 for (i = 0; i < spec->num_init_verbs; i++)
2075 snd_hda_sequence_write(codec, spec->init_verbs[i]);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002076 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002077 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002078
Takashi Iwai58701122011-01-13 15:41:45 +01002079 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2080
Takashi Iwai01a61e12011-10-28 00:03:22 +02002081 snd_hda_jack_report_sync(codec);
2082
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002083 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 return 0;
2085}
2086
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002087static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2088{
2089 struct alc_spec *spec = codec->spec;
2090
2091 if (spec->unsol_event)
2092 spec->unsol_event(codec, res);
2093}
2094
Takashi Iwaicb53c622007-08-10 17:21:45 +02002095#ifdef CONFIG_SND_HDA_POWER_SAVE
2096static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2097{
2098 struct alc_spec *spec = codec->spec;
2099 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2100}
2101#endif
2102
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103/*
2104 * Analog playback callbacks
2105 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002106static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002108 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109{
2110 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002111 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2112 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113}
2114
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002115static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 struct hda_codec *codec,
2117 unsigned int stream_tag,
2118 unsigned int format,
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 Iwai9c7f8522006-06-28 15:08:22 +02002122 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2123 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124}
2125
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002126static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002128 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129{
2130 struct alc_spec *spec = codec->spec;
2131 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2132}
2133
2134/*
2135 * Digital out
2136 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002137static int alc_dig_playback_pcm_open(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_dig_open(codec, &spec->multiout);
2143}
2144
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002145static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002146 struct hda_codec *codec,
2147 unsigned int stream_tag,
2148 unsigned int format,
2149 struct snd_pcm_substream *substream)
2150{
2151 struct alc_spec *spec = codec->spec;
2152 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2153 stream_tag, format, substream);
2154}
2155
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002156static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002157 struct hda_codec *codec,
2158 struct snd_pcm_substream *substream)
2159{
2160 struct alc_spec *spec = codec->spec;
2161 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2162}
2163
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002164static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002166 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167{
2168 struct alc_spec *spec = codec->spec;
2169 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2170}
2171
2172/*
2173 * Analog capture
2174 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002175static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176 struct hda_codec *codec,
2177 unsigned int stream_tag,
2178 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002179 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180{
2181 struct alc_spec *spec = codec->spec;
2182
Takashi Iwai63300792008-01-24 15:31:36 +01002183 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 stream_tag, 0, format);
2185 return 0;
2186}
2187
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002188static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 struct hda_codec *codec,
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 Iwai888afa12008-03-18 09:57:50 +01002194 snd_hda_codec_cleanup_stream(codec,
2195 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 return 0;
2197}
2198
Takashi Iwai840b64c2010-07-13 22:49:01 +02002199/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002200static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002201 struct hda_codec *codec,
2202 unsigned int stream_tag,
2203 unsigned int format,
2204 struct snd_pcm_substream *substream)
2205{
2206 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002207 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002208 spec->cur_adc_stream_tag = stream_tag;
2209 spec->cur_adc_format = format;
2210 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2211 return 0;
2212}
2213
Takashi Iwai21268962011-07-07 15:01:13 +02002214static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002215 struct hda_codec *codec,
2216 struct snd_pcm_substream *substream)
2217{
2218 struct alc_spec *spec = codec->spec;
2219 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2220 spec->cur_adc = 0;
2221 return 0;
2222}
2223
Takashi Iwai21268962011-07-07 15:01:13 +02002224static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002225 .substreams = 1,
2226 .channels_min = 2,
2227 .channels_max = 2,
2228 .nid = 0, /* fill later */
2229 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002230 .prepare = dyn_adc_capture_pcm_prepare,
2231 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002232 },
2233};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234
2235/*
2236 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002237static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238 .substreams = 1,
2239 .channels_min = 2,
2240 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002241 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002243 .open = alc_playback_pcm_open,
2244 .prepare = alc_playback_pcm_prepare,
2245 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 },
2247};
2248
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002249static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002250 .substreams = 1,
2251 .channels_min = 2,
2252 .channels_max = 2,
2253 /* NID is set in alc_build_pcms */
2254};
2255
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002256static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002257 .substreams = 1,
2258 .channels_min = 2,
2259 .channels_max = 2,
2260 /* NID is set in alc_build_pcms */
2261};
2262
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002263static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002264 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 .channels_min = 2,
2266 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002267 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002269 .prepare = alc_alt_capture_pcm_prepare,
2270 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 },
2272};
2273
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002274static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 .substreams = 1,
2276 .channels_min = 2,
2277 .channels_max = 2,
2278 /* NID is set in alc_build_pcms */
2279 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002280 .open = alc_dig_playback_pcm_open,
2281 .close = alc_dig_playback_pcm_close,
2282 .prepare = alc_dig_playback_pcm_prepare,
2283 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 },
2285};
2286
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002287static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 .substreams = 1,
2289 .channels_min = 2,
2290 .channels_max = 2,
2291 /* NID is set in alc_build_pcms */
2292};
2293
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002294/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002295static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002296 .substreams = 0,
2297 .channels_min = 0,
2298 .channels_max = 0,
2299};
2300
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301static int alc_build_pcms(struct hda_codec *codec)
2302{
2303 struct alc_spec *spec = codec->spec;
2304 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002305 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002306 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 int i;
2308
2309 codec->num_pcms = 1;
2310 codec->pcm_info = info;
2311
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002312 if (spec->no_analog)
2313 goto skip_analog;
2314
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002315 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2316 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002318
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002319 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002320 p = spec->stream_analog_playback;
2321 if (!p)
2322 p = &alc_pcm_analog_playback;
2323 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002324 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2325 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002326 if (spec->adc_nids) {
2327 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002328 if (!p) {
2329 if (spec->dyn_adc_switch)
2330 p = &dyn_adc_pcm_analog_capture;
2331 else
2332 p = &alc_pcm_analog_capture;
2333 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002334 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002335 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337
Takashi Iwai4a471b72005-12-07 13:56:29 +01002338 if (spec->channel_mode) {
2339 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2340 for (i = 0; i < spec->num_channel_mode; i++) {
2341 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2342 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 }
2345 }
2346
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002347 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002348 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002350 snprintf(spec->stream_name_digital,
2351 sizeof(spec->stream_name_digital),
2352 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002353 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002354 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002355 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002357 if (spec->dig_out_type)
2358 info->pcm_type = spec->dig_out_type;
2359 else
2360 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002361 if (spec->multiout.dig_out_nid) {
2362 p = spec->stream_digital_playback;
2363 if (!p)
2364 p = &alc_pcm_digital_playback;
2365 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2367 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002368 if (spec->dig_in_nid) {
2369 p = spec->stream_digital_capture;
2370 if (!p)
2371 p = &alc_pcm_digital_capture;
2372 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2374 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002375 /* FIXME: do we need this for all Realtek codec models? */
2376 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 }
2378
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002379 if (spec->no_analog)
2380 return 0;
2381
Takashi Iwaie08a0072006-09-07 17:52:14 +02002382 /* If the use of more than one ADC is requested for the current
2383 * model, configure a second analog capture-only PCM.
2384 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002385 have_multi_adcs = (spec->num_adc_nids > 1) &&
2386 !spec->dyn_adc_switch && !spec->auto_mic &&
2387 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002388 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002389 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002390 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002391 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002392 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002393 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002394 p = spec->stream_analog_alt_playback;
2395 if (!p)
2396 p = &alc_pcm_analog_alt_playback;
2397 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002398 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2399 spec->alt_dac_nid;
2400 } else {
2401 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2402 alc_pcm_null_stream;
2403 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2404 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002405 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002406 p = spec->stream_analog_alt_capture;
2407 if (!p)
2408 p = &alc_pcm_analog_alt_capture;
2409 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002410 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2411 spec->adc_nids[1];
2412 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2413 spec->num_adc_nids - 1;
2414 } else {
2415 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2416 alc_pcm_null_stream;
2417 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002418 }
2419 }
2420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 return 0;
2422}
2423
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002424static inline void alc_shutup(struct hda_codec *codec)
2425{
Takashi Iwai1c716152011-04-07 10:37:16 +02002426 struct alc_spec *spec = codec->spec;
2427
2428 if (spec && spec->shutup)
2429 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002430 snd_hda_shutup_pins(codec);
2431}
2432
Takashi Iwai603c4012008-07-30 15:01:44 +02002433static void alc_free_kctls(struct hda_codec *codec)
2434{
2435 struct alc_spec *spec = codec->spec;
2436
2437 if (spec->kctls.list) {
2438 struct snd_kcontrol_new *kctl = spec->kctls.list;
2439 int i;
2440 for (i = 0; i < spec->kctls.used; i++)
2441 kfree(kctl[i].name);
2442 }
2443 snd_array_free(&spec->kctls);
2444}
2445
Takashi Iwai23c09b02011-08-19 09:05:35 +02002446static void alc_free_bind_ctls(struct hda_codec *codec)
2447{
2448 struct alc_spec *spec = codec->spec;
2449 if (spec->bind_ctls.list) {
2450 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2451 int i;
2452 for (i = 0; i < spec->bind_ctls.used; i++)
2453 kfree(ctl[i]);
2454 }
2455 snd_array_free(&spec->bind_ctls);
2456}
2457
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458static void alc_free(struct hda_codec *codec)
2459{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002460 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002461
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002462 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002463 return;
2464
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002465 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002466 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002467 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002468 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002469 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470}
2471
Hector Martinf5de24b2009-12-20 22:51:31 +01002472#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002473static void alc_power_eapd(struct hda_codec *codec)
2474{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002475 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002476}
2477
Hector Martinf5de24b2009-12-20 22:51:31 +01002478static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2479{
2480 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002481 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002482 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002483 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002484 return 0;
2485}
2486#endif
2487
Takashi Iwai2a439522011-07-26 09:52:50 +02002488#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002489static int alc_resume(struct hda_codec *codec)
2490{
Takashi Iwai1c716152011-04-07 10:37:16 +02002491 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002492 codec->patch_ops.init(codec);
2493 snd_hda_codec_resume_amp(codec);
2494 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002495 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002496 return 0;
2497}
Takashi Iwaie044c392008-10-27 16:56:24 +01002498#endif
2499
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500/*
2501 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002502static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 .build_controls = alc_build_controls,
2504 .build_pcms = alc_build_pcms,
2505 .init = alc_init,
2506 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002507 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002508#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002509 .resume = alc_resume,
2510#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002511#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002512 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002513 .check_power_status = alc_check_power_status,
2514#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002515 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516};
2517
Kailang Yangc027ddc2010-03-19 11:33:06 +01002518/* replace the codec chip_name with the given string */
2519static int alc_codec_rename(struct hda_codec *codec, const char *name)
2520{
2521 kfree(codec->chip_name);
2522 codec->chip_name = kstrdup(name, GFP_KERNEL);
2523 if (!codec->chip_name) {
2524 alc_free(codec);
2525 return -ENOMEM;
2526 }
2527 return 0;
2528}
2529
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002530/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002531 * Rename codecs appropriately from COEF value
2532 */
2533struct alc_codec_rename_table {
2534 unsigned int vendor_id;
2535 unsigned short coef_mask;
2536 unsigned short coef_bits;
2537 const char *name;
2538};
2539
2540static struct alc_codec_rename_table rename_tbl[] = {
2541 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2542 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2543 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2544 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2545 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2546 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2547 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2548 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2549 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2550 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2551 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2552 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2553 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2554 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2555 { } /* terminator */
2556};
2557
2558static int alc_codec_rename_from_preset(struct hda_codec *codec)
2559{
2560 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002561
2562 for (p = rename_tbl; p->vendor_id; p++) {
2563 if (p->vendor_id != codec->vendor_id)
2564 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002565 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002566 return alc_codec_rename(codec, p->name);
2567 }
2568 return 0;
2569}
2570
2571/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002572 * Automatic parse of I/O pins from the BIOS configuration
2573 */
2574
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002575enum {
2576 ALC_CTL_WIDGET_VOL,
2577 ALC_CTL_WIDGET_MUTE,
2578 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002579 ALC_CTL_BIND_VOL,
2580 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002581};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002582static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002583 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2584 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002585 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002586 HDA_BIND_VOL(NULL, 0),
2587 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002588};
2589
2590/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002591static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002592 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002593{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002594 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002595
Takashi Iwaice764ab2011-04-27 16:35:23 +02002596 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002597 if (!knew)
2598 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002599 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002600 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002601 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002602 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002603 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002604 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002605 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002606 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002607 return 0;
2608}
2609
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002610static int add_control_with_pfx(struct alc_spec *spec, int type,
2611 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002612 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002613{
2614 char name[32];
2615 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002616 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002617}
2618
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002619#define add_pb_vol_ctrl(spec, type, pfx, val) \
2620 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2621#define add_pb_sw_ctrl(spec, type, pfx, val) \
2622 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2623#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2624 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2625#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2626 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002627
Takashi Iwai23c09b02011-08-19 09:05:35 +02002628static const char * const channel_name[4] = {
2629 "Front", "Surround", "CLFE", "Side"
2630};
2631
Takashi Iwai6843ca12011-06-24 11:03:58 +02002632static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2633 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002634{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002635 struct auto_pin_cfg *cfg = &spec->autocfg;
2636
Takashi Iwai6843ca12011-06-24 11:03:58 +02002637 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002638 if (cfg->line_outs == 1 && !spec->multi_ios &&
2639 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002640 return "Master";
2641
2642 switch (cfg->line_out_type) {
2643 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002644 if (cfg->line_outs == 1)
2645 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002646 if (cfg->line_outs == 2)
2647 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002648 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002649 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002650 /* for multi-io case, only the primary out */
2651 if (ch && spec->multi_ios)
2652 break;
2653 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002654 return "Headphone";
2655 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002656 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002657 return "PCM";
2658 break;
2659 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002660 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2661 return "PCM";
2662
2663 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002664}
2665
Takashi Iwai164f73e2012-02-21 11:27:09 +01002666#ifdef CONFIG_SND_HDA_POWER_SAVE
2667/* add the powersave loopback-list entry */
2668static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2669{
2670 struct hda_amp_list *list;
2671
2672 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2673 return;
2674 list = spec->loopback_list + spec->num_loopbacks;
2675 list->nid = mix;
2676 list->dir = HDA_INPUT;
2677 list->idx = idx;
2678 spec->num_loopbacks++;
2679 spec->loopback.amplist = spec->loopback_list;
2680}
2681#else
2682#define add_loopback_list(spec, mix, idx) /* NOP */
2683#endif
2684
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002685/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002686static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002687 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002688 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002689{
Kailang Yangdf694da2005-12-05 19:42:22 +01002690 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002691
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002692 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002693 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2694 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002695 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002696 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002697 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2698 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002699 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002700 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002701 return 0;
2702}
2703
Takashi Iwai05f5f472009-08-25 13:10:18 +02002704static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002705{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002706 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2707 return (pincap & AC_PINCAP_IN) != 0;
2708}
2709
Takashi Iwai1d045db2011-07-07 18:23:21 +02002710/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002711static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002712{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002713 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002714 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002715 hda_nid_t *adc_nids = spec->private_adc_nids;
2716 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2717 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002718 int i, nums = 0;
2719
2720 nid = codec->start_nid;
2721 for (i = 0; i < codec->num_nodes; i++, nid++) {
2722 hda_nid_t src;
2723 const hda_nid_t *list;
2724 unsigned int caps = get_wcaps(codec, nid);
2725 int type = get_wcaps_type(caps);
2726
2727 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2728 continue;
2729 adc_nids[nums] = nid;
2730 cap_nids[nums] = nid;
2731 src = nid;
2732 for (;;) {
2733 int n;
2734 type = get_wcaps_type(get_wcaps(codec, src));
2735 if (type == AC_WID_PIN)
2736 break;
2737 if (type == AC_WID_AUD_SEL) {
2738 cap_nids[nums] = src;
2739 break;
2740 }
2741 n = snd_hda_get_conn_list(codec, src, &list);
2742 if (n > 1) {
2743 cap_nids[nums] = src;
2744 break;
2745 } else if (n != 1)
2746 break;
2747 src = *list;
2748 }
2749 if (++nums >= max_nums)
2750 break;
2751 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002752 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002753 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002754 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002755 return nums;
2756}
2757
Takashi Iwai05f5f472009-08-25 13:10:18 +02002758/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002759static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002760{
2761 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002762 const struct auto_pin_cfg *cfg = &spec->autocfg;
2763 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002764 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002765 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002766 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002767 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002768
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002769 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002770 if (num_adcs < 0)
2771 return 0;
2772
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002773 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002774 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002775 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002776
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002777 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002778 if (!alc_is_input_pin(codec, pin))
2779 continue;
2780
David Henningsson5322bf22011-01-05 11:03:56 +01002781 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002782 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2783 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002784 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002785 type_idx++;
2786 else
2787 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002788 prev_label = label;
2789
Takashi Iwai05f5f472009-08-25 13:10:18 +02002790 if (mixer) {
2791 idx = get_connection_index(codec, mixer, pin);
2792 if (idx >= 0) {
2793 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002794 label, type_idx,
2795 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002796 if (err < 0)
2797 return err;
2798 }
2799 }
2800
Takashi Iwaib7821702011-07-06 15:12:46 +02002801 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002802 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002803 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002804 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002805 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002806 snd_hda_add_imux_item(imux, label, idx, NULL);
2807 break;
2808 }
2809 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002810 }
Takashi Iwai21268962011-07-07 15:01:13 +02002811
2812 spec->num_mux_defs = 1;
2813 spec->input_mux = imux;
2814
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002815 return 0;
2816}
2817
Takashi Iwai24de1832011-11-07 17:13:39 +01002818/* create a shared input with the headphone out */
2819static int alc_auto_create_shared_input(struct hda_codec *codec)
2820{
2821 struct alc_spec *spec = codec->spec;
2822 struct auto_pin_cfg *cfg = &spec->autocfg;
2823 unsigned int defcfg;
2824 hda_nid_t nid;
2825
2826 /* only one internal input pin? */
2827 if (cfg->num_inputs != 1)
2828 return 0;
2829 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2830 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2831 return 0;
2832
2833 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2834 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2835 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2836 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2837 else
2838 return 0; /* both not available */
2839
2840 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2841 return 0; /* no input */
2842
2843 cfg->inputs[1].pin = nid;
2844 cfg->inputs[1].type = AUTO_PIN_MIC;
2845 cfg->num_inputs = 2;
2846 spec->shared_mic_hp = 1;
2847 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2848 return 0;
2849}
2850
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002851static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2852 unsigned int pin_type)
2853{
2854 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
2855 pin_type);
2856 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002857 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2858 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002859 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002860}
2861
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002862static int get_pin_type(int line_out_type)
2863{
2864 if (line_out_type == AUTO_PIN_HP_OUT)
2865 return PIN_HP;
2866 else
2867 return PIN_OUT;
2868}
2869
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002870static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002871{
2872 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002873 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002874 int i;
2875
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002876 for (i = 0; i < cfg->num_inputs; i++) {
2877 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002878 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002879 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002880 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002881 snd_hda_codec_write(codec, nid, 0,
2882 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002883 AMP_OUT_MUTE);
2884 }
2885 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002886
2887 /* mute all loopback inputs */
2888 if (spec->mixer_nid) {
2889 int nums = snd_hda_get_conn_list(codec, spec->mixer_nid, NULL);
2890 for (i = 0; i < nums; i++)
2891 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2892 AC_VERB_SET_AMP_GAIN_MUTE,
2893 AMP_IN_MUTE(i));
2894 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002895}
2896
Takashi Iwai7085ec12009-10-02 09:03:58 +02002897/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002898static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002899{
Takashi Iwai604401a2011-04-27 15:14:23 +02002900 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002901 int i, num;
2902
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002903 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2904 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002905 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2906 for (i = 0; i < num; i++) {
2907 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2908 return list[i];
2909 }
2910 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002911}
2912
Takashi Iwai604401a2011-04-27 15:14:23 +02002913/* go down to the selector widget before the mixer */
2914static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2915{
2916 hda_nid_t srcs[5];
2917 int num = snd_hda_get_connections(codec, pin, srcs,
2918 ARRAY_SIZE(srcs));
2919 if (num != 1 ||
2920 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2921 return pin;
2922 return srcs[0];
2923}
2924
Takashi Iwai7085ec12009-10-02 09:03:58 +02002925/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002926static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002927 hda_nid_t dac)
2928{
David Henningssoncc1c4522010-11-24 14:17:47 +01002929 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002930 int i, num;
2931
Takashi Iwai604401a2011-04-27 15:14:23 +02002932 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002933 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2934 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002935 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002936 return mix[i];
2937 }
2938 return 0;
2939}
2940
Takashi Iwaice764ab2011-04-27 16:35:23 +02002941/* select the connection from pin to DAC if needed */
2942static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2943 hda_nid_t dac)
2944{
2945 hda_nid_t mix[5];
2946 int i, num;
2947
2948 pin = alc_go_down_to_selector(codec, pin);
2949 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2950 if (num < 2)
2951 return 0;
2952 for (i = 0; i < num; i++) {
2953 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2954 snd_hda_codec_update_cache(codec, pin, 0,
2955 AC_VERB_SET_CONNECT_SEL, i);
2956 return 0;
2957 }
2958 }
2959 return 0;
2960}
2961
Takashi Iwai185d99f2012-02-16 18:39:45 +01002962static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2963{
2964 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002965 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002966 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2967 ARRAY_SIZE(spec->private_dac_nids)) ||
2968 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2969 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2970 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2971 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2972 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002973 for (i = 0; i < spec->multi_ios; i++) {
2974 if (spec->multi_io[i].dac == nid)
2975 return true;
2976 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002977 return false;
2978}
2979
Takashi Iwai7085ec12009-10-02 09:03:58 +02002980/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002981static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002982{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002983 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002984 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002985
Takashi Iwai604401a2011-04-27 15:14:23 +02002986 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002987 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002988 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002989 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002990 if (!nid)
2991 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002992 if (!alc_is_dac_already_used(codec, nid))
2993 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002994 }
2995 return 0;
2996}
2997
Takashi Iwai07b18f62011-11-10 15:42:54 +01002998/* check whether the DAC is reachable from the pin */
2999static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
3000 hda_nid_t pin, hda_nid_t dac)
3001{
3002 hda_nid_t srcs[5];
3003 int i, num;
3004
Takashi Iwaidc31b582012-02-17 17:27:53 +01003005 if (!pin || !dac)
3006 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003007 pin = alc_go_down_to_selector(codec, pin);
3008 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
3009 for (i = 0; i < num; i++) {
3010 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
3011 if (nid == dac)
3012 return true;
3013 }
3014 return false;
3015}
3016
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003017static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
3018{
Takashi Iwai140547e2012-02-16 17:23:46 +01003019 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003020 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003021 hda_nid_t nid, nid_found, srcs[5];
3022 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01003023 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01003024 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003025 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003026 nid_found = 0;
3027 for (i = 0; i < num; i++) {
3028 if (srcs[i] == spec->mixer_nid)
3029 continue;
3030 nid = alc_auto_mix_to_dac(codec, srcs[i]);
3031 if (nid && !alc_is_dac_already_used(codec, nid)) {
3032 if (nid_found)
3033 return 0;
3034 nid_found = nid;
3035 }
3036 }
3037 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003038}
3039
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003040/* mark up volume and mute control NIDs: used during badness parsing and
3041 * at creating actual controls
3042 */
3043static inline unsigned int get_ctl_pos(unsigned int data)
3044{
3045 hda_nid_t nid = get_amp_nid_(data);
3046 unsigned int dir;
3047 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3048 return 0;
3049 dir = get_amp_direction_(data);
3050 return (nid << 1) | dir;
3051}
3052
3053#define is_ctl_used(bits, data) \
3054 test_bit(get_ctl_pos(data), bits)
3055#define mark_ctl_usage(bits, data) \
3056 set_bit(get_ctl_pos(data), bits)
3057
3058static void clear_vol_marks(struct hda_codec *codec)
3059{
3060 struct alc_spec *spec = codec->spec;
3061 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3062 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3063}
3064
3065/* badness definition */
3066enum {
3067 /* No primary DAC is found for the main output */
3068 BAD_NO_PRIMARY_DAC = 0x10000,
3069 /* No DAC is found for the extra output */
3070 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003071 /* No possible multi-ios */
3072 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003073 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003074 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003075 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003076 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003077 /* Primary DAC shared with main surrounds */
3078 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003079 /* Primary DAC shared with main CLFE */
3080 BAD_SHARED_CLFE = 0x10,
3081 /* Primary DAC shared with extra surrounds */
3082 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003083 /* Volume widget is shared */
3084 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003085};
3086
3087static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3088 hda_nid_t pin, hda_nid_t dac);
3089static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3090 hda_nid_t pin, hda_nid_t dac);
3091
3092static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3093 hda_nid_t dac)
3094{
3095 struct alc_spec *spec = codec->spec;
3096 hda_nid_t nid;
3097 unsigned int val;
3098 int badness = 0;
3099
3100 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3101 if (nid) {
3102 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3103 if (is_ctl_used(spec->vol_ctls, nid))
3104 badness += BAD_SHARED_VOL;
3105 else
3106 mark_ctl_usage(spec->vol_ctls, val);
3107 } else
3108 badness += BAD_SHARED_VOL;
3109 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3110 if (nid) {
3111 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3112 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3113 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3114 else
3115 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3116 if (is_ctl_used(spec->sw_ctls, val))
3117 badness += BAD_SHARED_VOL;
3118 else
3119 mark_ctl_usage(spec->sw_ctls, val);
3120 } else
3121 badness += BAD_SHARED_VOL;
3122 return badness;
3123}
3124
Takashi Iwaidc31b582012-02-17 17:27:53 +01003125struct badness_table {
3126 int no_primary_dac; /* no primary DAC */
3127 int no_dac; /* no secondary DACs */
3128 int shared_primary; /* primary DAC is shared with main output */
3129 int shared_surr; /* secondary DAC shared with main or primary */
3130 int shared_clfe; /* third DAC shared with main or primary */
3131 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3132};
3133
3134static struct badness_table main_out_badness = {
3135 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3136 .no_dac = BAD_NO_DAC,
3137 .shared_primary = BAD_NO_PRIMARY_DAC,
3138 .shared_surr = BAD_SHARED_SURROUND,
3139 .shared_clfe = BAD_SHARED_CLFE,
3140 .shared_surr_main = BAD_SHARED_SURROUND,
3141};
3142
3143static struct badness_table extra_out_badness = {
3144 .no_primary_dac = BAD_NO_DAC,
3145 .no_dac = BAD_NO_DAC,
3146 .shared_primary = BAD_NO_EXTRA_DAC,
3147 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3148 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3149 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3150};
3151
3152/* try to assign DACs to pins and return the resultant badness */
3153static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3154 const hda_nid_t *pins, hda_nid_t *dacs,
3155 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003156{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003157 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003158 struct auto_pin_cfg *cfg = &spec->autocfg;
3159 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003160 int badness = 0;
3161 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003162
Takashi Iwai185d99f2012-02-16 18:39:45 +01003163 if (!num_outs)
3164 return 0;
3165
Takashi Iwaidc31b582012-02-17 17:27:53 +01003166 for (i = 0; i < num_outs; i++) {
3167 hda_nid_t pin = pins[i];
3168 if (!dacs[i])
3169 dacs[i] = alc_auto_look_for_dac(codec, pin);
3170 if (!dacs[i] && !i) {
3171 for (j = 1; j < num_outs; j++) {
3172 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3173 dacs[0] = dacs[j];
3174 dacs[j] = 0;
3175 break;
3176 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003177 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003178 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003179 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003180 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003181 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003182 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003183 else if (cfg->line_outs > i &&
3184 alc_auto_is_dac_reachable(codec, pin,
3185 spec->private_dac_nids[i]))
3186 dac = spec->private_dac_nids[i];
3187 if (dac) {
3188 if (!i)
3189 badness += bad->shared_primary;
3190 else if (i == 1)
3191 badness += bad->shared_surr;
3192 else
3193 badness += bad->shared_clfe;
3194 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003195 spec->private_dac_nids[0])) {
3196 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003197 badness += bad->shared_surr_main;
3198 } else if (!i)
3199 badness += bad->no_primary_dac;
3200 else
3201 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003202 }
3203 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003204 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003205 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003206
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003207 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003208}
3209
3210static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003211 hda_nid_t reference_pin,
3212 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003213
Takashi Iwai185d99f2012-02-16 18:39:45 +01003214static bool alc_map_singles(struct hda_codec *codec, int outs,
3215 const hda_nid_t *pins, hda_nid_t *dacs)
3216{
3217 int i;
3218 bool found = false;
3219 for (i = 0; i < outs; i++) {
3220 if (dacs[i])
3221 continue;
3222 dacs[i] = get_dac_if_single(codec, pins[i]);
3223 if (dacs[i])
3224 found = true;
3225 }
3226 return found;
3227}
3228
Takashi Iwai7085ec12009-10-02 09:03:58 +02003229/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003230static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003231 bool fill_hardwired,
3232 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003233{
3234 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003235 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003236 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003237
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003238 /* set num_dacs once to full for alc_auto_look_for_dac() */
3239 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003240 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003241 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3242 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3243 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003244 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003245 clear_vol_marks(codec);
3246 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003247
3248 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003249 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003250 bool mapped;
3251 do {
3252 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003253 cfg->line_out_pins,
3254 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003255 mapped |= alc_map_singles(codec, cfg->hp_outs,
3256 cfg->hp_pins,
3257 spec->multiout.hp_out_nid);
3258 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3259 cfg->speaker_pins,
3260 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003261 if (fill_mio_first && cfg->line_outs == 1 &&
3262 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3263 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3264 if (!err)
3265 mapped = true;
3266 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003267 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003268 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003269
Takashi Iwaidc31b582012-02-17 17:27:53 +01003270 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3271 spec->private_dac_nids,
3272 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003273
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003274 /* re-count num_dacs and squash invalid entries */
3275 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003276 for (i = 0; i < cfg->line_outs; i++) {
3277 if (spec->private_dac_nids[i])
3278 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003279 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003280 memmove(spec->private_dac_nids + i,
3281 spec->private_dac_nids + i + 1,
3282 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003283 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3284 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003285 }
3286
Takashi Iwai276dd702012-02-17 16:17:03 +01003287 if (fill_mio_first &&
3288 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003289 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003290 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003291 if (err < 0)
3292 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003293 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003294 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003295
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003296 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003297 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3298 spec->multiout.hp_out_nid,
3299 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003300 if (err < 0)
3301 return err;
3302 badness += err;
3303 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003304 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003305 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3306 cfg->speaker_pins,
3307 spec->multiout.extra_out_nid,
3308 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003309 if (err < 0)
3310 return err;
3311 badness += err;
3312 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003313 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3314 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003315 if (err < 0)
3316 return err;
3317 badness += err;
3318 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003319 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3320 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003321 int offset = 0;
3322 if (cfg->line_outs >= 3)
3323 offset = 1;
3324 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3325 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003326 if (err < 0)
3327 return err;
3328 badness += err;
3329 }
3330
3331 if (spec->multi_ios == 2) {
3332 for (i = 0; i < 2; i++)
3333 spec->private_dac_nids[spec->multiout.num_dacs++] =
3334 spec->multi_io[i].dac;
3335 spec->ext_channel_count = 2;
3336 } else if (spec->multi_ios) {
3337 spec->multi_ios = 0;
3338 badness += BAD_MULTI_IO;
3339 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003340
3341 return badness;
3342}
3343
3344#define DEBUG_BADNESS
3345
3346#ifdef DEBUG_BADNESS
3347#define debug_badness snd_printdd
3348#else
3349#define debug_badness(...)
3350#endif
3351
3352static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3353{
3354 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3355 cfg->line_out_pins[0], cfg->line_out_pins[1],
3356 cfg->line_out_pins[2], cfg->line_out_pins[2],
3357 spec->multiout.dac_nids[0],
3358 spec->multiout.dac_nids[1],
3359 spec->multiout.dac_nids[2],
3360 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003361 if (spec->multi_ios > 0)
3362 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3363 spec->multi_ios,
3364 spec->multi_io[0].pin, spec->multi_io[1].pin,
3365 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003366 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3367 cfg->hp_pins[0], cfg->hp_pins[1],
3368 cfg->hp_pins[2], cfg->hp_pins[2],
3369 spec->multiout.hp_out_nid[0],
3370 spec->multiout.hp_out_nid[1],
3371 spec->multiout.hp_out_nid[2],
3372 spec->multiout.hp_out_nid[3]);
3373 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3374 cfg->speaker_pins[0], cfg->speaker_pins[1],
3375 cfg->speaker_pins[2], cfg->speaker_pins[3],
3376 spec->multiout.extra_out_nid[0],
3377 spec->multiout.extra_out_nid[1],
3378 spec->multiout.extra_out_nid[2],
3379 spec->multiout.extra_out_nid[3]);
3380}
3381
3382static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3383{
3384 struct alc_spec *spec = codec->spec;
3385 struct auto_pin_cfg *cfg = &spec->autocfg;
3386 struct auto_pin_cfg *best_cfg;
3387 int best_badness = INT_MAX;
3388 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003389 bool fill_hardwired = true, fill_mio_first = true;
3390 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003391 bool hp_spk_swapped = false;
3392
3393 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3394 if (!best_cfg)
3395 return -ENOMEM;
3396 *best_cfg = *cfg;
3397
3398 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003399 badness = fill_and_eval_dacs(codec, fill_hardwired,
3400 fill_mio_first);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003401 if (badness < 0)
3402 return badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003403 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3404 cfg->line_out_type, fill_hardwired, fill_mio_first,
3405 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003406 debug_show_configs(spec, cfg);
3407 if (badness < best_badness) {
3408 best_badness = badness;
3409 *best_cfg = *cfg;
3410 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003411 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003412 }
3413 if (!badness)
3414 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003415 fill_mio_first = !fill_mio_first;
3416 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003417 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003418 fill_hardwired = !fill_hardwired;
3419 if (!fill_hardwired)
3420 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003421 if (hp_spk_swapped)
3422 break;
3423 hp_spk_swapped = true;
3424 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003425 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3426 cfg->hp_outs = cfg->line_outs;
3427 memcpy(cfg->hp_pins, cfg->line_out_pins,
3428 sizeof(cfg->hp_pins));
3429 cfg->line_outs = cfg->speaker_outs;
3430 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3431 sizeof(cfg->speaker_pins));
3432 cfg->speaker_outs = 0;
3433 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3434 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003435 fill_hardwired = true;
3436 continue;
3437 }
3438 if (cfg->hp_outs > 0 &&
3439 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3440 cfg->speaker_outs = cfg->line_outs;
3441 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3442 sizeof(cfg->speaker_pins));
3443 cfg->line_outs = cfg->hp_outs;
3444 memcpy(cfg->line_out_pins, cfg->hp_pins,
3445 sizeof(cfg->hp_pins));
3446 cfg->hp_outs = 0;
3447 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3448 cfg->line_out_type = AUTO_PIN_HP_OUT;
3449 fill_hardwired = true;
3450 continue;
3451 }
3452 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003453 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003454
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003455 if (badness) {
3456 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003457 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003458 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003459 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3460 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003461 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003462
David Henningssonfde48a12011-12-09 18:27:42 +08003463 if (cfg->line_out_pins[0])
3464 spec->vmaster_nid =
3465 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3466 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003467
3468 /* clear the bitmap flags for creating controls */
3469 clear_vol_marks(codec);
3470 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003471 return 0;
3472}
3473
Takashi Iwai343a04b2011-07-06 14:28:39 +02003474static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003475 const char *pfx, int cidx,
3476 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003477{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003478 struct alc_spec *spec = codec->spec;
3479 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003480 if (!nid)
3481 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003482 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3483 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3484 return 0;
3485 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003486 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003487 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003488}
3489
Takashi Iwaie29d3772011-11-14 17:13:23 +01003490static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3491 const char *pfx, int cidx,
3492 hda_nid_t nid)
3493{
3494 int chs = 1;
3495 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3496 chs = 3;
3497 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3498}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003499
3500/* create a mute-switch for the given mixer widget;
3501 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3502 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003503static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003504 const char *pfx, int cidx,
3505 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003506{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003507 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003508 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003509 int type;
3510 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003511 if (!nid)
3512 return 0;
3513 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3514 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3515 type = ALC_CTL_WIDGET_MUTE;
3516 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3517 } else if (snd_hda_get_conn_list(codec, nid, NULL) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003518 type = ALC_CTL_WIDGET_MUTE;
3519 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3520 } else {
3521 type = ALC_CTL_BIND_MUTE;
3522 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3523 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003524 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3525 return 0;
3526 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003527 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003528}
3529
Takashi Iwaie29d3772011-11-14 17:13:23 +01003530static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3531 int cidx, hda_nid_t nid)
3532{
3533 int chs = 1;
3534 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3535 chs = 3;
3536 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3537}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003538
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003539static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3540 hda_nid_t pin, hda_nid_t dac)
3541{
3542 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3543 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3544 return pin;
3545 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3546 return mix;
3547 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3548 return dac;
3549 return 0;
3550}
3551
3552static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3553 hda_nid_t pin, hda_nid_t dac)
3554{
3555 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3556 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3557 return dac;
3558 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3559 return mix;
3560 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3561 return pin;
3562 return 0;
3563}
3564
Takashi Iwai7085ec12009-10-02 09:03:58 +02003565/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003566static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003567 const struct auto_pin_cfg *cfg)
3568{
3569 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003570 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003571
Takashi Iwaice764ab2011-04-27 16:35:23 +02003572 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003573 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003574 noutputs += spec->multi_ios;
3575
3576 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003577 const char *name;
3578 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003579 hda_nid_t dac, pin;
3580 hda_nid_t sw, vol;
3581
3582 dac = spec->multiout.dac_nids[i];
3583 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003584 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003585 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003586 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003587 index = 0;
3588 name = channel_name[i];
3589 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003590 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003591 name = alc_get_line_out_pfx(spec, i, true, &index);
3592 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003593
3594 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3595 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003596 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003597 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003598 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003599 if (err < 0)
3600 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003601 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003602 if (err < 0)
3603 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003604 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003605 if (err < 0)
3606 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003607 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003608 if (err < 0)
3609 return err;
3610 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003611 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003612 if (err < 0)
3613 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003614 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003615 if (err < 0)
3616 return err;
3617 }
3618 }
3619 return 0;
3620}
3621
Takashi Iwai343a04b2011-07-06 14:28:39 +02003622static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003623 hda_nid_t dac, const char *pfx,
3624 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003625{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003626 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003627 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003628 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003629
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003630 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003631 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003632 /* the corresponding DAC is already occupied */
3633 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3634 return 0; /* no way */
3635 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003636 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3637 if (is_ctl_used(spec->sw_ctls, val))
3638 return 0; /* already created */
3639 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003640 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003641 }
3642
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003643 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3644 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003645 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003646 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003647 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003648 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003649 if (err < 0)
3650 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003651 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003652}
3653
Takashi Iwai23c09b02011-08-19 09:05:35 +02003654static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3655 unsigned int nums,
3656 struct hda_ctl_ops *ops)
3657{
3658 struct alc_spec *spec = codec->spec;
3659 struct hda_bind_ctls **ctlp, *ctl;
3660 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3661 ctlp = snd_array_new(&spec->bind_ctls);
3662 if (!ctlp)
3663 return NULL;
3664 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3665 *ctlp = ctl;
3666 if (ctl)
3667 ctl->ops = ops;
3668 return ctl;
3669}
3670
3671/* add playback controls for speaker and HP outputs */
3672static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3673 const hda_nid_t *pins,
3674 const hda_nid_t *dacs,
3675 const char *pfx)
3676{
3677 struct alc_spec *spec = codec->spec;
3678 struct hda_bind_ctls *ctl;
3679 char name[32];
3680 int i, n, err;
3681
3682 if (!num_pins || !pins[0])
3683 return 0;
3684
Takashi Iwai527e4d72011-10-27 16:33:27 +02003685 if (num_pins == 1) {
3686 hda_nid_t dac = *dacs;
3687 if (!dac)
3688 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003689 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003690 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003691
Takashi Iwai23c09b02011-08-19 09:05:35 +02003692 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003693 hda_nid_t dac;
3694 if (dacs[num_pins - 1])
3695 dac = dacs[i]; /* with individual volumes */
3696 else
3697 dac = 0;
3698 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3699 err = alc_auto_create_extra_out(codec, pins[i], dac,
3700 "Bass Speaker", 0);
3701 } else if (num_pins >= 3) {
3702 snprintf(name, sizeof(name), "%s %s",
3703 pfx, channel_name[i]);
3704 err = alc_auto_create_extra_out(codec, pins[i], dac,
3705 name, 0);
3706 } else {
3707 err = alc_auto_create_extra_out(codec, pins[i], dac,
3708 pfx, i);
3709 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003710 if (err < 0)
3711 return err;
3712 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003713 if (dacs[num_pins - 1])
3714 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003715
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003716 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003717 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3718 if (!ctl)
3719 return -ENOMEM;
3720 n = 0;
3721 for (i = 0; i < num_pins; i++) {
3722 hda_nid_t vol;
3723 if (!pins[i] || !dacs[i])
3724 continue;
3725 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3726 if (vol)
3727 ctl->values[n++] =
3728 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3729 }
3730 if (n) {
3731 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3732 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3733 if (err < 0)
3734 return err;
3735 }
3736 return 0;
3737}
3738
Takashi Iwai343a04b2011-07-06 14:28:39 +02003739static int alc_auto_create_hp_out(struct hda_codec *codec)
3740{
3741 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003742 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3743 spec->autocfg.hp_pins,
3744 spec->multiout.hp_out_nid,
3745 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003746}
3747
3748static int alc_auto_create_speaker_out(struct hda_codec *codec)
3749{
3750 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003751 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3752 spec->autocfg.speaker_pins,
3753 spec->multiout.extra_out_nid,
3754 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003755}
3756
Takashi Iwai343a04b2011-07-06 14:28:39 +02003757static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003758 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003759 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003760{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003761 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003762 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003763 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003764
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003765 alc_set_pin_output(codec, pin, pin_type);
3766 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003767 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003768 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003769 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003770 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003771 mix = srcs[i];
3772 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003773 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003774 if (!mix)
3775 return;
3776
3777 /* need the manual connection? */
3778 if (num > 1)
3779 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3780 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003781 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3782 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003783 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003784 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003785 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003786 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003787 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003788 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3789 if (nid)
3790 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3791 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003792
3793 /* unmute DAC if it's not assigned to a mixer */
3794 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3795 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3796 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3797 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003798}
3799
Takashi Iwai343a04b2011-07-06 14:28:39 +02003800static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003801{
3802 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003803 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003804 int i;
3805
3806 for (i = 0; i <= HDA_SIDE; i++) {
3807 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3808 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003809 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003810 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003811 }
3812}
3813
Takashi Iwai343a04b2011-07-06 14:28:39 +02003814static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003815{
3816 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003817 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003818 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003819
David Henningsson636030e2011-10-12 19:26:03 +02003820 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003821 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3822 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003823 pin = spec->autocfg.hp_pins[i];
3824 if (!pin)
3825 break;
3826 dac = spec->multiout.hp_out_nid[i];
3827 if (!dac) {
3828 if (i > 0 && spec->multiout.hp_out_nid[0])
3829 dac = spec->multiout.hp_out_nid[0];
3830 else
3831 dac = spec->multiout.dac_nids[0];
3832 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003833 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3834 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003835 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003836 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3837 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003838 pin = spec->autocfg.speaker_pins[i];
3839 if (!pin)
3840 break;
3841 dac = spec->multiout.extra_out_nid[i];
3842 if (!dac) {
3843 if (i > 0 && spec->multiout.extra_out_nid[0])
3844 dac = spec->multiout.extra_out_nid[0];
3845 else
3846 dac = spec->multiout.dac_nids[0];
3847 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003848 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3849 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003850}
3851
Takashi Iwai276dd702012-02-17 16:17:03 +01003852/* check whether the given pin can be a multi-io pin */
3853static bool can_be_multiio_pin(struct hda_codec *codec,
3854 unsigned int location, hda_nid_t nid)
3855{
3856 unsigned int defcfg, caps;
3857
3858 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3859 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3860 return false;
3861 if (location && get_defcfg_location(defcfg) != location)
3862 return false;
3863 caps = snd_hda_query_pin_caps(codec, nid);
3864 if (!(caps & AC_PINCAP_OUT))
3865 return false;
3866 return true;
3867}
3868
Takashi Iwaice764ab2011-04-27 16:35:23 +02003869/*
3870 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003871 *
3872 * When hardwired is set, try to fill ony hardwired pins, and returns
3873 * zero if any pins are filled, non-zero if nothing found.
3874 * When hardwired is off, try to fill possible input pins, and returns
3875 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003876 */
3877static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003878 hda_nid_t reference_pin,
3879 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003880{
3881 struct alc_spec *spec = codec->spec;
3882 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003883 int type, i, j, dacs, num_pins, old_pins;
3884 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3885 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003886 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003887
Takashi Iwai276dd702012-02-17 16:17:03 +01003888 old_pins = spec->multi_ios;
3889 if (old_pins >= 2)
3890 goto end_fill;
3891
3892 num_pins = 0;
3893 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3894 for (i = 0; i < cfg->num_inputs; i++) {
3895 if (cfg->inputs[i].type != type)
3896 continue;
3897 if (can_be_multiio_pin(codec, location,
3898 cfg->inputs[i].pin))
3899 num_pins++;
3900 }
3901 }
3902 if (num_pins < 2)
3903 goto end_fill;
3904
Takashi Iwai07b18f62011-11-10 15:42:54 +01003905 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003906 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3907 for (i = 0; i < cfg->num_inputs; i++) {
3908 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003909 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003910
Takashi Iwaice764ab2011-04-27 16:35:23 +02003911 if (cfg->inputs[i].type != type)
3912 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003913 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003914 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003915 for (j = 0; j < spec->multi_ios; j++) {
3916 if (nid == spec->multi_io[j].pin)
3917 break;
3918 }
3919 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003920 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003921
3922 if (offset && offset + spec->multi_ios < dacs) {
3923 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003924 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3925 dac = 0;
3926 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003927 if (hardwired)
3928 dac = get_dac_if_single(codec, nid);
3929 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003930 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003931 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003932 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003933 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003934 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003935 spec->multi_io[spec->multi_ios].pin = nid;
3936 spec->multi_io[spec->multi_ios].dac = dac;
3937 spec->multi_ios++;
3938 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003939 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003940 }
3941 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003942 end_fill:
3943 if (badness)
3944 badness = BAD_MULTI_IO;
3945 if (old_pins == spec->multi_ios) {
3946 if (hardwired)
3947 return 1; /* nothing found */
3948 else
3949 return badness; /* no badness if nothing found */
3950 }
3951 if (!hardwired && spec->multi_ios < 2) {
3952 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003953 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003954 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003955
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003956 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003957}
3958
3959static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3960 struct snd_ctl_elem_info *uinfo)
3961{
3962 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3963 struct alc_spec *spec = codec->spec;
3964
3965 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3966 uinfo->count = 1;
3967 uinfo->value.enumerated.items = spec->multi_ios + 1;
3968 if (uinfo->value.enumerated.item > spec->multi_ios)
3969 uinfo->value.enumerated.item = spec->multi_ios;
3970 sprintf(uinfo->value.enumerated.name, "%dch",
3971 (uinfo->value.enumerated.item + 1) * 2);
3972 return 0;
3973}
3974
3975static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3976 struct snd_ctl_elem_value *ucontrol)
3977{
3978 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3979 struct alc_spec *spec = codec->spec;
3980 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3981 return 0;
3982}
3983
3984static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3985{
3986 struct alc_spec *spec = codec->spec;
3987 hda_nid_t nid = spec->multi_io[idx].pin;
3988
3989 if (!spec->multi_io[idx].ctl_in)
3990 spec->multi_io[idx].ctl_in =
3991 snd_hda_codec_read(codec, nid, 0,
3992 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3993 if (output) {
3994 snd_hda_codec_update_cache(codec, nid, 0,
3995 AC_VERB_SET_PIN_WIDGET_CONTROL,
3996 PIN_OUT);
3997 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3998 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3999 HDA_AMP_MUTE, 0);
4000 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
4001 } else {
4002 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
4003 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
4004 HDA_AMP_MUTE, HDA_AMP_MUTE);
4005 snd_hda_codec_update_cache(codec, nid, 0,
4006 AC_VERB_SET_PIN_WIDGET_CONTROL,
4007 spec->multi_io[idx].ctl_in);
4008 }
4009 return 0;
4010}
4011
4012static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
4013 struct snd_ctl_elem_value *ucontrol)
4014{
4015 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
4016 struct alc_spec *spec = codec->spec;
4017 int i, ch;
4018
4019 ch = ucontrol->value.enumerated.item[0];
4020 if (ch < 0 || ch > spec->multi_ios)
4021 return -EINVAL;
4022 if (ch == (spec->ext_channel_count - 1) / 2)
4023 return 0;
4024 spec->ext_channel_count = (ch + 1) * 2;
4025 for (i = 0; i < spec->multi_ios; i++)
4026 alc_set_multi_io(codec, i, i < ch);
4027 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004028 if (spec->need_dac_fix && !spec->const_channel_count)
4029 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004030 return 1;
4031}
4032
Takashi Iwaia9111322011-05-02 11:30:18 +02004033static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004034 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4035 .name = "Channel Mode",
4036 .info = alc_auto_ch_mode_info,
4037 .get = alc_auto_ch_mode_get,
4038 .put = alc_auto_ch_mode_put,
4039};
4040
Takashi Iwai23c09b02011-08-19 09:05:35 +02004041static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004042{
4043 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004044
Takashi Iwaic2674682011-08-24 17:57:44 +02004045 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004046 struct snd_kcontrol_new *knew;
4047
4048 knew = alc_kcontrol_new(spec);
4049 if (!knew)
4050 return -ENOMEM;
4051 *knew = alc_auto_channel_mode_enum;
4052 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4053 if (!knew->name)
4054 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004055 }
4056 return 0;
4057}
4058
Takashi Iwai1d045db2011-07-07 18:23:21 +02004059/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4060 * active input pins
4061 */
4062static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4063{
4064 struct alc_spec *spec = codec->spec;
4065 const struct hda_input_mux *imux;
4066 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4067 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4068 int i, n, nums;
4069
4070 imux = spec->input_mux;
4071 if (!imux)
4072 return;
4073 if (spec->dyn_adc_switch)
4074 return;
4075
Takashi Iwai26acaf02012-03-22 14:36:50 +01004076 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004077 nums = 0;
4078 for (n = 0; n < spec->num_adc_nids; n++) {
4079 hda_nid_t cap = spec->private_capsrc_nids[n];
4080 int num_conns = snd_hda_get_conn_list(codec, cap, NULL);
4081 for (i = 0; i < imux->num_items; i++) {
4082 hda_nid_t pin = spec->imux_pins[i];
4083 if (pin) {
4084 if (get_connection_index(codec, cap, pin) < 0)
4085 break;
4086 } else if (num_conns <= imux->items[i].index)
4087 break;
4088 }
4089 if (i >= imux->num_items) {
4090 adc_nids[nums] = spec->private_adc_nids[n];
4091 capsrc_nids[nums++] = cap;
4092 }
4093 }
4094 if (!nums) {
4095 /* check whether ADC-switch is possible */
4096 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004097 if (spec->shared_mic_hp) {
4098 spec->shared_mic_hp = 0;
4099 spec->private_imux[0].num_items = 1;
4100 goto again;
4101 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004102 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4103 " using fallback 0x%x\n",
4104 codec->chip_name, spec->private_adc_nids[0]);
4105 spec->num_adc_nids = 1;
4106 spec->auto_mic = 0;
4107 return;
4108 }
4109 } else if (nums != spec->num_adc_nids) {
4110 memcpy(spec->private_adc_nids, adc_nids,
4111 nums * sizeof(hda_nid_t));
4112 memcpy(spec->private_capsrc_nids, capsrc_nids,
4113 nums * sizeof(hda_nid_t));
4114 spec->num_adc_nids = nums;
4115 }
4116
4117 if (spec->auto_mic)
4118 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004119 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004120 spec->num_adc_nids = 1; /* reduce to a single ADC */
4121}
4122
4123/*
4124 * initialize ADC paths
4125 */
4126static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4127{
4128 struct alc_spec *spec = codec->spec;
4129 hda_nid_t nid;
4130
4131 nid = spec->adc_nids[adc_idx];
4132 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004133 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004134 snd_hda_codec_write(codec, nid, 0,
4135 AC_VERB_SET_AMP_GAIN_MUTE,
4136 AMP_IN_MUTE(0));
4137 return;
4138 }
4139 if (!spec->capsrc_nids)
4140 return;
4141 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004142 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004143 snd_hda_codec_write(codec, nid, 0,
4144 AC_VERB_SET_AMP_GAIN_MUTE,
4145 AMP_OUT_MUTE);
4146}
4147
4148static void alc_auto_init_input_src(struct hda_codec *codec)
4149{
4150 struct alc_spec *spec = codec->spec;
4151 int c, nums;
4152
4153 for (c = 0; c < spec->num_adc_nids; c++)
4154 alc_auto_init_adc(codec, c);
4155 if (spec->dyn_adc_switch)
4156 nums = 1;
4157 else
4158 nums = spec->num_adc_nids;
4159 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004160 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004161}
4162
4163/* add mic boosts if needed */
4164static int alc_auto_add_mic_boost(struct hda_codec *codec)
4165{
4166 struct alc_spec *spec = codec->spec;
4167 struct auto_pin_cfg *cfg = &spec->autocfg;
4168 int i, err;
4169 int type_idx = 0;
4170 hda_nid_t nid;
4171 const char *prev_label = NULL;
4172
4173 for (i = 0; i < cfg->num_inputs; i++) {
4174 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4175 break;
4176 nid = cfg->inputs[i].pin;
4177 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4178 const char *label;
4179 char boost_label[32];
4180
4181 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004182 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4183 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004184 if (prev_label && !strcmp(label, prev_label))
4185 type_idx++;
4186 else
4187 type_idx = 0;
4188 prev_label = label;
4189
4190 snprintf(boost_label, sizeof(boost_label),
4191 "%s Boost Volume", label);
4192 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4193 boost_label, type_idx,
4194 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4195 if (err < 0)
4196 return err;
4197 }
4198 }
4199 return 0;
4200}
4201
4202/* select or unmute the given capsrc route */
4203static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4204 int idx)
4205{
4206 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4207 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4208 HDA_AMP_MUTE, 0);
4209 } else if (snd_hda_get_conn_list(codec, cap, NULL) > 1) {
4210 snd_hda_codec_write_cache(codec, cap, 0,
4211 AC_VERB_SET_CONNECT_SEL, idx);
4212 }
4213}
4214
4215/* set the default connection to that pin */
4216static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4217{
4218 struct alc_spec *spec = codec->spec;
4219 int i;
4220
4221 if (!pin)
4222 return 0;
4223 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004224 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004225 int idx;
4226
4227 idx = get_connection_index(codec, cap, pin);
4228 if (idx < 0)
4229 continue;
4230 select_or_unmute_capsrc(codec, cap, idx);
4231 return i; /* return the found index */
4232 }
4233 return -1; /* not found */
4234}
4235
4236/* initialize some special cases for input sources */
4237static void alc_init_special_input_src(struct hda_codec *codec)
4238{
4239 struct alc_spec *spec = codec->spec;
4240 int i;
4241
4242 for (i = 0; i < spec->autocfg.num_inputs; i++)
4243 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4244}
4245
4246/* assign appropriate capture mixers */
4247static void set_capture_mixer(struct hda_codec *codec)
4248{
4249 struct alc_spec *spec = codec->spec;
4250 static const struct snd_kcontrol_new *caps[2][3] = {
4251 { alc_capture_mixer_nosrc1,
4252 alc_capture_mixer_nosrc2,
4253 alc_capture_mixer_nosrc3 },
4254 { alc_capture_mixer1,
4255 alc_capture_mixer2,
4256 alc_capture_mixer3 },
4257 };
4258
4259 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004260 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004261 if (!spec->capsrc_nids)
4262 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004263 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004264 return; /* no volume in capsrc, too */
4265 spec->vol_in_capsrc = 1;
4266 }
4267
4268 if (spec->num_adc_nids > 0) {
4269 int mux = 0;
4270 int num_adcs = 0;
4271
4272 if (spec->input_mux && spec->input_mux->num_items > 1)
4273 mux = 1;
4274 if (spec->auto_mic) {
4275 num_adcs = 1;
4276 mux = 0;
4277 } else if (spec->dyn_adc_switch)
4278 num_adcs = 1;
4279 if (!num_adcs) {
4280 if (spec->num_adc_nids > 3)
4281 spec->num_adc_nids = 3;
4282 else if (!spec->num_adc_nids)
4283 return;
4284 num_adcs = spec->num_adc_nids;
4285 }
4286 spec->cap_mixer = caps[mux][num_adcs - 1];
4287 }
4288}
4289
4290/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004291 * standard auto-parser initializations
4292 */
4293static void alc_auto_init_std(struct hda_codec *codec)
4294{
4295 struct alc_spec *spec = codec->spec;
4296 alc_auto_init_multi_out(codec);
4297 alc_auto_init_extra_out(codec);
4298 alc_auto_init_analog_input(codec);
4299 alc_auto_init_input_src(codec);
4300 alc_auto_init_digital(codec);
4301 if (spec->unsol_event)
4302 alc_inithook(codec);
4303}
4304
4305/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004306 * Digital-beep handlers
4307 */
4308#ifdef CONFIG_SND_HDA_INPUT_BEEP
4309#define set_beep_amp(spec, nid, idx, dir) \
4310 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4311
4312static const struct snd_pci_quirk beep_white_list[] = {
4313 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4314 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4315 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4316 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004317 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004318 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4319 {}
4320};
4321
4322static inline int has_cdefine_beep(struct hda_codec *codec)
4323{
4324 struct alc_spec *spec = codec->spec;
4325 const struct snd_pci_quirk *q;
4326 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4327 if (q)
4328 return q->value;
4329 return spec->cdefine.enable_pcbeep;
4330}
4331#else
4332#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4333#define has_cdefine_beep(codec) 0
4334#endif
4335
4336/* parse the BIOS configuration and set up the alc_spec */
4337/* return 1 if successful, 0 if the proper config is not found,
4338 * or a negative error code
4339 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004340static int alc_parse_auto_config(struct hda_codec *codec,
4341 const hda_nid_t *ignore_nids,
4342 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004343{
4344 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004345 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004346 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004347
Takashi Iwai53c334a2011-08-23 18:27:14 +02004348 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4349 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004350 if (err < 0)
4351 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004352 if (!cfg->line_outs) {
4353 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004354 spec->multiout.max_channels = 2;
4355 spec->no_analog = 1;
4356 goto dig_only;
4357 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004358 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004359 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004360
Takashi Iwai06503672011-10-06 08:27:19 +02004361 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4362 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004363 /* use HP as primary out */
4364 cfg->speaker_outs = cfg->line_outs;
4365 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4366 sizeof(cfg->speaker_pins));
4367 cfg->line_outs = cfg->hp_outs;
4368 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4369 cfg->hp_outs = 0;
4370 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4371 cfg->line_out_type = AUTO_PIN_HP_OUT;
4372 }
4373
Takashi Iwai1d045db2011-07-07 18:23:21 +02004374 err = alc_auto_fill_dac_nids(codec);
4375 if (err < 0)
4376 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004377 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004378 if (err < 0)
4379 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004380 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004381 if (err < 0)
4382 return err;
4383 err = alc_auto_create_hp_out(codec);
4384 if (err < 0)
4385 return err;
4386 err = alc_auto_create_speaker_out(codec);
4387 if (err < 0)
4388 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004389 err = alc_auto_create_shared_input(codec);
4390 if (err < 0)
4391 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004392 err = alc_auto_create_input_ctls(codec);
4393 if (err < 0)
4394 return err;
4395
4396 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4397
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004398 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004399 alc_auto_parse_digital(codec);
4400
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004401 if (!spec->no_analog)
4402 alc_remove_invalid_adc_nids(codec);
4403
4404 if (ssid_nids)
4405 alc_ssid_check(codec, ssid_nids);
4406
4407 if (!spec->no_analog) {
4408 alc_auto_check_switches(codec);
4409 err = alc_auto_add_mic_boost(codec);
4410 if (err < 0)
4411 return err;
4412 }
4413
Takashi Iwai1d045db2011-07-07 18:23:21 +02004414 if (spec->kctls.list)
4415 add_mixer(spec, spec->kctls.list);
4416
Takashi Iwai070cff42012-02-21 12:54:17 +01004417 if (!spec->no_analog && !spec->cap_mixer)
4418 set_capture_mixer(codec);
4419
Takashi Iwai1d045db2011-07-07 18:23:21 +02004420 return 1;
4421}
4422
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004423static int alc880_parse_auto_config(struct hda_codec *codec)
4424{
4425 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
4426 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
4427 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4428}
4429
Takashi Iwai1d045db2011-07-07 18:23:21 +02004430/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004431 * ALC880 fix-ups
4432 */
4433enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004434 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004435 ALC880_FIXUP_GPIO2,
4436 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004437 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004438 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004439 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004440 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004441 ALC880_FIXUP_VOL_KNOB,
4442 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004443 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004444 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004445 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004446 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004447 ALC880_FIXUP_3ST_BASE,
4448 ALC880_FIXUP_3ST,
4449 ALC880_FIXUP_3ST_DIG,
4450 ALC880_FIXUP_5ST_BASE,
4451 ALC880_FIXUP_5ST,
4452 ALC880_FIXUP_5ST_DIG,
4453 ALC880_FIXUP_6ST_BASE,
4454 ALC880_FIXUP_6ST,
4455 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004456};
4457
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004458/* enable the volume-knob widget support on NID 0x21 */
4459static void alc880_fixup_vol_knob(struct hda_codec *codec,
4460 const struct alc_fixup *fix, int action)
4461{
4462 if (action == ALC_FIXUP_ACT_PROBE)
4463 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4464}
4465
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004466static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004467 [ALC880_FIXUP_GPIO1] = {
4468 .type = ALC_FIXUP_VERBS,
4469 .v.verbs = alc_gpio1_init_verbs,
4470 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004471 [ALC880_FIXUP_GPIO2] = {
4472 .type = ALC_FIXUP_VERBS,
4473 .v.verbs = alc_gpio2_init_verbs,
4474 },
4475 [ALC880_FIXUP_MEDION_RIM] = {
4476 .type = ALC_FIXUP_VERBS,
4477 .v.verbs = (const struct hda_verb[]) {
4478 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4479 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4480 { }
4481 },
4482 .chained = true,
4483 .chain_id = ALC880_FIXUP_GPIO2,
4484 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004485 [ALC880_FIXUP_LG] = {
4486 .type = ALC_FIXUP_PINS,
4487 .v.pins = (const struct alc_pincfg[]) {
4488 /* disable bogus unused pins */
4489 { 0x16, 0x411111f0 },
4490 { 0x18, 0x411111f0 },
4491 { 0x1a, 0x411111f0 },
4492 { }
4493 }
4494 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004495 [ALC880_FIXUP_W810] = {
4496 .type = ALC_FIXUP_PINS,
4497 .v.pins = (const struct alc_pincfg[]) {
4498 /* disable bogus unused pins */
4499 { 0x17, 0x411111f0 },
4500 { }
4501 },
4502 .chained = true,
4503 .chain_id = ALC880_FIXUP_GPIO2,
4504 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004505 [ALC880_FIXUP_EAPD_COEF] = {
4506 .type = ALC_FIXUP_VERBS,
4507 .v.verbs = (const struct hda_verb[]) {
4508 /* change to EAPD mode */
4509 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4510 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4511 {}
4512 },
4513 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004514 [ALC880_FIXUP_TCL_S700] = {
4515 .type = ALC_FIXUP_VERBS,
4516 .v.verbs = (const struct hda_verb[]) {
4517 /* change to EAPD mode */
4518 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4519 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4520 {}
4521 },
4522 .chained = true,
4523 .chain_id = ALC880_FIXUP_GPIO2,
4524 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004525 [ALC880_FIXUP_VOL_KNOB] = {
4526 .type = ALC_FIXUP_FUNC,
4527 .v.func = alc880_fixup_vol_knob,
4528 },
4529 [ALC880_FIXUP_FUJITSU] = {
4530 /* override all pins as BIOS on old Amilo is broken */
4531 .type = ALC_FIXUP_PINS,
4532 .v.pins = (const struct alc_pincfg[]) {
4533 { 0x14, 0x0121411f }, /* HP */
4534 { 0x15, 0x99030120 }, /* speaker */
4535 { 0x16, 0x99030130 }, /* bass speaker */
4536 { 0x17, 0x411111f0 }, /* N/A */
4537 { 0x18, 0x411111f0 }, /* N/A */
4538 { 0x19, 0x01a19950 }, /* mic-in */
4539 { 0x1a, 0x411111f0 }, /* N/A */
4540 { 0x1b, 0x411111f0 }, /* N/A */
4541 { 0x1c, 0x411111f0 }, /* N/A */
4542 { 0x1d, 0x411111f0 }, /* N/A */
4543 { 0x1e, 0x01454140 }, /* SPDIF out */
4544 { }
4545 },
4546 .chained = true,
4547 .chain_id = ALC880_FIXUP_VOL_KNOB,
4548 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004549 [ALC880_FIXUP_F1734] = {
4550 /* almost compatible with FUJITSU, but no bass and SPDIF */
4551 .type = ALC_FIXUP_PINS,
4552 .v.pins = (const struct alc_pincfg[]) {
4553 { 0x14, 0x0121411f }, /* HP */
4554 { 0x15, 0x99030120 }, /* speaker */
4555 { 0x16, 0x411111f0 }, /* N/A */
4556 { 0x17, 0x411111f0 }, /* N/A */
4557 { 0x18, 0x411111f0 }, /* N/A */
4558 { 0x19, 0x01a19950 }, /* mic-in */
4559 { 0x1a, 0x411111f0 }, /* N/A */
4560 { 0x1b, 0x411111f0 }, /* N/A */
4561 { 0x1c, 0x411111f0 }, /* N/A */
4562 { 0x1d, 0x411111f0 }, /* N/A */
4563 { 0x1e, 0x411111f0 }, /* N/A */
4564 { }
4565 },
4566 .chained = true,
4567 .chain_id = ALC880_FIXUP_VOL_KNOB,
4568 },
Takashi Iwai817de922012-02-20 17:20:48 +01004569 [ALC880_FIXUP_UNIWILL] = {
4570 /* need to fix HP and speaker pins to be parsed correctly */
4571 .type = ALC_FIXUP_PINS,
4572 .v.pins = (const struct alc_pincfg[]) {
4573 { 0x14, 0x0121411f }, /* HP */
4574 { 0x15, 0x99030120 }, /* speaker */
4575 { 0x16, 0x99030130 }, /* bass speaker */
4576 { }
4577 },
4578 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004579 [ALC880_FIXUP_UNIWILL_DIG] = {
4580 .type = ALC_FIXUP_PINS,
4581 .v.pins = (const struct alc_pincfg[]) {
4582 /* disable bogus unused pins */
4583 { 0x17, 0x411111f0 },
4584 { 0x19, 0x411111f0 },
4585 { 0x1b, 0x411111f0 },
4586 { 0x1f, 0x411111f0 },
4587 { }
4588 }
4589 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004590 [ALC880_FIXUP_Z71V] = {
4591 .type = ALC_FIXUP_PINS,
4592 .v.pins = (const struct alc_pincfg[]) {
4593 /* set up the whole pins as BIOS is utterly broken */
4594 { 0x14, 0x99030120 }, /* speaker */
4595 { 0x15, 0x0121411f }, /* HP */
4596 { 0x16, 0x411111f0 }, /* N/A */
4597 { 0x17, 0x411111f0 }, /* N/A */
4598 { 0x18, 0x01a19950 }, /* mic-in */
4599 { 0x19, 0x411111f0 }, /* N/A */
4600 { 0x1a, 0x01813031 }, /* line-in */
4601 { 0x1b, 0x411111f0 }, /* N/A */
4602 { 0x1c, 0x411111f0 }, /* N/A */
4603 { 0x1d, 0x411111f0 }, /* N/A */
4604 { 0x1e, 0x0144111e }, /* SPDIF */
4605 { }
4606 }
4607 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004608 [ALC880_FIXUP_3ST_BASE] = {
4609 .type = ALC_FIXUP_PINS,
4610 .v.pins = (const struct alc_pincfg[]) {
4611 { 0x14, 0x01014010 }, /* line-out */
4612 { 0x15, 0x411111f0 }, /* N/A */
4613 { 0x16, 0x411111f0 }, /* N/A */
4614 { 0x17, 0x411111f0 }, /* N/A */
4615 { 0x18, 0x01a19c30 }, /* mic-in */
4616 { 0x19, 0x0121411f }, /* HP */
4617 { 0x1a, 0x01813031 }, /* line-in */
4618 { 0x1b, 0x02a19c40 }, /* front-mic */
4619 { 0x1c, 0x411111f0 }, /* N/A */
4620 { 0x1d, 0x411111f0 }, /* N/A */
4621 /* 0x1e is filled in below */
4622 { 0x1f, 0x411111f0 }, /* N/A */
4623 { }
4624 }
4625 },
4626 [ALC880_FIXUP_3ST] = {
4627 .type = ALC_FIXUP_PINS,
4628 .v.pins = (const struct alc_pincfg[]) {
4629 { 0x1e, 0x411111f0 }, /* N/A */
4630 { }
4631 },
4632 .chained = true,
4633 .chain_id = ALC880_FIXUP_3ST_BASE,
4634 },
4635 [ALC880_FIXUP_3ST_DIG] = {
4636 .type = ALC_FIXUP_PINS,
4637 .v.pins = (const struct alc_pincfg[]) {
4638 { 0x1e, 0x0144111e }, /* SPDIF */
4639 { }
4640 },
4641 .chained = true,
4642 .chain_id = ALC880_FIXUP_3ST_BASE,
4643 },
4644 [ALC880_FIXUP_5ST_BASE] = {
4645 .type = ALC_FIXUP_PINS,
4646 .v.pins = (const struct alc_pincfg[]) {
4647 { 0x14, 0x01014010 }, /* front */
4648 { 0x15, 0x411111f0 }, /* N/A */
4649 { 0x16, 0x01011411 }, /* CLFE */
4650 { 0x17, 0x01016412 }, /* surr */
4651 { 0x18, 0x01a19c30 }, /* mic-in */
4652 { 0x19, 0x0121411f }, /* HP */
4653 { 0x1a, 0x01813031 }, /* line-in */
4654 { 0x1b, 0x02a19c40 }, /* front-mic */
4655 { 0x1c, 0x411111f0 }, /* N/A */
4656 { 0x1d, 0x411111f0 }, /* N/A */
4657 /* 0x1e is filled in below */
4658 { 0x1f, 0x411111f0 }, /* N/A */
4659 { }
4660 }
4661 },
4662 [ALC880_FIXUP_5ST] = {
4663 .type = ALC_FIXUP_PINS,
4664 .v.pins = (const struct alc_pincfg[]) {
4665 { 0x1e, 0x411111f0 }, /* N/A */
4666 { }
4667 },
4668 .chained = true,
4669 .chain_id = ALC880_FIXUP_5ST_BASE,
4670 },
4671 [ALC880_FIXUP_5ST_DIG] = {
4672 .type = ALC_FIXUP_PINS,
4673 .v.pins = (const struct alc_pincfg[]) {
4674 { 0x1e, 0x0144111e }, /* SPDIF */
4675 { }
4676 },
4677 .chained = true,
4678 .chain_id = ALC880_FIXUP_5ST_BASE,
4679 },
4680 [ALC880_FIXUP_6ST_BASE] = {
4681 .type = ALC_FIXUP_PINS,
4682 .v.pins = (const struct alc_pincfg[]) {
4683 { 0x14, 0x01014010 }, /* front */
4684 { 0x15, 0x01016412 }, /* surr */
4685 { 0x16, 0x01011411 }, /* CLFE */
4686 { 0x17, 0x01012414 }, /* side */
4687 { 0x18, 0x01a19c30 }, /* mic-in */
4688 { 0x19, 0x02a19c40 }, /* front-mic */
4689 { 0x1a, 0x01813031 }, /* line-in */
4690 { 0x1b, 0x0121411f }, /* HP */
4691 { 0x1c, 0x411111f0 }, /* N/A */
4692 { 0x1d, 0x411111f0 }, /* N/A */
4693 /* 0x1e is filled in below */
4694 { 0x1f, 0x411111f0 }, /* N/A */
4695 { }
4696 }
4697 },
4698 [ALC880_FIXUP_6ST] = {
4699 .type = ALC_FIXUP_PINS,
4700 .v.pins = (const struct alc_pincfg[]) {
4701 { 0x1e, 0x411111f0 }, /* N/A */
4702 { }
4703 },
4704 .chained = true,
4705 .chain_id = ALC880_FIXUP_6ST_BASE,
4706 },
4707 [ALC880_FIXUP_6ST_DIG] = {
4708 .type = ALC_FIXUP_PINS,
4709 .v.pins = (const struct alc_pincfg[]) {
4710 { 0x1e, 0x0144111e }, /* SPDIF */
4711 { }
4712 },
4713 .chained = true,
4714 .chain_id = ALC880_FIXUP_6ST_BASE,
4715 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004716};
4717
4718static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004719 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004720 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004721 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4722 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004723 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004724 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004725 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004726 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004727 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004728 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004729 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004730 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004731 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004732 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004733 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004734 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4735 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4736 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004737 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004738
4739 /* Below is the copied entries from alc880_quirks.c.
4740 * It's not quite sure whether BIOS sets the correct pin-config table
4741 * on these machines, thus they are kept to be compatible with
4742 * the old static quirks. Once when it's confirmed to work without
4743 * these overrides, it'd be better to remove.
4744 */
4745 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4746 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4747 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4748 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4749 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4750 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4751 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4752 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4753 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4754 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4755 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4756 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4757 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4758 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4759 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4760 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4761 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4762 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4763 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4764 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4765 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4766 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4767 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4768 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4769 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4770 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4771 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4772 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4773 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4774 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4775 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4776 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4777 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4778 /* default Intel */
4779 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4780 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4781 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4782 {}
4783};
4784
4785static const struct alc_model_fixup alc880_fixup_models[] = {
4786 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4787 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4788 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4789 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4790 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4791 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004792 {}
4793};
4794
4795
4796/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004797 * OK, here we have finally the patch for ALC880
4798 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004799static int patch_alc880(struct hda_codec *codec)
4800{
4801 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004802 int err;
4803
4804 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4805 if (spec == NULL)
4806 return -ENOMEM;
4807
4808 codec->spec = spec;
4809
4810 spec->mixer_nid = 0x0b;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004811 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004812
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004813 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4814 alc880_fixups);
4815 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004816
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004817 /* automatic parse from the BIOS config */
4818 err = alc880_parse_auto_config(codec);
4819 if (err < 0)
4820 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004821
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004822 if (!spec->no_analog) {
4823 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004824 if (err < 0)
4825 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004826 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4827 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004828
Takashi Iwai1d045db2011-07-07 18:23:21 +02004829 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004830
Takashi Iwai589876e2012-02-20 15:47:55 +01004831 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4832
Takashi Iwai1d045db2011-07-07 18:23:21 +02004833 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004834
4835 error:
4836 alc_free(codec);
4837 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004838}
4839
4840
4841/*
4842 * ALC260 support
4843 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004844static int alc260_parse_auto_config(struct hda_codec *codec)
4845{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004846 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004847 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4848 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004849}
4850
Takashi Iwai1d045db2011-07-07 18:23:21 +02004851/*
4852 * Pin config fixes
4853 */
4854enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004855 ALC260_FIXUP_HP_DC5750,
4856 ALC260_FIXUP_HP_PIN_0F,
4857 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004858 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004859 ALC260_FIXUP_GPIO1_TOGGLE,
4860 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004861 ALC260_FIXUP_HP_B1900,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004862};
4863
Takashi Iwai20f7d922012-02-16 12:35:16 +01004864static void alc260_gpio1_automute(struct hda_codec *codec)
4865{
4866 struct alc_spec *spec = codec->spec;
4867 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4868 spec->hp_jack_present);
4869}
4870
4871static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4872 const struct alc_fixup *fix, int action)
4873{
4874 struct alc_spec *spec = codec->spec;
4875 if (action == ALC_FIXUP_ACT_PROBE) {
4876 /* although the machine has only one output pin, we need to
4877 * toggle GPIO1 according to the jack state
4878 */
4879 spec->automute_hook = alc260_gpio1_automute;
4880 spec->detect_hp = 1;
4881 spec->automute_speaker = 1;
4882 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4883 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4884 spec->unsol_event = alc_sku_unsol_event;
4885 add_verb(codec->spec, alc_gpio1_init_verbs);
4886 }
4887}
4888
Takashi Iwai1d045db2011-07-07 18:23:21 +02004889static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004890 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004891 .type = ALC_FIXUP_PINS,
4892 .v.pins = (const struct alc_pincfg[]) {
4893 { 0x11, 0x90130110 }, /* speaker */
4894 { }
4895 }
4896 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004897 [ALC260_FIXUP_HP_PIN_0F] = {
4898 .type = ALC_FIXUP_PINS,
4899 .v.pins = (const struct alc_pincfg[]) {
4900 { 0x0f, 0x01214000 }, /* HP */
4901 { }
4902 }
4903 },
4904 [ALC260_FIXUP_COEF] = {
4905 .type = ALC_FIXUP_VERBS,
4906 .v.verbs = (const struct hda_verb[]) {
4907 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4908 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4909 { }
4910 },
4911 .chained = true,
4912 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4913 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004914 [ALC260_FIXUP_GPIO1] = {
4915 .type = ALC_FIXUP_VERBS,
4916 .v.verbs = alc_gpio1_init_verbs,
4917 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004918 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4919 .type = ALC_FIXUP_FUNC,
4920 .v.func = alc260_fixup_gpio1_toggle,
4921 .chained = true,
4922 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4923 },
4924 [ALC260_FIXUP_REPLACER] = {
4925 .type = ALC_FIXUP_VERBS,
4926 .v.verbs = (const struct hda_verb[]) {
4927 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4928 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4929 { }
4930 },
4931 .chained = true,
4932 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4933 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004934 [ALC260_FIXUP_HP_B1900] = {
4935 .type = ALC_FIXUP_FUNC,
4936 .v.func = alc260_fixup_gpio1_toggle,
4937 .chained = true,
4938 .chain_id = ALC260_FIXUP_COEF,
4939 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004940};
4941
4942static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004943 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004944 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004945 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004946 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004947 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004948 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004949 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004950 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004951 {}
4952};
4953
4954/*
4955 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004956static int patch_alc260(struct hda_codec *codec)
4957{
4958 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004959 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004960
4961 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4962 if (spec == NULL)
4963 return -ENOMEM;
4964
4965 codec->spec = spec;
4966
4967 spec->mixer_nid = 0x07;
4968
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004969 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4970 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004971
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004972 /* automatic parse from the BIOS config */
4973 err = alc260_parse_auto_config(codec);
4974 if (err < 0)
4975 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004976
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004977 if (!spec->no_analog) {
4978 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004979 if (err < 0)
4980 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004981 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4982 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004983
Takashi Iwai1d045db2011-07-07 18:23:21 +02004984 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004985 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004986
Takashi Iwai589876e2012-02-20 15:47:55 +01004987 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4988
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004990
4991 error:
4992 alc_free(codec);
4993 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004994}
4995
4996
4997/*
4998 * ALC882/883/885/888/889 support
4999 *
5000 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5001 * configuration. Each pin widget can choose any input DACs and a mixer.
5002 * Each ADC is connected from a mixer of all inputs. This makes possible
5003 * 6-channel independent captures.
5004 *
5005 * In addition, an independent DAC for the multi-playback (not used in this
5006 * driver yet).
5007 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005008
5009/*
5010 * Pin config fixes
5011 */
5012enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005013 ALC882_FIXUP_ABIT_AW9D_MAX,
5014 ALC882_FIXUP_LENOVO_Y530,
5015 ALC882_FIXUP_PB_M5210,
5016 ALC882_FIXUP_ACER_ASPIRE_7736,
5017 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005018 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005019 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005020 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005021 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005022 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005023 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005024 ALC882_FIXUP_GPIO1,
5025 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005026 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005027 ALC889_FIXUP_COEF,
5028 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005029 ALC882_FIXUP_ACER_ASPIRE_4930G,
5030 ALC882_FIXUP_ACER_ASPIRE_8930G,
5031 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005032 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005033 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005034 ALC889_FIXUP_MBP_VREF,
5035 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005036};
5037
Takashi Iwai68ef0562011-11-09 18:24:44 +01005038static void alc889_fixup_coef(struct hda_codec *codec,
5039 const struct alc_fixup *fix, int action)
5040{
5041 if (action != ALC_FIXUP_ACT_INIT)
5042 return;
5043 alc889_coef_init(codec);
5044}
5045
Takashi Iwai56710872011-11-14 17:42:11 +01005046/* toggle speaker-output according to the hp-jack state */
5047static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5048{
5049 unsigned int gpiostate, gpiomask, gpiodir;
5050
5051 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5052 AC_VERB_GET_GPIO_DATA, 0);
5053
5054 if (!muted)
5055 gpiostate |= (1 << pin);
5056 else
5057 gpiostate &= ~(1 << pin);
5058
5059 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5060 AC_VERB_GET_GPIO_MASK, 0);
5061 gpiomask |= (1 << pin);
5062
5063 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5064 AC_VERB_GET_GPIO_DIRECTION, 0);
5065 gpiodir |= (1 << pin);
5066
5067
5068 snd_hda_codec_write(codec, codec->afg, 0,
5069 AC_VERB_SET_GPIO_MASK, gpiomask);
5070 snd_hda_codec_write(codec, codec->afg, 0,
5071 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5072
5073 msleep(1);
5074
5075 snd_hda_codec_write(codec, codec->afg, 0,
5076 AC_VERB_SET_GPIO_DATA, gpiostate);
5077}
5078
5079/* set up GPIO at initialization */
5080static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5081 const struct alc_fixup *fix, int action)
5082{
5083 if (action != ALC_FIXUP_ACT_INIT)
5084 return;
5085 alc882_gpio_mute(codec, 0, 0);
5086 alc882_gpio_mute(codec, 1, 0);
5087}
5088
Takashi Iwai02a237b2012-02-13 15:25:07 +01005089/* Fix the connection of some pins for ALC889:
5090 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5091 * work correctly (bko#42740)
5092 */
5093static void alc889_fixup_dac_route(struct hda_codec *codec,
5094 const struct alc_fixup *fix, int action)
5095{
5096 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005097 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005098 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5099 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5100 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5101 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5102 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5103 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005104 } else if (action == ALC_FIXUP_ACT_PROBE) {
5105 /* restore the connections */
5106 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5107 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5108 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5109 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5110 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005111 }
5112}
5113
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005114/* Set VREF on HP pin */
5115static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5116 const struct alc_fixup *fix, int action)
5117{
5118 struct alc_spec *spec = codec->spec;
5119 static hda_nid_t nids[2] = { 0x14, 0x15 };
5120 int i;
5121
5122 if (action != ALC_FIXUP_ACT_INIT)
5123 return;
5124 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5125 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5126 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5127 continue;
5128 val = snd_hda_codec_read(codec, nids[i], 0,
5129 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5130 val |= AC_PINCTL_VREF_80;
5131 snd_hda_codec_write(codec, nids[i], 0,
5132 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5133 spec->keep_vref_in_automute = 1;
5134 break;
5135 }
5136}
5137
5138/* Set VREF on speaker pins on imac91 */
5139static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5140 const struct alc_fixup *fix, int action)
5141{
5142 struct alc_spec *spec = codec->spec;
5143 static hda_nid_t nids[2] = { 0x18, 0x1a };
5144 int i;
5145
5146 if (action != ALC_FIXUP_ACT_INIT)
5147 return;
5148 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5149 unsigned int val;
5150 val = snd_hda_codec_read(codec, nids[i], 0,
5151 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5152 val |= AC_PINCTL_VREF_50;
5153 snd_hda_codec_write(codec, nids[i], 0,
5154 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
5155 }
5156 spec->keep_vref_in_automute = 1;
5157}
5158
Takashi Iwai1d045db2011-07-07 18:23:21 +02005159static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005160 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005161 .type = ALC_FIXUP_PINS,
5162 .v.pins = (const struct alc_pincfg[]) {
5163 { 0x15, 0x01080104 }, /* side */
5164 { 0x16, 0x01011012 }, /* rear */
5165 { 0x17, 0x01016011 }, /* clfe */
5166 { }
5167 }
5168 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005169 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005170 .type = ALC_FIXUP_PINS,
5171 .v.pins = (const struct alc_pincfg[]) {
5172 { 0x15, 0x99130112 }, /* rear int speakers */
5173 { 0x16, 0x99130111 }, /* subwoofer */
5174 { }
5175 }
5176 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005177 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005178 .type = ALC_FIXUP_VERBS,
5179 .v.verbs = (const struct hda_verb[]) {
5180 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5181 {}
5182 }
5183 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005184 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005185 .type = ALC_FIXUP_SKU,
5186 .v.sku = ALC_FIXUP_SKU_IGNORE,
5187 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005188 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005189 .type = ALC_FIXUP_PINS,
5190 .v.pins = (const struct alc_pincfg[]) {
5191 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5192 { }
5193 }
5194 },
Marton Balint8f239212012-03-05 21:33:23 +01005195 [ALC889_FIXUP_CD] = {
5196 .type = ALC_FIXUP_PINS,
5197 .v.pins = (const struct alc_pincfg[]) {
5198 { 0x1c, 0x993301f0 }, /* CD */
5199 { }
5200 }
5201 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005202 [ALC889_FIXUP_VAIO_TT] = {
5203 .type = ALC_FIXUP_PINS,
5204 .v.pins = (const struct alc_pincfg[]) {
5205 { 0x17, 0x90170111 }, /* hidden surround speaker */
5206 { }
5207 }
5208 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005209 [ALC888_FIXUP_EEE1601] = {
5210 .type = ALC_FIXUP_VERBS,
5211 .v.verbs = (const struct hda_verb[]) {
5212 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5213 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5214 { }
5215 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005216 },
5217 [ALC882_FIXUP_EAPD] = {
5218 .type = ALC_FIXUP_VERBS,
5219 .v.verbs = (const struct hda_verb[]) {
5220 /* change to EAPD mode */
5221 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5222 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5223 { }
5224 }
5225 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005226 [ALC883_FIXUP_EAPD] = {
5227 .type = ALC_FIXUP_VERBS,
5228 .v.verbs = (const struct hda_verb[]) {
5229 /* change to EAPD mode */
5230 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5231 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5232 { }
5233 }
5234 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005235 [ALC883_FIXUP_ACER_EAPD] = {
5236 .type = ALC_FIXUP_VERBS,
5237 .v.verbs = (const struct hda_verb[]) {
5238 /* eanable EAPD on Acer laptops */
5239 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5240 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5241 { }
5242 }
5243 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005244 [ALC882_FIXUP_GPIO1] = {
5245 .type = ALC_FIXUP_VERBS,
5246 .v.verbs = alc_gpio1_init_verbs,
5247 },
5248 [ALC882_FIXUP_GPIO2] = {
5249 .type = ALC_FIXUP_VERBS,
5250 .v.verbs = alc_gpio2_init_verbs,
5251 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005252 [ALC882_FIXUP_GPIO3] = {
5253 .type = ALC_FIXUP_VERBS,
5254 .v.verbs = alc_gpio3_init_verbs,
5255 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005256 [ALC882_FIXUP_ASUS_W2JC] = {
5257 .type = ALC_FIXUP_VERBS,
5258 .v.verbs = alc_gpio1_init_verbs,
5259 .chained = true,
5260 .chain_id = ALC882_FIXUP_EAPD,
5261 },
5262 [ALC889_FIXUP_COEF] = {
5263 .type = ALC_FIXUP_FUNC,
5264 .v.func = alc889_fixup_coef,
5265 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005266 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5267 .type = ALC_FIXUP_PINS,
5268 .v.pins = (const struct alc_pincfg[]) {
5269 { 0x16, 0x99130111 }, /* CLFE speaker */
5270 { 0x17, 0x99130112 }, /* surround speaker */
5271 { }
5272 }
5273 },
5274 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5275 .type = ALC_FIXUP_PINS,
5276 .v.pins = (const struct alc_pincfg[]) {
5277 { 0x16, 0x99130111 }, /* CLFE speaker */
5278 { 0x1b, 0x99130112 }, /* surround speaker */
5279 { }
5280 },
5281 .chained = true,
5282 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5283 },
5284 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5285 /* additional init verbs for Acer Aspire 8930G */
5286 .type = ALC_FIXUP_VERBS,
5287 .v.verbs = (const struct hda_verb[]) {
5288 /* Enable all DACs */
5289 /* DAC DISABLE/MUTE 1? */
5290 /* setting bits 1-5 disables DAC nids 0x02-0x06
5291 * apparently. Init=0x38 */
5292 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5293 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5294 /* DAC DISABLE/MUTE 2? */
5295 /* some bit here disables the other DACs.
5296 * Init=0x4900 */
5297 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5298 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5299 /* DMIC fix
5300 * This laptop has a stereo digital microphone.
5301 * The mics are only 1cm apart which makes the stereo
5302 * useless. However, either the mic or the ALC889
5303 * makes the signal become a difference/sum signal
5304 * instead of standard stereo, which is annoying.
5305 * So instead we flip this bit which makes the
5306 * codec replicate the sum signal to both channels,
5307 * turning it into a normal mono mic.
5308 */
5309 /* DMIC_CONTROL? Init value = 0x0001 */
5310 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5311 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5312 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5313 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5314 { }
5315 }
5316 },
Takashi Iwai56710872011-11-14 17:42:11 +01005317 [ALC885_FIXUP_MACPRO_GPIO] = {
5318 .type = ALC_FIXUP_FUNC,
5319 .v.func = alc885_fixup_macpro_gpio,
5320 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005321 [ALC889_FIXUP_DAC_ROUTE] = {
5322 .type = ALC_FIXUP_FUNC,
5323 .v.func = alc889_fixup_dac_route,
5324 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005325 [ALC889_FIXUP_MBP_VREF] = {
5326 .type = ALC_FIXUP_FUNC,
5327 .v.func = alc889_fixup_mbp_vref,
5328 .chained = true,
5329 .chain_id = ALC882_FIXUP_GPIO1,
5330 },
5331 [ALC889_FIXUP_IMAC91_VREF] = {
5332 .type = ALC_FIXUP_FUNC,
5333 .v.func = alc889_fixup_imac91_vref,
5334 .chained = true,
5335 .chain_id = ALC882_FIXUP_GPIO1,
5336 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005337};
5338
5339static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005340 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5341 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5342 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5343 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5344 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5345 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005346 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5347 ALC882_FIXUP_ACER_ASPIRE_4930G),
5348 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5349 ALC882_FIXUP_ACER_ASPIRE_4930G),
5350 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5351 ALC882_FIXUP_ACER_ASPIRE_8930G),
5352 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5353 ALC882_FIXUP_ACER_ASPIRE_8930G),
5354 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5355 ALC882_FIXUP_ACER_ASPIRE_4930G),
5356 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5357 ALC882_FIXUP_ACER_ASPIRE_4930G),
5358 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5359 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005360 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005361 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005362 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005363 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005364 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005365 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005366 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005367 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005368
5369 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005370 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5371 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5372 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005373 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5374 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5375 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005376 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5377 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005378 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005379 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5380 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5381 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5382 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005383 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005384 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5385 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5386 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
5387 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5388 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5389 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005390
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005391 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005392 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005393 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005394 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005395 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5396 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005397 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005398 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005399 {}
5400};
5401
5402/*
5403 * BIOS auto configuration
5404 */
5405/* almost identical with ALC880 parser... */
5406static int alc882_parse_auto_config(struct hda_codec *codec)
5407{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005408 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005409 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5410 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005411}
5412
Takashi Iwai1d045db2011-07-07 18:23:21 +02005413/*
5414 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005415static int patch_alc882(struct hda_codec *codec)
5416{
5417 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005418 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005419
5420 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5421 if (spec == NULL)
5422 return -ENOMEM;
5423
5424 codec->spec = spec;
5425
5426 spec->mixer_nid = 0x0b;
5427
5428 switch (codec->vendor_id) {
5429 case 0x10ec0882:
5430 case 0x10ec0885:
5431 break;
5432 default:
5433 /* ALC883 and variants */
5434 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5435 break;
5436 }
5437
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005438 err = alc_codec_rename_from_preset(codec);
5439 if (err < 0)
5440 goto error;
5441
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005442 alc_pick_fixup(codec, NULL, alc882_fixup_tbl, alc882_fixups);
5443 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005444
5445 alc_auto_parse_customize_define(codec);
5446
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005447 /* automatic parse from the BIOS config */
5448 err = alc882_parse_auto_config(codec);
5449 if (err < 0)
5450 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005452 if (!spec->no_analog && has_cdefine_beep(codec)) {
5453 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005454 if (err < 0)
5455 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005456 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005457 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005458
Takashi Iwai1d045db2011-07-07 18:23:21 +02005459 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005460
Takashi Iwai589876e2012-02-20 15:47:55 +01005461 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5462
Takashi Iwai1d045db2011-07-07 18:23:21 +02005463 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005464
5465 error:
5466 alc_free(codec);
5467 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005468}
5469
5470
5471/*
5472 * ALC262 support
5473 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005474static int alc262_parse_auto_config(struct hda_codec *codec)
5475{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005476 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005477 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5478 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005479}
5480
5481/*
5482 * Pin config fixes
5483 */
5484enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005485 ALC262_FIXUP_FSC_H270,
5486 ALC262_FIXUP_HP_Z200,
5487 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005488 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005489 ALC262_FIXUP_BENQ,
5490 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005491};
5492
5493static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005494 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005495 .type = ALC_FIXUP_PINS,
5496 .v.pins = (const struct alc_pincfg[]) {
5497 { 0x14, 0x99130110 }, /* speaker */
5498 { 0x15, 0x0221142f }, /* front HP */
5499 { 0x1b, 0x0121141f }, /* rear HP */
5500 { }
5501 }
5502 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005503 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005504 .type = ALC_FIXUP_PINS,
5505 .v.pins = (const struct alc_pincfg[]) {
5506 { 0x16, 0x99130120 }, /* internal speaker */
5507 { }
5508 }
5509 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005510 [ALC262_FIXUP_TYAN] = {
5511 .type = ALC_FIXUP_PINS,
5512 .v.pins = (const struct alc_pincfg[]) {
5513 { 0x14, 0x1993e1f0 }, /* int AUX */
5514 { }
5515 }
5516 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005517 [ALC262_FIXUP_LENOVO_3000] = {
5518 .type = ALC_FIXUP_VERBS,
5519 .v.verbs = (const struct hda_verb[]) {
5520 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005521 {}
5522 },
5523 .chained = true,
5524 .chain_id = ALC262_FIXUP_BENQ,
5525 },
5526 [ALC262_FIXUP_BENQ] = {
5527 .type = ALC_FIXUP_VERBS,
5528 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005529 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5530 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5531 {}
5532 }
5533 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005534 [ALC262_FIXUP_BENQ_T31] = {
5535 .type = ALC_FIXUP_VERBS,
5536 .v.verbs = (const struct hda_verb[]) {
5537 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5538 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5539 {}
5540 }
5541 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005542};
5543
5544static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005545 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005546 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5547 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005548 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5549 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005550 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005551 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5552 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005553 {}
5554};
5555
5556
Takashi Iwai1d045db2011-07-07 18:23:21 +02005557/*
5558 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005559static int patch_alc262(struct hda_codec *codec)
5560{
5561 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005562 int err;
5563
5564 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5565 if (spec == NULL)
5566 return -ENOMEM;
5567
5568 codec->spec = spec;
5569
5570 spec->mixer_nid = 0x0b;
5571
5572#if 0
5573 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5574 * under-run
5575 */
5576 {
5577 int tmp;
5578 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5579 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5580 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5581 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5582 }
5583#endif
5584 alc_auto_parse_customize_define(codec);
5585
5586 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5587
Takashi Iwai42399f72011-11-07 17:18:44 +01005588 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5589 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005590
Takashi Iwai42399f72011-11-07 17:18:44 +01005591 /* automatic parse from the BIOS config */
5592 err = alc262_parse_auto_config(codec);
5593 if (err < 0)
5594 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005595
Takashi Iwai1d045db2011-07-07 18:23:21 +02005596 if (!spec->no_analog && has_cdefine_beep(codec)) {
5597 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005598 if (err < 0)
5599 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005600 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005601 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005602
Takashi Iwai1d045db2011-07-07 18:23:21 +02005603 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604 spec->shutup = alc_eapd_shutup;
5605
Takashi Iwai589876e2012-02-20 15:47:55 +01005606 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5607
Takashi Iwai1d045db2011-07-07 18:23:21 +02005608 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005609
5610 error:
5611 alc_free(codec);
5612 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005613}
5614
5615/*
5616 * ALC268
5617 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005618/* bind Beep switches of both NID 0x0f and 0x10 */
5619static const struct hda_bind_ctls alc268_bind_beep_sw = {
5620 .ops = &snd_hda_bind_sw,
5621 .values = {
5622 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5623 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5624 0
5625 },
5626};
5627
5628static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5629 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5630 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5631 { }
5632};
5633
5634/* set PCBEEP vol = 0, mute connections */
5635static const struct hda_verb alc268_beep_init_verbs[] = {
5636 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5637 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5638 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5639 { }
5640};
5641
5642/*
5643 * BIOS auto configuration
5644 */
5645static int alc268_parse_auto_config(struct hda_codec *codec)
5646{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005647 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005648 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005649 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5650 if (err > 0) {
5651 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5652 add_mixer(spec, alc268_beep_mixer);
5653 add_verb(spec, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005654 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005655 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005656 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657}
5658
Takashi Iwai1d045db2011-07-07 18:23:21 +02005659/*
5660 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005661static int patch_alc268(struct hda_codec *codec)
5662{
5663 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005664 int i, has_beep, err;
5665
5666 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5667 if (spec == NULL)
5668 return -ENOMEM;
5669
5670 codec->spec = spec;
5671
5672 /* ALC268 has no aa-loopback mixer */
5673
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005674 /* automatic parse from the BIOS config */
5675 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005676 if (err < 0)
5677 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005678
Takashi Iwai1d045db2011-07-07 18:23:21 +02005679 has_beep = 0;
5680 for (i = 0; i < spec->num_mixers; i++) {
5681 if (spec->mixers[i] == alc268_beep_mixer) {
5682 has_beep = 1;
5683 break;
5684 }
5685 }
5686
5687 if (has_beep) {
5688 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005689 if (err < 0)
5690 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005691 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5692 /* override the amp caps for beep generator */
5693 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5694 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5695 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5696 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5697 (0 << AC_AMPCAP_MUTE_SHIFT));
5698 }
5699
Takashi Iwai1d045db2011-07-07 18:23:21 +02005700 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005701 spec->shutup = alc_eapd_shutup;
5702
Takashi Iwai1d045db2011-07-07 18:23:21 +02005703 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005704
5705 error:
5706 alc_free(codec);
5707 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005708}
5709
5710/*
5711 * ALC269
5712 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005713static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5714 .substreams = 1,
5715 .channels_min = 2,
5716 .channels_max = 8,
5717 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5718 /* NID is set in alc_build_pcms */
5719 .ops = {
5720 .open = alc_playback_pcm_open,
5721 .prepare = alc_playback_pcm_prepare,
5722 .cleanup = alc_playback_pcm_cleanup
5723 },
5724};
5725
5726static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5727 .substreams = 1,
5728 .channels_min = 2,
5729 .channels_max = 2,
5730 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5731 /* NID is set in alc_build_pcms */
5732};
5733
Takashi Iwai1d045db2011-07-07 18:23:21 +02005734/* different alc269-variants */
5735enum {
5736 ALC269_TYPE_ALC269VA,
5737 ALC269_TYPE_ALC269VB,
5738 ALC269_TYPE_ALC269VC,
5739};
5740
5741/*
5742 * BIOS auto configuration
5743 */
5744static int alc269_parse_auto_config(struct hda_codec *codec)
5745{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005746 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005747 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5748 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5749 struct alc_spec *spec = codec->spec;
5750 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5751 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005752
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005753 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005754}
5755
Takashi Iwai1d045db2011-07-07 18:23:21 +02005756static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5757{
5758 int val = alc_read_coef_idx(codec, 0x04);
5759 if (power_up)
5760 val |= 1 << 11;
5761 else
5762 val &= ~(1 << 11);
5763 alc_write_coef_idx(codec, 0x04, val);
5764}
5765
5766static void alc269_shutup(struct hda_codec *codec)
5767{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005768 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005769 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005770 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005771 alc269_toggle_power_output(codec, 0);
5772 msleep(150);
5773 }
5774}
5775
Takashi Iwai2a439522011-07-26 09:52:50 +02005776#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005777static int alc269_resume(struct hda_codec *codec)
5778{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005779 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005780 alc269_toggle_power_output(codec, 0);
5781 msleep(150);
5782 }
5783
5784 codec->patch_ops.init(codec);
5785
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005786 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005787 alc269_toggle_power_output(codec, 1);
5788 msleep(200);
5789 }
5790
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005791 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005792 alc269_toggle_power_output(codec, 1);
5793
5794 snd_hda_codec_resume_amp(codec);
5795 snd_hda_codec_resume_cache(codec);
5796 hda_call_check_power_status(codec, 0x01);
5797 return 0;
5798}
Takashi Iwai2a439522011-07-26 09:52:50 +02005799#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005800
5801static void alc269_fixup_hweq(struct hda_codec *codec,
5802 const struct alc_fixup *fix, int action)
5803{
5804 int coef;
5805
5806 if (action != ALC_FIXUP_ACT_INIT)
5807 return;
5808 coef = alc_read_coef_idx(codec, 0x1e);
5809 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5810}
5811
5812static void alc271_fixup_dmic(struct hda_codec *codec,
5813 const struct alc_fixup *fix, int action)
5814{
5815 static const struct hda_verb verbs[] = {
5816 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5817 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5818 {}
5819 };
5820 unsigned int cfg;
5821
5822 if (strcmp(codec->chip_name, "ALC271X"))
5823 return;
5824 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5825 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5826 snd_hda_sequence_write(codec, verbs);
5827}
5828
Takashi Iwai017f2a12011-07-09 14:42:25 +02005829static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5830 const struct alc_fixup *fix, int action)
5831{
5832 struct alc_spec *spec = codec->spec;
5833
5834 if (action != ALC_FIXUP_ACT_PROBE)
5835 return;
5836
5837 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5838 * fix the sample rate of analog I/O to 44.1kHz
5839 */
5840 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5841 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5842}
5843
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005844static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5845 const struct alc_fixup *fix, int action)
5846{
5847 int coef;
5848
5849 if (action != ALC_FIXUP_ACT_INIT)
5850 return;
5851 /* The digital-mic unit sends PDM (differential signal) instead of
5852 * the standard PCM, thus you can't record a valid mono stream as is.
5853 * Below is a workaround specific to ALC269 to control the dmic
5854 * signal source as mono.
5855 */
5856 coef = alc_read_coef_idx(codec, 0x07);
5857 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5858}
5859
Takashi Iwai24519912011-08-16 15:08:49 +02005860static void alc269_quanta_automute(struct hda_codec *codec)
5861{
David Henningsson42cf0d02011-09-20 12:04:56 +02005862 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005863
5864 snd_hda_codec_write(codec, 0x20, 0,
5865 AC_VERB_SET_COEF_INDEX, 0x0c);
5866 snd_hda_codec_write(codec, 0x20, 0,
5867 AC_VERB_SET_PROC_COEF, 0x680);
5868
5869 snd_hda_codec_write(codec, 0x20, 0,
5870 AC_VERB_SET_COEF_INDEX, 0x0c);
5871 snd_hda_codec_write(codec, 0x20, 0,
5872 AC_VERB_SET_PROC_COEF, 0x480);
5873}
5874
5875static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5876 const struct alc_fixup *fix, int action)
5877{
5878 struct alc_spec *spec = codec->spec;
5879 if (action != ALC_FIXUP_ACT_PROBE)
5880 return;
5881 spec->automute_hook = alc269_quanta_automute;
5882}
5883
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005884/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5885static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5886{
5887 struct hda_codec *codec = private_data;
5888 unsigned int pinval = enabled ? 0x20 : 0x24;
5889 snd_hda_codec_update_cache(codec, 0x19, 0,
5890 AC_VERB_SET_PIN_WIDGET_CONTROL,
5891 pinval);
5892}
5893
5894static void alc269_fixup_mic2_mute(struct hda_codec *codec,
5895 const struct alc_fixup *fix, int action)
5896{
5897 struct alc_spec *spec = codec->spec;
5898 switch (action) {
5899 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005900 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01005901 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005902 /* fallthru */
5903 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005904 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005905 break;
5906 }
5907}
5908
Takashi Iwai1d045db2011-07-07 18:23:21 +02005909enum {
5910 ALC269_FIXUP_SONY_VAIO,
5911 ALC275_FIXUP_SONY_VAIO_GPIO2,
5912 ALC269_FIXUP_DELL_M101Z,
5913 ALC269_FIXUP_SKU_IGNORE,
5914 ALC269_FIXUP_ASUS_G73JW,
5915 ALC269_FIXUP_LENOVO_EAPD,
5916 ALC275_FIXUP_SONY_HWEQ,
5917 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005918 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005919 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005920 ALC269_FIXUP_QUANTA_MUTE,
5921 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005922 ALC269_FIXUP_AMIC,
5923 ALC269_FIXUP_DMIC,
5924 ALC269VB_FIXUP_AMIC,
5925 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005926 ALC269_FIXUP_MIC2_MUTE_LED,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005927};
5928
5929static const struct alc_fixup alc269_fixups[] = {
5930 [ALC269_FIXUP_SONY_VAIO] = {
5931 .type = ALC_FIXUP_VERBS,
5932 .v.verbs = (const struct hda_verb[]) {
5933 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5934 {}
5935 }
5936 },
5937 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5938 .type = ALC_FIXUP_VERBS,
5939 .v.verbs = (const struct hda_verb[]) {
5940 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5941 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5942 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5943 { }
5944 },
5945 .chained = true,
5946 .chain_id = ALC269_FIXUP_SONY_VAIO
5947 },
5948 [ALC269_FIXUP_DELL_M101Z] = {
5949 .type = ALC_FIXUP_VERBS,
5950 .v.verbs = (const struct hda_verb[]) {
5951 /* Enables internal speaker */
5952 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5953 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5954 {}
5955 }
5956 },
5957 [ALC269_FIXUP_SKU_IGNORE] = {
5958 .type = ALC_FIXUP_SKU,
5959 .v.sku = ALC_FIXUP_SKU_IGNORE,
5960 },
5961 [ALC269_FIXUP_ASUS_G73JW] = {
5962 .type = ALC_FIXUP_PINS,
5963 .v.pins = (const struct alc_pincfg[]) {
5964 { 0x17, 0x99130111 }, /* subwoofer */
5965 { }
5966 }
5967 },
5968 [ALC269_FIXUP_LENOVO_EAPD] = {
5969 .type = ALC_FIXUP_VERBS,
5970 .v.verbs = (const struct hda_verb[]) {
5971 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5972 {}
5973 }
5974 },
5975 [ALC275_FIXUP_SONY_HWEQ] = {
5976 .type = ALC_FIXUP_FUNC,
5977 .v.func = alc269_fixup_hweq,
5978 .chained = true,
5979 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5980 },
5981 [ALC271_FIXUP_DMIC] = {
5982 .type = ALC_FIXUP_FUNC,
5983 .v.func = alc271_fixup_dmic,
5984 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005985 [ALC269_FIXUP_PCM_44K] = {
5986 .type = ALC_FIXUP_FUNC,
5987 .v.func = alc269_fixup_pcm_44k,
5988 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005989 [ALC269_FIXUP_STEREO_DMIC] = {
5990 .type = ALC_FIXUP_FUNC,
5991 .v.func = alc269_fixup_stereo_dmic,
5992 },
Takashi Iwai24519912011-08-16 15:08:49 +02005993 [ALC269_FIXUP_QUANTA_MUTE] = {
5994 .type = ALC_FIXUP_FUNC,
5995 .v.func = alc269_fixup_quanta_mute,
5996 },
5997 [ALC269_FIXUP_LIFEBOOK] = {
5998 .type = ALC_FIXUP_PINS,
5999 .v.pins = (const struct alc_pincfg[]) {
6000 { 0x1a, 0x2101103f }, /* dock line-out */
6001 { 0x1b, 0x23a11040 }, /* dock mic-in */
6002 { }
6003 },
6004 .chained = true,
6005 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6006 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006007 [ALC269_FIXUP_AMIC] = {
6008 .type = ALC_FIXUP_PINS,
6009 .v.pins = (const struct alc_pincfg[]) {
6010 { 0x14, 0x99130110 }, /* speaker */
6011 { 0x15, 0x0121401f }, /* HP out */
6012 { 0x18, 0x01a19c20 }, /* mic */
6013 { 0x19, 0x99a3092f }, /* int-mic */
6014 { }
6015 },
6016 },
6017 [ALC269_FIXUP_DMIC] = {
6018 .type = ALC_FIXUP_PINS,
6019 .v.pins = (const struct alc_pincfg[]) {
6020 { 0x12, 0x99a3092f }, /* int-mic */
6021 { 0x14, 0x99130110 }, /* speaker */
6022 { 0x15, 0x0121401f }, /* HP out */
6023 { 0x18, 0x01a19c20 }, /* mic */
6024 { }
6025 },
6026 },
6027 [ALC269VB_FIXUP_AMIC] = {
6028 .type = ALC_FIXUP_PINS,
6029 .v.pins = (const struct alc_pincfg[]) {
6030 { 0x14, 0x99130110 }, /* speaker */
6031 { 0x18, 0x01a19c20 }, /* mic */
6032 { 0x19, 0x99a3092f }, /* int-mic */
6033 { 0x21, 0x0121401f }, /* HP out */
6034 { }
6035 },
6036 },
David Henningsson2267ea92012-01-03 08:45:56 +01006037 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006038 .type = ALC_FIXUP_PINS,
6039 .v.pins = (const struct alc_pincfg[]) {
6040 { 0x12, 0x99a3092f }, /* int-mic */
6041 { 0x14, 0x99130110 }, /* speaker */
6042 { 0x18, 0x01a19c20 }, /* mic */
6043 { 0x21, 0x0121401f }, /* HP out */
6044 { }
6045 },
6046 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006047 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6048 .type = ALC_FIXUP_FUNC,
6049 .v.func = alc269_fixup_mic2_mute,
6050 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006051};
6052
6053static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006054 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006055 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006056 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6057 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6058 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6059 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6060 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006061 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6062 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6063 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6064 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6065 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6066 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006067 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006068 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6069 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6070 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6071 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6072 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006073 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006074 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006075 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006076
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006077#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006078 /* Below is a quirk table taken from the old code.
6079 * Basically the device should work as is without the fixup table.
6080 * If BIOS doesn't give a proper info, enable the corresponding
6081 * fixup entry.
6082 */
6083 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6084 ALC269_FIXUP_AMIC),
6085 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006086 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6087 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6088 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6089 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6090 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6091 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6092 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6093 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6094 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6095 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6096 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6097 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6098 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6099 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6100 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6101 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6102 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6103 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6104 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6105 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6106 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6107 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6108 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6109 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6110 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6111 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6112 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6113 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6114 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6115 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6116 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6117 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6118 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6119 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6120 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6121 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6122 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6123 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6124#endif
6125 {}
6126};
6127
6128static const struct alc_model_fixup alc269_fixup_models[] = {
6129 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6130 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006131 {}
6132};
6133
6134
Takashi Iwai546bb672012-03-07 08:37:19 +01006135static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006136{
Kailang Yang526af6e2012-03-07 08:25:20 +01006137 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006138 int val;
6139
Kailang Yang526af6e2012-03-07 08:25:20 +01006140 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006141 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006142
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006143 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006144 alc_write_coef_idx(codec, 0xf, 0x960b);
6145 alc_write_coef_idx(codec, 0xe, 0x8817);
6146 }
6147
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006148 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006149 alc_write_coef_idx(codec, 0xf, 0x960b);
6150 alc_write_coef_idx(codec, 0xe, 0x8814);
6151 }
6152
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006153 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006154 val = alc_read_coef_idx(codec, 0x04);
6155 /* Power up output pin */
6156 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6157 }
6158
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006159 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006160 val = alc_read_coef_idx(codec, 0xd);
6161 if ((val & 0x0c00) >> 10 != 0x1) {
6162 /* Capless ramp up clock control */
6163 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6164 }
6165 val = alc_read_coef_idx(codec, 0x17);
6166 if ((val & 0x01c0) >> 6 != 0x4) {
6167 /* Class D power on reset */
6168 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6169 }
6170 }
6171
6172 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6173 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6174
6175 val = alc_read_coef_idx(codec, 0x4); /* HP */
6176 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006177}
6178
6179/*
6180 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006181static int patch_alc269(struct hda_codec *codec)
6182{
6183 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006184 int err = 0;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006185
6186 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6187 if (spec == NULL)
6188 return -ENOMEM;
6189
6190 codec->spec = spec;
6191
6192 spec->mixer_nid = 0x0b;
6193
6194 alc_auto_parse_customize_define(codec);
6195
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006196 err = alc_codec_rename_from_preset(codec);
6197 if (err < 0)
6198 goto error;
6199
Takashi Iwai1d045db2011-07-07 18:23:21 +02006200 if (codec->vendor_id == 0x10ec0269) {
6201 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006202 switch (alc_get_coef0(codec) & 0x00f0) {
6203 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006204 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006205 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006206 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006207 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006208 break;
6209 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006210 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6211 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006212 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006213 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006214 break;
6215 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006216 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006217 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006218 if (err < 0)
6219 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006220 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006221 alc269_fill_coef(codec);
6222 }
6223
Takashi Iwaia4297b52011-08-23 18:40:12 +02006224 alc_pick_fixup(codec, alc269_fixup_models,
6225 alc269_fixup_tbl, alc269_fixups);
6226 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006227
Takashi Iwaia4297b52011-08-23 18:40:12 +02006228 /* automatic parse from the BIOS config */
6229 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006230 if (err < 0)
6231 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006232
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006233 if (!spec->no_analog && has_cdefine_beep(codec)) {
6234 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006235 if (err < 0)
6236 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006237 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006238 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006239
Takashi Iwai1d045db2011-07-07 18:23:21 +02006240 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006241#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006242 codec->patch_ops.resume = alc269_resume;
6243#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006244 spec->shutup = alc269_shutup;
6245
Takashi Iwai589876e2012-02-20 15:47:55 +01006246 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6247
Takashi Iwai1d045db2011-07-07 18:23:21 +02006248 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006249
6250 error:
6251 alc_free(codec);
6252 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006253}
6254
6255/*
6256 * ALC861
6257 */
6258
Takashi Iwai1d045db2011-07-07 18:23:21 +02006259static int alc861_parse_auto_config(struct hda_codec *codec)
6260{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006261 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006262 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6263 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006264}
6265
Takashi Iwai1d045db2011-07-07 18:23:21 +02006266/* Pin config fixes */
6267enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006268 ALC861_FIXUP_FSC_AMILO_PI1505,
6269 ALC861_FIXUP_AMP_VREF_0F,
6270 ALC861_FIXUP_NO_JACK_DETECT,
6271 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006272};
6273
Takashi Iwai31150f22012-01-30 10:54:08 +01006274/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6275static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6276 const struct alc_fixup *fix, int action)
6277{
6278 struct alc_spec *spec = codec->spec;
6279 unsigned int val;
6280
6281 if (action != ALC_FIXUP_ACT_INIT)
6282 return;
6283 val = snd_hda_codec_read(codec, 0x0f, 0,
6284 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6285 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6286 val |= AC_PINCTL_IN_EN;
6287 val |= AC_PINCTL_VREF_50;
6288 snd_hda_codec_write(codec, 0x0f, 0,
6289 AC_VERB_SET_PIN_WIDGET_CONTROL, val);
6290 spec->keep_vref_in_automute = 1;
6291}
6292
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006293/* suppress the jack-detection */
6294static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6295 const struct alc_fixup *fix, int action)
6296{
6297 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6298 codec->no_jack_detect = 1;
6299}
6300
Takashi Iwai1d045db2011-07-07 18:23:21 +02006301static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006302 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006303 .type = ALC_FIXUP_PINS,
6304 .v.pins = (const struct alc_pincfg[]) {
6305 { 0x0b, 0x0221101f }, /* HP */
6306 { 0x0f, 0x90170310 }, /* speaker */
6307 { }
6308 }
6309 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006310 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006311 .type = ALC_FIXUP_FUNC,
6312 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006313 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006314 [ALC861_FIXUP_NO_JACK_DETECT] = {
6315 .type = ALC_FIXUP_FUNC,
6316 .v.func = alc_fixup_no_jack_detect,
6317 },
6318 [ALC861_FIXUP_ASUS_A6RP] = {
6319 .type = ALC_FIXUP_FUNC,
6320 .v.func = alc861_fixup_asus_amp_vref_0f,
6321 .chained = true,
6322 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6323 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006324};
6325
6326static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006327 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6328 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6329 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6330 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6331 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6332 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006333 {}
6334};
6335
6336/*
6337 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006338static int patch_alc861(struct hda_codec *codec)
6339{
6340 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006341 int err;
6342
6343 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6344 if (spec == NULL)
6345 return -ENOMEM;
6346
6347 codec->spec = spec;
6348
6349 spec->mixer_nid = 0x15;
6350
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006351 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6352 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006353
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006354 /* automatic parse from the BIOS config */
6355 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006356 if (err < 0)
6357 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006358
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006359 if (!spec->no_analog) {
6360 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006361 if (err < 0)
6362 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006363 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6364 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006365
Takashi Iwai1d045db2011-07-07 18:23:21 +02006366 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006367#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006368 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006369#endif
6370
Takashi Iwai589876e2012-02-20 15:47:55 +01006371 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6372
Takashi Iwai1d045db2011-07-07 18:23:21 +02006373 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006374
6375 error:
6376 alc_free(codec);
6377 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006378}
6379
6380/*
6381 * ALC861-VD support
6382 *
6383 * Based on ALC882
6384 *
6385 * In addition, an independent DAC
6386 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006387static int alc861vd_parse_auto_config(struct hda_codec *codec)
6388{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006389 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006390 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6391 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006392}
6393
Takashi Iwai1d045db2011-07-07 18:23:21 +02006394enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006395 ALC660VD_FIX_ASUS_GPIO1,
6396 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006397};
6398
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006399/* exclude VREF80 */
6400static void alc861vd_fixup_dallas(struct hda_codec *codec,
6401 const struct alc_fixup *fix, int action)
6402{
6403 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6404 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6405 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6406 }
6407}
6408
Takashi Iwai1d045db2011-07-07 18:23:21 +02006409static const struct alc_fixup alc861vd_fixups[] = {
6410 [ALC660VD_FIX_ASUS_GPIO1] = {
6411 .type = ALC_FIXUP_VERBS,
6412 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006413 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006414 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6415 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6416 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6417 { }
6418 }
6419 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006420 [ALC861VD_FIX_DALLAS] = {
6421 .type = ALC_FIXUP_FUNC,
6422 .v.func = alc861vd_fixup_dallas,
6423 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006424};
6425
6426static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006427 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006428 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006429 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006430 {}
6431};
6432
6433static const struct hda_verb alc660vd_eapd_verbs[] = {
6434 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6435 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6436 { }
6437};
6438
6439/*
6440 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006441static int patch_alc861vd(struct hda_codec *codec)
6442{
6443 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006444 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006445
6446 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6447 if (spec == NULL)
6448 return -ENOMEM;
6449
6450 codec->spec = spec;
6451
6452 spec->mixer_nid = 0x0b;
6453
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006454 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6455 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006456
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006457 /* automatic parse from the BIOS config */
6458 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006459 if (err < 0)
6460 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006461
Takashi Iwai1d045db2011-07-07 18:23:21 +02006462 if (codec->vendor_id == 0x10ec0660) {
6463 /* always turn on EAPD */
6464 add_verb(spec, alc660vd_eapd_verbs);
6465 }
6466
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006467 if (!spec->no_analog) {
6468 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006469 if (err < 0)
6470 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006471 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6472 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006473
Takashi Iwai1d045db2011-07-07 18:23:21 +02006474 codec->patch_ops = alc_patch_ops;
6475
Takashi Iwai1d045db2011-07-07 18:23:21 +02006476 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006477
Takashi Iwai589876e2012-02-20 15:47:55 +01006478 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6479
Takashi Iwai1d045db2011-07-07 18:23:21 +02006480 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006481
6482 error:
6483 alc_free(codec);
6484 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006485}
6486
6487/*
6488 * ALC662 support
6489 *
6490 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6491 * configuration. Each pin widget can choose any input DACs and a mixer.
6492 * Each ADC is connected from a mixer of all inputs. This makes possible
6493 * 6-channel independent captures.
6494 *
6495 * In addition, an independent DAC for the multi-playback (not used in this
6496 * driver yet).
6497 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006498
6499/*
6500 * BIOS auto configuration
6501 */
6502
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006503static int alc662_parse_auto_config(struct hda_codec *codec)
6504{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006505 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006506 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6507 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6508 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006509
Kailang Yang6227cdc2010-02-25 08:36:52 +01006510 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6511 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006512 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006513 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006514 ssids = alc662_ssids;
6515 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006516}
6517
Todd Broch6be79482010-12-07 16:51:05 -08006518static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006519 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006520{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006521 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006522 return;
Todd Broch6be79482010-12-07 16:51:05 -08006523 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6524 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6525 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6526 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6527 (0 << AC_AMPCAP_MUTE_SHIFT)))
6528 printk(KERN_WARNING
6529 "hda_codec: failed to override amp caps for NID 0x2\n");
6530}
6531
David Henningsson6cb3b702010-09-09 08:51:44 +02006532enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006533 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006534 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006535 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006536 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006537 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006538 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006539 ALC662_FIXUP_ASUS_MODE1,
6540 ALC662_FIXUP_ASUS_MODE2,
6541 ALC662_FIXUP_ASUS_MODE3,
6542 ALC662_FIXUP_ASUS_MODE4,
6543 ALC662_FIXUP_ASUS_MODE5,
6544 ALC662_FIXUP_ASUS_MODE6,
6545 ALC662_FIXUP_ASUS_MODE7,
6546 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006547 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006548};
6549
6550static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006551 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006552 .type = ALC_FIXUP_PINS,
6553 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006554 { 0x15, 0x99130112 }, /* subwoofer */
6555 { }
6556 }
6557 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006558 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006559 .type = ALC_FIXUP_PINS,
6560 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006561 { 0x17, 0x99130112 }, /* subwoofer */
6562 { }
6563 }
6564 },
Todd Broch6be79482010-12-07 16:51:05 -08006565 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006566 .type = ALC_FIXUP_FUNC,
6567 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006568 },
6569 [ALC662_FIXUP_CZC_P10T] = {
6570 .type = ALC_FIXUP_VERBS,
6571 .v.verbs = (const struct hda_verb[]) {
6572 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6573 {}
6574 }
6575 },
David Henningsson94024cd2011-04-29 14:10:55 +02006576 [ALC662_FIXUP_SKU_IGNORE] = {
6577 .type = ALC_FIXUP_SKU,
6578 .v.sku = ALC_FIXUP_SKU_IGNORE,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006579 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006580 [ALC662_FIXUP_HP_RP5800] = {
6581 .type = ALC_FIXUP_PINS,
6582 .v.pins = (const struct alc_pincfg[]) {
6583 { 0x14, 0x0221201f }, /* HP out */
6584 { }
6585 },
6586 .chained = true,
6587 .chain_id = ALC662_FIXUP_SKU_IGNORE
6588 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006589 [ALC662_FIXUP_ASUS_MODE1] = {
6590 .type = ALC_FIXUP_PINS,
6591 .v.pins = (const struct alc_pincfg[]) {
6592 { 0x14, 0x99130110 }, /* speaker */
6593 { 0x18, 0x01a19c20 }, /* mic */
6594 { 0x19, 0x99a3092f }, /* int-mic */
6595 { 0x21, 0x0121401f }, /* HP out */
6596 { }
6597 },
6598 .chained = true,
6599 .chain_id = ALC662_FIXUP_SKU_IGNORE
6600 },
6601 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006602 .type = ALC_FIXUP_PINS,
6603 .v.pins = (const struct alc_pincfg[]) {
6604 { 0x14, 0x99130110 }, /* speaker */
6605 { 0x18, 0x01a19820 }, /* mic */
6606 { 0x19, 0x99a3092f }, /* int-mic */
6607 { 0x1b, 0x0121401f }, /* HP out */
6608 { }
6609 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006610 .chained = true,
6611 .chain_id = ALC662_FIXUP_SKU_IGNORE
6612 },
6613 [ALC662_FIXUP_ASUS_MODE3] = {
6614 .type = ALC_FIXUP_PINS,
6615 .v.pins = (const struct alc_pincfg[]) {
6616 { 0x14, 0x99130110 }, /* speaker */
6617 { 0x15, 0x0121441f }, /* HP */
6618 { 0x18, 0x01a19840 }, /* mic */
6619 { 0x19, 0x99a3094f }, /* int-mic */
6620 { 0x21, 0x01211420 }, /* HP2 */
6621 { }
6622 },
6623 .chained = true,
6624 .chain_id = ALC662_FIXUP_SKU_IGNORE
6625 },
6626 [ALC662_FIXUP_ASUS_MODE4] = {
6627 .type = ALC_FIXUP_PINS,
6628 .v.pins = (const struct alc_pincfg[]) {
6629 { 0x14, 0x99130110 }, /* speaker */
6630 { 0x16, 0x99130111 }, /* speaker */
6631 { 0x18, 0x01a19840 }, /* mic */
6632 { 0x19, 0x99a3094f }, /* int-mic */
6633 { 0x21, 0x0121441f }, /* HP */
6634 { }
6635 },
6636 .chained = true,
6637 .chain_id = ALC662_FIXUP_SKU_IGNORE
6638 },
6639 [ALC662_FIXUP_ASUS_MODE5] = {
6640 .type = ALC_FIXUP_PINS,
6641 .v.pins = (const struct alc_pincfg[]) {
6642 { 0x14, 0x99130110 }, /* speaker */
6643 { 0x15, 0x0121441f }, /* HP */
6644 { 0x16, 0x99130111 }, /* speaker */
6645 { 0x18, 0x01a19840 }, /* mic */
6646 { 0x19, 0x99a3094f }, /* int-mic */
6647 { }
6648 },
6649 .chained = true,
6650 .chain_id = ALC662_FIXUP_SKU_IGNORE
6651 },
6652 [ALC662_FIXUP_ASUS_MODE6] = {
6653 .type = ALC_FIXUP_PINS,
6654 .v.pins = (const struct alc_pincfg[]) {
6655 { 0x14, 0x99130110 }, /* speaker */
6656 { 0x15, 0x01211420 }, /* HP2 */
6657 { 0x18, 0x01a19840 }, /* mic */
6658 { 0x19, 0x99a3094f }, /* int-mic */
6659 { 0x1b, 0x0121441f }, /* HP */
6660 { }
6661 },
6662 .chained = true,
6663 .chain_id = ALC662_FIXUP_SKU_IGNORE
6664 },
6665 [ALC662_FIXUP_ASUS_MODE7] = {
6666 .type = ALC_FIXUP_PINS,
6667 .v.pins = (const struct alc_pincfg[]) {
6668 { 0x14, 0x99130110 }, /* speaker */
6669 { 0x17, 0x99130111 }, /* speaker */
6670 { 0x18, 0x01a19840 }, /* mic */
6671 { 0x19, 0x99a3094f }, /* int-mic */
6672 { 0x1b, 0x01214020 }, /* HP */
6673 { 0x21, 0x0121401f }, /* HP */
6674 { }
6675 },
6676 .chained = true,
6677 .chain_id = ALC662_FIXUP_SKU_IGNORE
6678 },
6679 [ALC662_FIXUP_ASUS_MODE8] = {
6680 .type = ALC_FIXUP_PINS,
6681 .v.pins = (const struct alc_pincfg[]) {
6682 { 0x14, 0x99130110 }, /* speaker */
6683 { 0x12, 0x99a30970 }, /* int-mic */
6684 { 0x15, 0x01214020 }, /* HP */
6685 { 0x17, 0x99130111 }, /* speaker */
6686 { 0x18, 0x01a19840 }, /* mic */
6687 { 0x21, 0x0121401f }, /* HP */
6688 { }
6689 },
6690 .chained = true,
6691 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006692 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006693 [ALC662_FIXUP_NO_JACK_DETECT] = {
6694 .type = ALC_FIXUP_FUNC,
6695 .v.func = alc_fixup_no_jack_detect,
6696 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006697};
6698
Takashi Iwaia9111322011-05-02 11:30:18 +02006699static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006700 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006701 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006702 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006703 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006704 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006705 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006706 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006707 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006708 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006709 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006710 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006711
6712#if 0
6713 /* Below is a quirk table taken from the old code.
6714 * Basically the device should work as is without the fixup table.
6715 * If BIOS doesn't give a proper info, enable the corresponding
6716 * fixup entry.
6717 */
6718 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6719 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6720 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6721 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6722 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6723 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6724 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6725 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6726 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6727 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6728 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6729 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6730 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6731 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6732 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6733 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6734 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6735 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6736 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6737 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6738 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6739 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6740 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6741 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6742 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6743 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6744 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6745 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6746 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6747 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6748 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6749 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6750 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6751 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6752 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6753 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6754 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6755 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6756 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6757 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6758 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6759 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6760 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6761 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6762 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6763 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6764 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6765 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6766 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6767 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6768#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006769 {}
6770};
6771
Todd Broch6be79482010-12-07 16:51:05 -08006772static const struct alc_model_fixup alc662_fixup_models[] = {
6773 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006774 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6775 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6776 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6777 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6778 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6779 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6780 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6781 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006782 {}
6783};
David Henningsson6cb3b702010-09-09 08:51:44 +02006784
6785
Takashi Iwai1d045db2011-07-07 18:23:21 +02006786/*
6787 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006788static int patch_alc662(struct hda_codec *codec)
6789{
6790 struct alc_spec *spec;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006791 int err = 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006792
6793 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6794 if (!spec)
6795 return -ENOMEM;
6796
6797 codec->spec = spec;
6798
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006799 spec->mixer_nid = 0x0b;
6800
Takashi Iwai53c334a2011-08-23 18:27:14 +02006801 /* handle multiple HPs as is */
6802 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6803
Kailang Yangda00c242010-03-19 11:23:45 +01006804 alc_auto_parse_customize_define(codec);
6805
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006806 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6807
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006808 err = alc_codec_rename_from_preset(codec);
6809 if (err < 0)
6810 goto error;
6811
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006812 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006813 codec->bus->pci->subsystem_vendor == 0x1025 &&
6814 spec->cdefine.platform_type == 1) {
6815 if (alc_codec_rename(codec, "ALC272X") < 0)
6816 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006817 }
Kailang Yang274693f2009-12-03 10:07:50 +01006818
Takashi Iwaib9c51062011-08-24 18:08:07 +02006819 alc_pick_fixup(codec, alc662_fixup_models,
6820 alc662_fixup_tbl, alc662_fixups);
6821 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6822 /* automatic parse from the BIOS config */
6823 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006824 if (err < 0)
6825 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006826
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006827 if (!spec->no_analog && has_cdefine_beep(codec)) {
6828 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006829 if (err < 0)
6830 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006831 switch (codec->vendor_id) {
6832 case 0x10ec0662:
6833 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6834 break;
6835 case 0x10ec0272:
6836 case 0x10ec0663:
6837 case 0x10ec0665:
6838 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6839 break;
6840 case 0x10ec0273:
6841 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6842 break;
6843 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006844 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006845
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006846 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02006847 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006848
Takashi Iwai589876e2012-02-20 15:47:55 +01006849 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6850
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006851 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006852
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006853 error:
6854 alc_free(codec);
6855 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006856}
6857
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006858/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006859 * ALC680 support
6860 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006861
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006862static int alc680_parse_auto_config(struct hda_codec *codec)
6863{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006864 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006865}
6866
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006867/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006868 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006869static int patch_alc680(struct hda_codec *codec)
6870{
6871 struct alc_spec *spec;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006872 int err;
6873
6874 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
6875 if (spec == NULL)
6876 return -ENOMEM;
6877
6878 codec->spec = spec;
6879
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006880 /* ALC680 has no aa-loopback mixer */
6881
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006882 /* automatic parse from the BIOS config */
6883 err = alc680_parse_auto_config(codec);
6884 if (err < 0) {
6885 alc_free(codec);
6886 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006887 }
6888
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006889 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006890
6891 return 0;
6892}
6893
6894/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006895 * patch entries
6896 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006897static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006898 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006899 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006900 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006901 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006902 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006903 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006904 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006905 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006906 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006907 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006908 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006909 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006910 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6911 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6912 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006913 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006914 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006915 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6916 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006917 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6918 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006919 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006920 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006921 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006922 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006923 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006924 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006925 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006926 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006927 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006928 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006929 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006930 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006931 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006932 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006933 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006934 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006935 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006936 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006937 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006938 {} /* terminator */
6939};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006940
6941MODULE_ALIAS("snd-hda-codec-id:10ec*");
6942
6943MODULE_LICENSE("GPL");
6944MODULE_DESCRIPTION("Realtek HD-audio codec");
6945
6946static struct hda_codec_preset_list realtek_list = {
6947 .preset = snd_hda_preset_realtek,
6948 .owner = THIS_MODULE,
6949};
6950
6951static int __init patch_realtek_init(void)
6952{
6953 return snd_hda_add_codec_preset(&realtek_list);
6954}
6955
6956static void __exit patch_realtek_exit(void)
6957{
6958 snd_hda_delete_codec_preset(&realtek_list);
6959}
6960
6961module_init(patch_realtek_init)
6962module_exit(patch_realtek_exit)