blob: f912d74438a6d55c0e2467d1cbbaf52a0afbef92 [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 Woithe409a3e92012-03-27 13:01:01 +10309 * Jonathan Woithe <jwoithe@just42.net>
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"
Takashi Iwai23d30f22012-05-07 17:17:32 +020035#include "hda_auto_parser.h"
Kusanagi Kouichi680cd532009-02-05 00:00:58 +090036#include "hda_beep.h"
Takashi Iwai1835a0f2011-10-27 22:12:46 +020037#include "hda_jack.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Takashi Iwai1d045db2011-07-07 18:23:21 +020039/* unsol event tags */
40#define ALC_FRONT_EVENT 0x01
41#define ALC_DCVOL_EVENT 0x02
42#define ALC_HP_EVENT 0x04
43#define ALC_MIC_EVENT 0x08
Takashi Iwaid4a86d82010-06-23 17:51:26 +020044
Kailang Yangdf694da2005-12-05 19:42:22 +010045/* for GPIO Poll */
46#define GPIO_MASK 0x03
47
Takashi Iwai4a79ba32009-04-22 16:31:35 +020048/* extra amp-initialization sequence types */
49enum {
50 ALC_INIT_NONE,
51 ALC_INIT_DEFAULT,
52 ALC_INIT_GPIO1,
53 ALC_INIT_GPIO2,
54 ALC_INIT_GPIO3,
55};
56
Kailang Yangda00c242010-03-19 11:23:45 +010057struct alc_customize_define {
58 unsigned int sku_cfg;
59 unsigned char port_connectivity;
60 unsigned char check_sum;
61 unsigned char customization;
62 unsigned char external_amp;
63 unsigned int enable_pcbeep:1;
64 unsigned int platform_type:1;
65 unsigned int swap:1;
66 unsigned int override:1;
David Henningsson90622912010-10-14 14:50:18 +020067 unsigned int fixup:1; /* Means that this sku is set by driver, not read from hw */
Kailang Yangda00c242010-03-19 11:23:45 +010068};
69
Takashi Iwaice764ab2011-04-27 16:35:23 +020070struct alc_multi_io {
71 hda_nid_t pin; /* multi-io widget pin NID */
72 hda_nid_t dac; /* DAC to be connected */
73 unsigned int ctl_in; /* cached input-pin control value */
74};
75
Takashi Iwaid922b512011-04-28 12:18:53 +020076enum {
Takashi Iwai3b8510c2011-04-28 14:03:24 +020077 ALC_AUTOMUTE_PIN, /* change the pin control */
78 ALC_AUTOMUTE_AMP, /* mute/unmute the pin AMP */
79 ALC_AUTOMUTE_MIXER, /* mute/unmute mixer widget AMP */
Takashi Iwaid922b512011-04-28 12:18:53 +020080};
81
Takashi Iwaic14c95f2012-02-16 16:38:07 +010082#define MAX_VOL_NIDS 0x40
83
Takashi Iwai23d30f22012-05-07 17:17:32 +020084/* make compatible with old code */
85#define alc_apply_pincfgs snd_hda_apply_pincfgs
86#define alc_apply_fixup snd_hda_apply_fixup
87#define alc_pick_fixup snd_hda_pick_fixup
88#define alc_fixup hda_fixup
89#define alc_pincfg hda_pintbl
90#define alc_model_fixup hda_model_fixup
91
92#define ALC_FIXUP_PINS HDA_FIXUP_PINS
93#define ALC_FIXUP_VERBS HDA_FIXUP_VERBS
94#define ALC_FIXUP_FUNC HDA_FIXUP_FUNC
95
96#define ALC_FIXUP_ACT_PRE_PROBE HDA_FIXUP_ACT_PRE_PROBE
97#define ALC_FIXUP_ACT_PROBE HDA_FIXUP_ACT_PROBE
98#define ALC_FIXUP_ACT_INIT HDA_FIXUP_ACT_INIT
99#define ALC_FIXUP_ACT_BUILD HDA_FIXUP_ACT_BUILD
100
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102struct alc_spec {
Takashi Iwai23d30f22012-05-07 17:17:32 +0200103 struct hda_gen_spec gen;
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* codec parameterization */
Takashi Iwaia9111322011-05-02 11:30:18 +0200106 const struct snd_kcontrol_new *mixers[5]; /* mixer arrays */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 unsigned int num_mixers;
Takashi Iwaia9111322011-05-02 11:30:18 +0200108 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
Takashi Iwai45bdd1c2009-02-06 16:11:25 +0100109 unsigned int beep_amp; /* beep amp value, set via set_beep_amp() */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200111 char stream_name_analog[32]; /* analog PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200112 const struct hda_pcm_stream *stream_analog_playback;
113 const struct hda_pcm_stream *stream_analog_capture;
114 const struct hda_pcm_stream *stream_analog_alt_playback;
115 const struct hda_pcm_stream *stream_analog_alt_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Takashi Iwaiaa563af2009-07-31 10:05:11 +0200117 char stream_name_digital[32]; /* digital PCM stream */
Takashi Iwaia9111322011-05-02 11:30:18 +0200118 const struct hda_pcm_stream *stream_digital_playback;
119 const struct hda_pcm_stream *stream_digital_capture;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 /* playback */
Takashi Iwai16ded522005-06-10 19:58:24 +0200122 struct hda_multi_out multiout; /* playback set-up
123 * max_channels, dacs must be set
124 * dig_out_nid and hp_nid are optional
125 */
Takashi Iwai63300792008-01-24 15:31:36 +0100126 hda_nid_t alt_dac_nid;
Takashi Iwai6a05ac42009-02-13 11:19:09 +0100127 hda_nid_t slave_dig_outs[3]; /* optional - for auto-parsing */
Takashi Iwai8c441982009-01-20 18:30:20 +0100128 int dig_out_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 /* capture */
131 unsigned int num_adc_nids;
Takashi Iwai4c6d72d2011-05-02 11:30:18 +0200132 const hda_nid_t *adc_nids;
133 const hda_nid_t *capsrc_nids;
Takashi Iwai16ded522005-06-10 19:58:24 +0200134 hda_nid_t dig_in_nid; /* digital-in NID; optional */
Takashi Iwai1f0f4b82011-06-27 10:52:59 +0200135 hda_nid_t mixer_nid; /* analog-mixer NID */
Takashi Iwaic14c95f2012-02-16 16:38:07 +0100136 DECLARE_BITMAP(vol_ctls, MAX_VOL_NIDS << 1);
137 DECLARE_BITMAP(sw_ctls, MAX_VOL_NIDS << 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Takashi Iwai840b64c2010-07-13 22:49:01 +0200139 /* capture setup for dynamic dual-adc switch */
Takashi Iwai840b64c2010-07-13 22:49:01 +0200140 hda_nid_t cur_adc;
141 unsigned int cur_adc_stream_tag;
142 unsigned int cur_adc_format;
143
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* capture source */
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200145 unsigned int num_mux_defs;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 const struct hda_input_mux *input_mux;
147 unsigned int cur_mux[3];
Takashi Iwai21268962011-07-07 15:01:13 +0200148 hda_nid_t ext_mic_pin;
149 hda_nid_t dock_mic_pin;
150 hda_nid_t int_mic_pin;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 /* channel model */
Takashi Iwaid2a6d7d2005-11-17 11:06:29 +0100153 const struct hda_channel_mode *channel_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 int num_channel_mode;
Takashi Iwai4e195a72006-07-28 14:47:34 +0200155 int need_dac_fix;
Hector Martin3b315d72009-06-02 10:54:19 +0200156 int const_channel_count;
157 int ext_channel_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159 /* PCM information */
Jonathan Woithe4c5186e2006-02-09 11:53:48 +0100160 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
Takashi Iwai41e41f12005-06-08 14:48:49 +0200161
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200162 /* dynamic controls, init_verbs and input_mux */
163 struct auto_pin_cfg autocfg;
Kailang Yangda00c242010-03-19 11:23:45 +0100164 struct alc_customize_define cdefine;
Takashi Iwai603c4012008-07-30 15:01:44 +0200165 struct snd_array kctls;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -0200166 struct hda_input_mux private_imux[3];
Takashi Iwai41923e42007-10-22 17:20:10 +0200167 hda_nid_t private_dac_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai4953550a2009-06-30 15:28:30 +0200168 hda_nid_t private_adc_nids[AUTO_CFG_MAX_OUTS];
169 hda_nid_t private_capsrc_nids[AUTO_CFG_MAX_OUTS];
Takashi Iwai21268962011-07-07 15:01:13 +0200170 hda_nid_t imux_pins[HDA_MAX_NUM_INPUTS];
171 unsigned int dyn_adc_idx[HDA_MAX_NUM_INPUTS];
172 int int_mic_idx, ext_mic_idx, dock_mic_idx; /* for auto-mic */
Takashi Iwai125821a2012-06-22 14:30:29 +0200173 hda_nid_t inv_dmic_pin;
Takashi Iwai834be882006-03-01 14:16:17 +0100174
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100175 /* hooks */
176 void (*init_hook)(struct hda_codec *codec);
177 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100178#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500179 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100180#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200181 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200182 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100183
Takashi Iwai834be882006-03-01 14:16:17 +0100184 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200185 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200186 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200187 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200188 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200189 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200190 unsigned int automute_speaker:1; /* automute speaker outputs */
191 unsigned int automute_lo:1; /* automute LO outputs */
192 unsigned int detect_hp:1; /* Headphone detection enabled */
193 unsigned int detect_lo:1; /* Line-out detection enabled */
194 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
195 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100196 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200197
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100198 /* other flags */
199 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200200 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100201 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200202 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200203 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100204 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwai125821a2012-06-22 14:30:29 +0200205 unsigned int inv_dmic_fixup:1; /* has inverted digital-mic workaround */
206 unsigned int inv_dmic_muted:1; /* R-ch of inv d-mic is muted? */
Takashi Iwaid922b512011-04-28 12:18:53 +0200207
208 /* auto-mute control */
209 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200210 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200211
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200212 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200213 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100214
Takashi Iwai2134ea42008-01-10 16:53:55 +0100215 /* for virtual master */
216 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100217 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200218#ifdef CONFIG_SND_HDA_POWER_SAVE
219 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100220 int num_loopbacks;
221 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200222#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200223
224 /* for PLL fix */
225 hda_nid_t pll_nid;
226 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200227 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100228
Takashi Iwaice764ab2011-04-27 16:35:23 +0200229 /* multi-io */
230 int multi_ios;
231 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200232
233 /* bind volumes */
234 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100235};
236
Takashi Iwai44c02402011-07-08 15:14:19 +0200237static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
238 int dir, unsigned int bits)
239{
240 if (!nid)
241 return false;
242 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
243 if (query_amp_caps(codec, nid, dir) & bits)
244 return true;
245 return false;
246}
247
248#define nid_has_mute(codec, nid, dir) \
249 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
250#define nid_has_volume(codec, nid, dir) \
251 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253/*
254 * input MUX handling
255 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200256static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
257 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
260 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200261 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
262 if (mux_idx >= spec->num_mux_defs)
263 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100264 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
265 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200266 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267}
268
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200269static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
270 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271{
272 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
273 struct alc_spec *spec = codec->spec;
274 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
275
276 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
277 return 0;
278}
279
Takashi Iwai21268962011-07-07 15:01:13 +0200280static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Takashi Iwai21268962011-07-07 15:01:13 +0200282 struct alc_spec *spec = codec->spec;
283 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
284
285 if (spec->cur_adc && spec->cur_adc != new_adc) {
286 /* stream is running, let's swap the current ADC */
287 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
288 spec->cur_adc = new_adc;
289 snd_hda_codec_setup_stream(codec, new_adc,
290 spec->cur_adc_stream_tag, 0,
291 spec->cur_adc_format);
292 return true;
293 }
294 return false;
295}
296
Takashi Iwai61071592011-11-23 07:52:15 +0100297static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
298{
299 return spec->capsrc_nids ?
300 spec->capsrc_nids[idx] : spec->adc_nids[idx];
301}
302
Takashi Iwai24de1832011-11-07 17:13:39 +0100303static void call_update_outputs(struct hda_codec *codec);
Takashi Iwai125821a2012-06-22 14:30:29 +0200304static void alc_inv_dmic_sync(struct hda_codec *codec, bool force);
Takashi Iwai24de1832011-11-07 17:13:39 +0100305
David Henningsson00227f12012-06-27 18:45:44 +0200306/* for shared I/O, change the pin-control accordingly */
307static void update_shared_mic_hp(struct hda_codec *codec, bool set_as_mic)
308{
309 struct alc_spec *spec = codec->spec;
310 unsigned int val;
311 hda_nid_t pin = spec->autocfg.inputs[1].pin;
312 /* NOTE: this assumes that there are only two inputs, the
313 * first is the real internal mic and the second is HP/mic jack.
314 */
315
316 val = snd_hda_get_default_vref(codec, pin);
317
318 /* This pin does not have vref caps - let's enable vref on pin 0x18
319 instead, as suggested by Realtek */
320 if (val == AC_PINCTL_VREF_HIZ) {
321 const hda_nid_t vref_pin = 0x18;
322 /* Sanity check pin 0x18 */
323 if (get_wcaps_type(get_wcaps(codec, vref_pin)) == AC_WID_PIN &&
324 get_defcfg_connect(snd_hda_codec_get_pincfg(codec, vref_pin)) == AC_JACK_PORT_NONE) {
325 unsigned int vref_val = snd_hda_get_default_vref(codec, vref_pin);
326 if (vref_val != AC_PINCTL_VREF_HIZ)
327 snd_hda_set_pin_ctl(codec, vref_pin, PIN_IN | (set_as_mic ? vref_val : 0));
328 }
329 }
330
331 val = set_as_mic ? val | PIN_IN : PIN_HP;
332 snd_hda_set_pin_ctl(codec, pin, val);
333
334 spec->automute_speaker = !set_as_mic;
335 call_update_outputs(codec);
336}
337
Takashi Iwai21268962011-07-07 15:01:13 +0200338/* select the given imux item; either unmute exclusively or select the route */
339static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
340 unsigned int idx, bool force)
341{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100343 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100344 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100345 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200346 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
Takashi Iwai5803a322012-02-21 11:59:45 +0100348 if (!spec->input_mux)
349 return 0;
350
Takashi Iwaicd896c32008-11-18 12:36:33 +0100351 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
352 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100353 if (!imux->num_items && mux_idx > 0)
354 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100355 if (!imux->num_items)
356 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100357
Takashi Iwai21268962011-07-07 15:01:13 +0200358 if (idx >= imux->num_items)
359 idx = imux->num_items - 1;
360 if (spec->cur_mux[adc_idx] == idx && !force)
361 return 0;
362 spec->cur_mux[adc_idx] = idx;
363
David Henningsson00227f12012-06-27 18:45:44 +0200364 if (spec->shared_mic_hp)
365 update_shared_mic_hp(codec, spec->cur_mux[adc_idx]);
Takashi Iwai24de1832011-11-07 17:13:39 +0100366
Takashi Iwai21268962011-07-07 15:01:13 +0200367 if (spec->dyn_adc_switch) {
368 alc_dyn_adc_pcm_resetup(codec, idx);
369 adc_idx = spec->dyn_adc_idx[idx];
370 }
371
Takashi Iwai61071592011-11-23 07:52:15 +0100372 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200373
374 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200375 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100376 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200377 return 1;
378
Takashi Iwaia22d5432009-07-27 12:54:26 +0200379 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200380 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100381 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100382 int active = imux->items[idx].index;
383 for (i = 0; i < num_conns; i++) {
384 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
385 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100386 HDA_AMP_MUTE, v);
387 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100388 } else {
389 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200390 snd_hda_codec_write_cache(codec, nid, 0,
391 AC_VERB_SET_CONNECT_SEL,
392 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100393 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200394 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200395 return 1;
396}
397
398static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
399 struct snd_ctl_elem_value *ucontrol)
400{
401 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
402 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
403 return alc_mux_select(codec, adc_idx,
404 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100405}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100408 * set up the input pin config (depending on the given auto-pin type)
409 */
410static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
411 int auto_pin_type)
412{
413 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200414 if (auto_pin_type == AUTO_PIN_MIC)
415 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200416 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100417}
418
419/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200420 * Append the given mixer and verb elements for the later use
421 * The mixer array is referred in build_controls(), and init_verbs are
422 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100423 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200424static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100425{
426 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
427 return;
428 spec->mixers[spec->num_mixers++] = mix;
429}
430
Takashi Iwaid88897e2008-10-31 15:01:37 +0100431/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200432 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100433 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200434/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200435static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200436 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
437 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
438 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
439 { }
440};
441
Takashi Iwaia9111322011-05-02 11:30:18 +0200442static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200443 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
444 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
445 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
446 { }
447};
448
Takashi Iwaia9111322011-05-02 11:30:18 +0200449static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200450 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
451 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
452 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
453 { }
454};
455
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200456/*
457 * Fix hardware PLL issue
458 * On some codecs, the analog PLL gating control must be off while
459 * the default value is 1.
460 */
461static void alc_fix_pll(struct hda_codec *codec)
462{
463 struct alc_spec *spec = codec->spec;
464 unsigned int val;
465
466 if (!spec->pll_nid)
467 return;
468 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
469 spec->pll_coef_idx);
470 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
471 AC_VERB_GET_PROC_COEF, 0);
472 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
473 spec->pll_coef_idx);
474 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
475 val & ~(1 << spec->pll_coef_bit));
476}
477
478static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
479 unsigned int coef_idx, unsigned int coef_bit)
480{
481 struct alc_spec *spec = codec->spec;
482 spec->pll_nid = nid;
483 spec->pll_coef_idx = coef_idx;
484 spec->pll_coef_bit = coef_bit;
485 alc_fix_pll(codec);
486}
487
Takashi Iwai1d045db2011-07-07 18:23:21 +0200488/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200489 * Jack detections for HP auto-mute and mic-switch
490 */
491
492/* check each pin in the given array; returns true if any of them is plugged */
493static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200494{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200495 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200496
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200497 for (i = 0; i < num_pins; i++) {
498 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200499 if (!nid)
500 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200501 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200502 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200503 return present;
504}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200505
Takashi Iwai1d045db2011-07-07 18:23:21 +0200506/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200507static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200508 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200509{
510 struct alc_spec *spec = codec->spec;
511 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200512 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200513 int i;
514
515 for (i = 0; i < num_pins; i++) {
516 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100517 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200518 if (!nid)
519 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200520 switch (spec->automute_mode) {
521 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100522 /* don't reset VREF value in case it's controlling
523 * the amp (see alc861_fixup_asus_amp_vref_0f())
524 */
525 if (spec->keep_vref_in_automute) {
526 val = snd_hda_codec_read(codec, nid, 0,
527 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
528 val &= ~PIN_HP;
529 } else
530 val = 0;
531 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200532 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200533 break;
534 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200535 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200536 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200537 break;
538 case ALC_AUTOMUTE_MIXER:
539 nid = spec->automute_mixer_nid[i];
540 if (!nid)
541 break;
542 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200543 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200544 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200545 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200546 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200547 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200548 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200549}
550
David Henningsson42cf0d02011-09-20 12:04:56 +0200551/* Toggle outputs muting */
552static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200553{
554 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200556
Takashi Iwaic0a20262011-06-10 15:28:15 +0200557 /* Control HP pins/amps depending on master_mute state;
558 * in general, HP pins/amps control should be enabled in all cases,
559 * but currently set only for master_mute, just to be safe
560 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100561 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
562 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200563 spec->autocfg.hp_pins, spec->master_mute, true);
564
David Henningsson42cf0d02011-09-20 12:04:56 +0200565 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200566 on = 0;
567 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200568 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200569 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200570 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200571 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200572
573 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200574 /* if LO is a copy of either HP or Speaker, don't need to handle it */
575 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
576 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200577 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200578 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200579 on = 0;
580 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200581 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200582 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200584 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200585}
586
David Henningsson42cf0d02011-09-20 12:04:56 +0200587static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200588{
589 struct alc_spec *spec = codec->spec;
590 if (spec->automute_hook)
591 spec->automute_hook(codec);
592 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200593 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200594}
595
Takashi Iwai1d045db2011-07-07 18:23:21 +0200596/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200597static void alc_hp_automute(struct hda_codec *codec)
598{
599 struct alc_spec *spec = codec->spec;
600
David Henningsson42cf0d02011-09-20 12:04:56 +0200601 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200602 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
603 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200604 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200605 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200606 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200607}
608
Takashi Iwai1d045db2011-07-07 18:23:21 +0200609/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200610static void alc_line_automute(struct hda_codec *codec)
611{
612 struct alc_spec *spec = codec->spec;
613
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200614 /* check LO jack only when it's different from HP */
615 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
616 return;
617
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200618 spec->line_jack_present =
619 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
620 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200621 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200622 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200623 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200624}
625
Takashi Iwai8d087c72011-06-28 12:45:47 +0200626#define get_connection_index(codec, mux, nid) \
627 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200628
Takashi Iwai1d045db2011-07-07 18:23:21 +0200629/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200630static void alc_mic_automute(struct hda_codec *codec)
631{
632 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200633 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200634
Takashi Iwai21268962011-07-07 15:01:13 +0200635 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200636 return;
637 if (snd_BUG_ON(!spec->adc_nids))
638 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200639 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200640 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200641
Takashi Iwai21268962011-07-07 15:01:13 +0200642 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
643 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
644 else if (spec->dock_mic_idx >= 0 &&
645 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
646 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
647 else
648 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200649}
650
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100651/* handle the specified unsol action (ALC_XXX_EVENT) */
652static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200653{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100654 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200655 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200656 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200657 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200658 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200659 alc_line_automute(codec);
660 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200661 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200662 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200663 break;
664 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200665 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200666}
667
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100668/* update the master volume per volume-knob's unsol event */
669static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
670{
671 unsigned int val;
672 struct snd_kcontrol *kctl;
673 struct snd_ctl_elem_value *uctl;
674
675 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
676 if (!kctl)
677 return;
678 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
679 if (!uctl)
680 return;
681 val = snd_hda_codec_read(codec, nid, 0,
682 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
683 val &= HDA_AMP_VOLMASK;
684 uctl->value.integer.value[0] = val;
685 uctl->value.integer.value[1] = val;
686 kctl->put(kctl, uctl);
687 kfree(uctl);
688}
689
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100690/* unsolicited event for HP jack sensing */
691static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
692{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100693 int action;
694
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100695 if (codec->vendor_id == 0x10ec0880)
696 res >>= 28;
697 else
698 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100699 action = snd_hda_jack_get_action(codec, res);
David Henningssone21af482012-03-05 11:38:46 +0100700 if (action == ALC_DCVOL_EVENT) {
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100701 /* Execute the dc-vol event here as it requires the NID
702 * but we don't pass NID to alc_exec_unsol_event().
703 * Once when we convert all static quirks to the auto-parser,
704 * this can be integerated into there.
705 */
706 struct hda_jack_tbl *jack;
707 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
708 if (jack)
709 alc_update_knob_master(codec, jack->nid);
710 return;
711 }
712 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100713}
714
Takashi Iwai1d045db2011-07-07 18:23:21 +0200715/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200716static void alc_inithook(struct hda_codec *codec)
717{
Takashi Iwaid922b512011-04-28 12:18:53 +0200718 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200719 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200720 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200721}
722
Kailang Yangf9423e72008-05-27 12:32:25 +0200723/* additional initialization for ALC888 variants */
724static void alc888_coef_init(struct hda_codec *codec)
725{
726 unsigned int tmp;
727
728 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
729 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
730 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100731 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200732 /* alc888S-VC */
733 snd_hda_codec_read(codec, 0x20, 0,
734 AC_VERB_SET_PROC_COEF, 0x830);
735 else
736 /* alc888-VB */
737 snd_hda_codec_read(codec, 0x20, 0,
738 AC_VERB_SET_PROC_COEF, 0x3030);
739}
740
Takashi Iwai1d045db2011-07-07 18:23:21 +0200741/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200742static void alc889_coef_init(struct hda_codec *codec)
743{
744 unsigned int tmp;
745
746 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
747 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
748 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
749 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
750}
751
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100752/* turn on/off EAPD control (only if available) */
753static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
754{
755 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
756 return;
757 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
758 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
759 on ? 2 : 0);
760}
761
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200762/* turn on/off EAPD controls of the codec */
763static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
764{
765 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200766 static hda_nid_t pins[] = {
767 0x0f, 0x10, 0x14, 0x15, 0
768 };
769 hda_nid_t *p;
770 for (p = pins; *p; p++)
771 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200772}
773
Takashi Iwai1c716152011-04-07 10:37:16 +0200774/* generic shutup callback;
775 * just turning off EPAD and a little pause for avoiding pop-noise
776 */
777static void alc_eapd_shutup(struct hda_codec *codec)
778{
779 alc_auto_setup_eapd(codec, false);
780 msleep(200);
781}
782
Takashi Iwai1d045db2011-07-07 18:23:21 +0200783/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200784static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200785{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200786 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200787
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200788 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200789 switch (type) {
790 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200791 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
792 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200793 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200794 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
795 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200796 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200797 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
798 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200799 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200800 switch (codec->vendor_id) {
801 case 0x10ec0260:
802 snd_hda_codec_write(codec, 0x1a, 0,
803 AC_VERB_SET_COEF_INDEX, 7);
804 tmp = snd_hda_codec_read(codec, 0x1a, 0,
805 AC_VERB_GET_PROC_COEF, 0);
806 snd_hda_codec_write(codec, 0x1a, 0,
807 AC_VERB_SET_COEF_INDEX, 7);
808 snd_hda_codec_write(codec, 0x1a, 0,
809 AC_VERB_SET_PROC_COEF,
810 tmp | 0x2010);
811 break;
812 case 0x10ec0262:
813 case 0x10ec0880:
814 case 0x10ec0882:
815 case 0x10ec0883:
816 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100817 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100818 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200819 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200820 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200821 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200822 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200823 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100824#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200825 case 0x10ec0267:
826 case 0x10ec0268:
827 snd_hda_codec_write(codec, 0x20, 0,
828 AC_VERB_SET_COEF_INDEX, 7);
829 tmp = snd_hda_codec_read(codec, 0x20, 0,
830 AC_VERB_GET_PROC_COEF, 0);
831 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200832 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200833 snd_hda_codec_write(codec, 0x20, 0,
834 AC_VERB_SET_PROC_COEF,
835 tmp | 0x3000);
836 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100837#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200838 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200839 break;
840 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200841}
Kailang Yangea1fb292008-08-26 12:58:38 +0200842
Takashi Iwai1d045db2011-07-07 18:23:21 +0200843/*
844 * Auto-Mute mode mixer enum support
845 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200846static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
847 struct snd_ctl_elem_info *uinfo)
848{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200849 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
850 struct alc_spec *spec = codec->spec;
851 static const char * const texts2[] = {
852 "Disabled", "Enabled"
853 };
854 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100855 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200856 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200857 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200858
859 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
860 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200861 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200862 uinfo->value.enumerated.items = 3;
863 texts = texts3;
864 } else {
865 uinfo->value.enumerated.items = 2;
866 texts = texts2;
867 }
868 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
869 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200870 strcpy(uinfo->value.enumerated.name,
871 texts[uinfo->value.enumerated.item]);
872 return 0;
873}
874
875static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
876 struct snd_ctl_elem_value *ucontrol)
877{
878 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
879 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200880 unsigned int val = 0;
881 if (spec->automute_speaker)
882 val++;
883 if (spec->automute_lo)
884 val++;
885
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200886 ucontrol->value.enumerated.item[0] = val;
887 return 0;
888}
889
890static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
891 struct snd_ctl_elem_value *ucontrol)
892{
893 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
894 struct alc_spec *spec = codec->spec;
895
896 switch (ucontrol->value.enumerated.item[0]) {
897 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200898 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200900 spec->automute_speaker = 0;
901 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200902 break;
903 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200904 if (spec->automute_speaker_possible) {
905 if (!spec->automute_lo && spec->automute_speaker)
906 return 0;
907 spec->automute_speaker = 1;
908 spec->automute_lo = 0;
909 } else if (spec->automute_lo_possible) {
910 if (spec->automute_lo)
911 return 0;
912 spec->automute_lo = 1;
913 } else
914 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200915 break;
916 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200917 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200918 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200919 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200920 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200921 spec->automute_speaker = 1;
922 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200923 break;
924 default:
925 return -EINVAL;
926 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200927 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200928 return 1;
929}
930
Takashi Iwaia9111322011-05-02 11:30:18 +0200931static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200932 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
933 .name = "Auto-Mute Mode",
934 .info = alc_automute_mode_info,
935 .get = alc_automute_mode_get,
936 .put = alc_automute_mode_put,
937};
938
Takashi Iwai1d045db2011-07-07 18:23:21 +0200939static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
940{
941 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
942 return snd_array_new(&spec->kctls);
943}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200944
945static int alc_add_automute_mode_enum(struct hda_codec *codec)
946{
947 struct alc_spec *spec = codec->spec;
948 struct snd_kcontrol_new *knew;
949
950 knew = alc_kcontrol_new(spec);
951 if (!knew)
952 return -ENOMEM;
953 *knew = alc_automute_mode_enum;
954 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
955 if (!knew->name)
956 return -ENOMEM;
957 return 0;
958}
959
Takashi Iwai1d045db2011-07-07 18:23:21 +0200960/*
961 * Check the availability of HP/line-out auto-mute;
962 * Set up appropriately if really supported
963 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200964static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200965{
966 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200967 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200968 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200969 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200970
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200971 if (cfg->hp_pins[0])
972 present++;
973 if (cfg->line_out_pins[0])
974 present++;
975 if (cfg->speaker_pins[0])
976 present++;
977 if (present < 2) /* need two different output types */
978 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200979
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200980 if (!cfg->speaker_pins[0] &&
981 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200982 memcpy(cfg->speaker_pins, cfg->line_out_pins,
983 sizeof(cfg->speaker_pins));
984 cfg->speaker_outs = cfg->line_outs;
985 }
986
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200987 if (!cfg->hp_pins[0] &&
988 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200989 memcpy(cfg->hp_pins, cfg->line_out_pins,
990 sizeof(cfg->hp_pins));
991 cfg->hp_outs = cfg->line_outs;
992 }
993
David Henningsson42cf0d02011-09-20 12:04:56 +0200994 spec->automute_mode = ALC_AUTOMUTE_PIN;
995
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200996 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200997 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200998 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200999 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +02001000 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001001 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001002 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001003 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001004 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001005
David Henningsson42cf0d02011-09-20 12:04:56 +02001006 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
1007 if (cfg->speaker_outs)
1008 for (i = 0; i < cfg->line_outs; i++) {
1009 hda_nid_t nid = cfg->line_out_pins[i];
1010 if (!is_jack_detectable(codec, nid))
1011 continue;
1012 snd_printdd("realtek: Enable Line-Out "
1013 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001014 snd_hda_jack_detect_enable(codec, nid,
1015 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +02001016 spec->detect_lo = 1;
1017 }
1018 spec->automute_lo_possible = spec->detect_hp;
1019 }
1020
1021 spec->automute_speaker_possible = cfg->speaker_outs &&
1022 (spec->detect_hp || spec->detect_lo);
1023
1024 spec->automute_lo = spec->automute_lo_possible;
1025 spec->automute_speaker = spec->automute_speaker_possible;
1026
1027 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001028 /* create a control for automute mode */
1029 alc_add_automute_mode_enum(codec);
1030 spec->unsol_event = alc_sku_unsol_event;
1031 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001032}
1033
Takashi Iwai1d045db2011-07-07 18:23:21 +02001034/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001035static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1036{
1037 int i;
1038 for (i = 0; i < nums; i++)
1039 if (list[i] == nid)
1040 return i;
1041 return -1;
1042}
1043
Takashi Iwai1d045db2011-07-07 18:23:21 +02001044/* check whether dynamic ADC-switching is available */
1045static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1046{
1047 struct alc_spec *spec = codec->spec;
1048 struct hda_input_mux *imux = &spec->private_imux[0];
1049 int i, n, idx;
1050 hda_nid_t cap, pin;
1051
1052 if (imux != spec->input_mux) /* no dynamic imux? */
1053 return false;
1054
1055 for (n = 0; n < spec->num_adc_nids; n++) {
1056 cap = spec->private_capsrc_nids[n];
1057 for (i = 0; i < imux->num_items; i++) {
1058 pin = spec->imux_pins[i];
1059 if (!pin)
1060 return false;
1061 if (get_connection_index(codec, cap, pin) < 0)
1062 break;
1063 }
1064 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001065 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001066 }
1067
1068 for (i = 0; i < imux->num_items; i++) {
1069 pin = spec->imux_pins[i];
1070 for (n = 0; n < spec->num_adc_nids; n++) {
1071 cap = spec->private_capsrc_nids[n];
1072 idx = get_connection_index(codec, cap, pin);
1073 if (idx >= 0) {
1074 imux->items[i].index = idx;
1075 spec->dyn_adc_idx[i] = n;
1076 break;
1077 }
1078 }
1079 }
1080
1081 snd_printdd("realtek: enabling ADC switching\n");
1082 spec->dyn_adc_switch = 1;
1083 return true;
1084}
Takashi Iwai21268962011-07-07 15:01:13 +02001085
Takashi Iwai21268962011-07-07 15:01:13 +02001086/* check whether all auto-mic pins are valid; setup indices if OK */
1087static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1088{
1089 struct alc_spec *spec = codec->spec;
1090 const struct hda_input_mux *imux;
1091
1092 if (!spec->auto_mic)
1093 return false;
1094 if (spec->auto_mic_valid_imux)
1095 return true; /* already checked */
1096
1097 /* fill up imux indices */
1098 if (!alc_check_dyn_adc_switch(codec)) {
1099 spec->auto_mic = 0;
1100 return false;
1101 }
1102
1103 imux = spec->input_mux;
1104 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1105 spec->imux_pins, imux->num_items);
1106 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1107 spec->imux_pins, imux->num_items);
1108 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1109 spec->imux_pins, imux->num_items);
1110 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1111 spec->auto_mic = 0;
1112 return false; /* no corresponding imux */
1113 }
1114
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001115 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001116 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001117 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1118 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001119
1120 spec->auto_mic_valid_imux = 1;
1121 spec->auto_mic = 1;
1122 return true;
1123}
1124
Takashi Iwai1d045db2011-07-07 18:23:21 +02001125/*
1126 * Check the availability of auto-mic switch;
1127 * Set up if really supported
1128 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001129static void alc_init_auto_mic(struct hda_codec *codec)
1130{
1131 struct alc_spec *spec = codec->spec;
1132 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001133 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001134 int i;
1135
Takashi Iwai24de1832011-11-07 17:13:39 +01001136 if (spec->shared_mic_hp)
1137 return; /* no auto-mic for the shared I/O */
1138
Takashi Iwai21268962011-07-07 15:01:13 +02001139 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1140
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001141 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001142 for (i = 0; i < cfg->num_inputs; i++) {
1143 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001144 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001146 switch (snd_hda_get_input_pin_attr(defcfg)) {
1147 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001148 if (fixed)
1149 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001150 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1151 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001152 fixed = nid;
1153 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001154 case INPUT_PIN_ATTR_UNUSED:
1155 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001156 case INPUT_PIN_ATTR_DOCK:
1157 if (dock)
1158 return; /* already occupied */
1159 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1160 return; /* invalid type */
1161 dock = nid;
1162 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001163 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001164 if (ext)
1165 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001166 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1167 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001168 ext = nid;
1169 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001170 }
1171 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001172 if (!ext && dock) {
1173 ext = dock;
1174 dock = 0;
1175 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001176 if (!ext || !fixed)
1177 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001178 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001179 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001180 if (dock && !is_jack_detectable(codec, dock))
1181 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001182
1183 /* check imux indices */
1184 spec->ext_mic_pin = ext;
1185 spec->int_mic_pin = fixed;
1186 spec->dock_mic_pin = dock;
1187
1188 spec->auto_mic = 1;
1189 if (!alc_auto_mic_check_imux(codec))
1190 return;
1191
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001192 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1193 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001194 spec->unsol_event = alc_sku_unsol_event;
1195}
1196
Takashi Iwai1d045db2011-07-07 18:23:21 +02001197/* check the availabilities of auto-mute and auto-mic switches */
1198static void alc_auto_check_switches(struct hda_codec *codec)
1199{
David Henningsson42cf0d02011-09-20 12:04:56 +02001200 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001201 alc_init_auto_mic(codec);
1202}
1203
1204/*
1205 * Realtek SSID verification
1206 */
1207
David Henningsson90622912010-10-14 14:50:18 +02001208/* Could be any non-zero and even value. When used as fixup, tells
1209 * the driver to ignore any present sku defines.
1210 */
1211#define ALC_FIXUP_SKU_IGNORE (2)
1212
Takashi Iwai23d30f22012-05-07 17:17:32 +02001213static void alc_fixup_sku_ignore(struct hda_codec *codec,
1214 const struct hda_fixup *fix, int action)
1215{
1216 struct alc_spec *spec = codec->spec;
1217 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1218 spec->cdefine.fixup = 1;
1219 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1220 }
1221}
1222
Kailang Yangda00c242010-03-19 11:23:45 +01001223static int alc_auto_parse_customize_define(struct hda_codec *codec)
1224{
1225 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001226 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001227 struct alc_spec *spec = codec->spec;
1228
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001229 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1230
David Henningsson90622912010-10-14 14:50:18 +02001231 if (spec->cdefine.fixup) {
1232 ass = spec->cdefine.sku_cfg;
1233 if (ass == ALC_FIXUP_SKU_IGNORE)
1234 return -1;
1235 goto do_sku;
1236 }
1237
Kailang Yangda00c242010-03-19 11:23:45 +01001238 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001239 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001240 goto do_sku;
1241
1242 nid = 0x1d;
1243 if (codec->vendor_id == 0x10ec0260)
1244 nid = 0x17;
1245 ass = snd_hda_codec_get_pincfg(codec, nid);
1246
1247 if (!(ass & 1)) {
1248 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1249 codec->chip_name, ass);
1250 return -1;
1251 }
1252
1253 /* check sum */
1254 tmp = 0;
1255 for (i = 1; i < 16; i++) {
1256 if ((ass >> i) & 1)
1257 tmp++;
1258 }
1259 if (((ass >> 16) & 0xf) != tmp)
1260 return -1;
1261
1262 spec->cdefine.port_connectivity = ass >> 30;
1263 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1264 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1265 spec->cdefine.customization = ass >> 8;
1266do_sku:
1267 spec->cdefine.sku_cfg = ass;
1268 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1269 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1270 spec->cdefine.swap = (ass & 0x2) >> 1;
1271 spec->cdefine.override = ass & 0x1;
1272
1273 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1274 nid, spec->cdefine.sku_cfg);
1275 snd_printd("SKU: port_connectivity=0x%x\n",
1276 spec->cdefine.port_connectivity);
1277 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1278 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1279 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1280 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1281 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1282 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1283 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1284
1285 return 0;
1286}
1287
Takashi Iwai1d045db2011-07-07 18:23:21 +02001288/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001289static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1290{
Takashi Iwai21268962011-07-07 15:01:13 +02001291 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001292}
1293
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001294/* check subsystem ID and set up device-specific initialization;
1295 * return 1 if initialized, 0 if invalid SSID
1296 */
1297/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1298 * 31 ~ 16 : Manufacture ID
1299 * 15 ~ 8 : SKU ID
1300 * 7 ~ 0 : Assembly ID
1301 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1302 */
1303static int alc_subsystem_id(struct hda_codec *codec,
1304 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001305 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001306{
1307 unsigned int ass, tmp, i;
1308 unsigned nid;
1309 struct alc_spec *spec = codec->spec;
1310
David Henningsson90622912010-10-14 14:50:18 +02001311 if (spec->cdefine.fixup) {
1312 ass = spec->cdefine.sku_cfg;
1313 if (ass == ALC_FIXUP_SKU_IGNORE)
1314 return 0;
1315 goto do_sku;
1316 }
1317
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001318 ass = codec->subsystem_id & 0xffff;
1319 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1320 goto do_sku;
1321
1322 /* invalid SSID, check the special NID pin defcfg instead */
1323 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001324 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001325 * 29~21 : reserve
1326 * 20 : PCBEEP input
1327 * 19~16 : Check sum (15:1)
1328 * 15~1 : Custom
1329 * 0 : override
1330 */
1331 nid = 0x1d;
1332 if (codec->vendor_id == 0x10ec0260)
1333 nid = 0x17;
1334 ass = snd_hda_codec_get_pincfg(codec, nid);
1335 snd_printd("realtek: No valid SSID, "
1336 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001337 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001338 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001339 return 0;
1340 if ((ass >> 30) != 1) /* no physical connection */
1341 return 0;
1342
1343 /* check sum */
1344 tmp = 0;
1345 for (i = 1; i < 16; i++) {
1346 if ((ass >> i) & 1)
1347 tmp++;
1348 }
1349 if (((ass >> 16) & 0xf) != tmp)
1350 return 0;
1351do_sku:
1352 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1353 ass & 0xffff, codec->vendor_id);
1354 /*
1355 * 0 : override
1356 * 1 : Swap Jack
1357 * 2 : 0 --> Desktop, 1 --> Laptop
1358 * 3~5 : External Amplifier control
1359 * 7~6 : Reserved
1360 */
1361 tmp = (ass & 0x38) >> 3; /* external Amp control */
1362 switch (tmp) {
1363 case 1:
1364 spec->init_amp = ALC_INIT_GPIO1;
1365 break;
1366 case 3:
1367 spec->init_amp = ALC_INIT_GPIO2;
1368 break;
1369 case 7:
1370 spec->init_amp = ALC_INIT_GPIO3;
1371 break;
1372 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001373 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001374 spec->init_amp = ALC_INIT_DEFAULT;
1375 break;
1376 }
1377
1378 /* is laptop or Desktop and enable the function "Mute internal speaker
1379 * when the external headphone out jack is plugged"
1380 */
1381 if (!(ass & 0x8000))
1382 return 1;
1383 /*
1384 * 10~8 : Jack location
1385 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1386 * 14~13: Resvered
1387 * 15 : 1 --> enable the function "Mute internal speaker
1388 * when the external headphone out jack is plugged"
1389 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001390 if (!spec->autocfg.hp_pins[0] &&
1391 !(spec->autocfg.line_out_pins[0] &&
1392 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001393 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001394 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1395 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001396 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001397 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001398 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001399 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001400 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001401 else if (tmp == 3)
1402 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001403 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001404 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001405 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1406 spec->autocfg.line_outs))
1407 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001408 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001409 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001410 return 1;
1411}
Kailang Yangea1fb292008-08-26 12:58:38 +02001412
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001413/* Check the validity of ALC subsystem-id
1414 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1415static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001416{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001417 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001418 struct alc_spec *spec = codec->spec;
1419 snd_printd("realtek: "
1420 "Enable default setup for auto mode as fallback\n");
1421 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001422 }
Takashi Iwai21268962011-07-07 15:01:13 +02001423}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001424
Takashi Iwai41e41f12005-06-08 14:48:49 +02001425/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001426 * COEF access helper functions
1427 */
Kailang Yang274693f2009-12-03 10:07:50 +01001428static int alc_read_coef_idx(struct hda_codec *codec,
1429 unsigned int coef_idx)
1430{
1431 unsigned int val;
1432 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1433 coef_idx);
1434 val = snd_hda_codec_read(codec, 0x20, 0,
1435 AC_VERB_GET_PROC_COEF, 0);
1436 return val;
1437}
1438
Kailang Yang977ddd62010-09-15 10:02:29 +02001439static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1440 unsigned int coef_val)
1441{
1442 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1443 coef_idx);
1444 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1445 coef_val);
1446}
1447
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001448/* a special bypass for COEF 0; read the cached value at the second time */
1449static unsigned int alc_get_coef0(struct hda_codec *codec)
1450{
1451 struct alc_spec *spec = codec->spec;
1452 if (!spec->coef0)
1453 spec->coef0 = alc_read_coef_idx(codec, 0);
1454 return spec->coef0;
1455}
1456
Takashi Iwai1d045db2011-07-07 18:23:21 +02001457/*
1458 * Digital I/O handling
1459 */
1460
Takashi Iwai757899a2010-07-30 10:48:14 +02001461/* set right pin controls for digital I/O */
1462static void alc_auto_init_digital(struct hda_codec *codec)
1463{
1464 struct alc_spec *spec = codec->spec;
1465 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001466 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001467
1468 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1469 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001470 if (!pin)
1471 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001472 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001473 if (!i)
1474 dac = spec->multiout.dig_out_nid;
1475 else
1476 dac = spec->slave_dig_outs[i - 1];
1477 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1478 continue;
1479 snd_hda_codec_write(codec, dac, 0,
1480 AC_VERB_SET_AMP_GAIN_MUTE,
1481 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001482 }
1483 pin = spec->autocfg.dig_in_pin;
1484 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001485 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001486}
1487
1488/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1489static void alc_auto_parse_digital(struct hda_codec *codec)
1490{
1491 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001492 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001493 hda_nid_t dig_nid;
1494
1495 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001496 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001497 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001498 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001499 err = snd_hda_get_connections(codec,
1500 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001501 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001502 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001503 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001504 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001505 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001506 spec->multiout.dig_out_nid = dig_nid;
1507 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1508 } else {
1509 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001510 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001511 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001512 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001513 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001514 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001515 }
1516
1517 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001518 dig_nid = codec->start_nid;
1519 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1520 unsigned int wcaps = get_wcaps(codec, dig_nid);
1521 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1522 continue;
1523 if (!(wcaps & AC_WCAP_DIGITAL))
1524 continue;
1525 if (!(wcaps & AC_WCAP_CONN_LIST))
1526 continue;
1527 err = get_connection_index(codec, dig_nid,
1528 spec->autocfg.dig_in_pin);
1529 if (err >= 0) {
1530 spec->dig_in_nid = dig_nid;
1531 break;
1532 }
1533 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001534 }
1535}
1536
Takashi Iwaif95474e2007-07-10 00:47:43 +02001537/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001538 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001539 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001540static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1541 struct snd_ctl_elem_info *uinfo)
1542{
1543 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1544 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001545 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001546 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001547
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001548 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001549 if (spec->vol_in_capsrc)
1550 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1551 else
1552 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1553 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001554 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001555 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001556 return err;
1557}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001559static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1560 unsigned int size, unsigned int __user *tlv)
1561{
1562 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1563 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001564 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001565 int err;
1566
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001567 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001568 if (spec->vol_in_capsrc)
1569 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1570 else
1571 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1572 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001573 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001574 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001575 return err;
1576}
1577
1578typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1579 struct snd_ctl_elem_value *ucontrol);
1580
1581static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1582 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001583 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001584{
1585 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1586 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001587 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001588
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001589 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001590 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001591 for (i = 0; i < spec->num_adc_nids; i++) {
1592 kcontrol->private_value =
1593 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1594 3, 0, HDA_INPUT);
1595 err = func(kcontrol, ucontrol);
1596 if (err < 0)
1597 goto error;
1598 }
1599 } else {
1600 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001601 if (spec->vol_in_capsrc)
1602 kcontrol->private_value =
1603 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1604 3, 0, HDA_OUTPUT);
1605 else
1606 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001607 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1608 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001609 err = func(kcontrol, ucontrol);
1610 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001611 if (err >= 0 && is_put)
1612 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001613 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001614 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001615 return err;
1616}
1617
1618static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1619 struct snd_ctl_elem_value *ucontrol)
1620{
1621 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001622 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001623}
1624
1625static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1626 struct snd_ctl_elem_value *ucontrol)
1627{
1628 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001629 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001630}
1631
1632/* capture mixer elements */
1633#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1634
1635static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1636 struct snd_ctl_elem_value *ucontrol)
1637{
1638 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001639 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001640}
1641
1642static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1643 struct snd_ctl_elem_value *ucontrol)
1644{
1645 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001646 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001647}
1648
Takashi Iwaia23b6882009-03-23 15:21:36 +01001649#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001650 { \
1651 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1652 .name = "Capture Switch", \
1653 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1654 .count = num, \
1655 .info = alc_cap_sw_info, \
1656 .get = alc_cap_sw_get, \
1657 .put = alc_cap_sw_put, \
1658 }, \
1659 { \
1660 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1661 .name = "Capture Volume", \
1662 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1663 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1664 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1665 .count = num, \
1666 .info = alc_cap_vol_info, \
1667 .get = alc_cap_vol_get, \
1668 .put = alc_cap_vol_put, \
1669 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001670 }
1671
1672#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001673 { \
1674 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1675 /* .name = "Capture Source", */ \
1676 .name = "Input Source", \
1677 .count = num, \
1678 .info = alc_mux_enum_info, \
1679 .get = alc_mux_enum_get, \
1680 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001681 }
1682
1683#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001684static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001685 _DEFINE_CAPMIX(num), \
1686 _DEFINE_CAPSRC(num), \
1687 { } /* end */ \
1688}
1689
1690#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001691static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001692 _DEFINE_CAPMIX(num), \
1693 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001694}
1695
1696/* up to three ADCs */
1697DEFINE_CAPMIX(1);
1698DEFINE_CAPMIX(2);
1699DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001700DEFINE_CAPMIX_NOSRC(1);
1701DEFINE_CAPMIX_NOSRC(2);
1702DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001703
1704/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001705 * Inverted digital-mic handling
1706 *
1707 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1708 * gives the additional mute only to the right channel of the digital mic
1709 * capture stream. This is a workaround for avoiding the almost silence
1710 * by summing the stereo stream from some (known to be ForteMedia)
1711 * digital mic unit.
1712 *
1713 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1714 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1715 * without caching so that the cache can still keep the original value.
1716 * The cached value is then restored when the flag is set off or any other
1717 * than d-mic is used as the current input source.
1718 */
1719static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1720{
1721 struct alc_spec *spec = codec->spec;
1722 int i;
1723
1724 if (!spec->inv_dmic_fixup)
1725 return;
1726 if (!spec->inv_dmic_muted && !force)
1727 return;
1728 for (i = 0; i < spec->num_adc_nids; i++) {
1729 int src = spec->dyn_adc_switch ? 0 : i;
1730 bool dmic_fixup = false;
1731 hda_nid_t nid;
1732 int parm, dir, v;
1733
1734 if (spec->inv_dmic_muted &&
1735 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1736 dmic_fixup = true;
1737 if (!dmic_fixup && !force)
1738 continue;
1739 if (spec->vol_in_capsrc) {
1740 nid = spec->capsrc_nids[i];
1741 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1742 dir = HDA_OUTPUT;
1743 } else {
1744 nid = spec->adc_nids[i];
1745 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1746 dir = HDA_INPUT;
1747 }
1748 /* we care only right channel */
1749 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1750 if (v & 0x80) /* if already muted, we don't need to touch */
1751 continue;
1752 if (dmic_fixup) /* add mute for d-mic */
1753 v |= 0x80;
1754 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1755 parm | v);
1756 }
1757}
1758
1759static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1760 struct snd_ctl_elem_value *ucontrol)
1761{
1762 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1763 struct alc_spec *spec = codec->spec;
1764
1765 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1766 return 0;
1767}
1768
1769static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1770 struct snd_ctl_elem_value *ucontrol)
1771{
1772 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1773 struct alc_spec *spec = codec->spec;
1774 unsigned int val = !ucontrol->value.integer.value[0];
1775
1776 if (val == spec->inv_dmic_muted)
1777 return 0;
1778 spec->inv_dmic_muted = val;
1779 alc_inv_dmic_sync(codec, true);
1780 return 0;
1781}
1782
1783static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1784 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1785 .info = snd_ctl_boolean_mono_info,
1786 .get = alc_inv_dmic_sw_get,
1787 .put = alc_inv_dmic_sw_put,
1788};
1789
1790static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1791{
1792 struct alc_spec *spec = codec->spec;
1793 struct snd_kcontrol_new *knew = alc_kcontrol_new(spec);
1794 if (!knew)
1795 return -ENOMEM;
1796 *knew = alc_inv_dmic_sw;
1797 knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL);
1798 if (!knew->name)
1799 return -ENOMEM;
1800 spec->inv_dmic_fixup = 1;
1801 spec->inv_dmic_muted = 0;
1802 spec->inv_dmic_pin = nid;
1803 return 0;
1804}
1805
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001806/* typically the digital mic is put at node 0x12 */
1807static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1808 const struct alc_fixup *fix, int action)
1809{
1810 if (action == ALC_FIXUP_ACT_PROBE)
1811 alc_add_inv_dmic_mixer(codec, 0x12);
1812}
1813
Takashi Iwai125821a2012-06-22 14:30:29 +02001814/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001815 * virtual master controls
1816 */
1817
1818/*
1819 * slave controls for virtual master
1820 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001821static const char * const alc_slave_pfxs[] = {
1822 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001823 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001824 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001825 NULL,
1826};
1827
1828/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001829 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001831
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001832#define NID_MAPPING (-1)
1833
1834#define SUBDEV_SPEAKER_ (0 << 6)
1835#define SUBDEV_HP_ (1 << 6)
1836#define SUBDEV_LINE_ (2 << 6)
1837#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1838#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1839#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1840
Takashi Iwai603c4012008-07-30 15:01:44 +02001841static void alc_free_kctls(struct hda_codec *codec);
1842
Takashi Iwai67d634c2009-11-16 15:35:59 +01001843#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001844/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001845static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001846 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001847 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001848 { } /* end */
1849};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001850#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001851
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001852static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853{
1854 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001855 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001856 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001857 int i, j, err;
1858 unsigned int u;
1859 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860
1861 for (i = 0; i < spec->num_mixers; i++) {
1862 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1863 if (err < 0)
1864 return err;
1865 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001866 if (spec->cap_mixer) {
1867 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1868 if (err < 0)
1869 return err;
1870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001872 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001873 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001874 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 if (err < 0)
1876 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001877 if (!spec->no_analog) {
1878 err = snd_hda_create_spdif_share_sw(codec,
1879 &spec->multiout);
1880 if (err < 0)
1881 return err;
1882 spec->multiout.share_spdif = 1;
1883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 }
1885 if (spec->dig_in_nid) {
1886 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1887 if (err < 0)
1888 return err;
1889 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001890
Takashi Iwai67d634c2009-11-16 15:35:59 +01001891#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001892 /* create beep controls if needed */
1893 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001894 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001895 for (knew = alc_beep_mixer; knew->name; knew++) {
1896 struct snd_kcontrol *kctl;
1897 kctl = snd_ctl_new1(knew, codec);
1898 if (!kctl)
1899 return -ENOMEM;
1900 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001901 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001902 if (err < 0)
1903 return err;
1904 }
1905 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001906#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001907
Takashi Iwai2134ea42008-01-10 16:53:55 +01001908 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001909 if (!spec->no_analog &&
1910 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001911 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001912 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001913 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001914 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001915 vmaster_tlv, alc_slave_pfxs,
1916 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001917 if (err < 0)
1918 return err;
1919 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001920 if (!spec->no_analog &&
1921 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001922 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1923 NULL, alc_slave_pfxs,
1924 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001925 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001926 if (err < 0)
1927 return err;
1928 }
1929
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001930 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001931 if (spec->capsrc_nids || spec->adc_nids) {
1932 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1933 if (!kctl)
1934 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1935 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001936 err = snd_hda_add_nid(codec, kctl, i,
1937 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001938 if (err < 0)
1939 return err;
1940 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001941 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001942 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001943 const char *kname = kctl ? kctl->id.name : NULL;
1944 for (knew = spec->cap_mixer; knew->name; knew++) {
1945 if (kname && strcmp(knew->name, kname) == 0)
1946 continue;
1947 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1948 for (i = 0; kctl && i < kctl->count; i++) {
1949 err = snd_hda_add_nid(codec, kctl, i,
1950 spec->adc_nids[i]);
1951 if (err < 0)
1952 return err;
1953 }
1954 }
1955 }
1956
1957 /* other nid->control mapping */
1958 for (i = 0; i < spec->num_mixers; i++) {
1959 for (knew = spec->mixers[i]; knew->name; knew++) {
1960 if (knew->iface != NID_MAPPING)
1961 continue;
1962 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1963 if (kctl == NULL)
1964 continue;
1965 u = knew->subdevice;
1966 for (j = 0; j < 4; j++, u >>= 8) {
1967 nid = u & 0x3f;
1968 if (nid == 0)
1969 continue;
1970 switch (u & 0xc0) {
1971 case SUBDEV_SPEAKER_:
1972 nid = spec->autocfg.speaker_pins[nid];
1973 break;
1974 case SUBDEV_LINE_:
1975 nid = spec->autocfg.line_out_pins[nid];
1976 break;
1977 case SUBDEV_HP_:
1978 nid = spec->autocfg.hp_pins[nid];
1979 break;
1980 default:
1981 continue;
1982 }
1983 err = snd_hda_add_nid(codec, kctl, 0, nid);
1984 if (err < 0)
1985 return err;
1986 }
1987 u = knew->private_value;
1988 for (j = 0; j < 4; j++, u >>= 8) {
1989 nid = u & 0xff;
1990 if (nid == 0)
1991 continue;
1992 err = snd_hda_add_nid(codec, kctl, 0, nid);
1993 if (err < 0)
1994 return err;
1995 }
1996 }
1997 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001998
1999 alc_free_kctls(codec); /* no longer needed */
2000
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002001 return 0;
2002}
2003
David Henningsson5780b622012-06-27 18:45:45 +02002004static int alc_build_jacks(struct hda_codec *codec)
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002005{
2006 struct alc_spec *spec = codec->spec;
David Henningsson5780b622012-06-27 18:45:45 +02002007
2008 if (spec->shared_mic_hp) {
2009 int err;
2010 int nid = spec->autocfg.inputs[1].pin;
2011 err = snd_hda_jack_add_kctl(codec, nid, "Headphone Mic", 0);
2012 if (err < 0)
2013 return err;
2014 err = snd_hda_jack_detect_enable(codec, nid, 0);
2015 if (err < 0)
2016 return err;
2017 }
2018
2019 return snd_hda_jack_add_kctls(codec, &spec->autocfg);
2020}
2021
2022static int alc_build_controls(struct hda_codec *codec)
2023{
Takashi Iwaif21d78e2012-01-19 12:10:29 +01002024 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02002025 if (err < 0)
2026 return err;
David Henningsson5780b622012-06-27 18:45:45 +02002027
2028 err = alc_build_jacks(codec);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01002029 if (err < 0)
2030 return err;
2031 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
2032 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033}
2034
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002035
Linus Torvalds1da177e2005-04-16 15:20:36 -07002036/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002037 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002038 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002039
Takashi Iwai584c0c42011-03-10 12:51:11 +01002040static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002041static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002042
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043static int alc_init(struct hda_codec *codec)
2044{
2045 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002046
Takashi Iwai546bb672012-03-07 08:37:19 +01002047 if (spec->init_hook)
2048 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002049
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002050 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002051 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002052
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002053 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002054 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002055 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002056
Takashi Iwai58701122011-01-13 15:41:45 +01002057 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2058
Takashi Iwai01a61e12011-10-28 00:03:22 +02002059 snd_hda_jack_report_sync(codec);
2060
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002061 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 return 0;
2063}
2064
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002065static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2066{
2067 struct alc_spec *spec = codec->spec;
2068
2069 if (spec->unsol_event)
2070 spec->unsol_event(codec, res);
2071}
2072
Takashi Iwaicb53c622007-08-10 17:21:45 +02002073#ifdef CONFIG_SND_HDA_POWER_SAVE
2074static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2075{
2076 struct alc_spec *spec = codec->spec;
2077 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2078}
2079#endif
2080
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081/*
2082 * Analog playback callbacks
2083 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002084static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002086 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087{
2088 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002089 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2090 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091}
2092
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002093static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 struct hda_codec *codec,
2095 unsigned int stream_tag,
2096 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002097 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098{
2099 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002100 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2101 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002102}
2103
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002104static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002106 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107{
2108 struct alc_spec *spec = codec->spec;
2109 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2110}
2111
2112/*
2113 * Digital out
2114 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002115static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002117 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
2119 struct alc_spec *spec = codec->spec;
2120 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2121}
2122
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002123static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002124 struct hda_codec *codec,
2125 unsigned int stream_tag,
2126 unsigned int format,
2127 struct snd_pcm_substream *substream)
2128{
2129 struct alc_spec *spec = codec->spec;
2130 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2131 stream_tag, format, substream);
2132}
2133
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002134static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002135 struct hda_codec *codec,
2136 struct snd_pcm_substream *substream)
2137{
2138 struct alc_spec *spec = codec->spec;
2139 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2140}
2141
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002142static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002144 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
2146 struct alc_spec *spec = codec->spec;
2147 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2148}
2149
2150/*
2151 * Analog capture
2152 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002153static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 struct hda_codec *codec,
2155 unsigned int stream_tag,
2156 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002157 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158{
2159 struct alc_spec *spec = codec->spec;
2160
Takashi Iwai63300792008-01-24 15:31:36 +01002161 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 stream_tag, 0, format);
2163 return 0;
2164}
2165
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002166static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002168 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169{
2170 struct alc_spec *spec = codec->spec;
2171
Takashi Iwai888afa12008-03-18 09:57:50 +01002172 snd_hda_codec_cleanup_stream(codec,
2173 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 return 0;
2175}
2176
Takashi Iwai840b64c2010-07-13 22:49:01 +02002177/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002178static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002179 struct hda_codec *codec,
2180 unsigned int stream_tag,
2181 unsigned int format,
2182 struct snd_pcm_substream *substream)
2183{
2184 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002185 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002186 spec->cur_adc_stream_tag = stream_tag;
2187 spec->cur_adc_format = format;
2188 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2189 return 0;
2190}
2191
Takashi Iwai21268962011-07-07 15:01:13 +02002192static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002193 struct hda_codec *codec,
2194 struct snd_pcm_substream *substream)
2195{
2196 struct alc_spec *spec = codec->spec;
2197 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2198 spec->cur_adc = 0;
2199 return 0;
2200}
2201
Takashi Iwai21268962011-07-07 15:01:13 +02002202static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002203 .substreams = 1,
2204 .channels_min = 2,
2205 .channels_max = 2,
2206 .nid = 0, /* fill later */
2207 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002208 .prepare = dyn_adc_capture_pcm_prepare,
2209 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002210 },
2211};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212
2213/*
2214 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002215static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 .substreams = 1,
2217 .channels_min = 2,
2218 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002219 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002221 .open = alc_playback_pcm_open,
2222 .prepare = alc_playback_pcm_prepare,
2223 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 },
2225};
2226
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002227static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002228 .substreams = 1,
2229 .channels_min = 2,
2230 .channels_max = 2,
2231 /* NID is set in alc_build_pcms */
2232};
2233
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002234static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002235 .substreams = 1,
2236 .channels_min = 2,
2237 .channels_max = 2,
2238 /* NID is set in alc_build_pcms */
2239};
2240
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002241static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002242 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 .channels_min = 2,
2244 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002245 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002247 .prepare = alc_alt_capture_pcm_prepare,
2248 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 },
2250};
2251
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002252static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 .substreams = 1,
2254 .channels_min = 2,
2255 .channels_max = 2,
2256 /* NID is set in alc_build_pcms */
2257 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002258 .open = alc_dig_playback_pcm_open,
2259 .close = alc_dig_playback_pcm_close,
2260 .prepare = alc_dig_playback_pcm_prepare,
2261 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262 },
2263};
2264
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002265static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 .substreams = 1,
2267 .channels_min = 2,
2268 .channels_max = 2,
2269 /* NID is set in alc_build_pcms */
2270};
2271
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002272/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002273static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002274 .substreams = 0,
2275 .channels_min = 0,
2276 .channels_max = 0,
2277};
2278
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279static int alc_build_pcms(struct hda_codec *codec)
2280{
2281 struct alc_spec *spec = codec->spec;
2282 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002283 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002284 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 int i;
2286
2287 codec->num_pcms = 1;
2288 codec->pcm_info = info;
2289
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002290 if (spec->no_analog)
2291 goto skip_analog;
2292
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002293 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2294 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002296
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002297 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002298 p = spec->stream_analog_playback;
2299 if (!p)
2300 p = &alc_pcm_analog_playback;
2301 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002302 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2303 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002304 if (spec->adc_nids) {
2305 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002306 if (!p) {
2307 if (spec->dyn_adc_switch)
2308 p = &dyn_adc_pcm_analog_capture;
2309 else
2310 p = &alc_pcm_analog_capture;
2311 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002312 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002313 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2314 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315
Takashi Iwai4a471b72005-12-07 13:56:29 +01002316 if (spec->channel_mode) {
2317 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2318 for (i = 0; i < spec->num_channel_mode; i++) {
2319 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2320 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 }
2323 }
2324
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002325 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002326 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002328 snprintf(spec->stream_name_digital,
2329 sizeof(spec->stream_name_digital),
2330 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002331 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002332 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002333 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002334 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002335 if (spec->dig_out_type)
2336 info->pcm_type = spec->dig_out_type;
2337 else
2338 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002339 if (spec->multiout.dig_out_nid) {
2340 p = spec->stream_digital_playback;
2341 if (!p)
2342 p = &alc_pcm_digital_playback;
2343 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2345 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002346 if (spec->dig_in_nid) {
2347 p = spec->stream_digital_capture;
2348 if (!p)
2349 p = &alc_pcm_digital_capture;
2350 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2352 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002353 /* FIXME: do we need this for all Realtek codec models? */
2354 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 }
2356
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002357 if (spec->no_analog)
2358 return 0;
2359
Takashi Iwaie08a0072006-09-07 17:52:14 +02002360 /* If the use of more than one ADC is requested for the current
2361 * model, configure a second analog capture-only PCM.
2362 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002363 have_multi_adcs = (spec->num_adc_nids > 1) &&
2364 !spec->dyn_adc_switch && !spec->auto_mic &&
2365 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002366 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002367 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002368 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002369 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002370 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002371 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002372 p = spec->stream_analog_alt_playback;
2373 if (!p)
2374 p = &alc_pcm_analog_alt_playback;
2375 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002376 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2377 spec->alt_dac_nid;
2378 } else {
2379 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2380 alc_pcm_null_stream;
2381 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2382 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002383 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002384 p = spec->stream_analog_alt_capture;
2385 if (!p)
2386 p = &alc_pcm_analog_alt_capture;
2387 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002388 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2389 spec->adc_nids[1];
2390 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2391 spec->num_adc_nids - 1;
2392 } else {
2393 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2394 alc_pcm_null_stream;
2395 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002396 }
2397 }
2398
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 return 0;
2400}
2401
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002402static inline void alc_shutup(struct hda_codec *codec)
2403{
Takashi Iwai1c716152011-04-07 10:37:16 +02002404 struct alc_spec *spec = codec->spec;
2405
2406 if (spec && spec->shutup)
2407 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002408 snd_hda_shutup_pins(codec);
2409}
2410
Takashi Iwai603c4012008-07-30 15:01:44 +02002411static void alc_free_kctls(struct hda_codec *codec)
2412{
2413 struct alc_spec *spec = codec->spec;
2414
2415 if (spec->kctls.list) {
2416 struct snd_kcontrol_new *kctl = spec->kctls.list;
2417 int i;
2418 for (i = 0; i < spec->kctls.used; i++)
2419 kfree(kctl[i].name);
2420 }
2421 snd_array_free(&spec->kctls);
2422}
2423
Takashi Iwai23c09b02011-08-19 09:05:35 +02002424static void alc_free_bind_ctls(struct hda_codec *codec)
2425{
2426 struct alc_spec *spec = codec->spec;
2427 if (spec->bind_ctls.list) {
2428 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2429 int i;
2430 for (i = 0; i < spec->bind_ctls.used; i++)
2431 kfree(ctl[i]);
2432 }
2433 snd_array_free(&spec->bind_ctls);
2434}
2435
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436static void alc_free(struct hda_codec *codec)
2437{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002438 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002439
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002440 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002441 return;
2442
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002443 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002444 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002445 alc_free_bind_ctls(codec);
Takashi Iwaiee48df52012-06-26 14:54:32 +02002446 snd_hda_gen_free(&spec->gen);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002447 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002448 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449}
2450
Hector Martinf5de24b2009-12-20 22:51:31 +01002451#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002452static void alc_power_eapd(struct hda_codec *codec)
2453{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002454 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002455}
2456
Hector Martinf5de24b2009-12-20 22:51:31 +01002457static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2458{
2459 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002460 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002461 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002462 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002463 return 0;
2464}
2465#endif
2466
Takashi Iwai2a439522011-07-26 09:52:50 +02002467#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002468static int alc_resume(struct hda_codec *codec)
2469{
Takashi Iwai1c716152011-04-07 10:37:16 +02002470 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002471 codec->patch_ops.init(codec);
2472 snd_hda_codec_resume_amp(codec);
2473 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002474 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002475 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002476 return 0;
2477}
Takashi Iwaie044c392008-10-27 16:56:24 +01002478#endif
2479
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480/*
2481 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002482static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 .build_controls = alc_build_controls,
2484 .build_pcms = alc_build_pcms,
2485 .init = alc_init,
2486 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002487 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002488#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002489 .resume = alc_resume,
2490#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002491#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002492 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002493 .check_power_status = alc_check_power_status,
2494#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002495 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496};
2497
Kailang Yangc027ddc2010-03-19 11:33:06 +01002498/* replace the codec chip_name with the given string */
2499static int alc_codec_rename(struct hda_codec *codec, const char *name)
2500{
2501 kfree(codec->chip_name);
2502 codec->chip_name = kstrdup(name, GFP_KERNEL);
2503 if (!codec->chip_name) {
2504 alc_free(codec);
2505 return -ENOMEM;
2506 }
2507 return 0;
2508}
2509
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002510/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002511 * Rename codecs appropriately from COEF value
2512 */
2513struct alc_codec_rename_table {
2514 unsigned int vendor_id;
2515 unsigned short coef_mask;
2516 unsigned short coef_bits;
2517 const char *name;
2518};
2519
2520static struct alc_codec_rename_table rename_tbl[] = {
2521 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2522 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2523 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2524 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2525 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2526 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2527 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002528 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002529 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2530 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2531 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2532 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2533 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2534 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2535 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2536 { } /* terminator */
2537};
2538
2539static int alc_codec_rename_from_preset(struct hda_codec *codec)
2540{
2541 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002542
2543 for (p = rename_tbl; p->vendor_id; p++) {
2544 if (p->vendor_id != codec->vendor_id)
2545 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002546 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002547 return alc_codec_rename(codec, p->name);
2548 }
2549 return 0;
2550}
2551
2552/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002553 * Automatic parse of I/O pins from the BIOS configuration
2554 */
2555
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002556enum {
2557 ALC_CTL_WIDGET_VOL,
2558 ALC_CTL_WIDGET_MUTE,
2559 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002560 ALC_CTL_BIND_VOL,
2561 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002562};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002563static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002564 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2565 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002566 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002567 HDA_BIND_VOL(NULL, 0),
2568 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002569};
2570
2571/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002572static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002573 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002574{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002575 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002576
Takashi Iwaice764ab2011-04-27 16:35:23 +02002577 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002578 if (!knew)
2579 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002580 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002581 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002582 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002583 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002584 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002585 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002586 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002587 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002588 return 0;
2589}
2590
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002591static int add_control_with_pfx(struct alc_spec *spec, int type,
2592 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002593 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002594{
2595 char name[32];
2596 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002597 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002598}
2599
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002600#define add_pb_vol_ctrl(spec, type, pfx, val) \
2601 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2602#define add_pb_sw_ctrl(spec, type, pfx, val) \
2603 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2604#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2605 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2606#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2607 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002608
Takashi Iwai23c09b02011-08-19 09:05:35 +02002609static const char * const channel_name[4] = {
2610 "Front", "Surround", "CLFE", "Side"
2611};
2612
Takashi Iwai6843ca12011-06-24 11:03:58 +02002613static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2614 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002615{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002616 struct auto_pin_cfg *cfg = &spec->autocfg;
2617
Takashi Iwai6843ca12011-06-24 11:03:58 +02002618 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002619 if (cfg->line_outs == 1 && !spec->multi_ios &&
2620 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002621 return "Master";
2622
2623 switch (cfg->line_out_type) {
2624 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002625 if (cfg->line_outs == 1)
2626 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002627 if (cfg->line_outs == 2)
2628 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002629 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002630 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002631 /* for multi-io case, only the primary out */
2632 if (ch && spec->multi_ios)
2633 break;
2634 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002635 return "Headphone";
2636 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002637 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002638 return "PCM";
2639 break;
2640 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002641 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2642 return "PCM";
2643
2644 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002645}
2646
Takashi Iwai164f73e2012-02-21 11:27:09 +01002647#ifdef CONFIG_SND_HDA_POWER_SAVE
2648/* add the powersave loopback-list entry */
2649static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2650{
2651 struct hda_amp_list *list;
2652
2653 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2654 return;
2655 list = spec->loopback_list + spec->num_loopbacks;
2656 list->nid = mix;
2657 list->dir = HDA_INPUT;
2658 list->idx = idx;
2659 spec->num_loopbacks++;
2660 spec->loopback.amplist = spec->loopback_list;
2661}
2662#else
2663#define add_loopback_list(spec, mix, idx) /* NOP */
2664#endif
2665
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002666/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002667static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002668 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002669 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002670{
Kailang Yangdf694da2005-12-05 19:42:22 +01002671 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002672
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002673 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002674 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2675 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002676 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002677 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002678 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2679 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002680 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002681 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002682 return 0;
2683}
2684
Takashi Iwai05f5f472009-08-25 13:10:18 +02002685static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002686{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002687 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2688 return (pincap & AC_PINCAP_IN) != 0;
2689}
2690
Takashi Iwai1d045db2011-07-07 18:23:21 +02002691/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002692static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002693{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002694 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002695 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002696 hda_nid_t *adc_nids = spec->private_adc_nids;
2697 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2698 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002699 int i, nums = 0;
2700
2701 nid = codec->start_nid;
2702 for (i = 0; i < codec->num_nodes; i++, nid++) {
2703 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002704 unsigned int caps = get_wcaps(codec, nid);
2705 int type = get_wcaps_type(caps);
2706
2707 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2708 continue;
2709 adc_nids[nums] = nid;
2710 cap_nids[nums] = nid;
2711 src = nid;
2712 for (;;) {
2713 int n;
2714 type = get_wcaps_type(get_wcaps(codec, src));
2715 if (type == AC_WID_PIN)
2716 break;
2717 if (type == AC_WID_AUD_SEL) {
2718 cap_nids[nums] = src;
2719 break;
2720 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002721 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002722 if (n > 1) {
2723 cap_nids[nums] = src;
2724 break;
2725 } else if (n != 1)
2726 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002727 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2728 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002729 }
2730 if (++nums >= max_nums)
2731 break;
2732 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002733 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002734 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002735 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002736 return nums;
2737}
2738
Takashi Iwai05f5f472009-08-25 13:10:18 +02002739/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002740static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002741{
2742 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002743 const struct auto_pin_cfg *cfg = &spec->autocfg;
2744 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002745 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002746 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002747 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002748 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002749
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002750 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002751 if (num_adcs < 0)
2752 return 0;
2753
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002754 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002755 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002756 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002757
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002758 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002759 if (!alc_is_input_pin(codec, pin))
2760 continue;
2761
David Henningsson5322bf22011-01-05 11:03:56 +01002762 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002763 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2764 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002765 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002766 type_idx++;
2767 else
2768 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002769 prev_label = label;
2770
Takashi Iwai05f5f472009-08-25 13:10:18 +02002771 if (mixer) {
2772 idx = get_connection_index(codec, mixer, pin);
2773 if (idx >= 0) {
2774 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002775 label, type_idx,
2776 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002777 if (err < 0)
2778 return err;
2779 }
2780 }
2781
Takashi Iwaib7821702011-07-06 15:12:46 +02002782 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002783 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002784 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002785 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002786 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002787 snd_hda_add_imux_item(imux, label, idx, NULL);
2788 break;
2789 }
2790 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002791 }
Takashi Iwai21268962011-07-07 15:01:13 +02002792
2793 spec->num_mux_defs = 1;
2794 spec->input_mux = imux;
2795
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002796 return 0;
2797}
2798
Takashi Iwai24de1832011-11-07 17:13:39 +01002799/* create a shared input with the headphone out */
2800static int alc_auto_create_shared_input(struct hda_codec *codec)
2801{
2802 struct alc_spec *spec = codec->spec;
2803 struct auto_pin_cfg *cfg = &spec->autocfg;
2804 unsigned int defcfg;
2805 hda_nid_t nid;
2806
2807 /* only one internal input pin? */
2808 if (cfg->num_inputs != 1)
2809 return 0;
2810 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2811 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2812 return 0;
2813
2814 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2815 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2816 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2817 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2818 else
2819 return 0; /* both not available */
2820
2821 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2822 return 0; /* no input */
2823
2824 cfg->inputs[1].pin = nid;
2825 cfg->inputs[1].type = AUTO_PIN_MIC;
2826 cfg->num_inputs = 2;
2827 spec->shared_mic_hp = 1;
2828 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2829 return 0;
2830}
2831
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002832static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2833 unsigned int pin_type)
2834{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002835 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002836 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002837 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2838 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002839 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002840}
2841
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002842static int get_pin_type(int line_out_type)
2843{
2844 if (line_out_type == AUTO_PIN_HP_OUT)
2845 return PIN_HP;
2846 else
2847 return PIN_OUT;
2848}
2849
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002850static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002851{
2852 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002853 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002854 int i;
2855
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002856 for (i = 0; i < cfg->num_inputs; i++) {
2857 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002858 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002859 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002860 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002861 snd_hda_codec_write(codec, nid, 0,
2862 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002863 AMP_OUT_MUTE);
2864 }
2865 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002866
2867 /* mute all loopback inputs */
2868 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002869 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002870 for (i = 0; i < nums; i++)
2871 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2872 AC_VERB_SET_AMP_GAIN_MUTE,
2873 AMP_IN_MUTE(i));
2874 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002875}
2876
Takashi Iwai7085ec12009-10-02 09:03:58 +02002877/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002878static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002879{
Takashi Iwai604401a2011-04-27 15:14:23 +02002880 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002881 int i, num;
2882
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002883 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2884 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002885 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2886 for (i = 0; i < num; i++) {
2887 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2888 return list[i];
2889 }
2890 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002891}
2892
Takashi Iwai604401a2011-04-27 15:14:23 +02002893/* go down to the selector widget before the mixer */
2894static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2895{
2896 hda_nid_t srcs[5];
2897 int num = snd_hda_get_connections(codec, pin, srcs,
2898 ARRAY_SIZE(srcs));
2899 if (num != 1 ||
2900 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2901 return pin;
2902 return srcs[0];
2903}
2904
Takashi Iwai7085ec12009-10-02 09:03:58 +02002905/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002906static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002907 hda_nid_t dac)
2908{
David Henningssoncc1c4522010-11-24 14:17:47 +01002909 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002910 int i, num;
2911
Takashi Iwai604401a2011-04-27 15:14:23 +02002912 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002913 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2914 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002915 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002916 return mix[i];
2917 }
2918 return 0;
2919}
2920
Takashi Iwaice764ab2011-04-27 16:35:23 +02002921/* select the connection from pin to DAC if needed */
2922static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2923 hda_nid_t dac)
2924{
2925 hda_nid_t mix[5];
2926 int i, num;
2927
2928 pin = alc_go_down_to_selector(codec, pin);
2929 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2930 if (num < 2)
2931 return 0;
2932 for (i = 0; i < num; i++) {
2933 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2934 snd_hda_codec_update_cache(codec, pin, 0,
2935 AC_VERB_SET_CONNECT_SEL, i);
2936 return 0;
2937 }
2938 }
2939 return 0;
2940}
2941
Takashi Iwai185d99f2012-02-16 18:39:45 +01002942static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2943{
2944 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002945 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002946 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2947 ARRAY_SIZE(spec->private_dac_nids)) ||
2948 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2949 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2950 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2951 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2952 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002953 for (i = 0; i < spec->multi_ios; i++) {
2954 if (spec->multi_io[i].dac == nid)
2955 return true;
2956 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002957 return false;
2958}
2959
Takashi Iwai7085ec12009-10-02 09:03:58 +02002960/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002961static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002962{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002963 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002964 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002965
Takashi Iwai604401a2011-04-27 15:14:23 +02002966 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002967 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002968 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002969 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002970 if (!nid)
2971 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002972 if (!alc_is_dac_already_used(codec, nid))
2973 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002974 }
2975 return 0;
2976}
2977
Takashi Iwai07b18f62011-11-10 15:42:54 +01002978/* check whether the DAC is reachable from the pin */
2979static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2980 hda_nid_t pin, hda_nid_t dac)
2981{
2982 hda_nid_t srcs[5];
2983 int i, num;
2984
Takashi Iwaidc31b582012-02-17 17:27:53 +01002985 if (!pin || !dac)
2986 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002987 pin = alc_go_down_to_selector(codec, pin);
2988 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2989 for (i = 0; i < num; i++) {
2990 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2991 if (nid == dac)
2992 return true;
2993 }
2994 return false;
2995}
2996
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002997static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2998{
Takashi Iwai140547e2012-02-16 17:23:46 +01002999 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003000 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003001 hda_nid_t nid, nid_found, srcs[5];
3002 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01003003 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01003004 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003005 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003006 nid_found = 0;
3007 for (i = 0; i < num; i++) {
3008 if (srcs[i] == spec->mixer_nid)
3009 continue;
3010 nid = alc_auto_mix_to_dac(codec, srcs[i]);
3011 if (nid && !alc_is_dac_already_used(codec, nid)) {
3012 if (nid_found)
3013 return 0;
3014 nid_found = nid;
3015 }
3016 }
3017 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003018}
3019
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003020/* mark up volume and mute control NIDs: used during badness parsing and
3021 * at creating actual controls
3022 */
3023static inline unsigned int get_ctl_pos(unsigned int data)
3024{
3025 hda_nid_t nid = get_amp_nid_(data);
3026 unsigned int dir;
3027 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
3028 return 0;
3029 dir = get_amp_direction_(data);
3030 return (nid << 1) | dir;
3031}
3032
3033#define is_ctl_used(bits, data) \
3034 test_bit(get_ctl_pos(data), bits)
3035#define mark_ctl_usage(bits, data) \
3036 set_bit(get_ctl_pos(data), bits)
3037
3038static void clear_vol_marks(struct hda_codec *codec)
3039{
3040 struct alc_spec *spec = codec->spec;
3041 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3042 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3043}
3044
3045/* badness definition */
3046enum {
3047 /* No primary DAC is found for the main output */
3048 BAD_NO_PRIMARY_DAC = 0x10000,
3049 /* No DAC is found for the extra output */
3050 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003051 /* No possible multi-ios */
3052 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003053 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003054 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003055 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003056 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003057 /* Primary DAC shared with main surrounds */
3058 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003059 /* Primary DAC shared with main CLFE */
3060 BAD_SHARED_CLFE = 0x10,
3061 /* Primary DAC shared with extra surrounds */
3062 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003063 /* Volume widget is shared */
3064 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003065};
3066
3067static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3068 hda_nid_t pin, hda_nid_t dac);
3069static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3070 hda_nid_t pin, hda_nid_t dac);
3071
3072static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3073 hda_nid_t dac)
3074{
3075 struct alc_spec *spec = codec->spec;
3076 hda_nid_t nid;
3077 unsigned int val;
3078 int badness = 0;
3079
3080 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3081 if (nid) {
3082 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3083 if (is_ctl_used(spec->vol_ctls, nid))
3084 badness += BAD_SHARED_VOL;
3085 else
3086 mark_ctl_usage(spec->vol_ctls, val);
3087 } else
3088 badness += BAD_SHARED_VOL;
3089 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3090 if (nid) {
3091 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3092 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3093 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3094 else
3095 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3096 if (is_ctl_used(spec->sw_ctls, val))
3097 badness += BAD_SHARED_VOL;
3098 else
3099 mark_ctl_usage(spec->sw_ctls, val);
3100 } else
3101 badness += BAD_SHARED_VOL;
3102 return badness;
3103}
3104
Takashi Iwaidc31b582012-02-17 17:27:53 +01003105struct badness_table {
3106 int no_primary_dac; /* no primary DAC */
3107 int no_dac; /* no secondary DACs */
3108 int shared_primary; /* primary DAC is shared with main output */
3109 int shared_surr; /* secondary DAC shared with main or primary */
3110 int shared_clfe; /* third DAC shared with main or primary */
3111 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3112};
3113
3114static struct badness_table main_out_badness = {
3115 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3116 .no_dac = BAD_NO_DAC,
3117 .shared_primary = BAD_NO_PRIMARY_DAC,
3118 .shared_surr = BAD_SHARED_SURROUND,
3119 .shared_clfe = BAD_SHARED_CLFE,
3120 .shared_surr_main = BAD_SHARED_SURROUND,
3121};
3122
3123static struct badness_table extra_out_badness = {
3124 .no_primary_dac = BAD_NO_DAC,
3125 .no_dac = BAD_NO_DAC,
3126 .shared_primary = BAD_NO_EXTRA_DAC,
3127 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3128 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3129 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3130};
3131
3132/* try to assign DACs to pins and return the resultant badness */
3133static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3134 const hda_nid_t *pins, hda_nid_t *dacs,
3135 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003136{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003137 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003138 struct auto_pin_cfg *cfg = &spec->autocfg;
3139 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003140 int badness = 0;
3141 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003142
Takashi Iwai185d99f2012-02-16 18:39:45 +01003143 if (!num_outs)
3144 return 0;
3145
Takashi Iwaidc31b582012-02-17 17:27:53 +01003146 for (i = 0; i < num_outs; i++) {
3147 hda_nid_t pin = pins[i];
3148 if (!dacs[i])
3149 dacs[i] = alc_auto_look_for_dac(codec, pin);
3150 if (!dacs[i] && !i) {
3151 for (j = 1; j < num_outs; j++) {
3152 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3153 dacs[0] = dacs[j];
3154 dacs[j] = 0;
3155 break;
3156 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003157 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003158 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003159 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003160 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003161 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003162 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003163 else if (cfg->line_outs > i &&
3164 alc_auto_is_dac_reachable(codec, pin,
3165 spec->private_dac_nids[i]))
3166 dac = spec->private_dac_nids[i];
3167 if (dac) {
3168 if (!i)
3169 badness += bad->shared_primary;
3170 else if (i == 1)
3171 badness += bad->shared_surr;
3172 else
3173 badness += bad->shared_clfe;
3174 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003175 spec->private_dac_nids[0])) {
3176 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003177 badness += bad->shared_surr_main;
3178 } else if (!i)
3179 badness += bad->no_primary_dac;
3180 else
3181 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003182 }
3183 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003184 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003185 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003186
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003187 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003188}
3189
3190static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003191 hda_nid_t reference_pin,
3192 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003193
Takashi Iwai185d99f2012-02-16 18:39:45 +01003194static bool alc_map_singles(struct hda_codec *codec, int outs,
3195 const hda_nid_t *pins, hda_nid_t *dacs)
3196{
3197 int i;
3198 bool found = false;
3199 for (i = 0; i < outs; i++) {
3200 if (dacs[i])
3201 continue;
3202 dacs[i] = get_dac_if_single(codec, pins[i]);
3203 if (dacs[i])
3204 found = true;
3205 }
3206 return found;
3207}
3208
Takashi Iwai7085ec12009-10-02 09:03:58 +02003209/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003210static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003211 bool fill_hardwired,
3212 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003213{
3214 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003215 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003216 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003217
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003218 /* set num_dacs once to full for alc_auto_look_for_dac() */
3219 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003220 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003221 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3222 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3223 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003224 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003225 clear_vol_marks(codec);
3226 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003227
3228 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003229 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003230 bool mapped;
3231 do {
3232 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003233 cfg->line_out_pins,
3234 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003235 mapped |= alc_map_singles(codec, cfg->hp_outs,
3236 cfg->hp_pins,
3237 spec->multiout.hp_out_nid);
3238 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3239 cfg->speaker_pins,
3240 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003241 if (fill_mio_first && cfg->line_outs == 1 &&
3242 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3243 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3244 if (!err)
3245 mapped = true;
3246 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003247 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003248 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003249
Takashi Iwaidc31b582012-02-17 17:27:53 +01003250 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3251 spec->private_dac_nids,
3252 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003253
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003254 /* re-count num_dacs and squash invalid entries */
3255 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003256 for (i = 0; i < cfg->line_outs; i++) {
3257 if (spec->private_dac_nids[i])
3258 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003259 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003260 memmove(spec->private_dac_nids + i,
3261 spec->private_dac_nids + i + 1,
3262 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003263 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3264 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003265 }
3266
Takashi Iwai276dd702012-02-17 16:17:03 +01003267 if (fill_mio_first &&
3268 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003269 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003270 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003271 if (err < 0)
3272 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003273 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003274 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003275
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003276 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003277 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3278 spec->multiout.hp_out_nid,
3279 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003280 if (err < 0)
3281 return err;
3282 badness += err;
3283 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003284 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003285 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3286 cfg->speaker_pins,
3287 spec->multiout.extra_out_nid,
3288 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003289 if (err < 0)
3290 return err;
3291 badness += err;
3292 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003293 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3294 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003295 if (err < 0)
3296 return err;
3297 badness += err;
3298 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003299 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3300 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003301 int offset = 0;
3302 if (cfg->line_outs >= 3)
3303 offset = 1;
3304 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3305 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003306 if (err < 0)
3307 return err;
3308 badness += err;
3309 }
3310
3311 if (spec->multi_ios == 2) {
3312 for (i = 0; i < 2; i++)
3313 spec->private_dac_nids[spec->multiout.num_dacs++] =
3314 spec->multi_io[i].dac;
3315 spec->ext_channel_count = 2;
3316 } else if (spec->multi_ios) {
3317 spec->multi_ios = 0;
3318 badness += BAD_MULTI_IO;
3319 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003320
3321 return badness;
3322}
3323
3324#define DEBUG_BADNESS
3325
3326#ifdef DEBUG_BADNESS
3327#define debug_badness snd_printdd
3328#else
3329#define debug_badness(...)
3330#endif
3331
3332static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3333{
3334 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3335 cfg->line_out_pins[0], cfg->line_out_pins[1],
3336 cfg->line_out_pins[2], cfg->line_out_pins[2],
3337 spec->multiout.dac_nids[0],
3338 spec->multiout.dac_nids[1],
3339 spec->multiout.dac_nids[2],
3340 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003341 if (spec->multi_ios > 0)
3342 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3343 spec->multi_ios,
3344 spec->multi_io[0].pin, spec->multi_io[1].pin,
3345 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003346 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3347 cfg->hp_pins[0], cfg->hp_pins[1],
3348 cfg->hp_pins[2], cfg->hp_pins[2],
3349 spec->multiout.hp_out_nid[0],
3350 spec->multiout.hp_out_nid[1],
3351 spec->multiout.hp_out_nid[2],
3352 spec->multiout.hp_out_nid[3]);
3353 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3354 cfg->speaker_pins[0], cfg->speaker_pins[1],
3355 cfg->speaker_pins[2], cfg->speaker_pins[3],
3356 spec->multiout.extra_out_nid[0],
3357 spec->multiout.extra_out_nid[1],
3358 spec->multiout.extra_out_nid[2],
3359 spec->multiout.extra_out_nid[3]);
3360}
3361
3362static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3363{
3364 struct alc_spec *spec = codec->spec;
3365 struct auto_pin_cfg *cfg = &spec->autocfg;
3366 struct auto_pin_cfg *best_cfg;
3367 int best_badness = INT_MAX;
3368 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003369 bool fill_hardwired = true, fill_mio_first = true;
3370 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003371 bool hp_spk_swapped = false;
3372
3373 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3374 if (!best_cfg)
3375 return -ENOMEM;
3376 *best_cfg = *cfg;
3377
3378 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003379 badness = fill_and_eval_dacs(codec, fill_hardwired,
3380 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003381 if (badness < 0) {
3382 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003383 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003384 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003385 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3386 cfg->line_out_type, fill_hardwired, fill_mio_first,
3387 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003388 debug_show_configs(spec, cfg);
3389 if (badness < best_badness) {
3390 best_badness = badness;
3391 *best_cfg = *cfg;
3392 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003393 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003394 }
3395 if (!badness)
3396 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003397 fill_mio_first = !fill_mio_first;
3398 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003399 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003400 fill_hardwired = !fill_hardwired;
3401 if (!fill_hardwired)
3402 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003403 if (hp_spk_swapped)
3404 break;
3405 hp_spk_swapped = true;
3406 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003407 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3408 cfg->hp_outs = cfg->line_outs;
3409 memcpy(cfg->hp_pins, cfg->line_out_pins,
3410 sizeof(cfg->hp_pins));
3411 cfg->line_outs = cfg->speaker_outs;
3412 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3413 sizeof(cfg->speaker_pins));
3414 cfg->speaker_outs = 0;
3415 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3416 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003417 fill_hardwired = true;
3418 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003419 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003420 if (cfg->hp_outs > 0 &&
3421 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3422 cfg->speaker_outs = cfg->line_outs;
3423 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3424 sizeof(cfg->speaker_pins));
3425 cfg->line_outs = cfg->hp_outs;
3426 memcpy(cfg->line_out_pins, cfg->hp_pins,
3427 sizeof(cfg->hp_pins));
3428 cfg->hp_outs = 0;
3429 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3430 cfg->line_out_type = AUTO_PIN_HP_OUT;
3431 fill_hardwired = true;
3432 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003433 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003434 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003435 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003436
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003437 if (badness) {
3438 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003439 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003440 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003441 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3442 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003443 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003444
David Henningssonfde48a12011-12-09 18:27:42 +08003445 if (cfg->line_out_pins[0])
3446 spec->vmaster_nid =
3447 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3448 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003449
3450 /* clear the bitmap flags for creating controls */
3451 clear_vol_marks(codec);
3452 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003453 return 0;
3454}
3455
Takashi Iwai343a04b2011-07-06 14:28:39 +02003456static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003457 const char *pfx, int cidx,
3458 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003459{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003460 struct alc_spec *spec = codec->spec;
3461 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003462 if (!nid)
3463 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003464 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3465 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3466 return 0;
3467 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003468 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003469 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003470}
3471
Takashi Iwaie29d3772011-11-14 17:13:23 +01003472static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3473 const char *pfx, int cidx,
3474 hda_nid_t nid)
3475{
3476 int chs = 1;
3477 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3478 chs = 3;
3479 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3480}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003481
3482/* create a mute-switch for the given mixer widget;
3483 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3484 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003485static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003486 const char *pfx, int cidx,
3487 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003488{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003489 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003490 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003491 int type;
3492 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003493 if (!nid)
3494 return 0;
3495 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3496 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3497 type = ALC_CTL_WIDGET_MUTE;
3498 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003499 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003500 type = ALC_CTL_WIDGET_MUTE;
3501 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3502 } else {
3503 type = ALC_CTL_BIND_MUTE;
3504 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3505 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003506 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3507 return 0;
3508 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003509 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003510}
3511
Takashi Iwaie29d3772011-11-14 17:13:23 +01003512static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3513 int cidx, hda_nid_t nid)
3514{
3515 int chs = 1;
3516 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3517 chs = 3;
3518 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3519}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003520
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003521static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3522 hda_nid_t pin, hda_nid_t dac)
3523{
3524 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3525 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3526 return pin;
3527 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3528 return mix;
3529 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3530 return dac;
3531 return 0;
3532}
3533
3534static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3535 hda_nid_t pin, hda_nid_t dac)
3536{
3537 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3538 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3539 return dac;
3540 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3541 return mix;
3542 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3543 return pin;
3544 return 0;
3545}
3546
Takashi Iwai7085ec12009-10-02 09:03:58 +02003547/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003548static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003549 const struct auto_pin_cfg *cfg)
3550{
3551 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003552 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003553
Takashi Iwaice764ab2011-04-27 16:35:23 +02003554 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003555 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003556 noutputs += spec->multi_ios;
3557
3558 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003559 const char *name;
3560 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003561 hda_nid_t dac, pin;
3562 hda_nid_t sw, vol;
3563
3564 dac = spec->multiout.dac_nids[i];
3565 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003566 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003567 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003568 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003569 index = 0;
3570 name = channel_name[i];
3571 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003572 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003573 name = alc_get_line_out_pfx(spec, i, true, &index);
3574 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003575
3576 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3577 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003578 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003579 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003580 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003581 if (err < 0)
3582 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003583 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003584 if (err < 0)
3585 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003586 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003587 if (err < 0)
3588 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003589 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003590 if (err < 0)
3591 return err;
3592 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003593 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003594 if (err < 0)
3595 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003596 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003597 if (err < 0)
3598 return err;
3599 }
3600 }
3601 return 0;
3602}
3603
Takashi Iwai343a04b2011-07-06 14:28:39 +02003604static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003605 hda_nid_t dac, const char *pfx,
3606 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003607{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003608 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003609 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003610 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003611
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003612 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003613 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003614 /* the corresponding DAC is already occupied */
3615 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3616 return 0; /* no way */
3617 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003618 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3619 if (is_ctl_used(spec->sw_ctls, val))
3620 return 0; /* already created */
3621 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003622 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003623 }
3624
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003625 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3626 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003627 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003628 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003629 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003630 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003631 if (err < 0)
3632 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003633 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003634}
3635
Takashi Iwai23c09b02011-08-19 09:05:35 +02003636static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3637 unsigned int nums,
3638 struct hda_ctl_ops *ops)
3639{
3640 struct alc_spec *spec = codec->spec;
3641 struct hda_bind_ctls **ctlp, *ctl;
3642 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3643 ctlp = snd_array_new(&spec->bind_ctls);
3644 if (!ctlp)
3645 return NULL;
3646 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3647 *ctlp = ctl;
3648 if (ctl)
3649 ctl->ops = ops;
3650 return ctl;
3651}
3652
3653/* add playback controls for speaker and HP outputs */
3654static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3655 const hda_nid_t *pins,
3656 const hda_nid_t *dacs,
3657 const char *pfx)
3658{
3659 struct alc_spec *spec = codec->spec;
3660 struct hda_bind_ctls *ctl;
3661 char name[32];
3662 int i, n, err;
3663
3664 if (!num_pins || !pins[0])
3665 return 0;
3666
Takashi Iwai527e4d72011-10-27 16:33:27 +02003667 if (num_pins == 1) {
3668 hda_nid_t dac = *dacs;
3669 if (!dac)
3670 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003671 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003672 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003673
Takashi Iwai23c09b02011-08-19 09:05:35 +02003674 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003675 hda_nid_t dac;
3676 if (dacs[num_pins - 1])
3677 dac = dacs[i]; /* with individual volumes */
3678 else
3679 dac = 0;
3680 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3681 err = alc_auto_create_extra_out(codec, pins[i], dac,
3682 "Bass Speaker", 0);
3683 } else if (num_pins >= 3) {
3684 snprintf(name, sizeof(name), "%s %s",
3685 pfx, channel_name[i]);
3686 err = alc_auto_create_extra_out(codec, pins[i], dac,
3687 name, 0);
3688 } else {
3689 err = alc_auto_create_extra_out(codec, pins[i], dac,
3690 pfx, i);
3691 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003692 if (err < 0)
3693 return err;
3694 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003695 if (dacs[num_pins - 1])
3696 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003697
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003698 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003699 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3700 if (!ctl)
3701 return -ENOMEM;
3702 n = 0;
3703 for (i = 0; i < num_pins; i++) {
3704 hda_nid_t vol;
3705 if (!pins[i] || !dacs[i])
3706 continue;
3707 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3708 if (vol)
3709 ctl->values[n++] =
3710 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3711 }
3712 if (n) {
3713 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3714 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3715 if (err < 0)
3716 return err;
3717 }
3718 return 0;
3719}
3720
Takashi Iwai343a04b2011-07-06 14:28:39 +02003721static int alc_auto_create_hp_out(struct hda_codec *codec)
3722{
3723 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003724 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3725 spec->autocfg.hp_pins,
3726 spec->multiout.hp_out_nid,
3727 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003728}
3729
3730static int alc_auto_create_speaker_out(struct hda_codec *codec)
3731{
3732 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003733 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3734 spec->autocfg.speaker_pins,
3735 spec->multiout.extra_out_nid,
3736 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003737}
3738
Takashi Iwai343a04b2011-07-06 14:28:39 +02003739static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003740 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003741 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003742{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003743 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003744 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003745 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003746
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003747 alc_set_pin_output(codec, pin, pin_type);
3748 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003749 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003750 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003751 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003752 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003753 mix = srcs[i];
3754 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003755 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003756 if (!mix)
3757 return;
3758
3759 /* need the manual connection? */
3760 if (num > 1)
3761 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3762 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003763 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3764 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003765 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003766 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003767 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003768 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003769 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003770 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3771 if (nid)
3772 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3773 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003774
3775 /* unmute DAC if it's not assigned to a mixer */
3776 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3777 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3778 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3779 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003780}
3781
Takashi Iwai343a04b2011-07-06 14:28:39 +02003782static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003783{
3784 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003785 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003786 int i;
3787
3788 for (i = 0; i <= HDA_SIDE; i++) {
3789 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3790 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003791 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003792 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003793 }
3794}
3795
Takashi Iwai343a04b2011-07-06 14:28:39 +02003796static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003797{
3798 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003799 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003800 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003801
David Henningsson636030e2011-10-12 19:26:03 +02003802 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003803 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3804 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003805 pin = spec->autocfg.hp_pins[i];
3806 if (!pin)
3807 break;
3808 dac = spec->multiout.hp_out_nid[i];
3809 if (!dac) {
3810 if (i > 0 && spec->multiout.hp_out_nid[0])
3811 dac = spec->multiout.hp_out_nid[0];
3812 else
3813 dac = spec->multiout.dac_nids[0];
3814 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003815 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3816 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003817 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003818 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3819 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003820 pin = spec->autocfg.speaker_pins[i];
3821 if (!pin)
3822 break;
3823 dac = spec->multiout.extra_out_nid[i];
3824 if (!dac) {
3825 if (i > 0 && spec->multiout.extra_out_nid[0])
3826 dac = spec->multiout.extra_out_nid[0];
3827 else
3828 dac = spec->multiout.dac_nids[0];
3829 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003830 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3831 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003832}
3833
Takashi Iwai276dd702012-02-17 16:17:03 +01003834/* check whether the given pin can be a multi-io pin */
3835static bool can_be_multiio_pin(struct hda_codec *codec,
3836 unsigned int location, hda_nid_t nid)
3837{
3838 unsigned int defcfg, caps;
3839
3840 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3841 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3842 return false;
3843 if (location && get_defcfg_location(defcfg) != location)
3844 return false;
3845 caps = snd_hda_query_pin_caps(codec, nid);
3846 if (!(caps & AC_PINCAP_OUT))
3847 return false;
3848 return true;
3849}
3850
Takashi Iwaice764ab2011-04-27 16:35:23 +02003851/*
3852 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003853 *
3854 * When hardwired is set, try to fill ony hardwired pins, and returns
3855 * zero if any pins are filled, non-zero if nothing found.
3856 * When hardwired is off, try to fill possible input pins, and returns
3857 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003858 */
3859static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003860 hda_nid_t reference_pin,
3861 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003862{
3863 struct alc_spec *spec = codec->spec;
3864 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003865 int type, i, j, dacs, num_pins, old_pins;
3866 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3867 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003868 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003869
Takashi Iwai276dd702012-02-17 16:17:03 +01003870 old_pins = spec->multi_ios;
3871 if (old_pins >= 2)
3872 goto end_fill;
3873
3874 num_pins = 0;
3875 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3876 for (i = 0; i < cfg->num_inputs; i++) {
3877 if (cfg->inputs[i].type != type)
3878 continue;
3879 if (can_be_multiio_pin(codec, location,
3880 cfg->inputs[i].pin))
3881 num_pins++;
3882 }
3883 }
3884 if (num_pins < 2)
3885 goto end_fill;
3886
Takashi Iwai07b18f62011-11-10 15:42:54 +01003887 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003888 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3889 for (i = 0; i < cfg->num_inputs; i++) {
3890 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003891 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003892
Takashi Iwaice764ab2011-04-27 16:35:23 +02003893 if (cfg->inputs[i].type != type)
3894 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003895 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003896 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003897 for (j = 0; j < spec->multi_ios; j++) {
3898 if (nid == spec->multi_io[j].pin)
3899 break;
3900 }
3901 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003902 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003903
3904 if (offset && offset + spec->multi_ios < dacs) {
3905 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003906 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3907 dac = 0;
3908 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003909 if (hardwired)
3910 dac = get_dac_if_single(codec, nid);
3911 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003912 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003913 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003914 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003915 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003916 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003917 spec->multi_io[spec->multi_ios].pin = nid;
3918 spec->multi_io[spec->multi_ios].dac = dac;
3919 spec->multi_ios++;
3920 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003921 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003922 }
3923 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003924 end_fill:
3925 if (badness)
3926 badness = BAD_MULTI_IO;
3927 if (old_pins == spec->multi_ios) {
3928 if (hardwired)
3929 return 1; /* nothing found */
3930 else
3931 return badness; /* no badness if nothing found */
3932 }
3933 if (!hardwired && spec->multi_ios < 2) {
3934 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003935 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003936 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003937
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003938 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003939}
3940
3941static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3942 struct snd_ctl_elem_info *uinfo)
3943{
3944 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3945 struct alc_spec *spec = codec->spec;
3946
3947 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3948 uinfo->count = 1;
3949 uinfo->value.enumerated.items = spec->multi_ios + 1;
3950 if (uinfo->value.enumerated.item > spec->multi_ios)
3951 uinfo->value.enumerated.item = spec->multi_ios;
3952 sprintf(uinfo->value.enumerated.name, "%dch",
3953 (uinfo->value.enumerated.item + 1) * 2);
3954 return 0;
3955}
3956
3957static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3958 struct snd_ctl_elem_value *ucontrol)
3959{
3960 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3961 struct alc_spec *spec = codec->spec;
3962 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3963 return 0;
3964}
3965
3966static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3967{
3968 struct alc_spec *spec = codec->spec;
3969 hda_nid_t nid = spec->multi_io[idx].pin;
3970
3971 if (!spec->multi_io[idx].ctl_in)
3972 spec->multi_io[idx].ctl_in =
3973 snd_hda_codec_read(codec, nid, 0,
3974 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3975 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003976 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003977 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3978 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3979 HDA_AMP_MUTE, 0);
3980 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3981 } else {
3982 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3983 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3984 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003985 snd_hda_set_pin_ctl_cache(codec, nid,
3986 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003987 }
3988 return 0;
3989}
3990
3991static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3992 struct snd_ctl_elem_value *ucontrol)
3993{
3994 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3995 struct alc_spec *spec = codec->spec;
3996 int i, ch;
3997
3998 ch = ucontrol->value.enumerated.item[0];
3999 if (ch < 0 || ch > spec->multi_ios)
4000 return -EINVAL;
4001 if (ch == (spec->ext_channel_count - 1) / 2)
4002 return 0;
4003 spec->ext_channel_count = (ch + 1) * 2;
4004 for (i = 0; i < spec->multi_ios; i++)
4005 alc_set_multi_io(codec, i, i < ch);
4006 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004007 if (spec->need_dac_fix && !spec->const_channel_count)
4008 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004009 return 1;
4010}
4011
Takashi Iwaia9111322011-05-02 11:30:18 +02004012static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004013 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
4014 .name = "Channel Mode",
4015 .info = alc_auto_ch_mode_info,
4016 .get = alc_auto_ch_mode_get,
4017 .put = alc_auto_ch_mode_put,
4018};
4019
Takashi Iwai23c09b02011-08-19 09:05:35 +02004020static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02004021{
4022 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004023
Takashi Iwaic2674682011-08-24 17:57:44 +02004024 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02004025 struct snd_kcontrol_new *knew;
4026
4027 knew = alc_kcontrol_new(spec);
4028 if (!knew)
4029 return -ENOMEM;
4030 *knew = alc_auto_channel_mode_enum;
4031 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
4032 if (!knew->name)
4033 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02004034 }
4035 return 0;
4036}
4037
Takashi Iwai1d045db2011-07-07 18:23:21 +02004038/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4039 * active input pins
4040 */
4041static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4042{
4043 struct alc_spec *spec = codec->spec;
4044 const struct hda_input_mux *imux;
4045 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4046 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4047 int i, n, nums;
4048
4049 imux = spec->input_mux;
4050 if (!imux)
4051 return;
4052 if (spec->dyn_adc_switch)
4053 return;
4054
Takashi Iwai26acaf02012-03-22 14:36:50 +01004055 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004056 nums = 0;
4057 for (n = 0; n < spec->num_adc_nids; n++) {
4058 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004059 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004060 for (i = 0; i < imux->num_items; i++) {
4061 hda_nid_t pin = spec->imux_pins[i];
4062 if (pin) {
4063 if (get_connection_index(codec, cap, pin) < 0)
4064 break;
4065 } else if (num_conns <= imux->items[i].index)
4066 break;
4067 }
4068 if (i >= imux->num_items) {
4069 adc_nids[nums] = spec->private_adc_nids[n];
4070 capsrc_nids[nums++] = cap;
4071 }
4072 }
4073 if (!nums) {
4074 /* check whether ADC-switch is possible */
4075 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004076 if (spec->shared_mic_hp) {
4077 spec->shared_mic_hp = 0;
4078 spec->private_imux[0].num_items = 1;
4079 goto again;
4080 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004081 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4082 " using fallback 0x%x\n",
4083 codec->chip_name, spec->private_adc_nids[0]);
4084 spec->num_adc_nids = 1;
4085 spec->auto_mic = 0;
4086 return;
4087 }
4088 } else if (nums != spec->num_adc_nids) {
4089 memcpy(spec->private_adc_nids, adc_nids,
4090 nums * sizeof(hda_nid_t));
4091 memcpy(spec->private_capsrc_nids, capsrc_nids,
4092 nums * sizeof(hda_nid_t));
4093 spec->num_adc_nids = nums;
4094 }
4095
4096 if (spec->auto_mic)
4097 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004098 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004099 spec->num_adc_nids = 1; /* reduce to a single ADC */
4100}
4101
4102/*
4103 * initialize ADC paths
4104 */
4105static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4106{
4107 struct alc_spec *spec = codec->spec;
4108 hda_nid_t nid;
4109
4110 nid = spec->adc_nids[adc_idx];
4111 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004112 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004113 snd_hda_codec_write(codec, nid, 0,
4114 AC_VERB_SET_AMP_GAIN_MUTE,
4115 AMP_IN_MUTE(0));
4116 return;
4117 }
4118 if (!spec->capsrc_nids)
4119 return;
4120 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004121 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004122 snd_hda_codec_write(codec, nid, 0,
4123 AC_VERB_SET_AMP_GAIN_MUTE,
4124 AMP_OUT_MUTE);
4125}
4126
4127static void alc_auto_init_input_src(struct hda_codec *codec)
4128{
4129 struct alc_spec *spec = codec->spec;
4130 int c, nums;
4131
4132 for (c = 0; c < spec->num_adc_nids; c++)
4133 alc_auto_init_adc(codec, c);
4134 if (spec->dyn_adc_switch)
4135 nums = 1;
4136 else
4137 nums = spec->num_adc_nids;
4138 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004139 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004140}
4141
4142/* add mic boosts if needed */
4143static int alc_auto_add_mic_boost(struct hda_codec *codec)
4144{
4145 struct alc_spec *spec = codec->spec;
4146 struct auto_pin_cfg *cfg = &spec->autocfg;
4147 int i, err;
4148 int type_idx = 0;
4149 hda_nid_t nid;
4150 const char *prev_label = NULL;
4151
4152 for (i = 0; i < cfg->num_inputs; i++) {
4153 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4154 break;
4155 nid = cfg->inputs[i].pin;
4156 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4157 const char *label;
4158 char boost_label[32];
4159
4160 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004161 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4162 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004163 if (prev_label && !strcmp(label, prev_label))
4164 type_idx++;
4165 else
4166 type_idx = 0;
4167 prev_label = label;
4168
4169 snprintf(boost_label, sizeof(boost_label),
4170 "%s Boost Volume", label);
4171 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4172 boost_label, type_idx,
4173 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4174 if (err < 0)
4175 return err;
4176 }
4177 }
4178 return 0;
4179}
4180
4181/* select or unmute the given capsrc route */
4182static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4183 int idx)
4184{
4185 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4186 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4187 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004188 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004189 snd_hda_codec_write_cache(codec, cap, 0,
4190 AC_VERB_SET_CONNECT_SEL, idx);
4191 }
4192}
4193
4194/* set the default connection to that pin */
4195static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4196{
4197 struct alc_spec *spec = codec->spec;
4198 int i;
4199
4200 if (!pin)
4201 return 0;
4202 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004203 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004204 int idx;
4205
4206 idx = get_connection_index(codec, cap, pin);
4207 if (idx < 0)
4208 continue;
4209 select_or_unmute_capsrc(codec, cap, idx);
4210 return i; /* return the found index */
4211 }
4212 return -1; /* not found */
4213}
4214
4215/* initialize some special cases for input sources */
4216static void alc_init_special_input_src(struct hda_codec *codec)
4217{
4218 struct alc_spec *spec = codec->spec;
4219 int i;
4220
4221 for (i = 0; i < spec->autocfg.num_inputs; i++)
4222 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4223}
4224
4225/* assign appropriate capture mixers */
4226static void set_capture_mixer(struct hda_codec *codec)
4227{
4228 struct alc_spec *spec = codec->spec;
4229 static const struct snd_kcontrol_new *caps[2][3] = {
4230 { alc_capture_mixer_nosrc1,
4231 alc_capture_mixer_nosrc2,
4232 alc_capture_mixer_nosrc3 },
4233 { alc_capture_mixer1,
4234 alc_capture_mixer2,
4235 alc_capture_mixer3 },
4236 };
4237
4238 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004239 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004240 if (!spec->capsrc_nids)
4241 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004242 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004243 return; /* no volume in capsrc, too */
4244 spec->vol_in_capsrc = 1;
4245 }
4246
4247 if (spec->num_adc_nids > 0) {
4248 int mux = 0;
4249 int num_adcs = 0;
4250
4251 if (spec->input_mux && spec->input_mux->num_items > 1)
4252 mux = 1;
4253 if (spec->auto_mic) {
4254 num_adcs = 1;
4255 mux = 0;
4256 } else if (spec->dyn_adc_switch)
4257 num_adcs = 1;
4258 if (!num_adcs) {
4259 if (spec->num_adc_nids > 3)
4260 spec->num_adc_nids = 3;
4261 else if (!spec->num_adc_nids)
4262 return;
4263 num_adcs = spec->num_adc_nids;
4264 }
4265 spec->cap_mixer = caps[mux][num_adcs - 1];
4266 }
4267}
4268
4269/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004270 * standard auto-parser initializations
4271 */
4272static void alc_auto_init_std(struct hda_codec *codec)
4273{
4274 struct alc_spec *spec = codec->spec;
4275 alc_auto_init_multi_out(codec);
4276 alc_auto_init_extra_out(codec);
4277 alc_auto_init_analog_input(codec);
4278 alc_auto_init_input_src(codec);
4279 alc_auto_init_digital(codec);
4280 if (spec->unsol_event)
4281 alc_inithook(codec);
4282}
4283
4284/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004285 * Digital-beep handlers
4286 */
4287#ifdef CONFIG_SND_HDA_INPUT_BEEP
4288#define set_beep_amp(spec, nid, idx, dir) \
4289 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4290
4291static const struct snd_pci_quirk beep_white_list[] = {
4292 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4293 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4294 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4295 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004296 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004297 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4298 {}
4299};
4300
4301static inline int has_cdefine_beep(struct hda_codec *codec)
4302{
4303 struct alc_spec *spec = codec->spec;
4304 const struct snd_pci_quirk *q;
4305 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4306 if (q)
4307 return q->value;
4308 return spec->cdefine.enable_pcbeep;
4309}
4310#else
4311#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4312#define has_cdefine_beep(codec) 0
4313#endif
4314
4315/* parse the BIOS configuration and set up the alc_spec */
4316/* return 1 if successful, 0 if the proper config is not found,
4317 * or a negative error code
4318 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004319static int alc_parse_auto_config(struct hda_codec *codec,
4320 const hda_nid_t *ignore_nids,
4321 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004322{
4323 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004324 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004325 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004326
Takashi Iwai53c334a2011-08-23 18:27:14 +02004327 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4328 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004329 if (err < 0)
4330 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004331 if (!cfg->line_outs) {
4332 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004333 spec->multiout.max_channels = 2;
4334 spec->no_analog = 1;
4335 goto dig_only;
4336 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004337 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004338 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004339
Takashi Iwai06503672011-10-06 08:27:19 +02004340 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4341 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004342 /* use HP as primary out */
4343 cfg->speaker_outs = cfg->line_outs;
4344 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4345 sizeof(cfg->speaker_pins));
4346 cfg->line_outs = cfg->hp_outs;
4347 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4348 cfg->hp_outs = 0;
4349 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4350 cfg->line_out_type = AUTO_PIN_HP_OUT;
4351 }
4352
Takashi Iwai1d045db2011-07-07 18:23:21 +02004353 err = alc_auto_fill_dac_nids(codec);
4354 if (err < 0)
4355 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004356 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004357 if (err < 0)
4358 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004359 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004360 if (err < 0)
4361 return err;
4362 err = alc_auto_create_hp_out(codec);
4363 if (err < 0)
4364 return err;
4365 err = alc_auto_create_speaker_out(codec);
4366 if (err < 0)
4367 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004368 err = alc_auto_create_shared_input(codec);
4369 if (err < 0)
4370 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004371 err = alc_auto_create_input_ctls(codec);
4372 if (err < 0)
4373 return err;
4374
4375 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4376
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004377 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004378 alc_auto_parse_digital(codec);
4379
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004380 if (!spec->no_analog)
4381 alc_remove_invalid_adc_nids(codec);
4382
4383 if (ssid_nids)
4384 alc_ssid_check(codec, ssid_nids);
4385
4386 if (!spec->no_analog) {
4387 alc_auto_check_switches(codec);
4388 err = alc_auto_add_mic_boost(codec);
4389 if (err < 0)
4390 return err;
4391 }
4392
Takashi Iwai1d045db2011-07-07 18:23:21 +02004393 if (spec->kctls.list)
4394 add_mixer(spec, spec->kctls.list);
4395
Takashi Iwai070cff42012-02-21 12:54:17 +01004396 if (!spec->no_analog && !spec->cap_mixer)
4397 set_capture_mixer(codec);
4398
Takashi Iwai1d045db2011-07-07 18:23:21 +02004399 return 1;
4400}
4401
Takashi Iwai3de95172012-05-07 18:03:15 +02004402/* common preparation job for alc_spec */
4403static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4404{
4405 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4406 int err;
4407
4408 if (!spec)
4409 return -ENOMEM;
4410 codec->spec = spec;
4411 spec->mixer_nid = mixer_nid;
Takashi Iwaiee48df52012-06-26 14:54:32 +02004412 snd_hda_gen_init(&spec->gen);
Takashi Iwai3de95172012-05-07 18:03:15 +02004413
4414 err = alc_codec_rename_from_preset(codec);
4415 if (err < 0) {
4416 kfree(spec);
4417 return err;
4418 }
4419 return 0;
4420}
4421
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004422static int alc880_parse_auto_config(struct hda_codec *codec)
4423{
4424 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004425 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004426 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4427}
4428
Takashi Iwai1d045db2011-07-07 18:23:21 +02004429/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004430 * ALC880 fix-ups
4431 */
4432enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004433 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004434 ALC880_FIXUP_GPIO2,
4435 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004436 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004437 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004438 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004439 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004440 ALC880_FIXUP_VOL_KNOB,
4441 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004442 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004443 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004444 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004445 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004446 ALC880_FIXUP_3ST_BASE,
4447 ALC880_FIXUP_3ST,
4448 ALC880_FIXUP_3ST_DIG,
4449 ALC880_FIXUP_5ST_BASE,
4450 ALC880_FIXUP_5ST,
4451 ALC880_FIXUP_5ST_DIG,
4452 ALC880_FIXUP_6ST_BASE,
4453 ALC880_FIXUP_6ST,
4454 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004455};
4456
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004457/* enable the volume-knob widget support on NID 0x21 */
4458static void alc880_fixup_vol_knob(struct hda_codec *codec,
4459 const struct alc_fixup *fix, int action)
4460{
4461 if (action == ALC_FIXUP_ACT_PROBE)
4462 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4463}
4464
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004465static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004466 [ALC880_FIXUP_GPIO1] = {
4467 .type = ALC_FIXUP_VERBS,
4468 .v.verbs = alc_gpio1_init_verbs,
4469 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004470 [ALC880_FIXUP_GPIO2] = {
4471 .type = ALC_FIXUP_VERBS,
4472 .v.verbs = alc_gpio2_init_verbs,
4473 },
4474 [ALC880_FIXUP_MEDION_RIM] = {
4475 .type = ALC_FIXUP_VERBS,
4476 .v.verbs = (const struct hda_verb[]) {
4477 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4478 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4479 { }
4480 },
4481 .chained = true,
4482 .chain_id = ALC880_FIXUP_GPIO2,
4483 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004484 [ALC880_FIXUP_LG] = {
4485 .type = ALC_FIXUP_PINS,
4486 .v.pins = (const struct alc_pincfg[]) {
4487 /* disable bogus unused pins */
4488 { 0x16, 0x411111f0 },
4489 { 0x18, 0x411111f0 },
4490 { 0x1a, 0x411111f0 },
4491 { }
4492 }
4493 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004494 [ALC880_FIXUP_W810] = {
4495 .type = ALC_FIXUP_PINS,
4496 .v.pins = (const struct alc_pincfg[]) {
4497 /* disable bogus unused pins */
4498 { 0x17, 0x411111f0 },
4499 { }
4500 },
4501 .chained = true,
4502 .chain_id = ALC880_FIXUP_GPIO2,
4503 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004504 [ALC880_FIXUP_EAPD_COEF] = {
4505 .type = ALC_FIXUP_VERBS,
4506 .v.verbs = (const struct hda_verb[]) {
4507 /* change to EAPD mode */
4508 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4509 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4510 {}
4511 },
4512 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004513 [ALC880_FIXUP_TCL_S700] = {
4514 .type = ALC_FIXUP_VERBS,
4515 .v.verbs = (const struct hda_verb[]) {
4516 /* change to EAPD mode */
4517 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4518 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4519 {}
4520 },
4521 .chained = true,
4522 .chain_id = ALC880_FIXUP_GPIO2,
4523 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004524 [ALC880_FIXUP_VOL_KNOB] = {
4525 .type = ALC_FIXUP_FUNC,
4526 .v.func = alc880_fixup_vol_knob,
4527 },
4528 [ALC880_FIXUP_FUJITSU] = {
4529 /* override all pins as BIOS on old Amilo is broken */
4530 .type = ALC_FIXUP_PINS,
4531 .v.pins = (const struct alc_pincfg[]) {
4532 { 0x14, 0x0121411f }, /* HP */
4533 { 0x15, 0x99030120 }, /* speaker */
4534 { 0x16, 0x99030130 }, /* bass speaker */
4535 { 0x17, 0x411111f0 }, /* N/A */
4536 { 0x18, 0x411111f0 }, /* N/A */
4537 { 0x19, 0x01a19950 }, /* mic-in */
4538 { 0x1a, 0x411111f0 }, /* N/A */
4539 { 0x1b, 0x411111f0 }, /* N/A */
4540 { 0x1c, 0x411111f0 }, /* N/A */
4541 { 0x1d, 0x411111f0 }, /* N/A */
4542 { 0x1e, 0x01454140 }, /* SPDIF out */
4543 { }
4544 },
4545 .chained = true,
4546 .chain_id = ALC880_FIXUP_VOL_KNOB,
4547 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004548 [ALC880_FIXUP_F1734] = {
4549 /* almost compatible with FUJITSU, but no bass and SPDIF */
4550 .type = ALC_FIXUP_PINS,
4551 .v.pins = (const struct alc_pincfg[]) {
4552 { 0x14, 0x0121411f }, /* HP */
4553 { 0x15, 0x99030120 }, /* speaker */
4554 { 0x16, 0x411111f0 }, /* N/A */
4555 { 0x17, 0x411111f0 }, /* N/A */
4556 { 0x18, 0x411111f0 }, /* N/A */
4557 { 0x19, 0x01a19950 }, /* mic-in */
4558 { 0x1a, 0x411111f0 }, /* N/A */
4559 { 0x1b, 0x411111f0 }, /* N/A */
4560 { 0x1c, 0x411111f0 }, /* N/A */
4561 { 0x1d, 0x411111f0 }, /* N/A */
4562 { 0x1e, 0x411111f0 }, /* N/A */
4563 { }
4564 },
4565 .chained = true,
4566 .chain_id = ALC880_FIXUP_VOL_KNOB,
4567 },
Takashi Iwai817de922012-02-20 17:20:48 +01004568 [ALC880_FIXUP_UNIWILL] = {
4569 /* need to fix HP and speaker pins to be parsed correctly */
4570 .type = ALC_FIXUP_PINS,
4571 .v.pins = (const struct alc_pincfg[]) {
4572 { 0x14, 0x0121411f }, /* HP */
4573 { 0x15, 0x99030120 }, /* speaker */
4574 { 0x16, 0x99030130 }, /* bass speaker */
4575 { }
4576 },
4577 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004578 [ALC880_FIXUP_UNIWILL_DIG] = {
4579 .type = ALC_FIXUP_PINS,
4580 .v.pins = (const struct alc_pincfg[]) {
4581 /* disable bogus unused pins */
4582 { 0x17, 0x411111f0 },
4583 { 0x19, 0x411111f0 },
4584 { 0x1b, 0x411111f0 },
4585 { 0x1f, 0x411111f0 },
4586 { }
4587 }
4588 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004589 [ALC880_FIXUP_Z71V] = {
4590 .type = ALC_FIXUP_PINS,
4591 .v.pins = (const struct alc_pincfg[]) {
4592 /* set up the whole pins as BIOS is utterly broken */
4593 { 0x14, 0x99030120 }, /* speaker */
4594 { 0x15, 0x0121411f }, /* HP */
4595 { 0x16, 0x411111f0 }, /* N/A */
4596 { 0x17, 0x411111f0 }, /* N/A */
4597 { 0x18, 0x01a19950 }, /* mic-in */
4598 { 0x19, 0x411111f0 }, /* N/A */
4599 { 0x1a, 0x01813031 }, /* line-in */
4600 { 0x1b, 0x411111f0 }, /* N/A */
4601 { 0x1c, 0x411111f0 }, /* N/A */
4602 { 0x1d, 0x411111f0 }, /* N/A */
4603 { 0x1e, 0x0144111e }, /* SPDIF */
4604 { }
4605 }
4606 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004607 [ALC880_FIXUP_3ST_BASE] = {
4608 .type = ALC_FIXUP_PINS,
4609 .v.pins = (const struct alc_pincfg[]) {
4610 { 0x14, 0x01014010 }, /* line-out */
4611 { 0x15, 0x411111f0 }, /* N/A */
4612 { 0x16, 0x411111f0 }, /* N/A */
4613 { 0x17, 0x411111f0 }, /* N/A */
4614 { 0x18, 0x01a19c30 }, /* mic-in */
4615 { 0x19, 0x0121411f }, /* HP */
4616 { 0x1a, 0x01813031 }, /* line-in */
4617 { 0x1b, 0x02a19c40 }, /* front-mic */
4618 { 0x1c, 0x411111f0 }, /* N/A */
4619 { 0x1d, 0x411111f0 }, /* N/A */
4620 /* 0x1e is filled in below */
4621 { 0x1f, 0x411111f0 }, /* N/A */
4622 { }
4623 }
4624 },
4625 [ALC880_FIXUP_3ST] = {
4626 .type = ALC_FIXUP_PINS,
4627 .v.pins = (const struct alc_pincfg[]) {
4628 { 0x1e, 0x411111f0 }, /* N/A */
4629 { }
4630 },
4631 .chained = true,
4632 .chain_id = ALC880_FIXUP_3ST_BASE,
4633 },
4634 [ALC880_FIXUP_3ST_DIG] = {
4635 .type = ALC_FIXUP_PINS,
4636 .v.pins = (const struct alc_pincfg[]) {
4637 { 0x1e, 0x0144111e }, /* SPDIF */
4638 { }
4639 },
4640 .chained = true,
4641 .chain_id = ALC880_FIXUP_3ST_BASE,
4642 },
4643 [ALC880_FIXUP_5ST_BASE] = {
4644 .type = ALC_FIXUP_PINS,
4645 .v.pins = (const struct alc_pincfg[]) {
4646 { 0x14, 0x01014010 }, /* front */
4647 { 0x15, 0x411111f0 }, /* N/A */
4648 { 0x16, 0x01011411 }, /* CLFE */
4649 { 0x17, 0x01016412 }, /* surr */
4650 { 0x18, 0x01a19c30 }, /* mic-in */
4651 { 0x19, 0x0121411f }, /* HP */
4652 { 0x1a, 0x01813031 }, /* line-in */
4653 { 0x1b, 0x02a19c40 }, /* front-mic */
4654 { 0x1c, 0x411111f0 }, /* N/A */
4655 { 0x1d, 0x411111f0 }, /* N/A */
4656 /* 0x1e is filled in below */
4657 { 0x1f, 0x411111f0 }, /* N/A */
4658 { }
4659 }
4660 },
4661 [ALC880_FIXUP_5ST] = {
4662 .type = ALC_FIXUP_PINS,
4663 .v.pins = (const struct alc_pincfg[]) {
4664 { 0x1e, 0x411111f0 }, /* N/A */
4665 { }
4666 },
4667 .chained = true,
4668 .chain_id = ALC880_FIXUP_5ST_BASE,
4669 },
4670 [ALC880_FIXUP_5ST_DIG] = {
4671 .type = ALC_FIXUP_PINS,
4672 .v.pins = (const struct alc_pincfg[]) {
4673 { 0x1e, 0x0144111e }, /* SPDIF */
4674 { }
4675 },
4676 .chained = true,
4677 .chain_id = ALC880_FIXUP_5ST_BASE,
4678 },
4679 [ALC880_FIXUP_6ST_BASE] = {
4680 .type = ALC_FIXUP_PINS,
4681 .v.pins = (const struct alc_pincfg[]) {
4682 { 0x14, 0x01014010 }, /* front */
4683 { 0x15, 0x01016412 }, /* surr */
4684 { 0x16, 0x01011411 }, /* CLFE */
4685 { 0x17, 0x01012414 }, /* side */
4686 { 0x18, 0x01a19c30 }, /* mic-in */
4687 { 0x19, 0x02a19c40 }, /* front-mic */
4688 { 0x1a, 0x01813031 }, /* line-in */
4689 { 0x1b, 0x0121411f }, /* HP */
4690 { 0x1c, 0x411111f0 }, /* N/A */
4691 { 0x1d, 0x411111f0 }, /* N/A */
4692 /* 0x1e is filled in below */
4693 { 0x1f, 0x411111f0 }, /* N/A */
4694 { }
4695 }
4696 },
4697 [ALC880_FIXUP_6ST] = {
4698 .type = ALC_FIXUP_PINS,
4699 .v.pins = (const struct alc_pincfg[]) {
4700 { 0x1e, 0x411111f0 }, /* N/A */
4701 { }
4702 },
4703 .chained = true,
4704 .chain_id = ALC880_FIXUP_6ST_BASE,
4705 },
4706 [ALC880_FIXUP_6ST_DIG] = {
4707 .type = ALC_FIXUP_PINS,
4708 .v.pins = (const struct alc_pincfg[]) {
4709 { 0x1e, 0x0144111e }, /* SPDIF */
4710 { }
4711 },
4712 .chained = true,
4713 .chain_id = ALC880_FIXUP_6ST_BASE,
4714 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004715};
4716
4717static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004718 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004719 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004720 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4721 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004722 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004723 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004724 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004725 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004726 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004727 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004728 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004729 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004730 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004731 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004732 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004733 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4734 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4735 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004736 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004737
4738 /* Below is the copied entries from alc880_quirks.c.
4739 * It's not quite sure whether BIOS sets the correct pin-config table
4740 * on these machines, thus they are kept to be compatible with
4741 * the old static quirks. Once when it's confirmed to work without
4742 * these overrides, it'd be better to remove.
4743 */
4744 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4745 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4746 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4747 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4748 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4749 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4750 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4751 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4752 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4753 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4754 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4755 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4756 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4757 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4758 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4759 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4760 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4761 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4762 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4763 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4764 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4765 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4766 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4767 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4768 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4769 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4770 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4771 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4772 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4773 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4774 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4775 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4776 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4777 /* default Intel */
4778 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4779 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4780 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4781 {}
4782};
4783
4784static const struct alc_model_fixup alc880_fixup_models[] = {
4785 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4786 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4787 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4788 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4789 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4790 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004791 {}
4792};
4793
4794
4795/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004796 * OK, here we have finally the patch for ALC880
4797 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004798static int patch_alc880(struct hda_codec *codec)
4799{
4800 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004801 int err;
4802
Takashi Iwai3de95172012-05-07 18:03:15 +02004803 err = alc_alloc_spec(codec, 0x0b);
4804 if (err < 0)
4805 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004806
Takashi Iwai3de95172012-05-07 18:03:15 +02004807 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004808 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004809
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004810 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4811 alc880_fixups);
4812 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004813
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004814 /* automatic parse from the BIOS config */
4815 err = alc880_parse_auto_config(codec);
4816 if (err < 0)
4817 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004818
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004819 if (!spec->no_analog) {
4820 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004821 if (err < 0)
4822 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004823 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4824 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004825
Takashi Iwai1d045db2011-07-07 18:23:21 +02004826 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004827
Takashi Iwai589876e2012-02-20 15:47:55 +01004828 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4829
Takashi Iwai1d045db2011-07-07 18:23:21 +02004830 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004831
4832 error:
4833 alc_free(codec);
4834 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004835}
4836
4837
4838/*
4839 * ALC260 support
4840 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004841static int alc260_parse_auto_config(struct hda_codec *codec)
4842{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004843 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004844 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4845 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004846}
4847
Takashi Iwai1d045db2011-07-07 18:23:21 +02004848/*
4849 * Pin config fixes
4850 */
4851enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004852 ALC260_FIXUP_HP_DC5750,
4853 ALC260_FIXUP_HP_PIN_0F,
4854 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004855 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004856 ALC260_FIXUP_GPIO1_TOGGLE,
4857 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004858 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004859 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004860};
4861
Takashi Iwai20f7d922012-02-16 12:35:16 +01004862static void alc260_gpio1_automute(struct hda_codec *codec)
4863{
4864 struct alc_spec *spec = codec->spec;
4865 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4866 spec->hp_jack_present);
4867}
4868
4869static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4870 const struct alc_fixup *fix, int action)
4871{
4872 struct alc_spec *spec = codec->spec;
4873 if (action == ALC_FIXUP_ACT_PROBE) {
4874 /* although the machine has only one output pin, we need to
4875 * toggle GPIO1 according to the jack state
4876 */
4877 spec->automute_hook = alc260_gpio1_automute;
4878 spec->detect_hp = 1;
4879 spec->automute_speaker = 1;
4880 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4881 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4882 spec->unsol_event = alc_sku_unsol_event;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004883 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004884 }
4885}
4886
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004887static void alc260_fixup_kn1(struct hda_codec *codec,
4888 const struct alc_fixup *fix, int action)
4889{
4890 struct alc_spec *spec = codec->spec;
4891 static const struct alc_pincfg pincfgs[] = {
4892 { 0x0f, 0x02214000 }, /* HP/speaker */
4893 { 0x12, 0x90a60160 }, /* int mic */
4894 { 0x13, 0x02a19000 }, /* ext mic */
4895 { 0x18, 0x01446000 }, /* SPDIF out */
4896 /* disable bogus I/O pins */
4897 { 0x10, 0x411111f0 },
4898 { 0x11, 0x411111f0 },
4899 { 0x14, 0x411111f0 },
4900 { 0x15, 0x411111f0 },
4901 { 0x16, 0x411111f0 },
4902 { 0x17, 0x411111f0 },
4903 { 0x19, 0x411111f0 },
4904 { }
4905 };
4906
4907 switch (action) {
4908 case ALC_FIXUP_ACT_PRE_PROBE:
4909 alc_apply_pincfgs(codec, pincfgs);
4910 break;
4911 case ALC_FIXUP_ACT_PROBE:
4912 spec->init_amp = ALC_INIT_NONE;
4913 break;
4914 }
4915}
4916
Takashi Iwai1d045db2011-07-07 18:23:21 +02004917static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004918 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004919 .type = ALC_FIXUP_PINS,
4920 .v.pins = (const struct alc_pincfg[]) {
4921 { 0x11, 0x90130110 }, /* speaker */
4922 { }
4923 }
4924 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004925 [ALC260_FIXUP_HP_PIN_0F] = {
4926 .type = ALC_FIXUP_PINS,
4927 .v.pins = (const struct alc_pincfg[]) {
4928 { 0x0f, 0x01214000 }, /* HP */
4929 { }
4930 }
4931 },
4932 [ALC260_FIXUP_COEF] = {
4933 .type = ALC_FIXUP_VERBS,
4934 .v.verbs = (const struct hda_verb[]) {
4935 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4936 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4937 { }
4938 },
4939 .chained = true,
4940 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4941 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004942 [ALC260_FIXUP_GPIO1] = {
4943 .type = ALC_FIXUP_VERBS,
4944 .v.verbs = alc_gpio1_init_verbs,
4945 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004946 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4947 .type = ALC_FIXUP_FUNC,
4948 .v.func = alc260_fixup_gpio1_toggle,
4949 .chained = true,
4950 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4951 },
4952 [ALC260_FIXUP_REPLACER] = {
4953 .type = ALC_FIXUP_VERBS,
4954 .v.verbs = (const struct hda_verb[]) {
4955 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4956 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4957 { }
4958 },
4959 .chained = true,
4960 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4961 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004962 [ALC260_FIXUP_HP_B1900] = {
4963 .type = ALC_FIXUP_FUNC,
4964 .v.func = alc260_fixup_gpio1_toggle,
4965 .chained = true,
4966 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004967 },
4968 [ALC260_FIXUP_KN1] = {
4969 .type = ALC_FIXUP_FUNC,
4970 .v.func = alc260_fixup_kn1,
4971 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004972};
4973
4974static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004975 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004976 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004977 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004978 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004979 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004980 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004981 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004982 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004983 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004984 {}
4985};
4986
4987/*
4988 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004989static int patch_alc260(struct hda_codec *codec)
4990{
4991 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004992 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004993
Takashi Iwai3de95172012-05-07 18:03:15 +02004994 err = alc_alloc_spec(codec, 0x07);
4995 if (err < 0)
4996 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004997
Takashi Iwai3de95172012-05-07 18:03:15 +02004998 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004999
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005000 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
5001 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005002
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01005003 /* automatic parse from the BIOS config */
5004 err = alc260_parse_auto_config(codec);
5005 if (err < 0)
5006 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005007
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005008 if (!spec->no_analog) {
5009 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005010 if (err < 0)
5011 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005012 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
5013 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005014
Takashi Iwai1d045db2011-07-07 18:23:21 +02005015 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005016 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005017
Takashi Iwai589876e2012-02-20 15:47:55 +01005018 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5019
Takashi Iwai1d045db2011-07-07 18:23:21 +02005020 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005021
5022 error:
5023 alc_free(codec);
5024 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005025}
5026
5027
5028/*
5029 * ALC882/883/885/888/889 support
5030 *
5031 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
5032 * configuration. Each pin widget can choose any input DACs and a mixer.
5033 * Each ADC is connected from a mixer of all inputs. This makes possible
5034 * 6-channel independent captures.
5035 *
5036 * In addition, an independent DAC for the multi-playback (not used in this
5037 * driver yet).
5038 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005039
5040/*
5041 * Pin config fixes
5042 */
5043enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005044 ALC882_FIXUP_ABIT_AW9D_MAX,
5045 ALC882_FIXUP_LENOVO_Y530,
5046 ALC882_FIXUP_PB_M5210,
5047 ALC882_FIXUP_ACER_ASPIRE_7736,
5048 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005049 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005050 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005051 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005052 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005053 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005054 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005055 ALC882_FIXUP_GPIO1,
5056 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005057 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005058 ALC889_FIXUP_COEF,
5059 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005060 ALC882_FIXUP_ACER_ASPIRE_4930G,
5061 ALC882_FIXUP_ACER_ASPIRE_8930G,
5062 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005063 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005064 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005065 ALC889_FIXUP_MBP_VREF,
5066 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005067 ALC882_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005068};
5069
Takashi Iwai68ef0562011-11-09 18:24:44 +01005070static void alc889_fixup_coef(struct hda_codec *codec,
5071 const struct alc_fixup *fix, int action)
5072{
5073 if (action != ALC_FIXUP_ACT_INIT)
5074 return;
5075 alc889_coef_init(codec);
5076}
5077
Takashi Iwai56710872011-11-14 17:42:11 +01005078/* toggle speaker-output according to the hp-jack state */
5079static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5080{
5081 unsigned int gpiostate, gpiomask, gpiodir;
5082
5083 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5084 AC_VERB_GET_GPIO_DATA, 0);
5085
5086 if (!muted)
5087 gpiostate |= (1 << pin);
5088 else
5089 gpiostate &= ~(1 << pin);
5090
5091 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5092 AC_VERB_GET_GPIO_MASK, 0);
5093 gpiomask |= (1 << pin);
5094
5095 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5096 AC_VERB_GET_GPIO_DIRECTION, 0);
5097 gpiodir |= (1 << pin);
5098
5099
5100 snd_hda_codec_write(codec, codec->afg, 0,
5101 AC_VERB_SET_GPIO_MASK, gpiomask);
5102 snd_hda_codec_write(codec, codec->afg, 0,
5103 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5104
5105 msleep(1);
5106
5107 snd_hda_codec_write(codec, codec->afg, 0,
5108 AC_VERB_SET_GPIO_DATA, gpiostate);
5109}
5110
5111/* set up GPIO at initialization */
5112static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5113 const struct alc_fixup *fix, int action)
5114{
5115 if (action != ALC_FIXUP_ACT_INIT)
5116 return;
5117 alc882_gpio_mute(codec, 0, 0);
5118 alc882_gpio_mute(codec, 1, 0);
5119}
5120
Takashi Iwai02a237b2012-02-13 15:25:07 +01005121/* Fix the connection of some pins for ALC889:
5122 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5123 * work correctly (bko#42740)
5124 */
5125static void alc889_fixup_dac_route(struct hda_codec *codec,
5126 const struct alc_fixup *fix, int action)
5127{
5128 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005129 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005130 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5131 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5132 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5133 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5134 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5135 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005136 } else if (action == ALC_FIXUP_ACT_PROBE) {
5137 /* restore the connections */
5138 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5139 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5140 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5141 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5142 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005143 }
5144}
5145
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005146/* Set VREF on HP pin */
5147static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5148 const struct alc_fixup *fix, int action)
5149{
5150 struct alc_spec *spec = codec->spec;
5151 static hda_nid_t nids[2] = { 0x14, 0x15 };
5152 int i;
5153
5154 if (action != ALC_FIXUP_ACT_INIT)
5155 return;
5156 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5157 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5158 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5159 continue;
5160 val = snd_hda_codec_read(codec, nids[i], 0,
5161 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5162 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005163 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005164 spec->keep_vref_in_automute = 1;
5165 break;
5166 }
5167}
5168
5169/* Set VREF on speaker pins on imac91 */
5170static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5171 const struct alc_fixup *fix, int action)
5172{
5173 struct alc_spec *spec = codec->spec;
5174 static hda_nid_t nids[2] = { 0x18, 0x1a };
5175 int i;
5176
5177 if (action != ALC_FIXUP_ACT_INIT)
5178 return;
5179 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5180 unsigned int val;
5181 val = snd_hda_codec_read(codec, nids[i], 0,
5182 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5183 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005184 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005185 }
5186 spec->keep_vref_in_automute = 1;
5187}
5188
Takashi Iwai1d045db2011-07-07 18:23:21 +02005189static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005190 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005191 .type = ALC_FIXUP_PINS,
5192 .v.pins = (const struct alc_pincfg[]) {
5193 { 0x15, 0x01080104 }, /* side */
5194 { 0x16, 0x01011012 }, /* rear */
5195 { 0x17, 0x01016011 }, /* clfe */
5196 { }
5197 }
5198 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005199 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005200 .type = ALC_FIXUP_PINS,
5201 .v.pins = (const struct alc_pincfg[]) {
5202 { 0x15, 0x99130112 }, /* rear int speakers */
5203 { 0x16, 0x99130111 }, /* subwoofer */
5204 { }
5205 }
5206 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005207 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005208 .type = ALC_FIXUP_VERBS,
5209 .v.verbs = (const struct hda_verb[]) {
5210 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5211 {}
5212 }
5213 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005214 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005215 .type = ALC_FIXUP_FUNC,
5216 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005217 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005218 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005219 .type = ALC_FIXUP_PINS,
5220 .v.pins = (const struct alc_pincfg[]) {
5221 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5222 { }
5223 }
5224 },
Marton Balint8f239212012-03-05 21:33:23 +01005225 [ALC889_FIXUP_CD] = {
5226 .type = ALC_FIXUP_PINS,
5227 .v.pins = (const struct alc_pincfg[]) {
5228 { 0x1c, 0x993301f0 }, /* CD */
5229 { }
5230 }
5231 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005232 [ALC889_FIXUP_VAIO_TT] = {
5233 .type = ALC_FIXUP_PINS,
5234 .v.pins = (const struct alc_pincfg[]) {
5235 { 0x17, 0x90170111 }, /* hidden surround speaker */
5236 { }
5237 }
5238 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005239 [ALC888_FIXUP_EEE1601] = {
5240 .type = ALC_FIXUP_VERBS,
5241 .v.verbs = (const struct hda_verb[]) {
5242 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5243 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5244 { }
5245 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005246 },
5247 [ALC882_FIXUP_EAPD] = {
5248 .type = ALC_FIXUP_VERBS,
5249 .v.verbs = (const struct hda_verb[]) {
5250 /* change to EAPD mode */
5251 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5252 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5253 { }
5254 }
5255 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005256 [ALC883_FIXUP_EAPD] = {
5257 .type = ALC_FIXUP_VERBS,
5258 .v.verbs = (const struct hda_verb[]) {
5259 /* change to EAPD mode */
5260 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5261 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5262 { }
5263 }
5264 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005265 [ALC883_FIXUP_ACER_EAPD] = {
5266 .type = ALC_FIXUP_VERBS,
5267 .v.verbs = (const struct hda_verb[]) {
5268 /* eanable EAPD on Acer laptops */
5269 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5270 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5271 { }
5272 }
5273 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005274 [ALC882_FIXUP_GPIO1] = {
5275 .type = ALC_FIXUP_VERBS,
5276 .v.verbs = alc_gpio1_init_verbs,
5277 },
5278 [ALC882_FIXUP_GPIO2] = {
5279 .type = ALC_FIXUP_VERBS,
5280 .v.verbs = alc_gpio2_init_verbs,
5281 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005282 [ALC882_FIXUP_GPIO3] = {
5283 .type = ALC_FIXUP_VERBS,
5284 .v.verbs = alc_gpio3_init_verbs,
5285 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005286 [ALC882_FIXUP_ASUS_W2JC] = {
5287 .type = ALC_FIXUP_VERBS,
5288 .v.verbs = alc_gpio1_init_verbs,
5289 .chained = true,
5290 .chain_id = ALC882_FIXUP_EAPD,
5291 },
5292 [ALC889_FIXUP_COEF] = {
5293 .type = ALC_FIXUP_FUNC,
5294 .v.func = alc889_fixup_coef,
5295 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005296 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5297 .type = ALC_FIXUP_PINS,
5298 .v.pins = (const struct alc_pincfg[]) {
5299 { 0x16, 0x99130111 }, /* CLFE speaker */
5300 { 0x17, 0x99130112 }, /* surround speaker */
5301 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005302 },
5303 .chained = true,
5304 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005305 },
5306 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5307 .type = ALC_FIXUP_PINS,
5308 .v.pins = (const struct alc_pincfg[]) {
5309 { 0x16, 0x99130111 }, /* CLFE speaker */
5310 { 0x1b, 0x99130112 }, /* surround speaker */
5311 { }
5312 },
5313 .chained = true,
5314 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5315 },
5316 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5317 /* additional init verbs for Acer Aspire 8930G */
5318 .type = ALC_FIXUP_VERBS,
5319 .v.verbs = (const struct hda_verb[]) {
5320 /* Enable all DACs */
5321 /* DAC DISABLE/MUTE 1? */
5322 /* setting bits 1-5 disables DAC nids 0x02-0x06
5323 * apparently. Init=0x38 */
5324 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5325 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5326 /* DAC DISABLE/MUTE 2? */
5327 /* some bit here disables the other DACs.
5328 * Init=0x4900 */
5329 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5330 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5331 /* DMIC fix
5332 * This laptop has a stereo digital microphone.
5333 * The mics are only 1cm apart which makes the stereo
5334 * useless. However, either the mic or the ALC889
5335 * makes the signal become a difference/sum signal
5336 * instead of standard stereo, which is annoying.
5337 * So instead we flip this bit which makes the
5338 * codec replicate the sum signal to both channels,
5339 * turning it into a normal mono mic.
5340 */
5341 /* DMIC_CONTROL? Init value = 0x0001 */
5342 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5343 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5344 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5345 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5346 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005347 },
5348 .chained = true,
5349 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005350 },
Takashi Iwai56710872011-11-14 17:42:11 +01005351 [ALC885_FIXUP_MACPRO_GPIO] = {
5352 .type = ALC_FIXUP_FUNC,
5353 .v.func = alc885_fixup_macpro_gpio,
5354 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005355 [ALC889_FIXUP_DAC_ROUTE] = {
5356 .type = ALC_FIXUP_FUNC,
5357 .v.func = alc889_fixup_dac_route,
5358 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005359 [ALC889_FIXUP_MBP_VREF] = {
5360 .type = ALC_FIXUP_FUNC,
5361 .v.func = alc889_fixup_mbp_vref,
5362 .chained = true,
5363 .chain_id = ALC882_FIXUP_GPIO1,
5364 },
5365 [ALC889_FIXUP_IMAC91_VREF] = {
5366 .type = ALC_FIXUP_FUNC,
5367 .v.func = alc889_fixup_imac91_vref,
5368 .chained = true,
5369 .chain_id = ALC882_FIXUP_GPIO1,
5370 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005371 [ALC882_FIXUP_INV_DMIC] = {
5372 .type = ALC_FIXUP_FUNC,
5373 .v.func = alc_fixup_inv_dmic_0x12,
5374 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005375};
5376
5377static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005378 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5379 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5380 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5381 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5382 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5383 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005384 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5385 ALC882_FIXUP_ACER_ASPIRE_4930G),
5386 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5387 ALC882_FIXUP_ACER_ASPIRE_4930G),
5388 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5389 ALC882_FIXUP_ACER_ASPIRE_8930G),
5390 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5391 ALC882_FIXUP_ACER_ASPIRE_8930G),
5392 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5393 ALC882_FIXUP_ACER_ASPIRE_4930G),
5394 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5395 ALC882_FIXUP_ACER_ASPIRE_4930G),
5396 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5397 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005398 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005399 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5400 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005401 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005402 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005403 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005404 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005405 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005406 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005407 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005408 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005409
5410 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005411 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5412 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5413 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005414 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5415 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5416 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005417 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5418 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005419 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005420 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5421 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5422 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5423 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005424 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005425 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5426 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5427 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005428 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005429 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5430 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5431 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005432
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005433 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005434 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005435 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005436 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005437 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005438 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5439 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005440 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005441 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005442 {}
5443};
5444
Takashi Iwai912093b2012-04-11 14:03:41 +02005445static const struct alc_model_fixup alc882_fixup_models[] = {
5446 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5447 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5448 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005449 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005450 {}
5451};
5452
Takashi Iwai1d045db2011-07-07 18:23:21 +02005453/*
5454 * BIOS auto configuration
5455 */
5456/* almost identical with ALC880 parser... */
5457static int alc882_parse_auto_config(struct hda_codec *codec)
5458{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005459 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005460 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5461 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005462}
5463
Takashi Iwai1d045db2011-07-07 18:23:21 +02005464/*
5465 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005466static int patch_alc882(struct hda_codec *codec)
5467{
5468 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005469 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005470
Takashi Iwai3de95172012-05-07 18:03:15 +02005471 err = alc_alloc_spec(codec, 0x0b);
5472 if (err < 0)
5473 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005474
Takashi Iwai3de95172012-05-07 18:03:15 +02005475 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005476
5477 switch (codec->vendor_id) {
5478 case 0x10ec0882:
5479 case 0x10ec0885:
5480 break;
5481 default:
5482 /* ALC883 and variants */
5483 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5484 break;
5485 }
5486
Takashi Iwai912093b2012-04-11 14:03:41 +02005487 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5488 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005489 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005490
5491 alc_auto_parse_customize_define(codec);
5492
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005493 /* automatic parse from the BIOS config */
5494 err = alc882_parse_auto_config(codec);
5495 if (err < 0)
5496 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005497
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005498 if (!spec->no_analog && has_cdefine_beep(codec)) {
5499 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005500 if (err < 0)
5501 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005502 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005503 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005504
Takashi Iwai1d045db2011-07-07 18:23:21 +02005505 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005506
Takashi Iwai589876e2012-02-20 15:47:55 +01005507 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5508
Takashi Iwai1d045db2011-07-07 18:23:21 +02005509 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005510
5511 error:
5512 alc_free(codec);
5513 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005514}
5515
5516
5517/*
5518 * ALC262 support
5519 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005520static int alc262_parse_auto_config(struct hda_codec *codec)
5521{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005522 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005523 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5524 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005525}
5526
5527/*
5528 * Pin config fixes
5529 */
5530enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005531 ALC262_FIXUP_FSC_H270,
5532 ALC262_FIXUP_HP_Z200,
5533 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005534 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005535 ALC262_FIXUP_BENQ,
5536 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005537 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005538};
5539
5540static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005541 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005542 .type = ALC_FIXUP_PINS,
5543 .v.pins = (const struct alc_pincfg[]) {
5544 { 0x14, 0x99130110 }, /* speaker */
5545 { 0x15, 0x0221142f }, /* front HP */
5546 { 0x1b, 0x0121141f }, /* rear HP */
5547 { }
5548 }
5549 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005550 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005551 .type = ALC_FIXUP_PINS,
5552 .v.pins = (const struct alc_pincfg[]) {
5553 { 0x16, 0x99130120 }, /* internal speaker */
5554 { }
5555 }
5556 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005557 [ALC262_FIXUP_TYAN] = {
5558 .type = ALC_FIXUP_PINS,
5559 .v.pins = (const struct alc_pincfg[]) {
5560 { 0x14, 0x1993e1f0 }, /* int AUX */
5561 { }
5562 }
5563 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005564 [ALC262_FIXUP_LENOVO_3000] = {
5565 .type = ALC_FIXUP_VERBS,
5566 .v.verbs = (const struct hda_verb[]) {
5567 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005568 {}
5569 },
5570 .chained = true,
5571 .chain_id = ALC262_FIXUP_BENQ,
5572 },
5573 [ALC262_FIXUP_BENQ] = {
5574 .type = ALC_FIXUP_VERBS,
5575 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005576 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5577 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5578 {}
5579 }
5580 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005581 [ALC262_FIXUP_BENQ_T31] = {
5582 .type = ALC_FIXUP_VERBS,
5583 .v.verbs = (const struct hda_verb[]) {
5584 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5585 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5586 {}
5587 }
5588 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005589 [ALC262_FIXUP_INV_DMIC] = {
5590 .type = ALC_FIXUP_FUNC,
5591 .v.func = alc_fixup_inv_dmic_0x12,
5592 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005593};
5594
5595static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005596 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005597 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5598 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005599 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5600 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005601 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005602 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5603 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005604 {}
5605};
5606
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005607static const struct alc_model_fixup alc262_fixup_models[] = {
5608 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5609 {}
5610};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005611
Takashi Iwai1d045db2011-07-07 18:23:21 +02005612/*
5613 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005614static int patch_alc262(struct hda_codec *codec)
5615{
5616 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005617 int err;
5618
Takashi Iwai3de95172012-05-07 18:03:15 +02005619 err = alc_alloc_spec(codec, 0x0b);
5620 if (err < 0)
5621 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005622
Takashi Iwai3de95172012-05-07 18:03:15 +02005623 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005624
5625#if 0
5626 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5627 * under-run
5628 */
5629 {
5630 int tmp;
5631 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5632 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5633 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5634 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5635 }
5636#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005637 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5638
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005639 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5640 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005641 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005642
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005643 alc_auto_parse_customize_define(codec);
5644
Takashi Iwai42399f72011-11-07 17:18:44 +01005645 /* automatic parse from the BIOS config */
5646 err = alc262_parse_auto_config(codec);
5647 if (err < 0)
5648 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005649
Takashi Iwai1d045db2011-07-07 18:23:21 +02005650 if (!spec->no_analog && has_cdefine_beep(codec)) {
5651 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005652 if (err < 0)
5653 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005654 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005655 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656
Takashi Iwai1d045db2011-07-07 18:23:21 +02005657 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005658 spec->shutup = alc_eapd_shutup;
5659
Takashi Iwai589876e2012-02-20 15:47:55 +01005660 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5661
Takashi Iwai1d045db2011-07-07 18:23:21 +02005662 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005663
5664 error:
5665 alc_free(codec);
5666 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005667}
5668
5669/*
5670 * ALC268
5671 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005672/* bind Beep switches of both NID 0x0f and 0x10 */
5673static const struct hda_bind_ctls alc268_bind_beep_sw = {
5674 .ops = &snd_hda_bind_sw,
5675 .values = {
5676 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5677 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5678 0
5679 },
5680};
5681
5682static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5683 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5684 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5685 { }
5686};
5687
5688/* set PCBEEP vol = 0, mute connections */
5689static const struct hda_verb alc268_beep_init_verbs[] = {
5690 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5691 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5692 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5693 { }
5694};
5695
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005696enum {
5697 ALC268_FIXUP_INV_DMIC,
5698};
5699
5700static const struct alc_fixup alc268_fixups[] = {
5701 [ALC268_FIXUP_INV_DMIC] = {
5702 .type = ALC_FIXUP_FUNC,
5703 .v.func = alc_fixup_inv_dmic_0x12,
5704 },
5705};
5706
5707static const struct alc_model_fixup alc268_fixup_models[] = {
5708 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5709 {}
5710};
5711
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712/*
5713 * BIOS auto configuration
5714 */
5715static int alc268_parse_auto_config(struct hda_codec *codec)
5716{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005717 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005718 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005719 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5720 if (err > 0) {
5721 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5722 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005723 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005724 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005725 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005726 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005727}
5728
Takashi Iwai1d045db2011-07-07 18:23:21 +02005729/*
5730 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005731static int patch_alc268(struct hda_codec *codec)
5732{
5733 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005734 int i, has_beep, err;
5735
Takashi Iwai1d045db2011-07-07 18:23:21 +02005736 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005737 err = alc_alloc_spec(codec, 0);
5738 if (err < 0)
5739 return err;
5740
5741 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005742
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005743 alc_pick_fixup(codec, alc268_fixup_models, NULL, alc268_fixups);
5744 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5745
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005746 /* automatic parse from the BIOS config */
5747 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005748 if (err < 0)
5749 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005750
Takashi Iwai1d045db2011-07-07 18:23:21 +02005751 has_beep = 0;
5752 for (i = 0; i < spec->num_mixers; i++) {
5753 if (spec->mixers[i] == alc268_beep_mixer) {
5754 has_beep = 1;
5755 break;
5756 }
5757 }
5758
5759 if (has_beep) {
5760 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005761 if (err < 0)
5762 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005763 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5764 /* override the amp caps for beep generator */
5765 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5766 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5767 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5768 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5769 (0 << AC_AMPCAP_MUTE_SHIFT));
5770 }
5771
Takashi Iwai1d045db2011-07-07 18:23:21 +02005772 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005773 spec->shutup = alc_eapd_shutup;
5774
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005775 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5776
Takashi Iwai1d045db2011-07-07 18:23:21 +02005777 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005778
5779 error:
5780 alc_free(codec);
5781 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005782}
5783
5784/*
5785 * ALC269
5786 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005787static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5788 .substreams = 1,
5789 .channels_min = 2,
5790 .channels_max = 8,
5791 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5792 /* NID is set in alc_build_pcms */
5793 .ops = {
5794 .open = alc_playback_pcm_open,
5795 .prepare = alc_playback_pcm_prepare,
5796 .cleanup = alc_playback_pcm_cleanup
5797 },
5798};
5799
5800static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5801 .substreams = 1,
5802 .channels_min = 2,
5803 .channels_max = 2,
5804 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5805 /* NID is set in alc_build_pcms */
5806};
5807
Takashi Iwai1d045db2011-07-07 18:23:21 +02005808/* different alc269-variants */
5809enum {
5810 ALC269_TYPE_ALC269VA,
5811 ALC269_TYPE_ALC269VB,
5812 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005813 ALC269_TYPE_ALC269VD,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005814};
5815
5816/*
5817 * BIOS auto configuration
5818 */
5819static int alc269_parse_auto_config(struct hda_codec *codec)
5820{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005821 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005822 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5823 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5824 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005825 const hda_nid_t *ssids;
5826
5827 switch (spec->codec_variant) {
5828 case ALC269_TYPE_ALC269VA:
5829 case ALC269_TYPE_ALC269VC:
5830 ssids = alc269va_ssids;
5831 break;
5832 case ALC269_TYPE_ALC269VB:
5833 case ALC269_TYPE_ALC269VD:
5834 ssids = alc269_ssids;
5835 break;
5836 default:
5837 ssids = alc269_ssids;
5838 break;
5839 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005840
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005841 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005842}
5843
Takashi Iwai1d045db2011-07-07 18:23:21 +02005844static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5845{
5846 int val = alc_read_coef_idx(codec, 0x04);
5847 if (power_up)
5848 val |= 1 << 11;
5849 else
5850 val &= ~(1 << 11);
5851 alc_write_coef_idx(codec, 0x04, val);
5852}
5853
5854static void alc269_shutup(struct hda_codec *codec)
5855{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005856 struct alc_spec *spec = codec->spec;
5857
5858 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5859 return;
5860
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005861 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005862 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005863 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005864 alc269_toggle_power_output(codec, 0);
5865 msleep(150);
5866 }
5867}
5868
Takashi Iwai2a439522011-07-26 09:52:50 +02005869#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005870static int alc269_resume(struct hda_codec *codec)
5871{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005872 struct alc_spec *spec = codec->spec;
5873
5874 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5875 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005876 alc269_toggle_power_output(codec, 0);
5877 msleep(150);
5878 }
5879
5880 codec->patch_ops.init(codec);
5881
Kailang Yangadcc70b2012-05-25 08:08:38 +02005882 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5883 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005884 alc269_toggle_power_output(codec, 1);
5885 msleep(200);
5886 }
5887
Kailang Yangadcc70b2012-05-25 08:08:38 +02005888 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5889 (alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005890 alc269_toggle_power_output(codec, 1);
5891
5892 snd_hda_codec_resume_amp(codec);
5893 snd_hda_codec_resume_cache(codec);
5894 hda_call_check_power_status(codec, 0x01);
5895 return 0;
5896}
Takashi Iwai2a439522011-07-26 09:52:50 +02005897#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005898
5899static void alc269_fixup_hweq(struct hda_codec *codec,
5900 const struct alc_fixup *fix, int action)
5901{
5902 int coef;
5903
5904 if (action != ALC_FIXUP_ACT_INIT)
5905 return;
5906 coef = alc_read_coef_idx(codec, 0x1e);
5907 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5908}
5909
5910static void alc271_fixup_dmic(struct hda_codec *codec,
5911 const struct alc_fixup *fix, int action)
5912{
5913 static const struct hda_verb verbs[] = {
5914 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5915 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5916 {}
5917 };
5918 unsigned int cfg;
5919
5920 if (strcmp(codec->chip_name, "ALC271X"))
5921 return;
5922 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5923 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5924 snd_hda_sequence_write(codec, verbs);
5925}
5926
Takashi Iwai017f2a12011-07-09 14:42:25 +02005927static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5928 const struct alc_fixup *fix, int action)
5929{
5930 struct alc_spec *spec = codec->spec;
5931
5932 if (action != ALC_FIXUP_ACT_PROBE)
5933 return;
5934
5935 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5936 * fix the sample rate of analog I/O to 44.1kHz
5937 */
5938 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5939 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5940}
5941
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005942static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5943 const struct alc_fixup *fix, int action)
5944{
5945 int coef;
5946
5947 if (action != ALC_FIXUP_ACT_INIT)
5948 return;
5949 /* The digital-mic unit sends PDM (differential signal) instead of
5950 * the standard PCM, thus you can't record a valid mono stream as is.
5951 * Below is a workaround specific to ALC269 to control the dmic
5952 * signal source as mono.
5953 */
5954 coef = alc_read_coef_idx(codec, 0x07);
5955 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5956}
5957
Takashi Iwai24519912011-08-16 15:08:49 +02005958static void alc269_quanta_automute(struct hda_codec *codec)
5959{
David Henningsson42cf0d02011-09-20 12:04:56 +02005960 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005961
5962 snd_hda_codec_write(codec, 0x20, 0,
5963 AC_VERB_SET_COEF_INDEX, 0x0c);
5964 snd_hda_codec_write(codec, 0x20, 0,
5965 AC_VERB_SET_PROC_COEF, 0x680);
5966
5967 snd_hda_codec_write(codec, 0x20, 0,
5968 AC_VERB_SET_COEF_INDEX, 0x0c);
5969 snd_hda_codec_write(codec, 0x20, 0,
5970 AC_VERB_SET_PROC_COEF, 0x480);
5971}
5972
5973static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5974 const struct alc_fixup *fix, int action)
5975{
5976 struct alc_spec *spec = codec->spec;
5977 if (action != ALC_FIXUP_ACT_PROBE)
5978 return;
5979 spec->automute_hook = alc269_quanta_automute;
5980}
5981
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005982/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5983static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5984{
5985 struct hda_codec *codec = private_data;
5986 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005987 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005988}
5989
5990static void alc269_fixup_mic2_mute(struct hda_codec *codec,
5991 const struct alc_fixup *fix, int action)
5992{
5993 struct alc_spec *spec = codec->spec;
5994 switch (action) {
5995 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005996 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01005997 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005998 /* fallthru */
5999 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01006000 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006001 break;
6002 }
6003}
6004
David Henningsson693b6132012-06-22 19:12:10 +02006005
Takashi Iwai1d045db2011-07-07 18:23:21 +02006006enum {
6007 ALC269_FIXUP_SONY_VAIO,
6008 ALC275_FIXUP_SONY_VAIO_GPIO2,
6009 ALC269_FIXUP_DELL_M101Z,
6010 ALC269_FIXUP_SKU_IGNORE,
6011 ALC269_FIXUP_ASUS_G73JW,
6012 ALC269_FIXUP_LENOVO_EAPD,
6013 ALC275_FIXUP_SONY_HWEQ,
6014 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02006015 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006016 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02006017 ALC269_FIXUP_QUANTA_MUTE,
6018 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02006019 ALC269_FIXUP_AMIC,
6020 ALC269_FIXUP_DMIC,
6021 ALC269VB_FIXUP_AMIC,
6022 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006023 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02006024 ALC269_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006025};
6026
6027static const struct alc_fixup alc269_fixups[] = {
6028 [ALC269_FIXUP_SONY_VAIO] = {
6029 .type = ALC_FIXUP_VERBS,
6030 .v.verbs = (const struct hda_verb[]) {
6031 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
6032 {}
6033 }
6034 },
6035 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
6036 .type = ALC_FIXUP_VERBS,
6037 .v.verbs = (const struct hda_verb[]) {
6038 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6039 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6040 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6041 { }
6042 },
6043 .chained = true,
6044 .chain_id = ALC269_FIXUP_SONY_VAIO
6045 },
6046 [ALC269_FIXUP_DELL_M101Z] = {
6047 .type = ALC_FIXUP_VERBS,
6048 .v.verbs = (const struct hda_verb[]) {
6049 /* Enables internal speaker */
6050 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6051 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6052 {}
6053 }
6054 },
6055 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006056 .type = ALC_FIXUP_FUNC,
6057 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006058 },
6059 [ALC269_FIXUP_ASUS_G73JW] = {
6060 .type = ALC_FIXUP_PINS,
6061 .v.pins = (const struct alc_pincfg[]) {
6062 { 0x17, 0x99130111 }, /* subwoofer */
6063 { }
6064 }
6065 },
6066 [ALC269_FIXUP_LENOVO_EAPD] = {
6067 .type = ALC_FIXUP_VERBS,
6068 .v.verbs = (const struct hda_verb[]) {
6069 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6070 {}
6071 }
6072 },
6073 [ALC275_FIXUP_SONY_HWEQ] = {
6074 .type = ALC_FIXUP_FUNC,
6075 .v.func = alc269_fixup_hweq,
6076 .chained = true,
6077 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6078 },
6079 [ALC271_FIXUP_DMIC] = {
6080 .type = ALC_FIXUP_FUNC,
6081 .v.func = alc271_fixup_dmic,
6082 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006083 [ALC269_FIXUP_PCM_44K] = {
6084 .type = ALC_FIXUP_FUNC,
6085 .v.func = alc269_fixup_pcm_44k,
6086 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006087 [ALC269_FIXUP_STEREO_DMIC] = {
6088 .type = ALC_FIXUP_FUNC,
6089 .v.func = alc269_fixup_stereo_dmic,
6090 },
Takashi Iwai24519912011-08-16 15:08:49 +02006091 [ALC269_FIXUP_QUANTA_MUTE] = {
6092 .type = ALC_FIXUP_FUNC,
6093 .v.func = alc269_fixup_quanta_mute,
6094 },
6095 [ALC269_FIXUP_LIFEBOOK] = {
6096 .type = ALC_FIXUP_PINS,
6097 .v.pins = (const struct alc_pincfg[]) {
6098 { 0x1a, 0x2101103f }, /* dock line-out */
6099 { 0x1b, 0x23a11040 }, /* dock mic-in */
6100 { }
6101 },
6102 .chained = true,
6103 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6104 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006105 [ALC269_FIXUP_AMIC] = {
6106 .type = ALC_FIXUP_PINS,
6107 .v.pins = (const struct alc_pincfg[]) {
6108 { 0x14, 0x99130110 }, /* speaker */
6109 { 0x15, 0x0121401f }, /* HP out */
6110 { 0x18, 0x01a19c20 }, /* mic */
6111 { 0x19, 0x99a3092f }, /* int-mic */
6112 { }
6113 },
6114 },
6115 [ALC269_FIXUP_DMIC] = {
6116 .type = ALC_FIXUP_PINS,
6117 .v.pins = (const struct alc_pincfg[]) {
6118 { 0x12, 0x99a3092f }, /* int-mic */
6119 { 0x14, 0x99130110 }, /* speaker */
6120 { 0x15, 0x0121401f }, /* HP out */
6121 { 0x18, 0x01a19c20 }, /* mic */
6122 { }
6123 },
6124 },
6125 [ALC269VB_FIXUP_AMIC] = {
6126 .type = ALC_FIXUP_PINS,
6127 .v.pins = (const struct alc_pincfg[]) {
6128 { 0x14, 0x99130110 }, /* speaker */
6129 { 0x18, 0x01a19c20 }, /* mic */
6130 { 0x19, 0x99a3092f }, /* int-mic */
6131 { 0x21, 0x0121401f }, /* HP out */
6132 { }
6133 },
6134 },
David Henningsson2267ea92012-01-03 08:45:56 +01006135 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006136 .type = ALC_FIXUP_PINS,
6137 .v.pins = (const struct alc_pincfg[]) {
6138 { 0x12, 0x99a3092f }, /* int-mic */
6139 { 0x14, 0x99130110 }, /* speaker */
6140 { 0x18, 0x01a19c20 }, /* mic */
6141 { 0x21, 0x0121401f }, /* HP out */
6142 { }
6143 },
6144 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006145 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6146 .type = ALC_FIXUP_FUNC,
6147 .v.func = alc269_fixup_mic2_mute,
6148 },
David Henningsson693b6132012-06-22 19:12:10 +02006149 [ALC269_FIXUP_INV_DMIC] = {
6150 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006151 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006152 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006153};
6154
6155static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006156 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6157 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006158 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006159 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006160 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006161 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006162 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6163 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6164 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6165 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6166 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006167 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6168 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6169 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6170 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6171 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6172 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006173 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006174 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6175 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6176 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6177 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6178 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006179 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006180 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006181 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006182
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006183#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006184 /* Below is a quirk table taken from the old code.
6185 * Basically the device should work as is without the fixup table.
6186 * If BIOS doesn't give a proper info, enable the corresponding
6187 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006188 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006189 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6190 ALC269_FIXUP_AMIC),
6191 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006192 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6193 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6194 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6195 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6196 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6197 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6198 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6199 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6200 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6201 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6202 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6203 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6204 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6205 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6206 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6207 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6208 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6209 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6210 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6211 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6212 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6213 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6214 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6215 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6216 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6217 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6218 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6219 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6220 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6221 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6222 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6223 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6224 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6225 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6226 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6227 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6228 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6229 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6230#endif
6231 {}
6232};
6233
6234static const struct alc_model_fixup alc269_fixup_models[] = {
6235 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6236 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006237 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6238 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6239 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006240 {}
6241};
6242
6243
Takashi Iwai546bb672012-03-07 08:37:19 +01006244static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006245{
Kailang Yang526af6e2012-03-07 08:25:20 +01006246 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006247 int val;
6248
Kailang Yang526af6e2012-03-07 08:25:20 +01006249 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006250 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006251
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006252 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006253 alc_write_coef_idx(codec, 0xf, 0x960b);
6254 alc_write_coef_idx(codec, 0xe, 0x8817);
6255 }
6256
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006257 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006258 alc_write_coef_idx(codec, 0xf, 0x960b);
6259 alc_write_coef_idx(codec, 0xe, 0x8814);
6260 }
6261
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006262 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006263 val = alc_read_coef_idx(codec, 0x04);
6264 /* Power up output pin */
6265 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6266 }
6267
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006268 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006269 val = alc_read_coef_idx(codec, 0xd);
6270 if ((val & 0x0c00) >> 10 != 0x1) {
6271 /* Capless ramp up clock control */
6272 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6273 }
6274 val = alc_read_coef_idx(codec, 0x17);
6275 if ((val & 0x01c0) >> 6 != 0x4) {
6276 /* Class D power on reset */
6277 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6278 }
6279 }
6280
6281 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6282 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6283
6284 val = alc_read_coef_idx(codec, 0x4); /* HP */
6285 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006286}
6287
6288/*
6289 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006290static int patch_alc269(struct hda_codec *codec)
6291{
6292 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006293 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006294
Takashi Iwai3de95172012-05-07 18:03:15 +02006295 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006296 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006297 return err;
6298
6299 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006300
Takashi Iwai1d045db2011-07-07 18:23:21 +02006301 if (codec->vendor_id == 0x10ec0269) {
6302 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006303 switch (alc_get_coef0(codec) & 0x00f0) {
6304 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006305 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006306 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006307 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006308 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006309 break;
6310 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006311 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6312 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006313 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006314 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006315 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006316 case 0x0030:
6317 spec->codec_variant = ALC269_TYPE_ALC269VD;
6318 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006319 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006320 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006321 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006322 if (err < 0)
6323 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006324 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006325 alc269_fill_coef(codec);
6326 }
6327
Takashi Iwaia4297b52011-08-23 18:40:12 +02006328 alc_pick_fixup(codec, alc269_fixup_models,
6329 alc269_fixup_tbl, alc269_fixups);
6330 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006331
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006332 alc_auto_parse_customize_define(codec);
6333
Takashi Iwaia4297b52011-08-23 18:40:12 +02006334 /* automatic parse from the BIOS config */
6335 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006336 if (err < 0)
6337 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006338
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006339 if (!spec->no_analog && has_cdefine_beep(codec)) {
6340 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006341 if (err < 0)
6342 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006343 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006344 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006345
Takashi Iwai1d045db2011-07-07 18:23:21 +02006346 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006347#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006348 codec->patch_ops.resume = alc269_resume;
6349#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006350 spec->shutup = alc269_shutup;
6351
Takashi Iwai589876e2012-02-20 15:47:55 +01006352 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6353
Takashi Iwai1d045db2011-07-07 18:23:21 +02006354 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006355
6356 error:
6357 alc_free(codec);
6358 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006359}
6360
6361/*
6362 * ALC861
6363 */
6364
Takashi Iwai1d045db2011-07-07 18:23:21 +02006365static int alc861_parse_auto_config(struct hda_codec *codec)
6366{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006367 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006368 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6369 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006370}
6371
Takashi Iwai1d045db2011-07-07 18:23:21 +02006372/* Pin config fixes */
6373enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006374 ALC861_FIXUP_FSC_AMILO_PI1505,
6375 ALC861_FIXUP_AMP_VREF_0F,
6376 ALC861_FIXUP_NO_JACK_DETECT,
6377 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006378};
6379
Takashi Iwai31150f22012-01-30 10:54:08 +01006380/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6381static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6382 const struct alc_fixup *fix, int action)
6383{
6384 struct alc_spec *spec = codec->spec;
6385 unsigned int val;
6386
6387 if (action != ALC_FIXUP_ACT_INIT)
6388 return;
6389 val = snd_hda_codec_read(codec, 0x0f, 0,
6390 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6391 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6392 val |= AC_PINCTL_IN_EN;
6393 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006394 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006395 spec->keep_vref_in_automute = 1;
6396}
6397
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006398/* suppress the jack-detection */
6399static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6400 const struct alc_fixup *fix, int action)
6401{
6402 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6403 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006404}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006405
Takashi Iwai1d045db2011-07-07 18:23:21 +02006406static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006407 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006408 .type = ALC_FIXUP_PINS,
6409 .v.pins = (const struct alc_pincfg[]) {
6410 { 0x0b, 0x0221101f }, /* HP */
6411 { 0x0f, 0x90170310 }, /* speaker */
6412 { }
6413 }
6414 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006415 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006416 .type = ALC_FIXUP_FUNC,
6417 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006418 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006419 [ALC861_FIXUP_NO_JACK_DETECT] = {
6420 .type = ALC_FIXUP_FUNC,
6421 .v.func = alc_fixup_no_jack_detect,
6422 },
6423 [ALC861_FIXUP_ASUS_A6RP] = {
6424 .type = ALC_FIXUP_FUNC,
6425 .v.func = alc861_fixup_asus_amp_vref_0f,
6426 .chained = true,
6427 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6428 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006429};
6430
6431static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006432 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6433 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6434 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6435 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6436 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6437 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006438 {}
6439};
6440
6441/*
6442 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006443static int patch_alc861(struct hda_codec *codec)
6444{
6445 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006446 int err;
6447
Takashi Iwai3de95172012-05-07 18:03:15 +02006448 err = alc_alloc_spec(codec, 0x15);
6449 if (err < 0)
6450 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006451
Takashi Iwai3de95172012-05-07 18:03:15 +02006452 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006453
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006454 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_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 = alc861_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 Iwai3e6179b2011-07-08 16:55:13 +02006462 if (!spec->no_analog) {
6463 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006464 if (err < 0)
6465 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006466 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6467 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006468
Takashi Iwai1d045db2011-07-07 18:23:21 +02006469 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006470#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006471 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006472#endif
6473
Takashi Iwai589876e2012-02-20 15:47:55 +01006474 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6475
Takashi Iwai1d045db2011-07-07 18:23:21 +02006476 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006477
6478 error:
6479 alc_free(codec);
6480 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006481}
6482
6483/*
6484 * ALC861-VD support
6485 *
6486 * Based on ALC882
6487 *
6488 * In addition, an independent DAC
6489 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006490static int alc861vd_parse_auto_config(struct hda_codec *codec)
6491{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006492 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006493 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6494 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006495}
6496
Takashi Iwai1d045db2011-07-07 18:23:21 +02006497enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006498 ALC660VD_FIX_ASUS_GPIO1,
6499 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006500};
6501
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006502/* exclude VREF80 */
6503static void alc861vd_fixup_dallas(struct hda_codec *codec,
6504 const struct alc_fixup *fix, int action)
6505{
6506 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6507 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6508 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6509 }
6510}
6511
Takashi Iwai1d045db2011-07-07 18:23:21 +02006512static const struct alc_fixup alc861vd_fixups[] = {
6513 [ALC660VD_FIX_ASUS_GPIO1] = {
6514 .type = ALC_FIXUP_VERBS,
6515 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006516 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006517 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6518 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6519 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6520 { }
6521 }
6522 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006523 [ALC861VD_FIX_DALLAS] = {
6524 .type = ALC_FIXUP_FUNC,
6525 .v.func = alc861vd_fixup_dallas,
6526 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006527};
6528
6529static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006530 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006531 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006532 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006533 {}
6534};
6535
Takashi Iwai1d045db2011-07-07 18:23:21 +02006536/*
6537 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006538static int patch_alc861vd(struct hda_codec *codec)
6539{
6540 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006541 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006542
Takashi Iwai3de95172012-05-07 18:03:15 +02006543 err = alc_alloc_spec(codec, 0x0b);
6544 if (err < 0)
6545 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006546
Takashi Iwai3de95172012-05-07 18:03:15 +02006547 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006548
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006549 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6550 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006551
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006552 /* automatic parse from the BIOS config */
6553 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006554 if (err < 0)
6555 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006556
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006557 if (!spec->no_analog) {
6558 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006559 if (err < 0)
6560 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006561 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6562 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006563
Takashi Iwai1d045db2011-07-07 18:23:21 +02006564 codec->patch_ops = alc_patch_ops;
6565
Takashi Iwai1d045db2011-07-07 18:23:21 +02006566 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006567
Takashi Iwai589876e2012-02-20 15:47:55 +01006568 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6569
Takashi Iwai1d045db2011-07-07 18:23:21 +02006570 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006571
6572 error:
6573 alc_free(codec);
6574 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006575}
6576
6577/*
6578 * ALC662 support
6579 *
6580 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6581 * configuration. Each pin widget can choose any input DACs and a mixer.
6582 * Each ADC is connected from a mixer of all inputs. This makes possible
6583 * 6-channel independent captures.
6584 *
6585 * In addition, an independent DAC for the multi-playback (not used in this
6586 * driver yet).
6587 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006588
6589/*
6590 * BIOS auto configuration
6591 */
6592
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006593static int alc662_parse_auto_config(struct hda_codec *codec)
6594{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006595 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006596 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6597 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6598 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006599
Kailang Yang6227cdc2010-02-25 08:36:52 +01006600 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6601 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006602 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006603 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006604 ssids = alc662_ssids;
6605 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006606}
6607
Todd Broch6be79482010-12-07 16:51:05 -08006608static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006609 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006610{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006611 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006612 return;
Todd Broch6be79482010-12-07 16:51:05 -08006613 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6614 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6615 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6616 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6617 (0 << AC_AMPCAP_MUTE_SHIFT)))
6618 printk(KERN_WARNING
6619 "hda_codec: failed to override amp caps for NID 0x2\n");
6620}
6621
David Henningsson6cb3b702010-09-09 08:51:44 +02006622enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006623 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006624 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006625 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006626 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006627 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006628 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006629 ALC662_FIXUP_ASUS_MODE1,
6630 ALC662_FIXUP_ASUS_MODE2,
6631 ALC662_FIXUP_ASUS_MODE3,
6632 ALC662_FIXUP_ASUS_MODE4,
6633 ALC662_FIXUP_ASUS_MODE5,
6634 ALC662_FIXUP_ASUS_MODE6,
6635 ALC662_FIXUP_ASUS_MODE7,
6636 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006637 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006638 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006639 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006640};
6641
6642static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006643 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006644 .type = ALC_FIXUP_PINS,
6645 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006646 { 0x15, 0x99130112 }, /* subwoofer */
6647 { }
6648 }
6649 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006650 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006651 .type = ALC_FIXUP_PINS,
6652 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006653 { 0x17, 0x99130112 }, /* subwoofer */
6654 { }
6655 }
6656 },
Todd Broch6be79482010-12-07 16:51:05 -08006657 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006658 .type = ALC_FIXUP_FUNC,
6659 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006660 },
6661 [ALC662_FIXUP_CZC_P10T] = {
6662 .type = ALC_FIXUP_VERBS,
6663 .v.verbs = (const struct hda_verb[]) {
6664 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6665 {}
6666 }
6667 },
David Henningsson94024cd2011-04-29 14:10:55 +02006668 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006669 .type = ALC_FIXUP_FUNC,
6670 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006671 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006672 [ALC662_FIXUP_HP_RP5800] = {
6673 .type = ALC_FIXUP_PINS,
6674 .v.pins = (const struct alc_pincfg[]) {
6675 { 0x14, 0x0221201f }, /* HP out */
6676 { }
6677 },
6678 .chained = true,
6679 .chain_id = ALC662_FIXUP_SKU_IGNORE
6680 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006681 [ALC662_FIXUP_ASUS_MODE1] = {
6682 .type = ALC_FIXUP_PINS,
6683 .v.pins = (const struct alc_pincfg[]) {
6684 { 0x14, 0x99130110 }, /* speaker */
6685 { 0x18, 0x01a19c20 }, /* mic */
6686 { 0x19, 0x99a3092f }, /* int-mic */
6687 { 0x21, 0x0121401f }, /* HP out */
6688 { }
6689 },
6690 .chained = true,
6691 .chain_id = ALC662_FIXUP_SKU_IGNORE
6692 },
6693 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006694 .type = ALC_FIXUP_PINS,
6695 .v.pins = (const struct alc_pincfg[]) {
6696 { 0x14, 0x99130110 }, /* speaker */
6697 { 0x18, 0x01a19820 }, /* mic */
6698 { 0x19, 0x99a3092f }, /* int-mic */
6699 { 0x1b, 0x0121401f }, /* HP out */
6700 { }
6701 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006702 .chained = true,
6703 .chain_id = ALC662_FIXUP_SKU_IGNORE
6704 },
6705 [ALC662_FIXUP_ASUS_MODE3] = {
6706 .type = ALC_FIXUP_PINS,
6707 .v.pins = (const struct alc_pincfg[]) {
6708 { 0x14, 0x99130110 }, /* speaker */
6709 { 0x15, 0x0121441f }, /* HP */
6710 { 0x18, 0x01a19840 }, /* mic */
6711 { 0x19, 0x99a3094f }, /* int-mic */
6712 { 0x21, 0x01211420 }, /* HP2 */
6713 { }
6714 },
6715 .chained = true,
6716 .chain_id = ALC662_FIXUP_SKU_IGNORE
6717 },
6718 [ALC662_FIXUP_ASUS_MODE4] = {
6719 .type = ALC_FIXUP_PINS,
6720 .v.pins = (const struct alc_pincfg[]) {
6721 { 0x14, 0x99130110 }, /* speaker */
6722 { 0x16, 0x99130111 }, /* speaker */
6723 { 0x18, 0x01a19840 }, /* mic */
6724 { 0x19, 0x99a3094f }, /* int-mic */
6725 { 0x21, 0x0121441f }, /* HP */
6726 { }
6727 },
6728 .chained = true,
6729 .chain_id = ALC662_FIXUP_SKU_IGNORE
6730 },
6731 [ALC662_FIXUP_ASUS_MODE5] = {
6732 .type = ALC_FIXUP_PINS,
6733 .v.pins = (const struct alc_pincfg[]) {
6734 { 0x14, 0x99130110 }, /* speaker */
6735 { 0x15, 0x0121441f }, /* HP */
6736 { 0x16, 0x99130111 }, /* speaker */
6737 { 0x18, 0x01a19840 }, /* mic */
6738 { 0x19, 0x99a3094f }, /* int-mic */
6739 { }
6740 },
6741 .chained = true,
6742 .chain_id = ALC662_FIXUP_SKU_IGNORE
6743 },
6744 [ALC662_FIXUP_ASUS_MODE6] = {
6745 .type = ALC_FIXUP_PINS,
6746 .v.pins = (const struct alc_pincfg[]) {
6747 { 0x14, 0x99130110 }, /* speaker */
6748 { 0x15, 0x01211420 }, /* HP2 */
6749 { 0x18, 0x01a19840 }, /* mic */
6750 { 0x19, 0x99a3094f }, /* int-mic */
6751 { 0x1b, 0x0121441f }, /* HP */
6752 { }
6753 },
6754 .chained = true,
6755 .chain_id = ALC662_FIXUP_SKU_IGNORE
6756 },
6757 [ALC662_FIXUP_ASUS_MODE7] = {
6758 .type = ALC_FIXUP_PINS,
6759 .v.pins = (const struct alc_pincfg[]) {
6760 { 0x14, 0x99130110 }, /* speaker */
6761 { 0x17, 0x99130111 }, /* speaker */
6762 { 0x18, 0x01a19840 }, /* mic */
6763 { 0x19, 0x99a3094f }, /* int-mic */
6764 { 0x1b, 0x01214020 }, /* HP */
6765 { 0x21, 0x0121401f }, /* HP */
6766 { }
6767 },
6768 .chained = true,
6769 .chain_id = ALC662_FIXUP_SKU_IGNORE
6770 },
6771 [ALC662_FIXUP_ASUS_MODE8] = {
6772 .type = ALC_FIXUP_PINS,
6773 .v.pins = (const struct alc_pincfg[]) {
6774 { 0x14, 0x99130110 }, /* speaker */
6775 { 0x12, 0x99a30970 }, /* int-mic */
6776 { 0x15, 0x01214020 }, /* HP */
6777 { 0x17, 0x99130111 }, /* speaker */
6778 { 0x18, 0x01a19840 }, /* mic */
6779 { 0x21, 0x0121401f }, /* HP */
6780 { }
6781 },
6782 .chained = true,
6783 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006784 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006785 [ALC662_FIXUP_NO_JACK_DETECT] = {
6786 .type = ALC_FIXUP_FUNC,
6787 .v.func = alc_fixup_no_jack_detect,
6788 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006789 [ALC662_FIXUP_ZOTAC_Z68] = {
6790 .type = ALC_FIXUP_PINS,
6791 .v.pins = (const struct alc_pincfg[]) {
6792 { 0x1b, 0x02214020 }, /* Front HP */
6793 { }
6794 }
6795 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006796 [ALC662_FIXUP_INV_DMIC] = {
6797 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006798 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006799 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006800};
6801
Takashi Iwaia9111322011-05-02 11:30:18 +02006802static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006803 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006804 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006805 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006806 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006807 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006808 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006809 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006810 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006811 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006812 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006813 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006814 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006815 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006816
6817#if 0
6818 /* Below is a quirk table taken from the old code.
6819 * Basically the device should work as is without the fixup table.
6820 * If BIOS doesn't give a proper info, enable the corresponding
6821 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006822 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006823 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6824 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6825 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6826 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6827 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6828 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6829 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6830 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6831 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6832 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6833 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6834 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6835 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6836 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6837 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6838 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6839 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6840 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6841 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6842 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6843 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6844 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6845 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6846 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6847 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6848 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6849 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6850 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6851 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6852 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6853 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6854 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6855 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6856 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6857 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6858 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6859 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6860 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6861 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6862 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6863 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6864 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6865 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6866 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6867 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6868 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6869 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6870 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6871 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6872 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6873#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006874 {}
6875};
6876
Todd Broch6be79482010-12-07 16:51:05 -08006877static const struct alc_model_fixup alc662_fixup_models[] = {
6878 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006879 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6880 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6881 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6882 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6883 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6884 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6885 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6886 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006887 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08006888 {}
6889};
David Henningsson6cb3b702010-09-09 08:51:44 +02006890
6891
Takashi Iwai1d045db2011-07-07 18:23:21 +02006892/*
6893 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006894static int patch_alc662(struct hda_codec *codec)
6895{
6896 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006897 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006898
Takashi Iwai3de95172012-05-07 18:03:15 +02006899 err = alc_alloc_spec(codec, 0x0b);
6900 if (err < 0)
6901 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006902
Takashi Iwai3de95172012-05-07 18:03:15 +02006903 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006904
Takashi Iwai53c334a2011-08-23 18:27:14 +02006905 /* handle multiple HPs as is */
6906 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6907
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006908 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6909
Takashi Iwai8e5a0502012-06-21 15:49:33 +02006910 alc_pick_fixup(codec, alc662_fixup_models,
6911 alc662_fixup_tbl, alc662_fixups);
6912 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
6913
6914 alc_auto_parse_customize_define(codec);
6915
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006916 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006917 codec->bus->pci->subsystem_vendor == 0x1025 &&
6918 spec->cdefine.platform_type == 1) {
6919 if (alc_codec_rename(codec, "ALC272X") < 0)
6920 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006921 }
Kailang Yang274693f2009-12-03 10:07:50 +01006922
Takashi Iwaib9c51062011-08-24 18:08:07 +02006923 /* automatic parse from the BIOS config */
6924 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006925 if (err < 0)
6926 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006927
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006928 if (!spec->no_analog && has_cdefine_beep(codec)) {
6929 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006930 if (err < 0)
6931 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006932 switch (codec->vendor_id) {
6933 case 0x10ec0662:
6934 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6935 break;
6936 case 0x10ec0272:
6937 case 0x10ec0663:
6938 case 0x10ec0665:
6939 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6940 break;
6941 case 0x10ec0273:
6942 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6943 break;
6944 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006945 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006946
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006947 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02006948 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006949
Takashi Iwai589876e2012-02-20 15:47:55 +01006950 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6951
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006952 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006953
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006954 error:
6955 alc_free(codec);
6956 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006957}
6958
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006959/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006960 * ALC680 support
6961 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006962
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006963static int alc680_parse_auto_config(struct hda_codec *codec)
6964{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006965 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006966}
6967
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006968/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006969 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006970static int patch_alc680(struct hda_codec *codec)
6971{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006972 int err;
6973
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006974 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006975 err = alc_alloc_spec(codec, 0);
6976 if (err < 0)
6977 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006978
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006979 /* automatic parse from the BIOS config */
6980 err = alc680_parse_auto_config(codec);
6981 if (err < 0) {
6982 alc_free(codec);
6983 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006984 }
6985
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006986 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006987
6988 return 0;
6989}
6990
6991/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006992 * patch entries
6993 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006994static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006995 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006996 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006997 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006998 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006999 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01007000 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007001 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02007002 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01007003 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02007004 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
David Henningssonbefae822012-06-25 19:49:28 +02007005 { .id = 0x10ec0280, .name = "ALC280", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007006 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007007 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007008 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
7009 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
7010 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007011 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007012 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02007013 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
7014 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02007015 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
7016 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02007017 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01007018 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01007019 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02007020 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01007021 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007022 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007023 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02007024 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007025 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02007026 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007027 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01007028 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007029 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007030 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007031 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007032 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007033 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007034 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007035 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007036 {} /* terminator */
7037};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007038
7039MODULE_ALIAS("snd-hda-codec-id:10ec*");
7040
7041MODULE_LICENSE("GPL");
7042MODULE_DESCRIPTION("Realtek HD-audio codec");
7043
7044static struct hda_codec_preset_list realtek_list = {
7045 .preset = snd_hda_preset_realtek,
7046 .owner = THIS_MODULE,
7047};
7048
7049static int __init patch_realtek_init(void)
7050{
7051 return snd_hda_add_codec_preset(&realtek_list);
7052}
7053
7054static void __exit patch_realtek_exit(void)
7055{
7056 snd_hda_delete_codec_preset(&realtek_list);
7057}
7058
7059module_init(patch_realtek_init)
7060module_exit(patch_realtek_exit)