blob: 3e698e239dd876e2917dc53d963b19804d788723 [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
Takashi Iwai21268962011-07-07 15:01:13 +0200306/* select the given imux item; either unmute exclusively or select the route */
307static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
308 unsigned int idx, bool force)
309{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100311 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100312 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100313 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200314 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315
Takashi Iwai5803a322012-02-21 11:59:45 +0100316 if (!spec->input_mux)
317 return 0;
318
Takashi Iwaicd896c32008-11-18 12:36:33 +0100319 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
320 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100321 if (!imux->num_items && mux_idx > 0)
322 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100323 if (!imux->num_items)
324 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100325
Takashi Iwai21268962011-07-07 15:01:13 +0200326 if (idx >= imux->num_items)
327 idx = imux->num_items - 1;
328 if (spec->cur_mux[adc_idx] == idx && !force)
329 return 0;
330 spec->cur_mux[adc_idx] = idx;
331
Takashi Iwai24de1832011-11-07 17:13:39 +0100332 /* for shared I/O, change the pin-control accordingly */
333 if (spec->shared_mic_hp) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200334 unsigned int val;
335 hda_nid_t pin = spec->autocfg.inputs[1].pin;
Takashi Iwai24de1832011-11-07 17:13:39 +0100336 /* NOTE: this assumes that there are only two inputs, the
337 * first is the real internal mic and the second is HP jack.
338 */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200339 if (spec->cur_mux[adc_idx])
Takashi Iwai47408602012-04-20 13:06:53 +0200340 val = snd_hda_get_default_vref(codec, pin) | PIN_IN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200341 else
342 val = PIN_HP;
343 snd_hda_set_pin_ctl(codec, pin, val);
Takashi Iwai24de1832011-11-07 17:13:39 +0100344 spec->automute_speaker = !spec->cur_mux[adc_idx];
345 call_update_outputs(codec);
346 }
347
Takashi Iwai21268962011-07-07 15:01:13 +0200348 if (spec->dyn_adc_switch) {
349 alc_dyn_adc_pcm_resetup(codec, idx);
350 adc_idx = spec->dyn_adc_idx[idx];
351 }
352
Takashi Iwai61071592011-11-23 07:52:15 +0100353 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200354
355 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200356 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100357 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200358 return 1;
359
Takashi Iwaia22d5432009-07-27 12:54:26 +0200360 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200361 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100362 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100363 int active = imux->items[idx].index;
364 for (i = 0; i < num_conns; i++) {
365 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
366 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100367 HDA_AMP_MUTE, v);
368 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100369 } else {
370 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200371 snd_hda_codec_write_cache(codec, nid, 0,
372 AC_VERB_SET_CONNECT_SEL,
373 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100374 }
Takashi Iwai125821a2012-06-22 14:30:29 +0200375 alc_inv_dmic_sync(codec, true);
Takashi Iwai21268962011-07-07 15:01:13 +0200376 return 1;
377}
378
379static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
380 struct snd_ctl_elem_value *ucontrol)
381{
382 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
383 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
384 return alc_mux_select(codec, adc_idx,
385 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100386}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200387
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100389 * set up the input pin config (depending on the given auto-pin type)
390 */
391static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
392 int auto_pin_type)
393{
394 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200395 if (auto_pin_type == AUTO_PIN_MIC)
396 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200397 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100398}
399
400/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200401 * Append the given mixer and verb elements for the later use
402 * The mixer array is referred in build_controls(), and init_verbs are
403 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100404 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200405static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100406{
407 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
408 return;
409 spec->mixers[spec->num_mixers++] = mix;
410}
411
Takashi Iwaid88897e2008-10-31 15:01:37 +0100412/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200413 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100414 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200415/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200416static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200417 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
418 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
419 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
420 { }
421};
422
Takashi Iwaia9111322011-05-02 11:30:18 +0200423static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200424 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
425 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
426 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
427 { }
428};
429
Takashi Iwaia9111322011-05-02 11:30:18 +0200430static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200431 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
432 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
433 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
434 { }
435};
436
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200437/*
438 * Fix hardware PLL issue
439 * On some codecs, the analog PLL gating control must be off while
440 * the default value is 1.
441 */
442static void alc_fix_pll(struct hda_codec *codec)
443{
444 struct alc_spec *spec = codec->spec;
445 unsigned int val;
446
447 if (!spec->pll_nid)
448 return;
449 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
450 spec->pll_coef_idx);
451 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
452 AC_VERB_GET_PROC_COEF, 0);
453 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
454 spec->pll_coef_idx);
455 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
456 val & ~(1 << spec->pll_coef_bit));
457}
458
459static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
460 unsigned int coef_idx, unsigned int coef_bit)
461{
462 struct alc_spec *spec = codec->spec;
463 spec->pll_nid = nid;
464 spec->pll_coef_idx = coef_idx;
465 spec->pll_coef_bit = coef_bit;
466 alc_fix_pll(codec);
467}
468
Takashi Iwai1d045db2011-07-07 18:23:21 +0200469/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200470 * Jack detections for HP auto-mute and mic-switch
471 */
472
473/* check each pin in the given array; returns true if any of them is plugged */
474static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200475{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200476 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200477
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200478 for (i = 0; i < num_pins; i++) {
479 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200480 if (!nid)
481 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200482 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200483 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200484 return present;
485}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200486
Takashi Iwai1d045db2011-07-07 18:23:21 +0200487/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200488static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200489 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200490{
491 struct alc_spec *spec = codec->spec;
492 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200493 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200494 int i;
495
496 for (i = 0; i < num_pins; i++) {
497 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100498 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200499 if (!nid)
500 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200501 switch (spec->automute_mode) {
502 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100503 /* don't reset VREF value in case it's controlling
504 * the amp (see alc861_fixup_asus_amp_vref_0f())
505 */
506 if (spec->keep_vref_in_automute) {
507 val = snd_hda_codec_read(codec, nid, 0,
508 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
509 val &= ~PIN_HP;
510 } else
511 val = 0;
512 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200513 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200514 break;
515 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200516 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200517 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200518 break;
519 case ALC_AUTOMUTE_MIXER:
520 nid = spec->automute_mixer_nid[i];
521 if (!nid)
522 break;
523 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200524 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200525 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200526 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200527 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200528 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200529 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200530}
531
David Henningsson42cf0d02011-09-20 12:04:56 +0200532/* Toggle outputs muting */
533static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200534{
535 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200536 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200537
Takashi Iwaic0a20262011-06-10 15:28:15 +0200538 /* Control HP pins/amps depending on master_mute state;
539 * in general, HP pins/amps control should be enabled in all cases,
540 * but currently set only for master_mute, just to be safe
541 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100542 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
543 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200544 spec->autocfg.hp_pins, spec->master_mute, true);
545
David Henningsson42cf0d02011-09-20 12:04:56 +0200546 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200547 on = 0;
548 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200549 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200550 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200551 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200552 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200553
554 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 /* if LO is a copy of either HP or Speaker, don't need to handle it */
556 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
557 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200558 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200559 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 on = 0;
561 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200562 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200563 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200564 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200565 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200566}
567
David Henningsson42cf0d02011-09-20 12:04:56 +0200568static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200569{
570 struct alc_spec *spec = codec->spec;
571 if (spec->automute_hook)
572 spec->automute_hook(codec);
573 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200574 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200575}
576
Takashi Iwai1d045db2011-07-07 18:23:21 +0200577/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200578static void alc_hp_automute(struct hda_codec *codec)
579{
580 struct alc_spec *spec = codec->spec;
581
David Henningsson42cf0d02011-09-20 12:04:56 +0200582 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
584 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200585 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200586 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200587 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200588}
589
Takashi Iwai1d045db2011-07-07 18:23:21 +0200590/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200591static void alc_line_automute(struct hda_codec *codec)
592{
593 struct alc_spec *spec = codec->spec;
594
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200595 /* check LO jack only when it's different from HP */
596 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
597 return;
598
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200599 spec->line_jack_present =
600 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
601 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200602 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200603 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200604 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200605}
606
Takashi Iwai8d087c72011-06-28 12:45:47 +0200607#define get_connection_index(codec, mux, nid) \
608 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200609
Takashi Iwai1d045db2011-07-07 18:23:21 +0200610/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200611static void alc_mic_automute(struct hda_codec *codec)
612{
613 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200614 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200615
Takashi Iwai21268962011-07-07 15:01:13 +0200616 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200617 return;
618 if (snd_BUG_ON(!spec->adc_nids))
619 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200620 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200621 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200622
Takashi Iwai21268962011-07-07 15:01:13 +0200623 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
624 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
625 else if (spec->dock_mic_idx >= 0 &&
626 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
627 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
628 else
629 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200630}
631
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100632/* handle the specified unsol action (ALC_XXX_EVENT) */
633static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200634{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100635 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200636 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200637 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200638 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200639 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200640 alc_line_automute(codec);
641 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200642 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200643 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200644 break;
645 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200646 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200647}
648
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100649/* update the master volume per volume-knob's unsol event */
650static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
651{
652 unsigned int val;
653 struct snd_kcontrol *kctl;
654 struct snd_ctl_elem_value *uctl;
655
656 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
657 if (!kctl)
658 return;
659 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
660 if (!uctl)
661 return;
662 val = snd_hda_codec_read(codec, nid, 0,
663 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
664 val &= HDA_AMP_VOLMASK;
665 uctl->value.integer.value[0] = val;
666 uctl->value.integer.value[1] = val;
667 kctl->put(kctl, uctl);
668 kfree(uctl);
669}
670
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100671/* unsolicited event for HP jack sensing */
672static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
673{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100674 int action;
675
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100676 if (codec->vendor_id == 0x10ec0880)
677 res >>= 28;
678 else
679 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100680 action = snd_hda_jack_get_action(codec, res);
David Henningssone21af482012-03-05 11:38:46 +0100681 if (action == ALC_DCVOL_EVENT) {
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100682 /* Execute the dc-vol event here as it requires the NID
683 * but we don't pass NID to alc_exec_unsol_event().
684 * Once when we convert all static quirks to the auto-parser,
685 * this can be integerated into there.
686 */
687 struct hda_jack_tbl *jack;
688 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
689 if (jack)
690 alc_update_knob_master(codec, jack->nid);
691 return;
692 }
693 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100694}
695
Takashi Iwai1d045db2011-07-07 18:23:21 +0200696/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200697static void alc_inithook(struct hda_codec *codec)
698{
Takashi Iwaid922b512011-04-28 12:18:53 +0200699 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200700 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200701 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200702}
703
Kailang Yangf9423e72008-05-27 12:32:25 +0200704/* additional initialization for ALC888 variants */
705static void alc888_coef_init(struct hda_codec *codec)
706{
707 unsigned int tmp;
708
709 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
710 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
711 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100712 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200713 /* alc888S-VC */
714 snd_hda_codec_read(codec, 0x20, 0,
715 AC_VERB_SET_PROC_COEF, 0x830);
716 else
717 /* alc888-VB */
718 snd_hda_codec_read(codec, 0x20, 0,
719 AC_VERB_SET_PROC_COEF, 0x3030);
720}
721
Takashi Iwai1d045db2011-07-07 18:23:21 +0200722/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200723static void alc889_coef_init(struct hda_codec *codec)
724{
725 unsigned int tmp;
726
727 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
728 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
729 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
730 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
731}
732
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100733/* turn on/off EAPD control (only if available) */
734static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
735{
736 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
737 return;
738 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
739 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
740 on ? 2 : 0);
741}
742
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200743/* turn on/off EAPD controls of the codec */
744static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
745{
746 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200747 static hda_nid_t pins[] = {
748 0x0f, 0x10, 0x14, 0x15, 0
749 };
750 hda_nid_t *p;
751 for (p = pins; *p; p++)
752 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200753}
754
Takashi Iwai1c716152011-04-07 10:37:16 +0200755/* generic shutup callback;
756 * just turning off EPAD and a little pause for avoiding pop-noise
757 */
758static void alc_eapd_shutup(struct hda_codec *codec)
759{
760 alc_auto_setup_eapd(codec, false);
761 msleep(200);
762}
763
Takashi Iwai1d045db2011-07-07 18:23:21 +0200764/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200765static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200766{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200767 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200768
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200769 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200770 switch (type) {
771 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200772 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
773 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200774 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200775 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
776 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200777 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200778 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
779 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200780 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200781 switch (codec->vendor_id) {
782 case 0x10ec0260:
783 snd_hda_codec_write(codec, 0x1a, 0,
784 AC_VERB_SET_COEF_INDEX, 7);
785 tmp = snd_hda_codec_read(codec, 0x1a, 0,
786 AC_VERB_GET_PROC_COEF, 0);
787 snd_hda_codec_write(codec, 0x1a, 0,
788 AC_VERB_SET_COEF_INDEX, 7);
789 snd_hda_codec_write(codec, 0x1a, 0,
790 AC_VERB_SET_PROC_COEF,
791 tmp | 0x2010);
792 break;
793 case 0x10ec0262:
794 case 0x10ec0880:
795 case 0x10ec0882:
796 case 0x10ec0883:
797 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100798 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100799 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200800 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200801 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200802 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200803 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200804 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100805#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200806 case 0x10ec0267:
807 case 0x10ec0268:
808 snd_hda_codec_write(codec, 0x20, 0,
809 AC_VERB_SET_COEF_INDEX, 7);
810 tmp = snd_hda_codec_read(codec, 0x20, 0,
811 AC_VERB_GET_PROC_COEF, 0);
812 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200813 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200814 snd_hda_codec_write(codec, 0x20, 0,
815 AC_VERB_SET_PROC_COEF,
816 tmp | 0x3000);
817 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100818#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200819 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200820 break;
821 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200822}
Kailang Yangea1fb292008-08-26 12:58:38 +0200823
Takashi Iwai1d045db2011-07-07 18:23:21 +0200824/*
825 * Auto-Mute mode mixer enum support
826 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200827static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
828 struct snd_ctl_elem_info *uinfo)
829{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
831 struct alc_spec *spec = codec->spec;
832 static const char * const texts2[] = {
833 "Disabled", "Enabled"
834 };
835 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100836 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200837 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200838 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200839
840 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
841 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200842 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200843 uinfo->value.enumerated.items = 3;
844 texts = texts3;
845 } else {
846 uinfo->value.enumerated.items = 2;
847 texts = texts2;
848 }
849 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
850 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200851 strcpy(uinfo->value.enumerated.name,
852 texts[uinfo->value.enumerated.item]);
853 return 0;
854}
855
856static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
857 struct snd_ctl_elem_value *ucontrol)
858{
859 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
860 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200861 unsigned int val = 0;
862 if (spec->automute_speaker)
863 val++;
864 if (spec->automute_lo)
865 val++;
866
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200867 ucontrol->value.enumerated.item[0] = val;
868 return 0;
869}
870
871static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
872 struct snd_ctl_elem_value *ucontrol)
873{
874 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
875 struct alc_spec *spec = codec->spec;
876
877 switch (ucontrol->value.enumerated.item[0]) {
878 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200879 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200880 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200881 spec->automute_speaker = 0;
882 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200883 break;
884 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200885 if (spec->automute_speaker_possible) {
886 if (!spec->automute_lo && spec->automute_speaker)
887 return 0;
888 spec->automute_speaker = 1;
889 spec->automute_lo = 0;
890 } else if (spec->automute_lo_possible) {
891 if (spec->automute_lo)
892 return 0;
893 spec->automute_lo = 1;
894 } else
895 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200896 break;
897 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200898 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200899 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200900 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200901 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200902 spec->automute_speaker = 1;
903 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200904 break;
905 default:
906 return -EINVAL;
907 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200908 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200909 return 1;
910}
911
Takashi Iwaia9111322011-05-02 11:30:18 +0200912static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200913 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
914 .name = "Auto-Mute Mode",
915 .info = alc_automute_mode_info,
916 .get = alc_automute_mode_get,
917 .put = alc_automute_mode_put,
918};
919
Takashi Iwai1d045db2011-07-07 18:23:21 +0200920static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
921{
922 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
923 return snd_array_new(&spec->kctls);
924}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200925
926static int alc_add_automute_mode_enum(struct hda_codec *codec)
927{
928 struct alc_spec *spec = codec->spec;
929 struct snd_kcontrol_new *knew;
930
931 knew = alc_kcontrol_new(spec);
932 if (!knew)
933 return -ENOMEM;
934 *knew = alc_automute_mode_enum;
935 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
936 if (!knew->name)
937 return -ENOMEM;
938 return 0;
939}
940
Takashi Iwai1d045db2011-07-07 18:23:21 +0200941/*
942 * Check the availability of HP/line-out auto-mute;
943 * Set up appropriately if really supported
944 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200945static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200946{
947 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200948 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200949 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200950 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200951
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200952 if (cfg->hp_pins[0])
953 present++;
954 if (cfg->line_out_pins[0])
955 present++;
956 if (cfg->speaker_pins[0])
957 present++;
958 if (present < 2) /* need two different output types */
959 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200960
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200961 if (!cfg->speaker_pins[0] &&
962 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200963 memcpy(cfg->speaker_pins, cfg->line_out_pins,
964 sizeof(cfg->speaker_pins));
965 cfg->speaker_outs = cfg->line_outs;
966 }
967
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200968 if (!cfg->hp_pins[0] &&
969 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200970 memcpy(cfg->hp_pins, cfg->line_out_pins,
971 sizeof(cfg->hp_pins));
972 cfg->hp_outs = cfg->line_outs;
973 }
974
David Henningsson42cf0d02011-09-20 12:04:56 +0200975 spec->automute_mode = ALC_AUTOMUTE_PIN;
976
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200977 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200978 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200979 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200980 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200981 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200982 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200983 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200984 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200985 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200986
David Henningsson42cf0d02011-09-20 12:04:56 +0200987 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
988 if (cfg->speaker_outs)
989 for (i = 0; i < cfg->line_outs; i++) {
990 hda_nid_t nid = cfg->line_out_pins[i];
991 if (!is_jack_detectable(codec, nid))
992 continue;
993 snd_printdd("realtek: Enable Line-Out "
994 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200995 snd_hda_jack_detect_enable(codec, nid,
996 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200997 spec->detect_lo = 1;
998 }
999 spec->automute_lo_possible = spec->detect_hp;
1000 }
1001
1002 spec->automute_speaker_possible = cfg->speaker_outs &&
1003 (spec->detect_hp || spec->detect_lo);
1004
1005 spec->automute_lo = spec->automute_lo_possible;
1006 spec->automute_speaker = spec->automute_speaker_possible;
1007
1008 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001009 /* create a control for automute mode */
1010 alc_add_automute_mode_enum(codec);
1011 spec->unsol_event = alc_sku_unsol_event;
1012 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001013}
1014
Takashi Iwai1d045db2011-07-07 18:23:21 +02001015/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001016static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1017{
1018 int i;
1019 for (i = 0; i < nums; i++)
1020 if (list[i] == nid)
1021 return i;
1022 return -1;
1023}
1024
Takashi Iwai1d045db2011-07-07 18:23:21 +02001025/* check whether dynamic ADC-switching is available */
1026static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1027{
1028 struct alc_spec *spec = codec->spec;
1029 struct hda_input_mux *imux = &spec->private_imux[0];
1030 int i, n, idx;
1031 hda_nid_t cap, pin;
1032
1033 if (imux != spec->input_mux) /* no dynamic imux? */
1034 return false;
1035
1036 for (n = 0; n < spec->num_adc_nids; n++) {
1037 cap = spec->private_capsrc_nids[n];
1038 for (i = 0; i < imux->num_items; i++) {
1039 pin = spec->imux_pins[i];
1040 if (!pin)
1041 return false;
1042 if (get_connection_index(codec, cap, pin) < 0)
1043 break;
1044 }
1045 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001046 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001047 }
1048
1049 for (i = 0; i < imux->num_items; i++) {
1050 pin = spec->imux_pins[i];
1051 for (n = 0; n < spec->num_adc_nids; n++) {
1052 cap = spec->private_capsrc_nids[n];
1053 idx = get_connection_index(codec, cap, pin);
1054 if (idx >= 0) {
1055 imux->items[i].index = idx;
1056 spec->dyn_adc_idx[i] = n;
1057 break;
1058 }
1059 }
1060 }
1061
1062 snd_printdd("realtek: enabling ADC switching\n");
1063 spec->dyn_adc_switch = 1;
1064 return true;
1065}
Takashi Iwai21268962011-07-07 15:01:13 +02001066
Takashi Iwai21268962011-07-07 15:01:13 +02001067/* check whether all auto-mic pins are valid; setup indices if OK */
1068static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1069{
1070 struct alc_spec *spec = codec->spec;
1071 const struct hda_input_mux *imux;
1072
1073 if (!spec->auto_mic)
1074 return false;
1075 if (spec->auto_mic_valid_imux)
1076 return true; /* already checked */
1077
1078 /* fill up imux indices */
1079 if (!alc_check_dyn_adc_switch(codec)) {
1080 spec->auto_mic = 0;
1081 return false;
1082 }
1083
1084 imux = spec->input_mux;
1085 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1086 spec->imux_pins, imux->num_items);
1087 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1088 spec->imux_pins, imux->num_items);
1089 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1090 spec->imux_pins, imux->num_items);
1091 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1092 spec->auto_mic = 0;
1093 return false; /* no corresponding imux */
1094 }
1095
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001096 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001097 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001098 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1099 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001100
1101 spec->auto_mic_valid_imux = 1;
1102 spec->auto_mic = 1;
1103 return true;
1104}
1105
Takashi Iwai1d045db2011-07-07 18:23:21 +02001106/*
1107 * Check the availability of auto-mic switch;
1108 * Set up if really supported
1109 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001110static void alc_init_auto_mic(struct hda_codec *codec)
1111{
1112 struct alc_spec *spec = codec->spec;
1113 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001114 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001115 int i;
1116
Takashi Iwai24de1832011-11-07 17:13:39 +01001117 if (spec->shared_mic_hp)
1118 return; /* no auto-mic for the shared I/O */
1119
Takashi Iwai21268962011-07-07 15:01:13 +02001120 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1121
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001122 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001123 for (i = 0; i < cfg->num_inputs; i++) {
1124 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001125 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001126 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001127 switch (snd_hda_get_input_pin_attr(defcfg)) {
1128 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001129 if (fixed)
1130 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001131 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1132 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001133 fixed = nid;
1134 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001135 case INPUT_PIN_ATTR_UNUSED:
1136 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001137 case INPUT_PIN_ATTR_DOCK:
1138 if (dock)
1139 return; /* already occupied */
1140 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1141 return; /* invalid type */
1142 dock = nid;
1143 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001144 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001145 if (ext)
1146 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001147 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1148 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001149 ext = nid;
1150 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001151 }
1152 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001153 if (!ext && dock) {
1154 ext = dock;
1155 dock = 0;
1156 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001157 if (!ext || !fixed)
1158 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001159 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001160 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001161 if (dock && !is_jack_detectable(codec, dock))
1162 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001163
1164 /* check imux indices */
1165 spec->ext_mic_pin = ext;
1166 spec->int_mic_pin = fixed;
1167 spec->dock_mic_pin = dock;
1168
1169 spec->auto_mic = 1;
1170 if (!alc_auto_mic_check_imux(codec))
1171 return;
1172
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001173 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1174 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001175 spec->unsol_event = alc_sku_unsol_event;
1176}
1177
Takashi Iwai1d045db2011-07-07 18:23:21 +02001178/* check the availabilities of auto-mute and auto-mic switches */
1179static void alc_auto_check_switches(struct hda_codec *codec)
1180{
David Henningsson42cf0d02011-09-20 12:04:56 +02001181 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001182 alc_init_auto_mic(codec);
1183}
1184
1185/*
1186 * Realtek SSID verification
1187 */
1188
David Henningsson90622912010-10-14 14:50:18 +02001189/* Could be any non-zero and even value. When used as fixup, tells
1190 * the driver to ignore any present sku defines.
1191 */
1192#define ALC_FIXUP_SKU_IGNORE (2)
1193
Takashi Iwai23d30f22012-05-07 17:17:32 +02001194static void alc_fixup_sku_ignore(struct hda_codec *codec,
1195 const struct hda_fixup *fix, int action)
1196{
1197 struct alc_spec *spec = codec->spec;
1198 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1199 spec->cdefine.fixup = 1;
1200 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1201 }
1202}
1203
Kailang Yangda00c242010-03-19 11:23:45 +01001204static int alc_auto_parse_customize_define(struct hda_codec *codec)
1205{
1206 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001207 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001208 struct alc_spec *spec = codec->spec;
1209
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001210 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1211
David Henningsson90622912010-10-14 14:50:18 +02001212 if (spec->cdefine.fixup) {
1213 ass = spec->cdefine.sku_cfg;
1214 if (ass == ALC_FIXUP_SKU_IGNORE)
1215 return -1;
1216 goto do_sku;
1217 }
1218
Kailang Yangda00c242010-03-19 11:23:45 +01001219 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001220 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001221 goto do_sku;
1222
1223 nid = 0x1d;
1224 if (codec->vendor_id == 0x10ec0260)
1225 nid = 0x17;
1226 ass = snd_hda_codec_get_pincfg(codec, nid);
1227
1228 if (!(ass & 1)) {
1229 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1230 codec->chip_name, ass);
1231 return -1;
1232 }
1233
1234 /* check sum */
1235 tmp = 0;
1236 for (i = 1; i < 16; i++) {
1237 if ((ass >> i) & 1)
1238 tmp++;
1239 }
1240 if (((ass >> 16) & 0xf) != tmp)
1241 return -1;
1242
1243 spec->cdefine.port_connectivity = ass >> 30;
1244 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1245 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1246 spec->cdefine.customization = ass >> 8;
1247do_sku:
1248 spec->cdefine.sku_cfg = ass;
1249 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1250 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1251 spec->cdefine.swap = (ass & 0x2) >> 1;
1252 spec->cdefine.override = ass & 0x1;
1253
1254 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1255 nid, spec->cdefine.sku_cfg);
1256 snd_printd("SKU: port_connectivity=0x%x\n",
1257 spec->cdefine.port_connectivity);
1258 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1259 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1260 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1261 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1262 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1263 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1264 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1265
1266 return 0;
1267}
1268
Takashi Iwai1d045db2011-07-07 18:23:21 +02001269/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001270static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1271{
Takashi Iwai21268962011-07-07 15:01:13 +02001272 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001273}
1274
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001275/* check subsystem ID and set up device-specific initialization;
1276 * return 1 if initialized, 0 if invalid SSID
1277 */
1278/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1279 * 31 ~ 16 : Manufacture ID
1280 * 15 ~ 8 : SKU ID
1281 * 7 ~ 0 : Assembly ID
1282 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1283 */
1284static int alc_subsystem_id(struct hda_codec *codec,
1285 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001286 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001287{
1288 unsigned int ass, tmp, i;
1289 unsigned nid;
1290 struct alc_spec *spec = codec->spec;
1291
David Henningsson90622912010-10-14 14:50:18 +02001292 if (spec->cdefine.fixup) {
1293 ass = spec->cdefine.sku_cfg;
1294 if (ass == ALC_FIXUP_SKU_IGNORE)
1295 return 0;
1296 goto do_sku;
1297 }
1298
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001299 ass = codec->subsystem_id & 0xffff;
1300 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1301 goto do_sku;
1302
1303 /* invalid SSID, check the special NID pin defcfg instead */
1304 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001305 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001306 * 29~21 : reserve
1307 * 20 : PCBEEP input
1308 * 19~16 : Check sum (15:1)
1309 * 15~1 : Custom
1310 * 0 : override
1311 */
1312 nid = 0x1d;
1313 if (codec->vendor_id == 0x10ec0260)
1314 nid = 0x17;
1315 ass = snd_hda_codec_get_pincfg(codec, nid);
1316 snd_printd("realtek: No valid SSID, "
1317 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001318 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001319 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001320 return 0;
1321 if ((ass >> 30) != 1) /* no physical connection */
1322 return 0;
1323
1324 /* check sum */
1325 tmp = 0;
1326 for (i = 1; i < 16; i++) {
1327 if ((ass >> i) & 1)
1328 tmp++;
1329 }
1330 if (((ass >> 16) & 0xf) != tmp)
1331 return 0;
1332do_sku:
1333 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1334 ass & 0xffff, codec->vendor_id);
1335 /*
1336 * 0 : override
1337 * 1 : Swap Jack
1338 * 2 : 0 --> Desktop, 1 --> Laptop
1339 * 3~5 : External Amplifier control
1340 * 7~6 : Reserved
1341 */
1342 tmp = (ass & 0x38) >> 3; /* external Amp control */
1343 switch (tmp) {
1344 case 1:
1345 spec->init_amp = ALC_INIT_GPIO1;
1346 break;
1347 case 3:
1348 spec->init_amp = ALC_INIT_GPIO2;
1349 break;
1350 case 7:
1351 spec->init_amp = ALC_INIT_GPIO3;
1352 break;
1353 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001354 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001355 spec->init_amp = ALC_INIT_DEFAULT;
1356 break;
1357 }
1358
1359 /* is laptop or Desktop and enable the function "Mute internal speaker
1360 * when the external headphone out jack is plugged"
1361 */
1362 if (!(ass & 0x8000))
1363 return 1;
1364 /*
1365 * 10~8 : Jack location
1366 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1367 * 14~13: Resvered
1368 * 15 : 1 --> enable the function "Mute internal speaker
1369 * when the external headphone out jack is plugged"
1370 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001371 if (!spec->autocfg.hp_pins[0] &&
1372 !(spec->autocfg.line_out_pins[0] &&
1373 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001374 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001375 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1376 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001377 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001378 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001379 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001380 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001381 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001382 else if (tmp == 3)
1383 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001384 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001385 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001386 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1387 spec->autocfg.line_outs))
1388 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001389 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001390 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001391 return 1;
1392}
Kailang Yangea1fb292008-08-26 12:58:38 +02001393
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001394/* Check the validity of ALC subsystem-id
1395 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1396static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001397{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001398 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001399 struct alc_spec *spec = codec->spec;
1400 snd_printd("realtek: "
1401 "Enable default setup for auto mode as fallback\n");
1402 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001403 }
Takashi Iwai21268962011-07-07 15:01:13 +02001404}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001405
Takashi Iwai41e41f12005-06-08 14:48:49 +02001406/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001407 * COEF access helper functions
1408 */
Kailang Yang274693f2009-12-03 10:07:50 +01001409static int alc_read_coef_idx(struct hda_codec *codec,
1410 unsigned int coef_idx)
1411{
1412 unsigned int val;
1413 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1414 coef_idx);
1415 val = snd_hda_codec_read(codec, 0x20, 0,
1416 AC_VERB_GET_PROC_COEF, 0);
1417 return val;
1418}
1419
Kailang Yang977ddd62010-09-15 10:02:29 +02001420static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1421 unsigned int coef_val)
1422{
1423 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1424 coef_idx);
1425 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1426 coef_val);
1427}
1428
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001429/* a special bypass for COEF 0; read the cached value at the second time */
1430static unsigned int alc_get_coef0(struct hda_codec *codec)
1431{
1432 struct alc_spec *spec = codec->spec;
1433 if (!spec->coef0)
1434 spec->coef0 = alc_read_coef_idx(codec, 0);
1435 return spec->coef0;
1436}
1437
Takashi Iwai1d045db2011-07-07 18:23:21 +02001438/*
1439 * Digital I/O handling
1440 */
1441
Takashi Iwai757899a2010-07-30 10:48:14 +02001442/* set right pin controls for digital I/O */
1443static void alc_auto_init_digital(struct hda_codec *codec)
1444{
1445 struct alc_spec *spec = codec->spec;
1446 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001447 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001448
1449 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1450 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001451 if (!pin)
1452 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001453 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001454 if (!i)
1455 dac = spec->multiout.dig_out_nid;
1456 else
1457 dac = spec->slave_dig_outs[i - 1];
1458 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1459 continue;
1460 snd_hda_codec_write(codec, dac, 0,
1461 AC_VERB_SET_AMP_GAIN_MUTE,
1462 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001463 }
1464 pin = spec->autocfg.dig_in_pin;
1465 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001466 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001467}
1468
1469/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1470static void alc_auto_parse_digital(struct hda_codec *codec)
1471{
1472 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001473 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001474 hda_nid_t dig_nid;
1475
1476 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001477 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001478 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001479 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001480 err = snd_hda_get_connections(codec,
1481 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001482 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001483 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001484 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001485 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001486 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001487 spec->multiout.dig_out_nid = dig_nid;
1488 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1489 } else {
1490 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001491 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001492 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001493 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001494 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001495 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001496 }
1497
1498 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001499 dig_nid = codec->start_nid;
1500 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1501 unsigned int wcaps = get_wcaps(codec, dig_nid);
1502 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1503 continue;
1504 if (!(wcaps & AC_WCAP_DIGITAL))
1505 continue;
1506 if (!(wcaps & AC_WCAP_CONN_LIST))
1507 continue;
1508 err = get_connection_index(codec, dig_nid,
1509 spec->autocfg.dig_in_pin);
1510 if (err >= 0) {
1511 spec->dig_in_nid = dig_nid;
1512 break;
1513 }
1514 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001515 }
1516}
1517
Takashi Iwaif95474e2007-07-10 00:47:43 +02001518/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001519 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001520 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001521static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1522 struct snd_ctl_elem_info *uinfo)
1523{
1524 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1525 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001526 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001527 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001528
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001529 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001530 if (spec->vol_in_capsrc)
1531 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1532 else
1533 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1534 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001535 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001536 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001537 return err;
1538}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001540static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1541 unsigned int size, unsigned int __user *tlv)
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;
1547
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_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001555 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001556 return err;
1557}
1558
1559typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1560 struct snd_ctl_elem_value *ucontrol);
1561
1562static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1563 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai125821a2012-06-22 14:30:29 +02001564 getput_call_t func, bool is_put)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001565{
1566 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1567 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001568 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001569
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001570 mutex_lock(&codec->control_mutex);
Takashi Iwai125821a2012-06-22 14:30:29 +02001571 if (is_put && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001572 for (i = 0; i < spec->num_adc_nids; i++) {
1573 kcontrol->private_value =
1574 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1575 3, 0, HDA_INPUT);
1576 err = func(kcontrol, ucontrol);
1577 if (err < 0)
1578 goto error;
1579 }
1580 } else {
1581 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001582 if (spec->vol_in_capsrc)
1583 kcontrol->private_value =
1584 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1585 3, 0, HDA_OUTPUT);
1586 else
1587 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001588 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1589 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001590 err = func(kcontrol, ucontrol);
1591 }
Takashi Iwai125821a2012-06-22 14:30:29 +02001592 if (err >= 0 && is_put)
1593 alc_inv_dmic_sync(codec, false);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001594 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001595 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001596 return err;
1597}
1598
1599static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1600 struct snd_ctl_elem_value *ucontrol)
1601{
1602 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001603 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001604}
1605
1606static int alc_cap_vol_put(struct snd_kcontrol *kcontrol,
1607 struct snd_ctl_elem_value *ucontrol)
1608{
1609 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001610 snd_hda_mixer_amp_volume_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001611}
1612
1613/* capture mixer elements */
1614#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1615
1616static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1617 struct snd_ctl_elem_value *ucontrol)
1618{
1619 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001620 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001621}
1622
1623static int alc_cap_sw_put(struct snd_kcontrol *kcontrol,
1624 struct snd_ctl_elem_value *ucontrol)
1625{
1626 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001627 snd_hda_mixer_amp_switch_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001628}
1629
Takashi Iwaia23b6882009-03-23 15:21:36 +01001630#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001631 { \
1632 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1633 .name = "Capture Switch", \
1634 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1635 .count = num, \
1636 .info = alc_cap_sw_info, \
1637 .get = alc_cap_sw_get, \
1638 .put = alc_cap_sw_put, \
1639 }, \
1640 { \
1641 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1642 .name = "Capture Volume", \
1643 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1644 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1645 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1646 .count = num, \
1647 .info = alc_cap_vol_info, \
1648 .get = alc_cap_vol_get, \
1649 .put = alc_cap_vol_put, \
1650 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001651 }
1652
1653#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001654 { \
1655 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1656 /* .name = "Capture Source", */ \
1657 .name = "Input Source", \
1658 .count = num, \
1659 .info = alc_mux_enum_info, \
1660 .get = alc_mux_enum_get, \
1661 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001662 }
1663
1664#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001665static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001666 _DEFINE_CAPMIX(num), \
1667 _DEFINE_CAPSRC(num), \
1668 { } /* end */ \
1669}
1670
1671#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001672static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001673 _DEFINE_CAPMIX(num), \
1674 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001675}
1676
1677/* up to three ADCs */
1678DEFINE_CAPMIX(1);
1679DEFINE_CAPMIX(2);
1680DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001681DEFINE_CAPMIX_NOSRC(1);
1682DEFINE_CAPMIX_NOSRC(2);
1683DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001684
1685/*
Takashi Iwai125821a2012-06-22 14:30:29 +02001686 * Inverted digital-mic handling
1687 *
1688 * First off, it's a bit tricky. The "Inverted Internal Mic Capture Switch"
1689 * gives the additional mute only to the right channel of the digital mic
1690 * capture stream. This is a workaround for avoiding the almost silence
1691 * by summing the stereo stream from some (known to be ForteMedia)
1692 * digital mic unit.
1693 *
1694 * The logic is to call alc_inv_dmic_sync() after each action (possibly)
1695 * modifying ADC amp. When the mute flag is set, it mutes the R-channel
1696 * without caching so that the cache can still keep the original value.
1697 * The cached value is then restored when the flag is set off or any other
1698 * than d-mic is used as the current input source.
1699 */
1700static void alc_inv_dmic_sync(struct hda_codec *codec, bool force)
1701{
1702 struct alc_spec *spec = codec->spec;
1703 int i;
1704
1705 if (!spec->inv_dmic_fixup)
1706 return;
1707 if (!spec->inv_dmic_muted && !force)
1708 return;
1709 for (i = 0; i < spec->num_adc_nids; i++) {
1710 int src = spec->dyn_adc_switch ? 0 : i;
1711 bool dmic_fixup = false;
1712 hda_nid_t nid;
1713 int parm, dir, v;
1714
1715 if (spec->inv_dmic_muted &&
1716 spec->imux_pins[spec->cur_mux[src]] == spec->inv_dmic_pin)
1717 dmic_fixup = true;
1718 if (!dmic_fixup && !force)
1719 continue;
1720 if (spec->vol_in_capsrc) {
1721 nid = spec->capsrc_nids[i];
1722 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_OUTPUT;
1723 dir = HDA_OUTPUT;
1724 } else {
1725 nid = spec->adc_nids[i];
1726 parm = AC_AMP_SET_RIGHT | AC_AMP_SET_INPUT;
1727 dir = HDA_INPUT;
1728 }
1729 /* we care only right channel */
1730 v = snd_hda_codec_amp_read(codec, nid, 1, dir, 0);
1731 if (v & 0x80) /* if already muted, we don't need to touch */
1732 continue;
1733 if (dmic_fixup) /* add mute for d-mic */
1734 v |= 0x80;
1735 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
1736 parm | v);
1737 }
1738}
1739
1740static int alc_inv_dmic_sw_get(struct snd_kcontrol *kcontrol,
1741 struct snd_ctl_elem_value *ucontrol)
1742{
1743 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1744 struct alc_spec *spec = codec->spec;
1745
1746 ucontrol->value.integer.value[0] = !spec->inv_dmic_muted;
1747 return 0;
1748}
1749
1750static int alc_inv_dmic_sw_put(struct snd_kcontrol *kcontrol,
1751 struct snd_ctl_elem_value *ucontrol)
1752{
1753 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1754 struct alc_spec *spec = codec->spec;
1755 unsigned int val = !ucontrol->value.integer.value[0];
1756
1757 if (val == spec->inv_dmic_muted)
1758 return 0;
1759 spec->inv_dmic_muted = val;
1760 alc_inv_dmic_sync(codec, true);
1761 return 0;
1762}
1763
1764static const struct snd_kcontrol_new alc_inv_dmic_sw = {
1765 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1766 .info = snd_ctl_boolean_mono_info,
1767 .get = alc_inv_dmic_sw_get,
1768 .put = alc_inv_dmic_sw_put,
1769};
1770
1771static int alc_add_inv_dmic_mixer(struct hda_codec *codec, hda_nid_t nid)
1772{
1773 struct alc_spec *spec = codec->spec;
1774 struct snd_kcontrol_new *knew = alc_kcontrol_new(spec);
1775 if (!knew)
1776 return -ENOMEM;
1777 *knew = alc_inv_dmic_sw;
1778 knew->name = kstrdup("Inverted Internal Mic Capture Switch", GFP_KERNEL);
1779 if (!knew->name)
1780 return -ENOMEM;
1781 spec->inv_dmic_fixup = 1;
1782 spec->inv_dmic_muted = 0;
1783 spec->inv_dmic_pin = nid;
1784 return 0;
1785}
1786
Takashi Iwai6e72aa52012-06-25 10:52:25 +02001787/* typically the digital mic is put at node 0x12 */
1788static void alc_fixup_inv_dmic_0x12(struct hda_codec *codec,
1789 const struct alc_fixup *fix, int action)
1790{
1791 if (action == ALC_FIXUP_ACT_PROBE)
1792 alc_add_inv_dmic_mixer(codec, 0x12);
1793}
1794
Takashi Iwai125821a2012-06-22 14:30:29 +02001795/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001796 * virtual master controls
1797 */
1798
1799/*
1800 * slave controls for virtual master
1801 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001802static const char * const alc_slave_pfxs[] = {
1803 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001804 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001805 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001806 NULL,
1807};
1808
1809/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001810 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001812
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001813#define NID_MAPPING (-1)
1814
1815#define SUBDEV_SPEAKER_ (0 << 6)
1816#define SUBDEV_HP_ (1 << 6)
1817#define SUBDEV_LINE_ (2 << 6)
1818#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1819#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1820#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1821
Takashi Iwai603c4012008-07-30 15:01:44 +02001822static void alc_free_kctls(struct hda_codec *codec);
1823
Takashi Iwai67d634c2009-11-16 15:35:59 +01001824#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001825/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001826static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001827 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001828 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001829 { } /* end */
1830};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001831#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001832
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001833static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834{
1835 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001836 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001837 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001838 int i, j, err;
1839 unsigned int u;
1840 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
1842 for (i = 0; i < spec->num_mixers; i++) {
1843 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1844 if (err < 0)
1845 return err;
1846 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001847 if (spec->cap_mixer) {
1848 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1849 if (err < 0)
1850 return err;
1851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001853 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001854 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001855 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 if (err < 0)
1857 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001858 if (!spec->no_analog) {
1859 err = snd_hda_create_spdif_share_sw(codec,
1860 &spec->multiout);
1861 if (err < 0)
1862 return err;
1863 spec->multiout.share_spdif = 1;
1864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 }
1866 if (spec->dig_in_nid) {
1867 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1868 if (err < 0)
1869 return err;
1870 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001871
Takashi Iwai67d634c2009-11-16 15:35:59 +01001872#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001873 /* create beep controls if needed */
1874 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001875 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001876 for (knew = alc_beep_mixer; knew->name; knew++) {
1877 struct snd_kcontrol *kctl;
1878 kctl = snd_ctl_new1(knew, codec);
1879 if (!kctl)
1880 return -ENOMEM;
1881 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001882 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001883 if (err < 0)
1884 return err;
1885 }
1886 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001887#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001888
Takashi Iwai2134ea42008-01-10 16:53:55 +01001889 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001890 if (!spec->no_analog &&
1891 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001892 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001893 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001894 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001895 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001896 vmaster_tlv, alc_slave_pfxs,
1897 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001898 if (err < 0)
1899 return err;
1900 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001901 if (!spec->no_analog &&
1902 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001903 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1904 NULL, alc_slave_pfxs,
1905 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001906 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001907 if (err < 0)
1908 return err;
1909 }
1910
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001911 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001912 if (spec->capsrc_nids || spec->adc_nids) {
1913 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1914 if (!kctl)
1915 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1916 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001917 err = snd_hda_add_nid(codec, kctl, i,
1918 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001919 if (err < 0)
1920 return err;
1921 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001922 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001923 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001924 const char *kname = kctl ? kctl->id.name : NULL;
1925 for (knew = spec->cap_mixer; knew->name; knew++) {
1926 if (kname && strcmp(knew->name, kname) == 0)
1927 continue;
1928 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1929 for (i = 0; kctl && i < kctl->count; i++) {
1930 err = snd_hda_add_nid(codec, kctl, i,
1931 spec->adc_nids[i]);
1932 if (err < 0)
1933 return err;
1934 }
1935 }
1936 }
1937
1938 /* other nid->control mapping */
1939 for (i = 0; i < spec->num_mixers; i++) {
1940 for (knew = spec->mixers[i]; knew->name; knew++) {
1941 if (knew->iface != NID_MAPPING)
1942 continue;
1943 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1944 if (kctl == NULL)
1945 continue;
1946 u = knew->subdevice;
1947 for (j = 0; j < 4; j++, u >>= 8) {
1948 nid = u & 0x3f;
1949 if (nid == 0)
1950 continue;
1951 switch (u & 0xc0) {
1952 case SUBDEV_SPEAKER_:
1953 nid = spec->autocfg.speaker_pins[nid];
1954 break;
1955 case SUBDEV_LINE_:
1956 nid = spec->autocfg.line_out_pins[nid];
1957 break;
1958 case SUBDEV_HP_:
1959 nid = spec->autocfg.hp_pins[nid];
1960 break;
1961 default:
1962 continue;
1963 }
1964 err = snd_hda_add_nid(codec, kctl, 0, nid);
1965 if (err < 0)
1966 return err;
1967 }
1968 u = knew->private_value;
1969 for (j = 0; j < 4; j++, u >>= 8) {
1970 nid = u & 0xff;
1971 if (nid == 0)
1972 continue;
1973 err = snd_hda_add_nid(codec, kctl, 0, nid);
1974 if (err < 0)
1975 return err;
1976 }
1977 }
1978 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001979
1980 alc_free_kctls(codec); /* no longer needed */
1981
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001982 return 0;
1983}
1984
1985static int alc_build_controls(struct hda_codec *codec)
1986{
1987 struct alc_spec *spec = codec->spec;
1988 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001989 if (err < 0)
1990 return err;
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001991 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1992 if (err < 0)
1993 return err;
1994 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1995 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996}
1997
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001998
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002000 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002001 */
Takashi Iwai16ded522005-06-10 19:58:24 +02002002
Takashi Iwai584c0c42011-03-10 12:51:11 +01002003static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002004static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002005
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006static int alc_init(struct hda_codec *codec)
2007{
2008 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002009
Takashi Iwai546bb672012-03-07 08:37:19 +01002010 if (spec->init_hook)
2011 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01002012
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002013 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02002014 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02002015
Takashi Iwai2e8b2b22012-06-13 16:47:32 +02002016 snd_hda_gen_apply_verbs(codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01002017 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01002018 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002019
Takashi Iwai58701122011-01-13 15:41:45 +01002020 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
2021
Takashi Iwai01a61e12011-10-28 00:03:22 +02002022 snd_hda_jack_report_sync(codec);
2023
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002024 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 return 0;
2026}
2027
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002028static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
2029{
2030 struct alc_spec *spec = codec->spec;
2031
2032 if (spec->unsol_event)
2033 spec->unsol_event(codec, res);
2034}
2035
Takashi Iwaicb53c622007-08-10 17:21:45 +02002036#ifdef CONFIG_SND_HDA_POWER_SAVE
2037static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
2038{
2039 struct alc_spec *spec = codec->spec;
2040 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
2041}
2042#endif
2043
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044/*
2045 * Analog playback callbacks
2046 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002047static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002049 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050{
2051 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01002052 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2053 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054}
2055
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002056static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 struct hda_codec *codec,
2058 unsigned int stream_tag,
2059 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002060 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061{
2062 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02002063 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
2064 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065}
2066
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002067static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002069 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070{
2071 struct alc_spec *spec = codec->spec;
2072 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
2073}
2074
2075/*
2076 * Digital out
2077 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002078static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002080 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081{
2082 struct alc_spec *spec = codec->spec;
2083 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
2084}
2085
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002086static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02002087 struct hda_codec *codec,
2088 unsigned int stream_tag,
2089 unsigned int format,
2090 struct snd_pcm_substream *substream)
2091{
2092 struct alc_spec *spec = codec->spec;
2093 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
2094 stream_tag, format, substream);
2095}
2096
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002097static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01002098 struct hda_codec *codec,
2099 struct snd_pcm_substream *substream)
2100{
2101 struct alc_spec *spec = codec->spec;
2102 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
2103}
2104
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002105static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002107 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108{
2109 struct alc_spec *spec = codec->spec;
2110 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
2111}
2112
2113/*
2114 * Analog capture
2115 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002116static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 struct hda_codec *codec,
2118 unsigned int stream_tag,
2119 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002120 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121{
2122 struct alc_spec *spec = codec->spec;
2123
Takashi Iwai63300792008-01-24 15:31:36 +01002124 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 stream_tag, 0, format);
2126 return 0;
2127}
2128
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002129static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002131 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132{
2133 struct alc_spec *spec = codec->spec;
2134
Takashi Iwai888afa12008-03-18 09:57:50 +01002135 snd_hda_codec_cleanup_stream(codec,
2136 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 return 0;
2138}
2139
Takashi Iwai840b64c2010-07-13 22:49:01 +02002140/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002141static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002142 struct hda_codec *codec,
2143 unsigned int stream_tag,
2144 unsigned int format,
2145 struct snd_pcm_substream *substream)
2146{
2147 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002148 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002149 spec->cur_adc_stream_tag = stream_tag;
2150 spec->cur_adc_format = format;
2151 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2152 return 0;
2153}
2154
Takashi Iwai21268962011-07-07 15:01:13 +02002155static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002156 struct hda_codec *codec,
2157 struct snd_pcm_substream *substream)
2158{
2159 struct alc_spec *spec = codec->spec;
2160 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2161 spec->cur_adc = 0;
2162 return 0;
2163}
2164
Takashi Iwai21268962011-07-07 15:01:13 +02002165static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002166 .substreams = 1,
2167 .channels_min = 2,
2168 .channels_max = 2,
2169 .nid = 0, /* fill later */
2170 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002171 .prepare = dyn_adc_capture_pcm_prepare,
2172 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002173 },
2174};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
2176/*
2177 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002178static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 .substreams = 1,
2180 .channels_min = 2,
2181 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002182 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002184 .open = alc_playback_pcm_open,
2185 .prepare = alc_playback_pcm_prepare,
2186 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 },
2188};
2189
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002190static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002191 .substreams = 1,
2192 .channels_min = 2,
2193 .channels_max = 2,
2194 /* NID is set in alc_build_pcms */
2195};
2196
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002197static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002198 .substreams = 1,
2199 .channels_min = 2,
2200 .channels_max = 2,
2201 /* NID is set in alc_build_pcms */
2202};
2203
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002204static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002205 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 .channels_min = 2,
2207 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002208 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002210 .prepare = alc_alt_capture_pcm_prepare,
2211 .cleanup = alc_alt_capture_pcm_cleanup
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_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 .substreams = 1,
2217 .channels_min = 2,
2218 .channels_max = 2,
2219 /* NID is set in alc_build_pcms */
2220 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002221 .open = alc_dig_playback_pcm_open,
2222 .close = alc_dig_playback_pcm_close,
2223 .prepare = alc_dig_playback_pcm_prepare,
2224 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 },
2226};
2227
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002228static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 .substreams = 1,
2230 .channels_min = 2,
2231 .channels_max = 2,
2232 /* NID is set in alc_build_pcms */
2233};
2234
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002235/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002236static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002237 .substreams = 0,
2238 .channels_min = 0,
2239 .channels_max = 0,
2240};
2241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242static int alc_build_pcms(struct hda_codec *codec)
2243{
2244 struct alc_spec *spec = codec->spec;
2245 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002246 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002247 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248 int i;
2249
2250 codec->num_pcms = 1;
2251 codec->pcm_info = info;
2252
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002253 if (spec->no_analog)
2254 goto skip_analog;
2255
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002256 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2257 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002259
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002260 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002261 p = spec->stream_analog_playback;
2262 if (!p)
2263 p = &alc_pcm_analog_playback;
2264 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002265 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2266 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002267 if (spec->adc_nids) {
2268 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002269 if (!p) {
2270 if (spec->dyn_adc_switch)
2271 p = &dyn_adc_pcm_analog_capture;
2272 else
2273 p = &alc_pcm_analog_capture;
2274 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002275 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002276 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2277 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278
Takashi Iwai4a471b72005-12-07 13:56:29 +01002279 if (spec->channel_mode) {
2280 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2281 for (i = 0; i < spec->num_channel_mode; i++) {
2282 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2283 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2284 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 }
2286 }
2287
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002288 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002289 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002291 snprintf(spec->stream_name_digital,
2292 sizeof(spec->stream_name_digital),
2293 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002294 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002295 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002296 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002298 if (spec->dig_out_type)
2299 info->pcm_type = spec->dig_out_type;
2300 else
2301 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002302 if (spec->multiout.dig_out_nid) {
2303 p = spec->stream_digital_playback;
2304 if (!p)
2305 p = &alc_pcm_digital_playback;
2306 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2308 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002309 if (spec->dig_in_nid) {
2310 p = spec->stream_digital_capture;
2311 if (!p)
2312 p = &alc_pcm_digital_capture;
2313 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2315 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002316 /* FIXME: do we need this for all Realtek codec models? */
2317 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 }
2319
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002320 if (spec->no_analog)
2321 return 0;
2322
Takashi Iwaie08a0072006-09-07 17:52:14 +02002323 /* If the use of more than one ADC is requested for the current
2324 * model, configure a second analog capture-only PCM.
2325 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002326 have_multi_adcs = (spec->num_adc_nids > 1) &&
2327 !spec->dyn_adc_switch && !spec->auto_mic &&
2328 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002329 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002330 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002331 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002332 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002333 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002334 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002335 p = spec->stream_analog_alt_playback;
2336 if (!p)
2337 p = &alc_pcm_analog_alt_playback;
2338 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002339 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2340 spec->alt_dac_nid;
2341 } else {
2342 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2343 alc_pcm_null_stream;
2344 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2345 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002346 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002347 p = spec->stream_analog_alt_capture;
2348 if (!p)
2349 p = &alc_pcm_analog_alt_capture;
2350 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002351 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2352 spec->adc_nids[1];
2353 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2354 spec->num_adc_nids - 1;
2355 } else {
2356 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2357 alc_pcm_null_stream;
2358 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002359 }
2360 }
2361
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362 return 0;
2363}
2364
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002365static inline void alc_shutup(struct hda_codec *codec)
2366{
Takashi Iwai1c716152011-04-07 10:37:16 +02002367 struct alc_spec *spec = codec->spec;
2368
2369 if (spec && spec->shutup)
2370 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002371 snd_hda_shutup_pins(codec);
2372}
2373
Takashi Iwai603c4012008-07-30 15:01:44 +02002374static void alc_free_kctls(struct hda_codec *codec)
2375{
2376 struct alc_spec *spec = codec->spec;
2377
2378 if (spec->kctls.list) {
2379 struct snd_kcontrol_new *kctl = spec->kctls.list;
2380 int i;
2381 for (i = 0; i < spec->kctls.used; i++)
2382 kfree(kctl[i].name);
2383 }
2384 snd_array_free(&spec->kctls);
2385}
2386
Takashi Iwai23c09b02011-08-19 09:05:35 +02002387static void alc_free_bind_ctls(struct hda_codec *codec)
2388{
2389 struct alc_spec *spec = codec->spec;
2390 if (spec->bind_ctls.list) {
2391 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2392 int i;
2393 for (i = 0; i < spec->bind_ctls.used; i++)
2394 kfree(ctl[i]);
2395 }
2396 snd_array_free(&spec->bind_ctls);
2397}
2398
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399static void alc_free(struct hda_codec *codec)
2400{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002401 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002402
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002403 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002404 return;
2405
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002406 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002407 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002408 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002409 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002410 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
Hector Martinf5de24b2009-12-20 22:51:31 +01002413#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002414static void alc_power_eapd(struct hda_codec *codec)
2415{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002416 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002417}
2418
Hector Martinf5de24b2009-12-20 22:51:31 +01002419static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2420{
2421 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002422 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002423 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002424 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002425 return 0;
2426}
2427#endif
2428
Takashi Iwai2a439522011-07-26 09:52:50 +02002429#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002430static int alc_resume(struct hda_codec *codec)
2431{
Takashi Iwai1c716152011-04-07 10:37:16 +02002432 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002433 codec->patch_ops.init(codec);
2434 snd_hda_codec_resume_amp(codec);
2435 snd_hda_codec_resume_cache(codec);
Takashi Iwai125821a2012-06-22 14:30:29 +02002436 alc_inv_dmic_sync(codec, true);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002437 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002438 return 0;
2439}
Takashi Iwaie044c392008-10-27 16:56:24 +01002440#endif
2441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442/*
2443 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002444static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 .build_controls = alc_build_controls,
2446 .build_pcms = alc_build_pcms,
2447 .init = alc_init,
2448 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002449 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002450#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002451 .resume = alc_resume,
2452#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002453#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002454 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002455 .check_power_status = alc_check_power_status,
2456#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002457 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458};
2459
Kailang Yangc027ddc2010-03-19 11:33:06 +01002460/* replace the codec chip_name with the given string */
2461static int alc_codec_rename(struct hda_codec *codec, const char *name)
2462{
2463 kfree(codec->chip_name);
2464 codec->chip_name = kstrdup(name, GFP_KERNEL);
2465 if (!codec->chip_name) {
2466 alc_free(codec);
2467 return -ENOMEM;
2468 }
2469 return 0;
2470}
2471
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002472/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002473 * Rename codecs appropriately from COEF value
2474 */
2475struct alc_codec_rename_table {
2476 unsigned int vendor_id;
2477 unsigned short coef_mask;
2478 unsigned short coef_bits;
2479 const char *name;
2480};
2481
2482static struct alc_codec_rename_table rename_tbl[] = {
2483 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2484 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2485 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2486 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2487 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2488 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2489 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
Kailang Yangadcc70b2012-05-25 08:08:38 +02002490 { 0x10ec0269, 0x00f0, 0x0030, "ALC269VD" },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002491 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2492 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2493 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2494 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2495 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2496 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2497 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2498 { } /* terminator */
2499};
2500
2501static int alc_codec_rename_from_preset(struct hda_codec *codec)
2502{
2503 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002504
2505 for (p = rename_tbl; p->vendor_id; p++) {
2506 if (p->vendor_id != codec->vendor_id)
2507 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002508 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002509 return alc_codec_rename(codec, p->name);
2510 }
2511 return 0;
2512}
2513
2514/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002515 * Automatic parse of I/O pins from the BIOS configuration
2516 */
2517
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002518enum {
2519 ALC_CTL_WIDGET_VOL,
2520 ALC_CTL_WIDGET_MUTE,
2521 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002522 ALC_CTL_BIND_VOL,
2523 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002524};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002525static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002526 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2527 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002528 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002529 HDA_BIND_VOL(NULL, 0),
2530 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002531};
2532
2533/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002534static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002535 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002536{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002537 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002538
Takashi Iwaice764ab2011-04-27 16:35:23 +02002539 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002540 if (!knew)
2541 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002542 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002543 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002544 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002545 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002546 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002547 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002548 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002549 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002550 return 0;
2551}
2552
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002553static int add_control_with_pfx(struct alc_spec *spec, int type,
2554 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002555 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002556{
2557 char name[32];
2558 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002559 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002560}
2561
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002562#define add_pb_vol_ctrl(spec, type, pfx, val) \
2563 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2564#define add_pb_sw_ctrl(spec, type, pfx, val) \
2565 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2566#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2567 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2568#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2569 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002570
Takashi Iwai23c09b02011-08-19 09:05:35 +02002571static const char * const channel_name[4] = {
2572 "Front", "Surround", "CLFE", "Side"
2573};
2574
Takashi Iwai6843ca12011-06-24 11:03:58 +02002575static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2576 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002577{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002578 struct auto_pin_cfg *cfg = &spec->autocfg;
2579
Takashi Iwai6843ca12011-06-24 11:03:58 +02002580 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002581 if (cfg->line_outs == 1 && !spec->multi_ios &&
2582 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002583 return "Master";
2584
2585 switch (cfg->line_out_type) {
2586 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002587 if (cfg->line_outs == 1)
2588 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002589 if (cfg->line_outs == 2)
2590 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002591 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002592 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002593 /* for multi-io case, only the primary out */
2594 if (ch && spec->multi_ios)
2595 break;
2596 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002597 return "Headphone";
2598 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002599 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002600 return "PCM";
2601 break;
2602 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002603 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2604 return "PCM";
2605
2606 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002607}
2608
Takashi Iwai164f73e2012-02-21 11:27:09 +01002609#ifdef CONFIG_SND_HDA_POWER_SAVE
2610/* add the powersave loopback-list entry */
2611static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2612{
2613 struct hda_amp_list *list;
2614
2615 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2616 return;
2617 list = spec->loopback_list + spec->num_loopbacks;
2618 list->nid = mix;
2619 list->dir = HDA_INPUT;
2620 list->idx = idx;
2621 spec->num_loopbacks++;
2622 spec->loopback.amplist = spec->loopback_list;
2623}
2624#else
2625#define add_loopback_list(spec, mix, idx) /* NOP */
2626#endif
2627
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002628/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002629static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002630 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002631 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002632{
Kailang Yangdf694da2005-12-05 19:42:22 +01002633 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002634
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002635 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002636 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2637 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002638 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002639 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002640 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2641 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002642 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002643 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002644 return 0;
2645}
2646
Takashi Iwai05f5f472009-08-25 13:10:18 +02002647static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002648{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002649 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2650 return (pincap & AC_PINCAP_IN) != 0;
2651}
2652
Takashi Iwai1d045db2011-07-07 18:23:21 +02002653/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002654static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002655{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002656 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002657 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002658 hda_nid_t *adc_nids = spec->private_adc_nids;
2659 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2660 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002661 int i, nums = 0;
2662
2663 nid = codec->start_nid;
2664 for (i = 0; i < codec->num_nodes; i++, nid++) {
2665 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002666 unsigned int caps = get_wcaps(codec, nid);
2667 int type = get_wcaps_type(caps);
2668
2669 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2670 continue;
2671 adc_nids[nums] = nid;
2672 cap_nids[nums] = nid;
2673 src = nid;
2674 for (;;) {
2675 int n;
2676 type = get_wcaps_type(get_wcaps(codec, src));
2677 if (type == AC_WID_PIN)
2678 break;
2679 if (type == AC_WID_AUD_SEL) {
2680 cap_nids[nums] = src;
2681 break;
2682 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002683 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002684 if (n > 1) {
2685 cap_nids[nums] = src;
2686 break;
2687 } else if (n != 1)
2688 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002689 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2690 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002691 }
2692 if (++nums >= max_nums)
2693 break;
2694 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002695 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002696 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002697 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002698 return nums;
2699}
2700
Takashi Iwai05f5f472009-08-25 13:10:18 +02002701/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002702static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002703{
2704 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002705 const struct auto_pin_cfg *cfg = &spec->autocfg;
2706 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002707 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002708 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002709 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002710 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002711
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002712 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002713 if (num_adcs < 0)
2714 return 0;
2715
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002716 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002717 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002718 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002719
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002720 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002721 if (!alc_is_input_pin(codec, pin))
2722 continue;
2723
David Henningsson5322bf22011-01-05 11:03:56 +01002724 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002725 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2726 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002727 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002728 type_idx++;
2729 else
2730 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002731 prev_label = label;
2732
Takashi Iwai05f5f472009-08-25 13:10:18 +02002733 if (mixer) {
2734 idx = get_connection_index(codec, mixer, pin);
2735 if (idx >= 0) {
2736 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002737 label, type_idx,
2738 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002739 if (err < 0)
2740 return err;
2741 }
2742 }
2743
Takashi Iwaib7821702011-07-06 15:12:46 +02002744 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002745 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002746 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002747 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002748 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002749 snd_hda_add_imux_item(imux, label, idx, NULL);
2750 break;
2751 }
2752 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002753 }
Takashi Iwai21268962011-07-07 15:01:13 +02002754
2755 spec->num_mux_defs = 1;
2756 spec->input_mux = imux;
2757
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002758 return 0;
2759}
2760
Takashi Iwai24de1832011-11-07 17:13:39 +01002761/* create a shared input with the headphone out */
2762static int alc_auto_create_shared_input(struct hda_codec *codec)
2763{
2764 struct alc_spec *spec = codec->spec;
2765 struct auto_pin_cfg *cfg = &spec->autocfg;
2766 unsigned int defcfg;
2767 hda_nid_t nid;
2768
2769 /* only one internal input pin? */
2770 if (cfg->num_inputs != 1)
2771 return 0;
2772 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2773 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2774 return 0;
2775
2776 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2777 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2778 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2779 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2780 else
2781 return 0; /* both not available */
2782
2783 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2784 return 0; /* no input */
2785
2786 cfg->inputs[1].pin = nid;
2787 cfg->inputs[1].type = AUTO_PIN_MIC;
2788 cfg->num_inputs = 2;
2789 spec->shared_mic_hp = 1;
2790 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2791 return 0;
2792}
2793
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002794static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2795 unsigned int pin_type)
2796{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002797 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002798 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002799 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2800 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002801 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002802}
2803
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002804static int get_pin_type(int line_out_type)
2805{
2806 if (line_out_type == AUTO_PIN_HP_OUT)
2807 return PIN_HP;
2808 else
2809 return PIN_OUT;
2810}
2811
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002812static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002813{
2814 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002815 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002816 int i;
2817
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002818 for (i = 0; i < cfg->num_inputs; i++) {
2819 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002820 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002821 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002822 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002823 snd_hda_codec_write(codec, nid, 0,
2824 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002825 AMP_OUT_MUTE);
2826 }
2827 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002828
2829 /* mute all loopback inputs */
2830 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002831 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002832 for (i = 0; i < nums; i++)
2833 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2834 AC_VERB_SET_AMP_GAIN_MUTE,
2835 AMP_IN_MUTE(i));
2836 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002837}
2838
Takashi Iwai7085ec12009-10-02 09:03:58 +02002839/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002840static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002841{
Takashi Iwai604401a2011-04-27 15:14:23 +02002842 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002843 int i, num;
2844
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002845 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2846 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002847 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2848 for (i = 0; i < num; i++) {
2849 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2850 return list[i];
2851 }
2852 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002853}
2854
Takashi Iwai604401a2011-04-27 15:14:23 +02002855/* go down to the selector widget before the mixer */
2856static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2857{
2858 hda_nid_t srcs[5];
2859 int num = snd_hda_get_connections(codec, pin, srcs,
2860 ARRAY_SIZE(srcs));
2861 if (num != 1 ||
2862 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2863 return pin;
2864 return srcs[0];
2865}
2866
Takashi Iwai7085ec12009-10-02 09:03:58 +02002867/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002868static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002869 hda_nid_t dac)
2870{
David Henningssoncc1c4522010-11-24 14:17:47 +01002871 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002872 int i, num;
2873
Takashi Iwai604401a2011-04-27 15:14:23 +02002874 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002875 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2876 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002877 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002878 return mix[i];
2879 }
2880 return 0;
2881}
2882
Takashi Iwaice764ab2011-04-27 16:35:23 +02002883/* select the connection from pin to DAC if needed */
2884static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2885 hda_nid_t dac)
2886{
2887 hda_nid_t mix[5];
2888 int i, num;
2889
2890 pin = alc_go_down_to_selector(codec, pin);
2891 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2892 if (num < 2)
2893 return 0;
2894 for (i = 0; i < num; i++) {
2895 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2896 snd_hda_codec_update_cache(codec, pin, 0,
2897 AC_VERB_SET_CONNECT_SEL, i);
2898 return 0;
2899 }
2900 }
2901 return 0;
2902}
2903
Takashi Iwai185d99f2012-02-16 18:39:45 +01002904static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2905{
2906 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002907 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002908 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2909 ARRAY_SIZE(spec->private_dac_nids)) ||
2910 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2911 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2912 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2913 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2914 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002915 for (i = 0; i < spec->multi_ios; i++) {
2916 if (spec->multi_io[i].dac == nid)
2917 return true;
2918 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002919 return false;
2920}
2921
Takashi Iwai7085ec12009-10-02 09:03:58 +02002922/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002923static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002924{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002925 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002926 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002927
Takashi Iwai604401a2011-04-27 15:14:23 +02002928 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002929 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002930 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002931 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002932 if (!nid)
2933 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002934 if (!alc_is_dac_already_used(codec, nid))
2935 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002936 }
2937 return 0;
2938}
2939
Takashi Iwai07b18f62011-11-10 15:42:54 +01002940/* check whether the DAC is reachable from the pin */
2941static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2942 hda_nid_t pin, hda_nid_t dac)
2943{
2944 hda_nid_t srcs[5];
2945 int i, num;
2946
Takashi Iwaidc31b582012-02-17 17:27:53 +01002947 if (!pin || !dac)
2948 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002949 pin = alc_go_down_to_selector(codec, pin);
2950 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2951 for (i = 0; i < num; i++) {
2952 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2953 if (nid == dac)
2954 return true;
2955 }
2956 return false;
2957}
2958
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002959static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2960{
Takashi Iwai140547e2012-02-16 17:23:46 +01002961 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002962 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002963 hda_nid_t nid, nid_found, srcs[5];
2964 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01002965 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01002966 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002967 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002968 nid_found = 0;
2969 for (i = 0; i < num; i++) {
2970 if (srcs[i] == spec->mixer_nid)
2971 continue;
2972 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2973 if (nid && !alc_is_dac_already_used(codec, nid)) {
2974 if (nid_found)
2975 return 0;
2976 nid_found = nid;
2977 }
2978 }
2979 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002980}
2981
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002982/* mark up volume and mute control NIDs: used during badness parsing and
2983 * at creating actual controls
2984 */
2985static inline unsigned int get_ctl_pos(unsigned int data)
2986{
2987 hda_nid_t nid = get_amp_nid_(data);
2988 unsigned int dir;
2989 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
2990 return 0;
2991 dir = get_amp_direction_(data);
2992 return (nid << 1) | dir;
2993}
2994
2995#define is_ctl_used(bits, data) \
2996 test_bit(get_ctl_pos(data), bits)
2997#define mark_ctl_usage(bits, data) \
2998 set_bit(get_ctl_pos(data), bits)
2999
3000static void clear_vol_marks(struct hda_codec *codec)
3001{
3002 struct alc_spec *spec = codec->spec;
3003 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
3004 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
3005}
3006
3007/* badness definition */
3008enum {
3009 /* No primary DAC is found for the main output */
3010 BAD_NO_PRIMARY_DAC = 0x10000,
3011 /* No DAC is found for the extra output */
3012 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01003013 /* No possible multi-ios */
3014 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003015 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01003016 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003017 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01003018 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003019 /* Primary DAC shared with main surrounds */
3020 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003021 /* Primary DAC shared with main CLFE */
3022 BAD_SHARED_CLFE = 0x10,
3023 /* Primary DAC shared with extra surrounds */
3024 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01003025 /* Volume widget is shared */
3026 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003027};
3028
3029static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3030 hda_nid_t pin, hda_nid_t dac);
3031static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3032 hda_nid_t pin, hda_nid_t dac);
3033
3034static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
3035 hda_nid_t dac)
3036{
3037 struct alc_spec *spec = codec->spec;
3038 hda_nid_t nid;
3039 unsigned int val;
3040 int badness = 0;
3041
3042 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3043 if (nid) {
3044 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3045 if (is_ctl_used(spec->vol_ctls, nid))
3046 badness += BAD_SHARED_VOL;
3047 else
3048 mark_ctl_usage(spec->vol_ctls, val);
3049 } else
3050 badness += BAD_SHARED_VOL;
3051 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3052 if (nid) {
3053 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
3054 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
3055 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
3056 else
3057 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
3058 if (is_ctl_used(spec->sw_ctls, val))
3059 badness += BAD_SHARED_VOL;
3060 else
3061 mark_ctl_usage(spec->sw_ctls, val);
3062 } else
3063 badness += BAD_SHARED_VOL;
3064 return badness;
3065}
3066
Takashi Iwaidc31b582012-02-17 17:27:53 +01003067struct badness_table {
3068 int no_primary_dac; /* no primary DAC */
3069 int no_dac; /* no secondary DACs */
3070 int shared_primary; /* primary DAC is shared with main output */
3071 int shared_surr; /* secondary DAC shared with main or primary */
3072 int shared_clfe; /* third DAC shared with main or primary */
3073 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
3074};
3075
3076static struct badness_table main_out_badness = {
3077 .no_primary_dac = BAD_NO_PRIMARY_DAC,
3078 .no_dac = BAD_NO_DAC,
3079 .shared_primary = BAD_NO_PRIMARY_DAC,
3080 .shared_surr = BAD_SHARED_SURROUND,
3081 .shared_clfe = BAD_SHARED_CLFE,
3082 .shared_surr_main = BAD_SHARED_SURROUND,
3083};
3084
3085static struct badness_table extra_out_badness = {
3086 .no_primary_dac = BAD_NO_DAC,
3087 .no_dac = BAD_NO_DAC,
3088 .shared_primary = BAD_NO_EXTRA_DAC,
3089 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
3090 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
3091 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
3092};
3093
3094/* try to assign DACs to pins and return the resultant badness */
3095static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
3096 const hda_nid_t *pins, hda_nid_t *dacs,
3097 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02003098{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003099 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003100 struct auto_pin_cfg *cfg = &spec->autocfg;
3101 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003102 int badness = 0;
3103 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02003104
Takashi Iwai185d99f2012-02-16 18:39:45 +01003105 if (!num_outs)
3106 return 0;
3107
Takashi Iwaidc31b582012-02-17 17:27:53 +01003108 for (i = 0; i < num_outs; i++) {
3109 hda_nid_t pin = pins[i];
3110 if (!dacs[i])
3111 dacs[i] = alc_auto_look_for_dac(codec, pin);
3112 if (!dacs[i] && !i) {
3113 for (j = 1; j < num_outs; j++) {
3114 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
3115 dacs[0] = dacs[j];
3116 dacs[j] = 0;
3117 break;
3118 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003119 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003120 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003121 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003122 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003123 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003124 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003125 else if (cfg->line_outs > i &&
3126 alc_auto_is_dac_reachable(codec, pin,
3127 spec->private_dac_nids[i]))
3128 dac = spec->private_dac_nids[i];
3129 if (dac) {
3130 if (!i)
3131 badness += bad->shared_primary;
3132 else if (i == 1)
3133 badness += bad->shared_surr;
3134 else
3135 badness += bad->shared_clfe;
3136 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003137 spec->private_dac_nids[0])) {
3138 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003139 badness += bad->shared_surr_main;
3140 } else if (!i)
3141 badness += bad->no_primary_dac;
3142 else
3143 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003144 }
3145 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003146 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003147 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003148
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003149 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003150}
3151
3152static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003153 hda_nid_t reference_pin,
3154 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003155
Takashi Iwai185d99f2012-02-16 18:39:45 +01003156static bool alc_map_singles(struct hda_codec *codec, int outs,
3157 const hda_nid_t *pins, hda_nid_t *dacs)
3158{
3159 int i;
3160 bool found = false;
3161 for (i = 0; i < outs; i++) {
3162 if (dacs[i])
3163 continue;
3164 dacs[i] = get_dac_if_single(codec, pins[i]);
3165 if (dacs[i])
3166 found = true;
3167 }
3168 return found;
3169}
3170
Takashi Iwai7085ec12009-10-02 09:03:58 +02003171/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003172static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003173 bool fill_hardwired,
3174 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003175{
3176 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003177 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003178 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003179
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003180 /* set num_dacs once to full for alc_auto_look_for_dac() */
3181 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003182 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003183 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3184 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3185 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003186 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003187 clear_vol_marks(codec);
3188 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003189
3190 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003191 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003192 bool mapped;
3193 do {
3194 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003195 cfg->line_out_pins,
3196 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003197 mapped |= alc_map_singles(codec, cfg->hp_outs,
3198 cfg->hp_pins,
3199 spec->multiout.hp_out_nid);
3200 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3201 cfg->speaker_pins,
3202 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003203 if (fill_mio_first && cfg->line_outs == 1 &&
3204 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3205 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3206 if (!err)
3207 mapped = true;
3208 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003209 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003210 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003211
Takashi Iwaidc31b582012-02-17 17:27:53 +01003212 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3213 spec->private_dac_nids,
3214 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003215
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003216 /* re-count num_dacs and squash invalid entries */
3217 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003218 for (i = 0; i < cfg->line_outs; i++) {
3219 if (spec->private_dac_nids[i])
3220 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003221 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003222 memmove(spec->private_dac_nids + i,
3223 spec->private_dac_nids + i + 1,
3224 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003225 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3226 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003227 }
3228
Takashi Iwai276dd702012-02-17 16:17:03 +01003229 if (fill_mio_first &&
3230 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003231 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003232 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003233 if (err < 0)
3234 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003235 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003236 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003237
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003238 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003239 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3240 spec->multiout.hp_out_nid,
3241 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003242 if (err < 0)
3243 return err;
3244 badness += err;
3245 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003246 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003247 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3248 cfg->speaker_pins,
3249 spec->multiout.extra_out_nid,
3250 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003251 if (err < 0)
3252 return err;
3253 badness += err;
3254 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003255 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3256 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003257 if (err < 0)
3258 return err;
3259 badness += err;
3260 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003261 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3262 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003263 int offset = 0;
3264 if (cfg->line_outs >= 3)
3265 offset = 1;
3266 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3267 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003268 if (err < 0)
3269 return err;
3270 badness += err;
3271 }
3272
3273 if (spec->multi_ios == 2) {
3274 for (i = 0; i < 2; i++)
3275 spec->private_dac_nids[spec->multiout.num_dacs++] =
3276 spec->multi_io[i].dac;
3277 spec->ext_channel_count = 2;
3278 } else if (spec->multi_ios) {
3279 spec->multi_ios = 0;
3280 badness += BAD_MULTI_IO;
3281 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003282
3283 return badness;
3284}
3285
3286#define DEBUG_BADNESS
3287
3288#ifdef DEBUG_BADNESS
3289#define debug_badness snd_printdd
3290#else
3291#define debug_badness(...)
3292#endif
3293
3294static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3295{
3296 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3297 cfg->line_out_pins[0], cfg->line_out_pins[1],
3298 cfg->line_out_pins[2], cfg->line_out_pins[2],
3299 spec->multiout.dac_nids[0],
3300 spec->multiout.dac_nids[1],
3301 spec->multiout.dac_nids[2],
3302 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003303 if (spec->multi_ios > 0)
3304 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3305 spec->multi_ios,
3306 spec->multi_io[0].pin, spec->multi_io[1].pin,
3307 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003308 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3309 cfg->hp_pins[0], cfg->hp_pins[1],
3310 cfg->hp_pins[2], cfg->hp_pins[2],
3311 spec->multiout.hp_out_nid[0],
3312 spec->multiout.hp_out_nid[1],
3313 spec->multiout.hp_out_nid[2],
3314 spec->multiout.hp_out_nid[3]);
3315 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3316 cfg->speaker_pins[0], cfg->speaker_pins[1],
3317 cfg->speaker_pins[2], cfg->speaker_pins[3],
3318 spec->multiout.extra_out_nid[0],
3319 spec->multiout.extra_out_nid[1],
3320 spec->multiout.extra_out_nid[2],
3321 spec->multiout.extra_out_nid[3]);
3322}
3323
3324static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3325{
3326 struct alc_spec *spec = codec->spec;
3327 struct auto_pin_cfg *cfg = &spec->autocfg;
3328 struct auto_pin_cfg *best_cfg;
3329 int best_badness = INT_MAX;
3330 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003331 bool fill_hardwired = true, fill_mio_first = true;
3332 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003333 bool hp_spk_swapped = false;
3334
3335 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3336 if (!best_cfg)
3337 return -ENOMEM;
3338 *best_cfg = *cfg;
3339
3340 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003341 badness = fill_and_eval_dacs(codec, fill_hardwired,
3342 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003343 if (badness < 0) {
3344 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003345 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003346 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003347 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3348 cfg->line_out_type, fill_hardwired, fill_mio_first,
3349 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003350 debug_show_configs(spec, cfg);
3351 if (badness < best_badness) {
3352 best_badness = badness;
3353 *best_cfg = *cfg;
3354 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003355 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003356 }
3357 if (!badness)
3358 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003359 fill_mio_first = !fill_mio_first;
3360 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003361 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003362 fill_hardwired = !fill_hardwired;
3363 if (!fill_hardwired)
3364 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003365 if (hp_spk_swapped)
3366 break;
3367 hp_spk_swapped = true;
3368 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003369 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3370 cfg->hp_outs = cfg->line_outs;
3371 memcpy(cfg->hp_pins, cfg->line_out_pins,
3372 sizeof(cfg->hp_pins));
3373 cfg->line_outs = cfg->speaker_outs;
3374 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3375 sizeof(cfg->speaker_pins));
3376 cfg->speaker_outs = 0;
3377 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3378 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003379 fill_hardwired = true;
3380 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003381 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003382 if (cfg->hp_outs > 0 &&
3383 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3384 cfg->speaker_outs = cfg->line_outs;
3385 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3386 sizeof(cfg->speaker_pins));
3387 cfg->line_outs = cfg->hp_outs;
3388 memcpy(cfg->line_out_pins, cfg->hp_pins,
3389 sizeof(cfg->hp_pins));
3390 cfg->hp_outs = 0;
3391 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3392 cfg->line_out_type = AUTO_PIN_HP_OUT;
3393 fill_hardwired = true;
3394 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003395 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003396 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003397 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003398
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003399 if (badness) {
3400 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003401 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003402 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003403 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3404 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003405 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003406
David Henningssonfde48a12011-12-09 18:27:42 +08003407 if (cfg->line_out_pins[0])
3408 spec->vmaster_nid =
3409 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3410 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003411
3412 /* clear the bitmap flags for creating controls */
3413 clear_vol_marks(codec);
3414 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003415 return 0;
3416}
3417
Takashi Iwai343a04b2011-07-06 14:28:39 +02003418static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003419 const char *pfx, int cidx,
3420 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003421{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003422 struct alc_spec *spec = codec->spec;
3423 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003424 if (!nid)
3425 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003426 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3427 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3428 return 0;
3429 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003430 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003431 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003432}
3433
Takashi Iwaie29d3772011-11-14 17:13:23 +01003434static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3435 const char *pfx, int cidx,
3436 hda_nid_t nid)
3437{
3438 int chs = 1;
3439 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3440 chs = 3;
3441 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3442}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003443
3444/* create a mute-switch for the given mixer widget;
3445 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3446 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003447static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003448 const char *pfx, int cidx,
3449 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003450{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003451 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003452 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003453 int type;
3454 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003455 if (!nid)
3456 return 0;
3457 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3458 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3459 type = ALC_CTL_WIDGET_MUTE;
3460 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003461 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003462 type = ALC_CTL_WIDGET_MUTE;
3463 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3464 } else {
3465 type = ALC_CTL_BIND_MUTE;
3466 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3467 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003468 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3469 return 0;
3470 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003471 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003472}
3473
Takashi Iwaie29d3772011-11-14 17:13:23 +01003474static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3475 int cidx, hda_nid_t nid)
3476{
3477 int chs = 1;
3478 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3479 chs = 3;
3480 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3481}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003482
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003483static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3484 hda_nid_t pin, hda_nid_t dac)
3485{
3486 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3487 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3488 return pin;
3489 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3490 return mix;
3491 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3492 return dac;
3493 return 0;
3494}
3495
3496static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3497 hda_nid_t pin, hda_nid_t dac)
3498{
3499 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3500 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3501 return dac;
3502 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3503 return mix;
3504 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3505 return pin;
3506 return 0;
3507}
3508
Takashi Iwai7085ec12009-10-02 09:03:58 +02003509/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003510static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003511 const struct auto_pin_cfg *cfg)
3512{
3513 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003514 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003515
Takashi Iwaice764ab2011-04-27 16:35:23 +02003516 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003517 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003518 noutputs += spec->multi_ios;
3519
3520 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003521 const char *name;
3522 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003523 hda_nid_t dac, pin;
3524 hda_nid_t sw, vol;
3525
3526 dac = spec->multiout.dac_nids[i];
3527 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003528 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003529 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003530 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003531 index = 0;
3532 name = channel_name[i];
3533 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003534 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003535 name = alc_get_line_out_pfx(spec, i, true, &index);
3536 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003537
3538 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3539 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003540 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003541 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003542 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003543 if (err < 0)
3544 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003545 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003546 if (err < 0)
3547 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003548 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003549 if (err < 0)
3550 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003551 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003552 if (err < 0)
3553 return err;
3554 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003555 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003556 if (err < 0)
3557 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003558 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003559 if (err < 0)
3560 return err;
3561 }
3562 }
3563 return 0;
3564}
3565
Takashi Iwai343a04b2011-07-06 14:28:39 +02003566static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003567 hda_nid_t dac, const char *pfx,
3568 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003569{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003570 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003571 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003572 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003573
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003574 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003575 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003576 /* the corresponding DAC is already occupied */
3577 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3578 return 0; /* no way */
3579 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003580 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3581 if (is_ctl_used(spec->sw_ctls, val))
3582 return 0; /* already created */
3583 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003584 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003585 }
3586
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003587 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3588 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003589 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003590 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003591 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003592 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003593 if (err < 0)
3594 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003595 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003596}
3597
Takashi Iwai23c09b02011-08-19 09:05:35 +02003598static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3599 unsigned int nums,
3600 struct hda_ctl_ops *ops)
3601{
3602 struct alc_spec *spec = codec->spec;
3603 struct hda_bind_ctls **ctlp, *ctl;
3604 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3605 ctlp = snd_array_new(&spec->bind_ctls);
3606 if (!ctlp)
3607 return NULL;
3608 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3609 *ctlp = ctl;
3610 if (ctl)
3611 ctl->ops = ops;
3612 return ctl;
3613}
3614
3615/* add playback controls for speaker and HP outputs */
3616static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3617 const hda_nid_t *pins,
3618 const hda_nid_t *dacs,
3619 const char *pfx)
3620{
3621 struct alc_spec *spec = codec->spec;
3622 struct hda_bind_ctls *ctl;
3623 char name[32];
3624 int i, n, err;
3625
3626 if (!num_pins || !pins[0])
3627 return 0;
3628
Takashi Iwai527e4d72011-10-27 16:33:27 +02003629 if (num_pins == 1) {
3630 hda_nid_t dac = *dacs;
3631 if (!dac)
3632 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003633 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003634 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003635
Takashi Iwai23c09b02011-08-19 09:05:35 +02003636 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003637 hda_nid_t dac;
3638 if (dacs[num_pins - 1])
3639 dac = dacs[i]; /* with individual volumes */
3640 else
3641 dac = 0;
3642 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3643 err = alc_auto_create_extra_out(codec, pins[i], dac,
3644 "Bass Speaker", 0);
3645 } else if (num_pins >= 3) {
3646 snprintf(name, sizeof(name), "%s %s",
3647 pfx, channel_name[i]);
3648 err = alc_auto_create_extra_out(codec, pins[i], dac,
3649 name, 0);
3650 } else {
3651 err = alc_auto_create_extra_out(codec, pins[i], dac,
3652 pfx, i);
3653 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003654 if (err < 0)
3655 return err;
3656 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003657 if (dacs[num_pins - 1])
3658 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003659
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003660 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003661 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3662 if (!ctl)
3663 return -ENOMEM;
3664 n = 0;
3665 for (i = 0; i < num_pins; i++) {
3666 hda_nid_t vol;
3667 if (!pins[i] || !dacs[i])
3668 continue;
3669 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3670 if (vol)
3671 ctl->values[n++] =
3672 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3673 }
3674 if (n) {
3675 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3676 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3677 if (err < 0)
3678 return err;
3679 }
3680 return 0;
3681}
3682
Takashi Iwai343a04b2011-07-06 14:28:39 +02003683static int alc_auto_create_hp_out(struct hda_codec *codec)
3684{
3685 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003686 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3687 spec->autocfg.hp_pins,
3688 spec->multiout.hp_out_nid,
3689 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003690}
3691
3692static int alc_auto_create_speaker_out(struct hda_codec *codec)
3693{
3694 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003695 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3696 spec->autocfg.speaker_pins,
3697 spec->multiout.extra_out_nid,
3698 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003699}
3700
Takashi Iwai343a04b2011-07-06 14:28:39 +02003701static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003702 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003703 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003704{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003705 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003706 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003707 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003708
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003709 alc_set_pin_output(codec, pin, pin_type);
3710 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003711 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003712 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003713 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003714 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003715 mix = srcs[i];
3716 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003717 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003718 if (!mix)
3719 return;
3720
3721 /* need the manual connection? */
3722 if (num > 1)
3723 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3724 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003725 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3726 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003727 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003728 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003729 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003730 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003731 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003732 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3733 if (nid)
3734 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3735 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003736
3737 /* unmute DAC if it's not assigned to a mixer */
3738 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3739 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3740 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3741 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003742}
3743
Takashi Iwai343a04b2011-07-06 14:28:39 +02003744static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003745{
3746 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003747 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003748 int i;
3749
3750 for (i = 0; i <= HDA_SIDE; i++) {
3751 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3752 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003753 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003754 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003755 }
3756}
3757
Takashi Iwai343a04b2011-07-06 14:28:39 +02003758static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003759{
3760 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003761 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003762 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003763
David Henningsson636030e2011-10-12 19:26:03 +02003764 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003765 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3766 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003767 pin = spec->autocfg.hp_pins[i];
3768 if (!pin)
3769 break;
3770 dac = spec->multiout.hp_out_nid[i];
3771 if (!dac) {
3772 if (i > 0 && spec->multiout.hp_out_nid[0])
3773 dac = spec->multiout.hp_out_nid[0];
3774 else
3775 dac = spec->multiout.dac_nids[0];
3776 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003777 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3778 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003779 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003780 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3781 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003782 pin = spec->autocfg.speaker_pins[i];
3783 if (!pin)
3784 break;
3785 dac = spec->multiout.extra_out_nid[i];
3786 if (!dac) {
3787 if (i > 0 && spec->multiout.extra_out_nid[0])
3788 dac = spec->multiout.extra_out_nid[0];
3789 else
3790 dac = spec->multiout.dac_nids[0];
3791 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003792 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3793 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003794}
3795
Takashi Iwai276dd702012-02-17 16:17:03 +01003796/* check whether the given pin can be a multi-io pin */
3797static bool can_be_multiio_pin(struct hda_codec *codec,
3798 unsigned int location, hda_nid_t nid)
3799{
3800 unsigned int defcfg, caps;
3801
3802 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3803 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3804 return false;
3805 if (location && get_defcfg_location(defcfg) != location)
3806 return false;
3807 caps = snd_hda_query_pin_caps(codec, nid);
3808 if (!(caps & AC_PINCAP_OUT))
3809 return false;
3810 return true;
3811}
3812
Takashi Iwaice764ab2011-04-27 16:35:23 +02003813/*
3814 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003815 *
3816 * When hardwired is set, try to fill ony hardwired pins, and returns
3817 * zero if any pins are filled, non-zero if nothing found.
3818 * When hardwired is off, try to fill possible input pins, and returns
3819 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003820 */
3821static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003822 hda_nid_t reference_pin,
3823 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003824{
3825 struct alc_spec *spec = codec->spec;
3826 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003827 int type, i, j, dacs, num_pins, old_pins;
3828 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3829 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003830 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003831
Takashi Iwai276dd702012-02-17 16:17:03 +01003832 old_pins = spec->multi_ios;
3833 if (old_pins >= 2)
3834 goto end_fill;
3835
3836 num_pins = 0;
3837 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3838 for (i = 0; i < cfg->num_inputs; i++) {
3839 if (cfg->inputs[i].type != type)
3840 continue;
3841 if (can_be_multiio_pin(codec, location,
3842 cfg->inputs[i].pin))
3843 num_pins++;
3844 }
3845 }
3846 if (num_pins < 2)
3847 goto end_fill;
3848
Takashi Iwai07b18f62011-11-10 15:42:54 +01003849 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003850 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3851 for (i = 0; i < cfg->num_inputs; i++) {
3852 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003853 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003854
Takashi Iwaice764ab2011-04-27 16:35:23 +02003855 if (cfg->inputs[i].type != type)
3856 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003857 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003858 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003859 for (j = 0; j < spec->multi_ios; j++) {
3860 if (nid == spec->multi_io[j].pin)
3861 break;
3862 }
3863 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003864 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003865
3866 if (offset && offset + spec->multi_ios < dacs) {
3867 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003868 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3869 dac = 0;
3870 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003871 if (hardwired)
3872 dac = get_dac_if_single(codec, nid);
3873 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003874 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003875 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003876 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003877 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003878 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003879 spec->multi_io[spec->multi_ios].pin = nid;
3880 spec->multi_io[spec->multi_ios].dac = dac;
3881 spec->multi_ios++;
3882 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003883 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003884 }
3885 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003886 end_fill:
3887 if (badness)
3888 badness = BAD_MULTI_IO;
3889 if (old_pins == spec->multi_ios) {
3890 if (hardwired)
3891 return 1; /* nothing found */
3892 else
3893 return badness; /* no badness if nothing found */
3894 }
3895 if (!hardwired && spec->multi_ios < 2) {
3896 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003897 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003898 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003899
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003900 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003901}
3902
3903static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3904 struct snd_ctl_elem_info *uinfo)
3905{
3906 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3907 struct alc_spec *spec = codec->spec;
3908
3909 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3910 uinfo->count = 1;
3911 uinfo->value.enumerated.items = spec->multi_ios + 1;
3912 if (uinfo->value.enumerated.item > spec->multi_ios)
3913 uinfo->value.enumerated.item = spec->multi_ios;
3914 sprintf(uinfo->value.enumerated.name, "%dch",
3915 (uinfo->value.enumerated.item + 1) * 2);
3916 return 0;
3917}
3918
3919static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3920 struct snd_ctl_elem_value *ucontrol)
3921{
3922 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3923 struct alc_spec *spec = codec->spec;
3924 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3925 return 0;
3926}
3927
3928static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3929{
3930 struct alc_spec *spec = codec->spec;
3931 hda_nid_t nid = spec->multi_io[idx].pin;
3932
3933 if (!spec->multi_io[idx].ctl_in)
3934 spec->multi_io[idx].ctl_in =
3935 snd_hda_codec_read(codec, nid, 0,
3936 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3937 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003938 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003939 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3940 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3941 HDA_AMP_MUTE, 0);
3942 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3943 } else {
3944 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3945 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3946 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003947 snd_hda_set_pin_ctl_cache(codec, nid,
3948 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003949 }
3950 return 0;
3951}
3952
3953static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3954 struct snd_ctl_elem_value *ucontrol)
3955{
3956 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3957 struct alc_spec *spec = codec->spec;
3958 int i, ch;
3959
3960 ch = ucontrol->value.enumerated.item[0];
3961 if (ch < 0 || ch > spec->multi_ios)
3962 return -EINVAL;
3963 if (ch == (spec->ext_channel_count - 1) / 2)
3964 return 0;
3965 spec->ext_channel_count = (ch + 1) * 2;
3966 for (i = 0; i < spec->multi_ios; i++)
3967 alc_set_multi_io(codec, i, i < ch);
3968 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003969 if (spec->need_dac_fix && !spec->const_channel_count)
3970 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003971 return 1;
3972}
3973
Takashi Iwaia9111322011-05-02 11:30:18 +02003974static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003975 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3976 .name = "Channel Mode",
3977 .info = alc_auto_ch_mode_info,
3978 .get = alc_auto_ch_mode_get,
3979 .put = alc_auto_ch_mode_put,
3980};
3981
Takashi Iwai23c09b02011-08-19 09:05:35 +02003982static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003983{
3984 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003985
Takashi Iwaic2674682011-08-24 17:57:44 +02003986 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003987 struct snd_kcontrol_new *knew;
3988
3989 knew = alc_kcontrol_new(spec);
3990 if (!knew)
3991 return -ENOMEM;
3992 *knew = alc_auto_channel_mode_enum;
3993 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3994 if (!knew->name)
3995 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003996 }
3997 return 0;
3998}
3999
Takashi Iwai1d045db2011-07-07 18:23:21 +02004000/* filter out invalid adc_nids (and capsrc_nids) that don't give all
4001 * active input pins
4002 */
4003static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
4004{
4005 struct alc_spec *spec = codec->spec;
4006 const struct hda_input_mux *imux;
4007 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4008 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
4009 int i, n, nums;
4010
4011 imux = spec->input_mux;
4012 if (!imux)
4013 return;
4014 if (spec->dyn_adc_switch)
4015 return;
4016
Takashi Iwai26acaf02012-03-22 14:36:50 +01004017 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004018 nums = 0;
4019 for (n = 0; n < spec->num_adc_nids; n++) {
4020 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004021 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004022 for (i = 0; i < imux->num_items; i++) {
4023 hda_nid_t pin = spec->imux_pins[i];
4024 if (pin) {
4025 if (get_connection_index(codec, cap, pin) < 0)
4026 break;
4027 } else if (num_conns <= imux->items[i].index)
4028 break;
4029 }
4030 if (i >= imux->num_items) {
4031 adc_nids[nums] = spec->private_adc_nids[n];
4032 capsrc_nids[nums++] = cap;
4033 }
4034 }
4035 if (!nums) {
4036 /* check whether ADC-switch is possible */
4037 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01004038 if (spec->shared_mic_hp) {
4039 spec->shared_mic_hp = 0;
4040 spec->private_imux[0].num_items = 1;
4041 goto again;
4042 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004043 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
4044 " using fallback 0x%x\n",
4045 codec->chip_name, spec->private_adc_nids[0]);
4046 spec->num_adc_nids = 1;
4047 spec->auto_mic = 0;
4048 return;
4049 }
4050 } else if (nums != spec->num_adc_nids) {
4051 memcpy(spec->private_adc_nids, adc_nids,
4052 nums * sizeof(hda_nid_t));
4053 memcpy(spec->private_capsrc_nids, capsrc_nids,
4054 nums * sizeof(hda_nid_t));
4055 spec->num_adc_nids = nums;
4056 }
4057
4058 if (spec->auto_mic)
4059 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01004060 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004061 spec->num_adc_nids = 1; /* reduce to a single ADC */
4062}
4063
4064/*
4065 * initialize ADC paths
4066 */
4067static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
4068{
4069 struct alc_spec *spec = codec->spec;
4070 hda_nid_t nid;
4071
4072 nid = spec->adc_nids[adc_idx];
4073 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02004074 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004075 snd_hda_codec_write(codec, nid, 0,
4076 AC_VERB_SET_AMP_GAIN_MUTE,
4077 AMP_IN_MUTE(0));
4078 return;
4079 }
4080 if (!spec->capsrc_nids)
4081 return;
4082 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02004083 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004084 snd_hda_codec_write(codec, nid, 0,
4085 AC_VERB_SET_AMP_GAIN_MUTE,
4086 AMP_OUT_MUTE);
4087}
4088
4089static void alc_auto_init_input_src(struct hda_codec *codec)
4090{
4091 struct alc_spec *spec = codec->spec;
4092 int c, nums;
4093
4094 for (c = 0; c < spec->num_adc_nids; c++)
4095 alc_auto_init_adc(codec, c);
4096 if (spec->dyn_adc_switch)
4097 nums = 1;
4098 else
4099 nums = spec->num_adc_nids;
4100 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01004101 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004102}
4103
4104/* add mic boosts if needed */
4105static int alc_auto_add_mic_boost(struct hda_codec *codec)
4106{
4107 struct alc_spec *spec = codec->spec;
4108 struct auto_pin_cfg *cfg = &spec->autocfg;
4109 int i, err;
4110 int type_idx = 0;
4111 hda_nid_t nid;
4112 const char *prev_label = NULL;
4113
4114 for (i = 0; i < cfg->num_inputs; i++) {
4115 if (cfg->inputs[i].type > AUTO_PIN_MIC)
4116 break;
4117 nid = cfg->inputs[i].pin;
4118 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4119 const char *label;
4120 char boost_label[32];
4121
4122 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004123 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4124 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004125 if (prev_label && !strcmp(label, prev_label))
4126 type_idx++;
4127 else
4128 type_idx = 0;
4129 prev_label = label;
4130
4131 snprintf(boost_label, sizeof(boost_label),
4132 "%s Boost Volume", label);
4133 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4134 boost_label, type_idx,
4135 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4136 if (err < 0)
4137 return err;
4138 }
4139 }
4140 return 0;
4141}
4142
4143/* select or unmute the given capsrc route */
4144static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4145 int idx)
4146{
4147 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4148 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4149 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004150 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004151 snd_hda_codec_write_cache(codec, cap, 0,
4152 AC_VERB_SET_CONNECT_SEL, idx);
4153 }
4154}
4155
4156/* set the default connection to that pin */
4157static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4158{
4159 struct alc_spec *spec = codec->spec;
4160 int i;
4161
4162 if (!pin)
4163 return 0;
4164 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004165 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004166 int idx;
4167
4168 idx = get_connection_index(codec, cap, pin);
4169 if (idx < 0)
4170 continue;
4171 select_or_unmute_capsrc(codec, cap, idx);
4172 return i; /* return the found index */
4173 }
4174 return -1; /* not found */
4175}
4176
4177/* initialize some special cases for input sources */
4178static void alc_init_special_input_src(struct hda_codec *codec)
4179{
4180 struct alc_spec *spec = codec->spec;
4181 int i;
4182
4183 for (i = 0; i < spec->autocfg.num_inputs; i++)
4184 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4185}
4186
4187/* assign appropriate capture mixers */
4188static void set_capture_mixer(struct hda_codec *codec)
4189{
4190 struct alc_spec *spec = codec->spec;
4191 static const struct snd_kcontrol_new *caps[2][3] = {
4192 { alc_capture_mixer_nosrc1,
4193 alc_capture_mixer_nosrc2,
4194 alc_capture_mixer_nosrc3 },
4195 { alc_capture_mixer1,
4196 alc_capture_mixer2,
4197 alc_capture_mixer3 },
4198 };
4199
4200 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004201 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004202 if (!spec->capsrc_nids)
4203 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004204 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004205 return; /* no volume in capsrc, too */
4206 spec->vol_in_capsrc = 1;
4207 }
4208
4209 if (spec->num_adc_nids > 0) {
4210 int mux = 0;
4211 int num_adcs = 0;
4212
4213 if (spec->input_mux && spec->input_mux->num_items > 1)
4214 mux = 1;
4215 if (spec->auto_mic) {
4216 num_adcs = 1;
4217 mux = 0;
4218 } else if (spec->dyn_adc_switch)
4219 num_adcs = 1;
4220 if (!num_adcs) {
4221 if (spec->num_adc_nids > 3)
4222 spec->num_adc_nids = 3;
4223 else if (!spec->num_adc_nids)
4224 return;
4225 num_adcs = spec->num_adc_nids;
4226 }
4227 spec->cap_mixer = caps[mux][num_adcs - 1];
4228 }
4229}
4230
4231/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004232 * standard auto-parser initializations
4233 */
4234static void alc_auto_init_std(struct hda_codec *codec)
4235{
4236 struct alc_spec *spec = codec->spec;
4237 alc_auto_init_multi_out(codec);
4238 alc_auto_init_extra_out(codec);
4239 alc_auto_init_analog_input(codec);
4240 alc_auto_init_input_src(codec);
4241 alc_auto_init_digital(codec);
4242 if (spec->unsol_event)
4243 alc_inithook(codec);
4244}
4245
4246/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004247 * Digital-beep handlers
4248 */
4249#ifdef CONFIG_SND_HDA_INPUT_BEEP
4250#define set_beep_amp(spec, nid, idx, dir) \
4251 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4252
4253static const struct snd_pci_quirk beep_white_list[] = {
4254 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4255 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4256 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4257 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004258 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004259 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4260 {}
4261};
4262
4263static inline int has_cdefine_beep(struct hda_codec *codec)
4264{
4265 struct alc_spec *spec = codec->spec;
4266 const struct snd_pci_quirk *q;
4267 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4268 if (q)
4269 return q->value;
4270 return spec->cdefine.enable_pcbeep;
4271}
4272#else
4273#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4274#define has_cdefine_beep(codec) 0
4275#endif
4276
4277/* parse the BIOS configuration and set up the alc_spec */
4278/* return 1 if successful, 0 if the proper config is not found,
4279 * or a negative error code
4280 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004281static int alc_parse_auto_config(struct hda_codec *codec,
4282 const hda_nid_t *ignore_nids,
4283 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004284{
4285 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004286 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004287 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004288
Takashi Iwai53c334a2011-08-23 18:27:14 +02004289 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4290 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004291 if (err < 0)
4292 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004293 if (!cfg->line_outs) {
4294 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004295 spec->multiout.max_channels = 2;
4296 spec->no_analog = 1;
4297 goto dig_only;
4298 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004299 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004300 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004301
Takashi Iwai06503672011-10-06 08:27:19 +02004302 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4303 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004304 /* use HP as primary out */
4305 cfg->speaker_outs = cfg->line_outs;
4306 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4307 sizeof(cfg->speaker_pins));
4308 cfg->line_outs = cfg->hp_outs;
4309 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4310 cfg->hp_outs = 0;
4311 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4312 cfg->line_out_type = AUTO_PIN_HP_OUT;
4313 }
4314
Takashi Iwai1d045db2011-07-07 18:23:21 +02004315 err = alc_auto_fill_dac_nids(codec);
4316 if (err < 0)
4317 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004318 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004319 if (err < 0)
4320 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004321 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004322 if (err < 0)
4323 return err;
4324 err = alc_auto_create_hp_out(codec);
4325 if (err < 0)
4326 return err;
4327 err = alc_auto_create_speaker_out(codec);
4328 if (err < 0)
4329 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004330 err = alc_auto_create_shared_input(codec);
4331 if (err < 0)
4332 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004333 err = alc_auto_create_input_ctls(codec);
4334 if (err < 0)
4335 return err;
4336
4337 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4338
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004339 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004340 alc_auto_parse_digital(codec);
4341
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004342 if (!spec->no_analog)
4343 alc_remove_invalid_adc_nids(codec);
4344
4345 if (ssid_nids)
4346 alc_ssid_check(codec, ssid_nids);
4347
4348 if (!spec->no_analog) {
4349 alc_auto_check_switches(codec);
4350 err = alc_auto_add_mic_boost(codec);
4351 if (err < 0)
4352 return err;
4353 }
4354
Takashi Iwai1d045db2011-07-07 18:23:21 +02004355 if (spec->kctls.list)
4356 add_mixer(spec, spec->kctls.list);
4357
Takashi Iwai070cff42012-02-21 12:54:17 +01004358 if (!spec->no_analog && !spec->cap_mixer)
4359 set_capture_mixer(codec);
4360
Takashi Iwai1d045db2011-07-07 18:23:21 +02004361 return 1;
4362}
4363
Takashi Iwai3de95172012-05-07 18:03:15 +02004364/* common preparation job for alc_spec */
4365static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4366{
4367 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4368 int err;
4369
4370 if (!spec)
4371 return -ENOMEM;
4372 codec->spec = spec;
4373 spec->mixer_nid = mixer_nid;
4374
4375 err = alc_codec_rename_from_preset(codec);
4376 if (err < 0) {
4377 kfree(spec);
4378 return err;
4379 }
4380 return 0;
4381}
4382
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004383static int alc880_parse_auto_config(struct hda_codec *codec)
4384{
4385 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004386 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004387 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4388}
4389
Takashi Iwai1d045db2011-07-07 18:23:21 +02004390/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004391 * ALC880 fix-ups
4392 */
4393enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004394 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004395 ALC880_FIXUP_GPIO2,
4396 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004397 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004398 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004399 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004400 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004401 ALC880_FIXUP_VOL_KNOB,
4402 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004403 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004404 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004405 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004406 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004407 ALC880_FIXUP_3ST_BASE,
4408 ALC880_FIXUP_3ST,
4409 ALC880_FIXUP_3ST_DIG,
4410 ALC880_FIXUP_5ST_BASE,
4411 ALC880_FIXUP_5ST,
4412 ALC880_FIXUP_5ST_DIG,
4413 ALC880_FIXUP_6ST_BASE,
4414 ALC880_FIXUP_6ST,
4415 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004416};
4417
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004418/* enable the volume-knob widget support on NID 0x21 */
4419static void alc880_fixup_vol_knob(struct hda_codec *codec,
4420 const struct alc_fixup *fix, int action)
4421{
4422 if (action == ALC_FIXUP_ACT_PROBE)
4423 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4424}
4425
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004426static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004427 [ALC880_FIXUP_GPIO1] = {
4428 .type = ALC_FIXUP_VERBS,
4429 .v.verbs = alc_gpio1_init_verbs,
4430 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004431 [ALC880_FIXUP_GPIO2] = {
4432 .type = ALC_FIXUP_VERBS,
4433 .v.verbs = alc_gpio2_init_verbs,
4434 },
4435 [ALC880_FIXUP_MEDION_RIM] = {
4436 .type = ALC_FIXUP_VERBS,
4437 .v.verbs = (const struct hda_verb[]) {
4438 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4439 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4440 { }
4441 },
4442 .chained = true,
4443 .chain_id = ALC880_FIXUP_GPIO2,
4444 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004445 [ALC880_FIXUP_LG] = {
4446 .type = ALC_FIXUP_PINS,
4447 .v.pins = (const struct alc_pincfg[]) {
4448 /* disable bogus unused pins */
4449 { 0x16, 0x411111f0 },
4450 { 0x18, 0x411111f0 },
4451 { 0x1a, 0x411111f0 },
4452 { }
4453 }
4454 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004455 [ALC880_FIXUP_W810] = {
4456 .type = ALC_FIXUP_PINS,
4457 .v.pins = (const struct alc_pincfg[]) {
4458 /* disable bogus unused pins */
4459 { 0x17, 0x411111f0 },
4460 { }
4461 },
4462 .chained = true,
4463 .chain_id = ALC880_FIXUP_GPIO2,
4464 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004465 [ALC880_FIXUP_EAPD_COEF] = {
4466 .type = ALC_FIXUP_VERBS,
4467 .v.verbs = (const struct hda_verb[]) {
4468 /* change to EAPD mode */
4469 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4470 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4471 {}
4472 },
4473 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004474 [ALC880_FIXUP_TCL_S700] = {
4475 .type = ALC_FIXUP_VERBS,
4476 .v.verbs = (const struct hda_verb[]) {
4477 /* change to EAPD mode */
4478 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4479 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4480 {}
4481 },
4482 .chained = true,
4483 .chain_id = ALC880_FIXUP_GPIO2,
4484 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004485 [ALC880_FIXUP_VOL_KNOB] = {
4486 .type = ALC_FIXUP_FUNC,
4487 .v.func = alc880_fixup_vol_knob,
4488 },
4489 [ALC880_FIXUP_FUJITSU] = {
4490 /* override all pins as BIOS on old Amilo is broken */
4491 .type = ALC_FIXUP_PINS,
4492 .v.pins = (const struct alc_pincfg[]) {
4493 { 0x14, 0x0121411f }, /* HP */
4494 { 0x15, 0x99030120 }, /* speaker */
4495 { 0x16, 0x99030130 }, /* bass speaker */
4496 { 0x17, 0x411111f0 }, /* N/A */
4497 { 0x18, 0x411111f0 }, /* N/A */
4498 { 0x19, 0x01a19950 }, /* mic-in */
4499 { 0x1a, 0x411111f0 }, /* N/A */
4500 { 0x1b, 0x411111f0 }, /* N/A */
4501 { 0x1c, 0x411111f0 }, /* N/A */
4502 { 0x1d, 0x411111f0 }, /* N/A */
4503 { 0x1e, 0x01454140 }, /* SPDIF out */
4504 { }
4505 },
4506 .chained = true,
4507 .chain_id = ALC880_FIXUP_VOL_KNOB,
4508 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004509 [ALC880_FIXUP_F1734] = {
4510 /* almost compatible with FUJITSU, but no bass and SPDIF */
4511 .type = ALC_FIXUP_PINS,
4512 .v.pins = (const struct alc_pincfg[]) {
4513 { 0x14, 0x0121411f }, /* HP */
4514 { 0x15, 0x99030120 }, /* speaker */
4515 { 0x16, 0x411111f0 }, /* N/A */
4516 { 0x17, 0x411111f0 }, /* N/A */
4517 { 0x18, 0x411111f0 }, /* N/A */
4518 { 0x19, 0x01a19950 }, /* mic-in */
4519 { 0x1a, 0x411111f0 }, /* N/A */
4520 { 0x1b, 0x411111f0 }, /* N/A */
4521 { 0x1c, 0x411111f0 }, /* N/A */
4522 { 0x1d, 0x411111f0 }, /* N/A */
4523 { 0x1e, 0x411111f0 }, /* N/A */
4524 { }
4525 },
4526 .chained = true,
4527 .chain_id = ALC880_FIXUP_VOL_KNOB,
4528 },
Takashi Iwai817de922012-02-20 17:20:48 +01004529 [ALC880_FIXUP_UNIWILL] = {
4530 /* need to fix HP and speaker pins to be parsed correctly */
4531 .type = ALC_FIXUP_PINS,
4532 .v.pins = (const struct alc_pincfg[]) {
4533 { 0x14, 0x0121411f }, /* HP */
4534 { 0x15, 0x99030120 }, /* speaker */
4535 { 0x16, 0x99030130 }, /* bass speaker */
4536 { }
4537 },
4538 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004539 [ALC880_FIXUP_UNIWILL_DIG] = {
4540 .type = ALC_FIXUP_PINS,
4541 .v.pins = (const struct alc_pincfg[]) {
4542 /* disable bogus unused pins */
4543 { 0x17, 0x411111f0 },
4544 { 0x19, 0x411111f0 },
4545 { 0x1b, 0x411111f0 },
4546 { 0x1f, 0x411111f0 },
4547 { }
4548 }
4549 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004550 [ALC880_FIXUP_Z71V] = {
4551 .type = ALC_FIXUP_PINS,
4552 .v.pins = (const struct alc_pincfg[]) {
4553 /* set up the whole pins as BIOS is utterly broken */
4554 { 0x14, 0x99030120 }, /* speaker */
4555 { 0x15, 0x0121411f }, /* HP */
4556 { 0x16, 0x411111f0 }, /* N/A */
4557 { 0x17, 0x411111f0 }, /* N/A */
4558 { 0x18, 0x01a19950 }, /* mic-in */
4559 { 0x19, 0x411111f0 }, /* N/A */
4560 { 0x1a, 0x01813031 }, /* line-in */
4561 { 0x1b, 0x411111f0 }, /* N/A */
4562 { 0x1c, 0x411111f0 }, /* N/A */
4563 { 0x1d, 0x411111f0 }, /* N/A */
4564 { 0x1e, 0x0144111e }, /* SPDIF */
4565 { }
4566 }
4567 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004568 [ALC880_FIXUP_3ST_BASE] = {
4569 .type = ALC_FIXUP_PINS,
4570 .v.pins = (const struct alc_pincfg[]) {
4571 { 0x14, 0x01014010 }, /* line-out */
4572 { 0x15, 0x411111f0 }, /* N/A */
4573 { 0x16, 0x411111f0 }, /* N/A */
4574 { 0x17, 0x411111f0 }, /* N/A */
4575 { 0x18, 0x01a19c30 }, /* mic-in */
4576 { 0x19, 0x0121411f }, /* HP */
4577 { 0x1a, 0x01813031 }, /* line-in */
4578 { 0x1b, 0x02a19c40 }, /* front-mic */
4579 { 0x1c, 0x411111f0 }, /* N/A */
4580 { 0x1d, 0x411111f0 }, /* N/A */
4581 /* 0x1e is filled in below */
4582 { 0x1f, 0x411111f0 }, /* N/A */
4583 { }
4584 }
4585 },
4586 [ALC880_FIXUP_3ST] = {
4587 .type = ALC_FIXUP_PINS,
4588 .v.pins = (const struct alc_pincfg[]) {
4589 { 0x1e, 0x411111f0 }, /* N/A */
4590 { }
4591 },
4592 .chained = true,
4593 .chain_id = ALC880_FIXUP_3ST_BASE,
4594 },
4595 [ALC880_FIXUP_3ST_DIG] = {
4596 .type = ALC_FIXUP_PINS,
4597 .v.pins = (const struct alc_pincfg[]) {
4598 { 0x1e, 0x0144111e }, /* SPDIF */
4599 { }
4600 },
4601 .chained = true,
4602 .chain_id = ALC880_FIXUP_3ST_BASE,
4603 },
4604 [ALC880_FIXUP_5ST_BASE] = {
4605 .type = ALC_FIXUP_PINS,
4606 .v.pins = (const struct alc_pincfg[]) {
4607 { 0x14, 0x01014010 }, /* front */
4608 { 0x15, 0x411111f0 }, /* N/A */
4609 { 0x16, 0x01011411 }, /* CLFE */
4610 { 0x17, 0x01016412 }, /* surr */
4611 { 0x18, 0x01a19c30 }, /* mic-in */
4612 { 0x19, 0x0121411f }, /* HP */
4613 { 0x1a, 0x01813031 }, /* line-in */
4614 { 0x1b, 0x02a19c40 }, /* front-mic */
4615 { 0x1c, 0x411111f0 }, /* N/A */
4616 { 0x1d, 0x411111f0 }, /* N/A */
4617 /* 0x1e is filled in below */
4618 { 0x1f, 0x411111f0 }, /* N/A */
4619 { }
4620 }
4621 },
4622 [ALC880_FIXUP_5ST] = {
4623 .type = ALC_FIXUP_PINS,
4624 .v.pins = (const struct alc_pincfg[]) {
4625 { 0x1e, 0x411111f0 }, /* N/A */
4626 { }
4627 },
4628 .chained = true,
4629 .chain_id = ALC880_FIXUP_5ST_BASE,
4630 },
4631 [ALC880_FIXUP_5ST_DIG] = {
4632 .type = ALC_FIXUP_PINS,
4633 .v.pins = (const struct alc_pincfg[]) {
4634 { 0x1e, 0x0144111e }, /* SPDIF */
4635 { }
4636 },
4637 .chained = true,
4638 .chain_id = ALC880_FIXUP_5ST_BASE,
4639 },
4640 [ALC880_FIXUP_6ST_BASE] = {
4641 .type = ALC_FIXUP_PINS,
4642 .v.pins = (const struct alc_pincfg[]) {
4643 { 0x14, 0x01014010 }, /* front */
4644 { 0x15, 0x01016412 }, /* surr */
4645 { 0x16, 0x01011411 }, /* CLFE */
4646 { 0x17, 0x01012414 }, /* side */
4647 { 0x18, 0x01a19c30 }, /* mic-in */
4648 { 0x19, 0x02a19c40 }, /* front-mic */
4649 { 0x1a, 0x01813031 }, /* line-in */
4650 { 0x1b, 0x0121411f }, /* HP */
4651 { 0x1c, 0x411111f0 }, /* N/A */
4652 { 0x1d, 0x411111f0 }, /* N/A */
4653 /* 0x1e is filled in below */
4654 { 0x1f, 0x411111f0 }, /* N/A */
4655 { }
4656 }
4657 },
4658 [ALC880_FIXUP_6ST] = {
4659 .type = ALC_FIXUP_PINS,
4660 .v.pins = (const struct alc_pincfg[]) {
4661 { 0x1e, 0x411111f0 }, /* N/A */
4662 { }
4663 },
4664 .chained = true,
4665 .chain_id = ALC880_FIXUP_6ST_BASE,
4666 },
4667 [ALC880_FIXUP_6ST_DIG] = {
4668 .type = ALC_FIXUP_PINS,
4669 .v.pins = (const struct alc_pincfg[]) {
4670 { 0x1e, 0x0144111e }, /* SPDIF */
4671 { }
4672 },
4673 .chained = true,
4674 .chain_id = ALC880_FIXUP_6ST_BASE,
4675 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004676};
4677
4678static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004679 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004680 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004681 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4682 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004683 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004684 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004685 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004686 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004687 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004688 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004689 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004690 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004691 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004692 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004693 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004694 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4695 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4696 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004697 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004698
4699 /* Below is the copied entries from alc880_quirks.c.
4700 * It's not quite sure whether BIOS sets the correct pin-config table
4701 * on these machines, thus they are kept to be compatible with
4702 * the old static quirks. Once when it's confirmed to work without
4703 * these overrides, it'd be better to remove.
4704 */
4705 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4706 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4707 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4708 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4709 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4710 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4711 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4712 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4713 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4714 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4715 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4716 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4717 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4718 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4719 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4720 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4721 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4722 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4723 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4724 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4725 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4726 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4727 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4728 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4729 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4730 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4731 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4732 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4733 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4734 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4735 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4736 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4737 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4738 /* default Intel */
4739 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4740 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4741 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4742 {}
4743};
4744
4745static const struct alc_model_fixup alc880_fixup_models[] = {
4746 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4747 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4748 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4749 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4750 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4751 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004752 {}
4753};
4754
4755
4756/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004757 * OK, here we have finally the patch for ALC880
4758 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004759static int patch_alc880(struct hda_codec *codec)
4760{
4761 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004762 int err;
4763
Takashi Iwai3de95172012-05-07 18:03:15 +02004764 err = alc_alloc_spec(codec, 0x0b);
4765 if (err < 0)
4766 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004767
Takashi Iwai3de95172012-05-07 18:03:15 +02004768 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004769 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004770
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004771 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4772 alc880_fixups);
4773 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004774
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004775 /* automatic parse from the BIOS config */
4776 err = alc880_parse_auto_config(codec);
4777 if (err < 0)
4778 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004779
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004780 if (!spec->no_analog) {
4781 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004782 if (err < 0)
4783 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004784 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4785 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004786
Takashi Iwai1d045db2011-07-07 18:23:21 +02004787 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004788
Takashi Iwai589876e2012-02-20 15:47:55 +01004789 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4790
Takashi Iwai1d045db2011-07-07 18:23:21 +02004791 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004792
4793 error:
4794 alc_free(codec);
4795 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004796}
4797
4798
4799/*
4800 * ALC260 support
4801 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004802static int alc260_parse_auto_config(struct hda_codec *codec)
4803{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004804 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004805 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4806 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004807}
4808
Takashi Iwai1d045db2011-07-07 18:23:21 +02004809/*
4810 * Pin config fixes
4811 */
4812enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004813 ALC260_FIXUP_HP_DC5750,
4814 ALC260_FIXUP_HP_PIN_0F,
4815 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004816 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004817 ALC260_FIXUP_GPIO1_TOGGLE,
4818 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004819 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004820 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004821};
4822
Takashi Iwai20f7d922012-02-16 12:35:16 +01004823static void alc260_gpio1_automute(struct hda_codec *codec)
4824{
4825 struct alc_spec *spec = codec->spec;
4826 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4827 spec->hp_jack_present);
4828}
4829
4830static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4831 const struct alc_fixup *fix, int action)
4832{
4833 struct alc_spec *spec = codec->spec;
4834 if (action == ALC_FIXUP_ACT_PROBE) {
4835 /* although the machine has only one output pin, we need to
4836 * toggle GPIO1 according to the jack state
4837 */
4838 spec->automute_hook = alc260_gpio1_automute;
4839 spec->detect_hp = 1;
4840 spec->automute_speaker = 1;
4841 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4842 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4843 spec->unsol_event = alc_sku_unsol_event;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004844 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004845 }
4846}
4847
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004848static void alc260_fixup_kn1(struct hda_codec *codec,
4849 const struct alc_fixup *fix, int action)
4850{
4851 struct alc_spec *spec = codec->spec;
4852 static const struct alc_pincfg pincfgs[] = {
4853 { 0x0f, 0x02214000 }, /* HP/speaker */
4854 { 0x12, 0x90a60160 }, /* int mic */
4855 { 0x13, 0x02a19000 }, /* ext mic */
4856 { 0x18, 0x01446000 }, /* SPDIF out */
4857 /* disable bogus I/O pins */
4858 { 0x10, 0x411111f0 },
4859 { 0x11, 0x411111f0 },
4860 { 0x14, 0x411111f0 },
4861 { 0x15, 0x411111f0 },
4862 { 0x16, 0x411111f0 },
4863 { 0x17, 0x411111f0 },
4864 { 0x19, 0x411111f0 },
4865 { }
4866 };
4867
4868 switch (action) {
4869 case ALC_FIXUP_ACT_PRE_PROBE:
4870 alc_apply_pincfgs(codec, pincfgs);
4871 break;
4872 case ALC_FIXUP_ACT_PROBE:
4873 spec->init_amp = ALC_INIT_NONE;
4874 break;
4875 }
4876}
4877
Takashi Iwai1d045db2011-07-07 18:23:21 +02004878static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004879 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004880 .type = ALC_FIXUP_PINS,
4881 .v.pins = (const struct alc_pincfg[]) {
4882 { 0x11, 0x90130110 }, /* speaker */
4883 { }
4884 }
4885 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004886 [ALC260_FIXUP_HP_PIN_0F] = {
4887 .type = ALC_FIXUP_PINS,
4888 .v.pins = (const struct alc_pincfg[]) {
4889 { 0x0f, 0x01214000 }, /* HP */
4890 { }
4891 }
4892 },
4893 [ALC260_FIXUP_COEF] = {
4894 .type = ALC_FIXUP_VERBS,
4895 .v.verbs = (const struct hda_verb[]) {
4896 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4897 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4898 { }
4899 },
4900 .chained = true,
4901 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4902 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004903 [ALC260_FIXUP_GPIO1] = {
4904 .type = ALC_FIXUP_VERBS,
4905 .v.verbs = alc_gpio1_init_verbs,
4906 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004907 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4908 .type = ALC_FIXUP_FUNC,
4909 .v.func = alc260_fixup_gpio1_toggle,
4910 .chained = true,
4911 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4912 },
4913 [ALC260_FIXUP_REPLACER] = {
4914 .type = ALC_FIXUP_VERBS,
4915 .v.verbs = (const struct hda_verb[]) {
4916 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4917 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4918 { }
4919 },
4920 .chained = true,
4921 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4922 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004923 [ALC260_FIXUP_HP_B1900] = {
4924 .type = ALC_FIXUP_FUNC,
4925 .v.func = alc260_fixup_gpio1_toggle,
4926 .chained = true,
4927 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004928 },
4929 [ALC260_FIXUP_KN1] = {
4930 .type = ALC_FIXUP_FUNC,
4931 .v.func = alc260_fixup_kn1,
4932 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004933};
4934
4935static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004936 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004937 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004938 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004939 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004940 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004941 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004942 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004943 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004944 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004945 {}
4946};
4947
4948/*
4949 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004950static int patch_alc260(struct hda_codec *codec)
4951{
4952 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004953 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004954
Takashi Iwai3de95172012-05-07 18:03:15 +02004955 err = alc_alloc_spec(codec, 0x07);
4956 if (err < 0)
4957 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004958
Takashi Iwai3de95172012-05-07 18:03:15 +02004959 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004960
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004961 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4962 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004963
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004964 /* automatic parse from the BIOS config */
4965 err = alc260_parse_auto_config(codec);
4966 if (err < 0)
4967 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004968
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004969 if (!spec->no_analog) {
4970 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004971 if (err < 0)
4972 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004973 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4974 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004975
Takashi Iwai1d045db2011-07-07 18:23:21 +02004976 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004977 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004978
Takashi Iwai589876e2012-02-20 15:47:55 +01004979 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4980
Takashi Iwai1d045db2011-07-07 18:23:21 +02004981 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004982
4983 error:
4984 alc_free(codec);
4985 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004986}
4987
4988
4989/*
4990 * ALC882/883/885/888/889 support
4991 *
4992 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4993 * configuration. Each pin widget can choose any input DACs and a mixer.
4994 * Each ADC is connected from a mixer of all inputs. This makes possible
4995 * 6-channel independent captures.
4996 *
4997 * In addition, an independent DAC for the multi-playback (not used in this
4998 * driver yet).
4999 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005000
5001/*
5002 * Pin config fixes
5003 */
5004enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005005 ALC882_FIXUP_ABIT_AW9D_MAX,
5006 ALC882_FIXUP_LENOVO_Y530,
5007 ALC882_FIXUP_PB_M5210,
5008 ALC882_FIXUP_ACER_ASPIRE_7736,
5009 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01005010 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005011 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005012 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01005013 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005014 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005015 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005016 ALC882_FIXUP_GPIO1,
5017 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01005018 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01005019 ALC889_FIXUP_COEF,
5020 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005021 ALC882_FIXUP_ACER_ASPIRE_4930G,
5022 ALC882_FIXUP_ACER_ASPIRE_8930G,
5023 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01005024 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01005025 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005026 ALC889_FIXUP_MBP_VREF,
5027 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005028 ALC882_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005029};
5030
Takashi Iwai68ef0562011-11-09 18:24:44 +01005031static void alc889_fixup_coef(struct hda_codec *codec,
5032 const struct alc_fixup *fix, int action)
5033{
5034 if (action != ALC_FIXUP_ACT_INIT)
5035 return;
5036 alc889_coef_init(codec);
5037}
5038
Takashi Iwai56710872011-11-14 17:42:11 +01005039/* toggle speaker-output according to the hp-jack state */
5040static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
5041{
5042 unsigned int gpiostate, gpiomask, gpiodir;
5043
5044 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
5045 AC_VERB_GET_GPIO_DATA, 0);
5046
5047 if (!muted)
5048 gpiostate |= (1 << pin);
5049 else
5050 gpiostate &= ~(1 << pin);
5051
5052 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
5053 AC_VERB_GET_GPIO_MASK, 0);
5054 gpiomask |= (1 << pin);
5055
5056 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
5057 AC_VERB_GET_GPIO_DIRECTION, 0);
5058 gpiodir |= (1 << pin);
5059
5060
5061 snd_hda_codec_write(codec, codec->afg, 0,
5062 AC_VERB_SET_GPIO_MASK, gpiomask);
5063 snd_hda_codec_write(codec, codec->afg, 0,
5064 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
5065
5066 msleep(1);
5067
5068 snd_hda_codec_write(codec, codec->afg, 0,
5069 AC_VERB_SET_GPIO_DATA, gpiostate);
5070}
5071
5072/* set up GPIO at initialization */
5073static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
5074 const struct alc_fixup *fix, int action)
5075{
5076 if (action != ALC_FIXUP_ACT_INIT)
5077 return;
5078 alc882_gpio_mute(codec, 0, 0);
5079 alc882_gpio_mute(codec, 1, 0);
5080}
5081
Takashi Iwai02a237b2012-02-13 15:25:07 +01005082/* Fix the connection of some pins for ALC889:
5083 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
5084 * work correctly (bko#42740)
5085 */
5086static void alc889_fixup_dac_route(struct hda_codec *codec,
5087 const struct alc_fixup *fix, int action)
5088{
5089 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005090 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01005091 hda_nid_t conn1[2] = { 0x0c, 0x0d };
5092 hda_nid_t conn2[2] = { 0x0e, 0x0f };
5093 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
5094 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
5095 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
5096 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01005097 } else if (action == ALC_FIXUP_ACT_PROBE) {
5098 /* restore the connections */
5099 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
5100 snd_hda_override_conn_list(codec, 0x14, 5, conn);
5101 snd_hda_override_conn_list(codec, 0x15, 5, conn);
5102 snd_hda_override_conn_list(codec, 0x18, 5, conn);
5103 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01005104 }
5105}
5106
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005107/* Set VREF on HP pin */
5108static void alc889_fixup_mbp_vref(struct hda_codec *codec,
5109 const struct alc_fixup *fix, int action)
5110{
5111 struct alc_spec *spec = codec->spec;
5112 static hda_nid_t nids[2] = { 0x14, 0x15 };
5113 int i;
5114
5115 if (action != ALC_FIXUP_ACT_INIT)
5116 return;
5117 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5118 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
5119 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5120 continue;
5121 val = snd_hda_codec_read(codec, nids[i], 0,
5122 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5123 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005124 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005125 spec->keep_vref_in_automute = 1;
5126 break;
5127 }
5128}
5129
5130/* Set VREF on speaker pins on imac91 */
5131static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5132 const struct alc_fixup *fix, int action)
5133{
5134 struct alc_spec *spec = codec->spec;
5135 static hda_nid_t nids[2] = { 0x18, 0x1a };
5136 int i;
5137
5138 if (action != ALC_FIXUP_ACT_INIT)
5139 return;
5140 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5141 unsigned int val;
5142 val = snd_hda_codec_read(codec, nids[i], 0,
5143 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5144 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005145 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005146 }
5147 spec->keep_vref_in_automute = 1;
5148}
5149
Takashi Iwai1d045db2011-07-07 18:23:21 +02005150static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005151 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005152 .type = ALC_FIXUP_PINS,
5153 .v.pins = (const struct alc_pincfg[]) {
5154 { 0x15, 0x01080104 }, /* side */
5155 { 0x16, 0x01011012 }, /* rear */
5156 { 0x17, 0x01016011 }, /* clfe */
5157 { }
5158 }
5159 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005160 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005161 .type = ALC_FIXUP_PINS,
5162 .v.pins = (const struct alc_pincfg[]) {
5163 { 0x15, 0x99130112 }, /* rear int speakers */
5164 { 0x16, 0x99130111 }, /* subwoofer */
5165 { }
5166 }
5167 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005168 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005169 .type = ALC_FIXUP_VERBS,
5170 .v.verbs = (const struct hda_verb[]) {
5171 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5172 {}
5173 }
5174 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005175 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005176 .type = ALC_FIXUP_FUNC,
5177 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005178 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005179 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005180 .type = ALC_FIXUP_PINS,
5181 .v.pins = (const struct alc_pincfg[]) {
5182 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5183 { }
5184 }
5185 },
Marton Balint8f239212012-03-05 21:33:23 +01005186 [ALC889_FIXUP_CD] = {
5187 .type = ALC_FIXUP_PINS,
5188 .v.pins = (const struct alc_pincfg[]) {
5189 { 0x1c, 0x993301f0 }, /* CD */
5190 { }
5191 }
5192 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005193 [ALC889_FIXUP_VAIO_TT] = {
5194 .type = ALC_FIXUP_PINS,
5195 .v.pins = (const struct alc_pincfg[]) {
5196 { 0x17, 0x90170111 }, /* hidden surround speaker */
5197 { }
5198 }
5199 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005200 [ALC888_FIXUP_EEE1601] = {
5201 .type = ALC_FIXUP_VERBS,
5202 .v.verbs = (const struct hda_verb[]) {
5203 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5204 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5205 { }
5206 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005207 },
5208 [ALC882_FIXUP_EAPD] = {
5209 .type = ALC_FIXUP_VERBS,
5210 .v.verbs = (const struct hda_verb[]) {
5211 /* change to EAPD mode */
5212 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5213 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5214 { }
5215 }
5216 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005217 [ALC883_FIXUP_EAPD] = {
5218 .type = ALC_FIXUP_VERBS,
5219 .v.verbs = (const struct hda_verb[]) {
5220 /* change to EAPD mode */
5221 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5222 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5223 { }
5224 }
5225 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005226 [ALC883_FIXUP_ACER_EAPD] = {
5227 .type = ALC_FIXUP_VERBS,
5228 .v.verbs = (const struct hda_verb[]) {
5229 /* eanable EAPD on Acer laptops */
5230 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5231 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5232 { }
5233 }
5234 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005235 [ALC882_FIXUP_GPIO1] = {
5236 .type = ALC_FIXUP_VERBS,
5237 .v.verbs = alc_gpio1_init_verbs,
5238 },
5239 [ALC882_FIXUP_GPIO2] = {
5240 .type = ALC_FIXUP_VERBS,
5241 .v.verbs = alc_gpio2_init_verbs,
5242 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005243 [ALC882_FIXUP_GPIO3] = {
5244 .type = ALC_FIXUP_VERBS,
5245 .v.verbs = alc_gpio3_init_verbs,
5246 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005247 [ALC882_FIXUP_ASUS_W2JC] = {
5248 .type = ALC_FIXUP_VERBS,
5249 .v.verbs = alc_gpio1_init_verbs,
5250 .chained = true,
5251 .chain_id = ALC882_FIXUP_EAPD,
5252 },
5253 [ALC889_FIXUP_COEF] = {
5254 .type = ALC_FIXUP_FUNC,
5255 .v.func = alc889_fixup_coef,
5256 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005257 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5258 .type = ALC_FIXUP_PINS,
5259 .v.pins = (const struct alc_pincfg[]) {
5260 { 0x16, 0x99130111 }, /* CLFE speaker */
5261 { 0x17, 0x99130112 }, /* surround speaker */
5262 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005263 },
5264 .chained = true,
5265 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005266 },
5267 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5268 .type = ALC_FIXUP_PINS,
5269 .v.pins = (const struct alc_pincfg[]) {
5270 { 0x16, 0x99130111 }, /* CLFE speaker */
5271 { 0x1b, 0x99130112 }, /* surround speaker */
5272 { }
5273 },
5274 .chained = true,
5275 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5276 },
5277 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5278 /* additional init verbs for Acer Aspire 8930G */
5279 .type = ALC_FIXUP_VERBS,
5280 .v.verbs = (const struct hda_verb[]) {
5281 /* Enable all DACs */
5282 /* DAC DISABLE/MUTE 1? */
5283 /* setting bits 1-5 disables DAC nids 0x02-0x06
5284 * apparently. Init=0x38 */
5285 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5286 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5287 /* DAC DISABLE/MUTE 2? */
5288 /* some bit here disables the other DACs.
5289 * Init=0x4900 */
5290 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5291 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5292 /* DMIC fix
5293 * This laptop has a stereo digital microphone.
5294 * The mics are only 1cm apart which makes the stereo
5295 * useless. However, either the mic or the ALC889
5296 * makes the signal become a difference/sum signal
5297 * instead of standard stereo, which is annoying.
5298 * So instead we flip this bit which makes the
5299 * codec replicate the sum signal to both channels,
5300 * turning it into a normal mono mic.
5301 */
5302 /* DMIC_CONTROL? Init value = 0x0001 */
5303 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5304 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5305 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5306 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5307 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005308 },
5309 .chained = true,
5310 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005311 },
Takashi Iwai56710872011-11-14 17:42:11 +01005312 [ALC885_FIXUP_MACPRO_GPIO] = {
5313 .type = ALC_FIXUP_FUNC,
5314 .v.func = alc885_fixup_macpro_gpio,
5315 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005316 [ALC889_FIXUP_DAC_ROUTE] = {
5317 .type = ALC_FIXUP_FUNC,
5318 .v.func = alc889_fixup_dac_route,
5319 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005320 [ALC889_FIXUP_MBP_VREF] = {
5321 .type = ALC_FIXUP_FUNC,
5322 .v.func = alc889_fixup_mbp_vref,
5323 .chained = true,
5324 .chain_id = ALC882_FIXUP_GPIO1,
5325 },
5326 [ALC889_FIXUP_IMAC91_VREF] = {
5327 .type = ALC_FIXUP_FUNC,
5328 .v.func = alc889_fixup_imac91_vref,
5329 .chained = true,
5330 .chain_id = ALC882_FIXUP_GPIO1,
5331 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005332 [ALC882_FIXUP_INV_DMIC] = {
5333 .type = ALC_FIXUP_FUNC,
5334 .v.func = alc_fixup_inv_dmic_0x12,
5335 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005336};
5337
5338static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005339 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5340 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5341 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5342 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5343 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5344 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005345 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5346 ALC882_FIXUP_ACER_ASPIRE_4930G),
5347 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5348 ALC882_FIXUP_ACER_ASPIRE_4930G),
5349 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5350 ALC882_FIXUP_ACER_ASPIRE_8930G),
5351 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5352 ALC882_FIXUP_ACER_ASPIRE_8930G),
5353 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5354 ALC882_FIXUP_ACER_ASPIRE_4930G),
5355 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5356 ALC882_FIXUP_ACER_ASPIRE_4930G),
5357 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5358 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005359 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005360 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5361 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005362 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005363 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005364 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005365 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005366 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005367 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005368 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005369 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005370
5371 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005372 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5373 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5374 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005375 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5376 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5377 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005378 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5379 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005380 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005381 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5382 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5383 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5384 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005385 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005386 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5387 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5388 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005389 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005390 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5391 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5392 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005393
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005394 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005395 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005396 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005397 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005398 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005399 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5400 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005401 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005402 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005403 {}
5404};
5405
Takashi Iwai912093b2012-04-11 14:03:41 +02005406static const struct alc_model_fixup alc882_fixup_models[] = {
5407 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5408 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5409 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005410 {.id = ALC882_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwai912093b2012-04-11 14:03:41 +02005411 {}
5412};
5413
Takashi Iwai1d045db2011-07-07 18:23:21 +02005414/*
5415 * BIOS auto configuration
5416 */
5417/* almost identical with ALC880 parser... */
5418static int alc882_parse_auto_config(struct hda_codec *codec)
5419{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005420 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005421 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5422 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005423}
5424
Takashi Iwai1d045db2011-07-07 18:23:21 +02005425/*
5426 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005427static int patch_alc882(struct hda_codec *codec)
5428{
5429 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005430 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005431
Takashi Iwai3de95172012-05-07 18:03:15 +02005432 err = alc_alloc_spec(codec, 0x0b);
5433 if (err < 0)
5434 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005435
Takashi Iwai3de95172012-05-07 18:03:15 +02005436 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005437
5438 switch (codec->vendor_id) {
5439 case 0x10ec0882:
5440 case 0x10ec0885:
5441 break;
5442 default:
5443 /* ALC883 and variants */
5444 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5445 break;
5446 }
5447
Takashi Iwai912093b2012-04-11 14:03:41 +02005448 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5449 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005450 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451
5452 alc_auto_parse_customize_define(codec);
5453
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005454 /* automatic parse from the BIOS config */
5455 err = alc882_parse_auto_config(codec);
5456 if (err < 0)
5457 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005458
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005459 if (!spec->no_analog && has_cdefine_beep(codec)) {
5460 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005461 if (err < 0)
5462 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005463 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005464 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005465
Takashi Iwai1d045db2011-07-07 18:23:21 +02005466 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005467
Takashi Iwai589876e2012-02-20 15:47:55 +01005468 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5469
Takashi Iwai1d045db2011-07-07 18:23:21 +02005470 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005471
5472 error:
5473 alc_free(codec);
5474 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005475}
5476
5477
5478/*
5479 * ALC262 support
5480 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005481static int alc262_parse_auto_config(struct hda_codec *codec)
5482{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005483 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005484 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5485 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005486}
5487
5488/*
5489 * Pin config fixes
5490 */
5491enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005492 ALC262_FIXUP_FSC_H270,
5493 ALC262_FIXUP_HP_Z200,
5494 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005495 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005496 ALC262_FIXUP_BENQ,
5497 ALC262_FIXUP_BENQ_T31,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005498 ALC262_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005499};
5500
5501static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005502 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005503 .type = ALC_FIXUP_PINS,
5504 .v.pins = (const struct alc_pincfg[]) {
5505 { 0x14, 0x99130110 }, /* speaker */
5506 { 0x15, 0x0221142f }, /* front HP */
5507 { 0x1b, 0x0121141f }, /* rear HP */
5508 { }
5509 }
5510 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005511 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005512 .type = ALC_FIXUP_PINS,
5513 .v.pins = (const struct alc_pincfg[]) {
5514 { 0x16, 0x99130120 }, /* internal speaker */
5515 { }
5516 }
5517 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005518 [ALC262_FIXUP_TYAN] = {
5519 .type = ALC_FIXUP_PINS,
5520 .v.pins = (const struct alc_pincfg[]) {
5521 { 0x14, 0x1993e1f0 }, /* int AUX */
5522 { }
5523 }
5524 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005525 [ALC262_FIXUP_LENOVO_3000] = {
5526 .type = ALC_FIXUP_VERBS,
5527 .v.verbs = (const struct hda_verb[]) {
5528 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005529 {}
5530 },
5531 .chained = true,
5532 .chain_id = ALC262_FIXUP_BENQ,
5533 },
5534 [ALC262_FIXUP_BENQ] = {
5535 .type = ALC_FIXUP_VERBS,
5536 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005537 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5538 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5539 {}
5540 }
5541 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005542 [ALC262_FIXUP_BENQ_T31] = {
5543 .type = ALC_FIXUP_VERBS,
5544 .v.verbs = (const struct hda_verb[]) {
5545 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5546 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5547 {}
5548 }
5549 },
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005550 [ALC262_FIXUP_INV_DMIC] = {
5551 .type = ALC_FIXUP_FUNC,
5552 .v.func = alc_fixup_inv_dmic_0x12,
5553 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005554};
5555
5556static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005557 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005558 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5559 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005560 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5561 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005562 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005563 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5564 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005565 {}
5566};
5567
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005568static const struct alc_model_fixup alc262_fixup_models[] = {
5569 {.id = ALC262_FIXUP_INV_DMIC, .name = "inv-dmic"},
5570 {}
5571};
Takashi Iwai1d045db2011-07-07 18:23:21 +02005572
Takashi Iwai1d045db2011-07-07 18:23:21 +02005573/*
5574 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005575static int patch_alc262(struct hda_codec *codec)
5576{
5577 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005578 int err;
5579
Takashi Iwai3de95172012-05-07 18:03:15 +02005580 err = alc_alloc_spec(codec, 0x0b);
5581 if (err < 0)
5582 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005583
Takashi Iwai3de95172012-05-07 18:03:15 +02005584 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005585
5586#if 0
5587 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5588 * under-run
5589 */
5590 {
5591 int tmp;
5592 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5593 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5594 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5595 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5596 }
5597#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005598 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5599
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005600 alc_pick_fixup(codec, alc262_fixup_models, alc262_fixup_tbl,
5601 alc262_fixups);
Takashi Iwai42399f72011-11-07 17:18:44 +01005602 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005603
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005604 alc_auto_parse_customize_define(codec);
5605
Takashi Iwai42399f72011-11-07 17:18:44 +01005606 /* automatic parse from the BIOS config */
5607 err = alc262_parse_auto_config(codec);
5608 if (err < 0)
5609 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005610
Takashi Iwai1d045db2011-07-07 18:23:21 +02005611 if (!spec->no_analog && has_cdefine_beep(codec)) {
5612 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005613 if (err < 0)
5614 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005615 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005616 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005617
Takashi Iwai1d045db2011-07-07 18:23:21 +02005618 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005619 spec->shutup = alc_eapd_shutup;
5620
Takashi Iwai589876e2012-02-20 15:47:55 +01005621 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5622
Takashi Iwai1d045db2011-07-07 18:23:21 +02005623 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005624
5625 error:
5626 alc_free(codec);
5627 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005628}
5629
5630/*
5631 * ALC268
5632 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005633/* bind Beep switches of both NID 0x0f and 0x10 */
5634static const struct hda_bind_ctls alc268_bind_beep_sw = {
5635 .ops = &snd_hda_bind_sw,
5636 .values = {
5637 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5638 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5639 0
5640 },
5641};
5642
5643static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5644 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5645 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5646 { }
5647};
5648
5649/* set PCBEEP vol = 0, mute connections */
5650static const struct hda_verb alc268_beep_init_verbs[] = {
5651 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5652 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5653 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5654 { }
5655};
5656
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005657enum {
5658 ALC268_FIXUP_INV_DMIC,
5659};
5660
5661static const struct alc_fixup alc268_fixups[] = {
5662 [ALC268_FIXUP_INV_DMIC] = {
5663 .type = ALC_FIXUP_FUNC,
5664 .v.func = alc_fixup_inv_dmic_0x12,
5665 },
5666};
5667
5668static const struct alc_model_fixup alc268_fixup_models[] = {
5669 {.id = ALC268_FIXUP_INV_DMIC, .name = "inv-dmic"},
5670 {}
5671};
5672
Takashi Iwai1d045db2011-07-07 18:23:21 +02005673/*
5674 * BIOS auto configuration
5675 */
5676static int alc268_parse_auto_config(struct hda_codec *codec)
5677{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005678 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005679 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005680 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5681 if (err > 0) {
5682 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5683 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005684 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005685 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005686 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005687 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005688}
5689
Takashi Iwai1d045db2011-07-07 18:23:21 +02005690/*
5691 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005692static int patch_alc268(struct hda_codec *codec)
5693{
5694 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005695 int i, has_beep, err;
5696
Takashi Iwai1d045db2011-07-07 18:23:21 +02005697 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005698 err = alc_alloc_spec(codec, 0);
5699 if (err < 0)
5700 return err;
5701
5702 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005703
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005704 alc_pick_fixup(codec, alc268_fixup_models, NULL, alc268_fixups);
5705 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5706
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005707 /* automatic parse from the BIOS config */
5708 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005709 if (err < 0)
5710 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005711
Takashi Iwai1d045db2011-07-07 18:23:21 +02005712 has_beep = 0;
5713 for (i = 0; i < spec->num_mixers; i++) {
5714 if (spec->mixers[i] == alc268_beep_mixer) {
5715 has_beep = 1;
5716 break;
5717 }
5718 }
5719
5720 if (has_beep) {
5721 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005722 if (err < 0)
5723 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005724 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5725 /* override the amp caps for beep generator */
5726 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5727 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5728 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5729 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5730 (0 << AC_AMPCAP_MUTE_SHIFT));
5731 }
5732
Takashi Iwai1d045db2011-07-07 18:23:21 +02005733 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005734 spec->shutup = alc_eapd_shutup;
5735
Takashi Iwai6e72aa52012-06-25 10:52:25 +02005736 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5737
Takashi Iwai1d045db2011-07-07 18:23:21 +02005738 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005739
5740 error:
5741 alc_free(codec);
5742 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005743}
5744
5745/*
5746 * ALC269
5747 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005748static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5749 .substreams = 1,
5750 .channels_min = 2,
5751 .channels_max = 8,
5752 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5753 /* NID is set in alc_build_pcms */
5754 .ops = {
5755 .open = alc_playback_pcm_open,
5756 .prepare = alc_playback_pcm_prepare,
5757 .cleanup = alc_playback_pcm_cleanup
5758 },
5759};
5760
5761static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5762 .substreams = 1,
5763 .channels_min = 2,
5764 .channels_max = 2,
5765 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5766 /* NID is set in alc_build_pcms */
5767};
5768
Takashi Iwai1d045db2011-07-07 18:23:21 +02005769/* different alc269-variants */
5770enum {
5771 ALC269_TYPE_ALC269VA,
5772 ALC269_TYPE_ALC269VB,
5773 ALC269_TYPE_ALC269VC,
Kailang Yangadcc70b2012-05-25 08:08:38 +02005774 ALC269_TYPE_ALC269VD,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005775};
5776
5777/*
5778 * BIOS auto configuration
5779 */
5780static int alc269_parse_auto_config(struct hda_codec *codec)
5781{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005782 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005783 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5784 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5785 struct alc_spec *spec = codec->spec;
Kailang Yangadcc70b2012-05-25 08:08:38 +02005786 const hda_nid_t *ssids;
5787
5788 switch (spec->codec_variant) {
5789 case ALC269_TYPE_ALC269VA:
5790 case ALC269_TYPE_ALC269VC:
5791 ssids = alc269va_ssids;
5792 break;
5793 case ALC269_TYPE_ALC269VB:
5794 case ALC269_TYPE_ALC269VD:
5795 ssids = alc269_ssids;
5796 break;
5797 default:
5798 ssids = alc269_ssids;
5799 break;
5800 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005801
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005802 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005803}
5804
Takashi Iwai1d045db2011-07-07 18:23:21 +02005805static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5806{
5807 int val = alc_read_coef_idx(codec, 0x04);
5808 if (power_up)
5809 val |= 1 << 11;
5810 else
5811 val &= ~(1 << 11);
5812 alc_write_coef_idx(codec, 0x04, val);
5813}
5814
5815static void alc269_shutup(struct hda_codec *codec)
5816{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005817 struct alc_spec *spec = codec->spec;
5818
5819 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
5820 return;
5821
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005822 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005823 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005824 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005825 alc269_toggle_power_output(codec, 0);
5826 msleep(150);
5827 }
5828}
5829
Takashi Iwai2a439522011-07-26 09:52:50 +02005830#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005831static int alc269_resume(struct hda_codec *codec)
5832{
Kailang Yangadcc70b2012-05-25 08:08:38 +02005833 struct alc_spec *spec = codec->spec;
5834
5835 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5836 (alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005837 alc269_toggle_power_output(codec, 0);
5838 msleep(150);
5839 }
5840
5841 codec->patch_ops.init(codec);
5842
Kailang Yangadcc70b2012-05-25 08:08:38 +02005843 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5844 (alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005845 alc269_toggle_power_output(codec, 1);
5846 msleep(200);
5847 }
5848
Kailang Yangadcc70b2012-05-25 08:08:38 +02005849 if (spec->codec_variant == ALC269_TYPE_ALC269VB ||
5850 (alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005851 alc269_toggle_power_output(codec, 1);
5852
5853 snd_hda_codec_resume_amp(codec);
5854 snd_hda_codec_resume_cache(codec);
5855 hda_call_check_power_status(codec, 0x01);
5856 return 0;
5857}
Takashi Iwai2a439522011-07-26 09:52:50 +02005858#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005859
5860static void alc269_fixup_hweq(struct hda_codec *codec,
5861 const struct alc_fixup *fix, int action)
5862{
5863 int coef;
5864
5865 if (action != ALC_FIXUP_ACT_INIT)
5866 return;
5867 coef = alc_read_coef_idx(codec, 0x1e);
5868 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5869}
5870
5871static void alc271_fixup_dmic(struct hda_codec *codec,
5872 const struct alc_fixup *fix, int action)
5873{
5874 static const struct hda_verb verbs[] = {
5875 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5876 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5877 {}
5878 };
5879 unsigned int cfg;
5880
5881 if (strcmp(codec->chip_name, "ALC271X"))
5882 return;
5883 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5884 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5885 snd_hda_sequence_write(codec, verbs);
5886}
5887
Takashi Iwai017f2a12011-07-09 14:42:25 +02005888static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5889 const struct alc_fixup *fix, int action)
5890{
5891 struct alc_spec *spec = codec->spec;
5892
5893 if (action != ALC_FIXUP_ACT_PROBE)
5894 return;
5895
5896 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5897 * fix the sample rate of analog I/O to 44.1kHz
5898 */
5899 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5900 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5901}
5902
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005903static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5904 const struct alc_fixup *fix, int action)
5905{
5906 int coef;
5907
5908 if (action != ALC_FIXUP_ACT_INIT)
5909 return;
5910 /* The digital-mic unit sends PDM (differential signal) instead of
5911 * the standard PCM, thus you can't record a valid mono stream as is.
5912 * Below is a workaround specific to ALC269 to control the dmic
5913 * signal source as mono.
5914 */
5915 coef = alc_read_coef_idx(codec, 0x07);
5916 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5917}
5918
Takashi Iwai24519912011-08-16 15:08:49 +02005919static void alc269_quanta_automute(struct hda_codec *codec)
5920{
David Henningsson42cf0d02011-09-20 12:04:56 +02005921 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005922
5923 snd_hda_codec_write(codec, 0x20, 0,
5924 AC_VERB_SET_COEF_INDEX, 0x0c);
5925 snd_hda_codec_write(codec, 0x20, 0,
5926 AC_VERB_SET_PROC_COEF, 0x680);
5927
5928 snd_hda_codec_write(codec, 0x20, 0,
5929 AC_VERB_SET_COEF_INDEX, 0x0c);
5930 snd_hda_codec_write(codec, 0x20, 0,
5931 AC_VERB_SET_PROC_COEF, 0x480);
5932}
5933
5934static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5935 const struct alc_fixup *fix, int action)
5936{
5937 struct alc_spec *spec = codec->spec;
5938 if (action != ALC_FIXUP_ACT_PROBE)
5939 return;
5940 spec->automute_hook = alc269_quanta_automute;
5941}
5942
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005943/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5944static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5945{
5946 struct hda_codec *codec = private_data;
5947 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005948 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005949}
5950
5951static void alc269_fixup_mic2_mute(struct hda_codec *codec,
5952 const struct alc_fixup *fix, int action)
5953{
5954 struct alc_spec *spec = codec->spec;
5955 switch (action) {
5956 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005957 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01005958 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005959 /* fallthru */
5960 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005961 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005962 break;
5963 }
5964}
5965
David Henningsson693b6132012-06-22 19:12:10 +02005966
Takashi Iwai1d045db2011-07-07 18:23:21 +02005967enum {
5968 ALC269_FIXUP_SONY_VAIO,
5969 ALC275_FIXUP_SONY_VAIO_GPIO2,
5970 ALC269_FIXUP_DELL_M101Z,
5971 ALC269_FIXUP_SKU_IGNORE,
5972 ALC269_FIXUP_ASUS_G73JW,
5973 ALC269_FIXUP_LENOVO_EAPD,
5974 ALC275_FIXUP_SONY_HWEQ,
5975 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005976 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005977 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005978 ALC269_FIXUP_QUANTA_MUTE,
5979 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005980 ALC269_FIXUP_AMIC,
5981 ALC269_FIXUP_DMIC,
5982 ALC269VB_FIXUP_AMIC,
5983 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005984 ALC269_FIXUP_MIC2_MUTE_LED,
David Henningsson693b6132012-06-22 19:12:10 +02005985 ALC269_FIXUP_INV_DMIC,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005986};
5987
5988static const struct alc_fixup alc269_fixups[] = {
5989 [ALC269_FIXUP_SONY_VAIO] = {
5990 .type = ALC_FIXUP_VERBS,
5991 .v.verbs = (const struct hda_verb[]) {
5992 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5993 {}
5994 }
5995 },
5996 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5997 .type = ALC_FIXUP_VERBS,
5998 .v.verbs = (const struct hda_verb[]) {
5999 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
6000 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
6001 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
6002 { }
6003 },
6004 .chained = true,
6005 .chain_id = ALC269_FIXUP_SONY_VAIO
6006 },
6007 [ALC269_FIXUP_DELL_M101Z] = {
6008 .type = ALC_FIXUP_VERBS,
6009 .v.verbs = (const struct hda_verb[]) {
6010 /* Enables internal speaker */
6011 {0x20, AC_VERB_SET_COEF_INDEX, 13},
6012 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
6013 {}
6014 }
6015 },
6016 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006017 .type = ALC_FIXUP_FUNC,
6018 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006019 },
6020 [ALC269_FIXUP_ASUS_G73JW] = {
6021 .type = ALC_FIXUP_PINS,
6022 .v.pins = (const struct alc_pincfg[]) {
6023 { 0x17, 0x99130111 }, /* subwoofer */
6024 { }
6025 }
6026 },
6027 [ALC269_FIXUP_LENOVO_EAPD] = {
6028 .type = ALC_FIXUP_VERBS,
6029 .v.verbs = (const struct hda_verb[]) {
6030 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6031 {}
6032 }
6033 },
6034 [ALC275_FIXUP_SONY_HWEQ] = {
6035 .type = ALC_FIXUP_FUNC,
6036 .v.func = alc269_fixup_hweq,
6037 .chained = true,
6038 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
6039 },
6040 [ALC271_FIXUP_DMIC] = {
6041 .type = ALC_FIXUP_FUNC,
6042 .v.func = alc271_fixup_dmic,
6043 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02006044 [ALC269_FIXUP_PCM_44K] = {
6045 .type = ALC_FIXUP_FUNC,
6046 .v.func = alc269_fixup_pcm_44k,
6047 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006048 [ALC269_FIXUP_STEREO_DMIC] = {
6049 .type = ALC_FIXUP_FUNC,
6050 .v.func = alc269_fixup_stereo_dmic,
6051 },
Takashi Iwai24519912011-08-16 15:08:49 +02006052 [ALC269_FIXUP_QUANTA_MUTE] = {
6053 .type = ALC_FIXUP_FUNC,
6054 .v.func = alc269_fixup_quanta_mute,
6055 },
6056 [ALC269_FIXUP_LIFEBOOK] = {
6057 .type = ALC_FIXUP_PINS,
6058 .v.pins = (const struct alc_pincfg[]) {
6059 { 0x1a, 0x2101103f }, /* dock line-out */
6060 { 0x1b, 0x23a11040 }, /* dock mic-in */
6061 { }
6062 },
6063 .chained = true,
6064 .chain_id = ALC269_FIXUP_QUANTA_MUTE
6065 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02006066 [ALC269_FIXUP_AMIC] = {
6067 .type = ALC_FIXUP_PINS,
6068 .v.pins = (const struct alc_pincfg[]) {
6069 { 0x14, 0x99130110 }, /* speaker */
6070 { 0x15, 0x0121401f }, /* HP out */
6071 { 0x18, 0x01a19c20 }, /* mic */
6072 { 0x19, 0x99a3092f }, /* int-mic */
6073 { }
6074 },
6075 },
6076 [ALC269_FIXUP_DMIC] = {
6077 .type = ALC_FIXUP_PINS,
6078 .v.pins = (const struct alc_pincfg[]) {
6079 { 0x12, 0x99a3092f }, /* int-mic */
6080 { 0x14, 0x99130110 }, /* speaker */
6081 { 0x15, 0x0121401f }, /* HP out */
6082 { 0x18, 0x01a19c20 }, /* mic */
6083 { }
6084 },
6085 },
6086 [ALC269VB_FIXUP_AMIC] = {
6087 .type = ALC_FIXUP_PINS,
6088 .v.pins = (const struct alc_pincfg[]) {
6089 { 0x14, 0x99130110 }, /* speaker */
6090 { 0x18, 0x01a19c20 }, /* mic */
6091 { 0x19, 0x99a3092f }, /* int-mic */
6092 { 0x21, 0x0121401f }, /* HP out */
6093 { }
6094 },
6095 },
David Henningsson2267ea92012-01-03 08:45:56 +01006096 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02006097 .type = ALC_FIXUP_PINS,
6098 .v.pins = (const struct alc_pincfg[]) {
6099 { 0x12, 0x99a3092f }, /* int-mic */
6100 { 0x14, 0x99130110 }, /* speaker */
6101 { 0x18, 0x01a19c20 }, /* mic */
6102 { 0x21, 0x0121401f }, /* HP out */
6103 { }
6104 },
6105 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006106 [ALC269_FIXUP_MIC2_MUTE_LED] = {
6107 .type = ALC_FIXUP_FUNC,
6108 .v.func = alc269_fixup_mic2_mute,
6109 },
David Henningsson693b6132012-06-22 19:12:10 +02006110 [ALC269_FIXUP_INV_DMIC] = {
6111 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006112 .v.func = alc_fixup_inv_dmic_0x12,
David Henningsson693b6132012-06-22 19:12:10 +02006113 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006114};
6115
6116static const struct snd_pci_quirk alc269_fixup_tbl[] = {
David Henningsson693b6132012-06-22 19:12:10 +02006117 SND_PCI_QUIRK(0x1025, 0x029b, "Acer 1810TZ", ALC269_FIXUP_INV_DMIC),
6118 SND_PCI_QUIRK(0x1025, 0x0349, "Acer AOD260", ALC269_FIXUP_INV_DMIC),
Takashi Iwai420b0fe2012-03-12 12:35:27 +01006119 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02006120 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006121 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
David Henningsson693b6132012-06-22 19:12:10 +02006122 SND_PCI_QUIRK(0x1043, 0x1b13, "Asus U41SV", ALC269_FIXUP_INV_DMIC),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02006123 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
6124 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
6125 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
6126 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
6127 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006128 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
6129 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6130 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
6131 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
6132 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
6133 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02006134 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006135 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
6136 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
6137 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
6138 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
6139 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02006140 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02006141 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006142 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006143
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01006144#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02006145 /* Below is a quirk table taken from the old code.
6146 * Basically the device should work as is without the fixup table.
6147 * If BIOS doesn't give a proper info, enable the corresponding
6148 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006149 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02006150 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
6151 ALC269_FIXUP_AMIC),
6152 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02006153 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
6154 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
6155 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
6156 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
6157 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
6158 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
6159 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
6160 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
6161 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
6162 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
6163 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
6164 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
6165 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
6166 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
6167 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
6168 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
6169 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
6170 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
6171 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
6172 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
6173 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
6174 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
6175 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
6176 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
6177 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
6178 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
6179 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
6180 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
6181 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
6182 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
6183 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
6184 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
6185 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
6186 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
6187 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
6188 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6189 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6190 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6191#endif
6192 {}
6193};
6194
6195static const struct alc_model_fixup alc269_fixup_models[] = {
6196 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6197 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006198 {.id = ALC269_FIXUP_STEREO_DMIC, .name = "alc269-dmic"},
6199 {.id = ALC271_FIXUP_DMIC, .name = "alc271-dmic"},
6200 {.id = ALC269_FIXUP_INV_DMIC, .name = "inv-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006201 {}
6202};
6203
6204
Takashi Iwai546bb672012-03-07 08:37:19 +01006205static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006206{
Kailang Yang526af6e2012-03-07 08:25:20 +01006207 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006208 int val;
6209
Kailang Yang526af6e2012-03-07 08:25:20 +01006210 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006211 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006212
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006213 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006214 alc_write_coef_idx(codec, 0xf, 0x960b);
6215 alc_write_coef_idx(codec, 0xe, 0x8817);
6216 }
6217
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006218 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006219 alc_write_coef_idx(codec, 0xf, 0x960b);
6220 alc_write_coef_idx(codec, 0xe, 0x8814);
6221 }
6222
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006223 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006224 val = alc_read_coef_idx(codec, 0x04);
6225 /* Power up output pin */
6226 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6227 }
6228
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006229 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006230 val = alc_read_coef_idx(codec, 0xd);
6231 if ((val & 0x0c00) >> 10 != 0x1) {
6232 /* Capless ramp up clock control */
6233 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6234 }
6235 val = alc_read_coef_idx(codec, 0x17);
6236 if ((val & 0x01c0) >> 6 != 0x4) {
6237 /* Class D power on reset */
6238 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6239 }
6240 }
6241
6242 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6243 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6244
6245 val = alc_read_coef_idx(codec, 0x4); /* HP */
6246 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006247}
6248
6249/*
6250 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006251static int patch_alc269(struct hda_codec *codec)
6252{
6253 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006254 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006255
Takashi Iwai3de95172012-05-07 18:03:15 +02006256 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006257 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006258 return err;
6259
6260 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006261
Takashi Iwai1d045db2011-07-07 18:23:21 +02006262 if (codec->vendor_id == 0x10ec0269) {
6263 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006264 switch (alc_get_coef0(codec) & 0x00f0) {
6265 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006266 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006267 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006268 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006269 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006270 break;
6271 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006272 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6273 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006274 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006275 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006276 break;
Kailang Yangadcc70b2012-05-25 08:08:38 +02006277 case 0x0030:
6278 spec->codec_variant = ALC269_TYPE_ALC269VD;
6279 break;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006280 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006281 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006282 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006283 if (err < 0)
6284 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006285 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006286 alc269_fill_coef(codec);
6287 }
6288
Takashi Iwaia4297b52011-08-23 18:40:12 +02006289 alc_pick_fixup(codec, alc269_fixup_models,
6290 alc269_fixup_tbl, alc269_fixups);
6291 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006292
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006293 alc_auto_parse_customize_define(codec);
6294
Takashi Iwaia4297b52011-08-23 18:40:12 +02006295 /* automatic parse from the BIOS config */
6296 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006297 if (err < 0)
6298 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006300 if (!spec->no_analog && has_cdefine_beep(codec)) {
6301 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006302 if (err < 0)
6303 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006304 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006305 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006306
Takashi Iwai1d045db2011-07-07 18:23:21 +02006307 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006308#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006309 codec->patch_ops.resume = alc269_resume;
6310#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006311 spec->shutup = alc269_shutup;
6312
Takashi Iwai589876e2012-02-20 15:47:55 +01006313 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6314
Takashi Iwai1d045db2011-07-07 18:23:21 +02006315 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006316
6317 error:
6318 alc_free(codec);
6319 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006320}
6321
6322/*
6323 * ALC861
6324 */
6325
Takashi Iwai1d045db2011-07-07 18:23:21 +02006326static int alc861_parse_auto_config(struct hda_codec *codec)
6327{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006328 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006329 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6330 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006331}
6332
Takashi Iwai1d045db2011-07-07 18:23:21 +02006333/* Pin config fixes */
6334enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006335 ALC861_FIXUP_FSC_AMILO_PI1505,
6336 ALC861_FIXUP_AMP_VREF_0F,
6337 ALC861_FIXUP_NO_JACK_DETECT,
6338 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006339};
6340
Takashi Iwai31150f22012-01-30 10:54:08 +01006341/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6342static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6343 const struct alc_fixup *fix, int action)
6344{
6345 struct alc_spec *spec = codec->spec;
6346 unsigned int val;
6347
6348 if (action != ALC_FIXUP_ACT_INIT)
6349 return;
6350 val = snd_hda_codec_read(codec, 0x0f, 0,
6351 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6352 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6353 val |= AC_PINCTL_IN_EN;
6354 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006355 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006356 spec->keep_vref_in_automute = 1;
6357}
6358
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006359/* suppress the jack-detection */
6360static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6361 const struct alc_fixup *fix, int action)
6362{
6363 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6364 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006365}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006366
Takashi Iwai1d045db2011-07-07 18:23:21 +02006367static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006368 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006369 .type = ALC_FIXUP_PINS,
6370 .v.pins = (const struct alc_pincfg[]) {
6371 { 0x0b, 0x0221101f }, /* HP */
6372 { 0x0f, 0x90170310 }, /* speaker */
6373 { }
6374 }
6375 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006376 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006377 .type = ALC_FIXUP_FUNC,
6378 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006379 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006380 [ALC861_FIXUP_NO_JACK_DETECT] = {
6381 .type = ALC_FIXUP_FUNC,
6382 .v.func = alc_fixup_no_jack_detect,
6383 },
6384 [ALC861_FIXUP_ASUS_A6RP] = {
6385 .type = ALC_FIXUP_FUNC,
6386 .v.func = alc861_fixup_asus_amp_vref_0f,
6387 .chained = true,
6388 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6389 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006390};
6391
6392static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006393 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6394 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6395 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6396 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6397 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6398 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006399 {}
6400};
6401
6402/*
6403 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006404static int patch_alc861(struct hda_codec *codec)
6405{
6406 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006407 int err;
6408
Takashi Iwai3de95172012-05-07 18:03:15 +02006409 err = alc_alloc_spec(codec, 0x15);
6410 if (err < 0)
6411 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006412
Takashi Iwai3de95172012-05-07 18:03:15 +02006413 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006414
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006415 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6416 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006417
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006418 /* automatic parse from the BIOS config */
6419 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006420 if (err < 0)
6421 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006422
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006423 if (!spec->no_analog) {
6424 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006425 if (err < 0)
6426 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006427 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6428 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006429
Takashi Iwai1d045db2011-07-07 18:23:21 +02006430 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006431#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006432 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006433#endif
6434
Takashi Iwai589876e2012-02-20 15:47:55 +01006435 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6436
Takashi Iwai1d045db2011-07-07 18:23:21 +02006437 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006438
6439 error:
6440 alc_free(codec);
6441 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006442}
6443
6444/*
6445 * ALC861-VD support
6446 *
6447 * Based on ALC882
6448 *
6449 * In addition, an independent DAC
6450 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006451static int alc861vd_parse_auto_config(struct hda_codec *codec)
6452{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006453 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006454 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6455 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006456}
6457
Takashi Iwai1d045db2011-07-07 18:23:21 +02006458enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006459 ALC660VD_FIX_ASUS_GPIO1,
6460 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006461};
6462
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006463/* exclude VREF80 */
6464static void alc861vd_fixup_dallas(struct hda_codec *codec,
6465 const struct alc_fixup *fix, int action)
6466{
6467 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6468 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6469 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6470 }
6471}
6472
Takashi Iwai1d045db2011-07-07 18:23:21 +02006473static const struct alc_fixup alc861vd_fixups[] = {
6474 [ALC660VD_FIX_ASUS_GPIO1] = {
6475 .type = ALC_FIXUP_VERBS,
6476 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006477 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006478 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6479 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6480 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6481 { }
6482 }
6483 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006484 [ALC861VD_FIX_DALLAS] = {
6485 .type = ALC_FIXUP_FUNC,
6486 .v.func = alc861vd_fixup_dallas,
6487 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006488};
6489
6490static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006491 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006492 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006493 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006494 {}
6495};
6496
6497static const struct hda_verb alc660vd_eapd_verbs[] = {
6498 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6499 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6500 { }
6501};
6502
6503/*
6504 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006505static int patch_alc861vd(struct hda_codec *codec)
6506{
6507 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006508 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006509
Takashi Iwai3de95172012-05-07 18:03:15 +02006510 err = alc_alloc_spec(codec, 0x0b);
6511 if (err < 0)
6512 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006513
Takashi Iwai3de95172012-05-07 18:03:15 +02006514 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006515
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006516 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6517 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006518
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006519 /* automatic parse from the BIOS config */
6520 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006521 if (err < 0)
6522 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006523
Takashi Iwai1d045db2011-07-07 18:23:21 +02006524 if (codec->vendor_id == 0x10ec0660) {
6525 /* always turn on EAPD */
Takashi Iwai23d30f22012-05-07 17:17:32 +02006526 snd_hda_gen_add_verbs(&spec->gen, alc660vd_eapd_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006527 }
6528
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006529 if (!spec->no_analog) {
6530 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006531 if (err < 0)
6532 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006533 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6534 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006535
Takashi Iwai1d045db2011-07-07 18:23:21 +02006536 codec->patch_ops = alc_patch_ops;
6537
Takashi Iwai1d045db2011-07-07 18:23:21 +02006538 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006539
Takashi Iwai589876e2012-02-20 15:47:55 +01006540 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6541
Takashi Iwai1d045db2011-07-07 18:23:21 +02006542 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006543
6544 error:
6545 alc_free(codec);
6546 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006547}
6548
6549/*
6550 * ALC662 support
6551 *
6552 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6553 * configuration. Each pin widget can choose any input DACs and a mixer.
6554 * Each ADC is connected from a mixer of all inputs. This makes possible
6555 * 6-channel independent captures.
6556 *
6557 * In addition, an independent DAC for the multi-playback (not used in this
6558 * driver yet).
6559 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006560
6561/*
6562 * BIOS auto configuration
6563 */
6564
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006565static int alc662_parse_auto_config(struct hda_codec *codec)
6566{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006567 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006568 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6569 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6570 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006571
Kailang Yang6227cdc2010-02-25 08:36:52 +01006572 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6573 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006574 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006575 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006576 ssids = alc662_ssids;
6577 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006578}
6579
Todd Broch6be79482010-12-07 16:51:05 -08006580static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006581 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006582{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006583 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006584 return;
Todd Broch6be79482010-12-07 16:51:05 -08006585 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6586 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6587 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6588 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6589 (0 << AC_AMPCAP_MUTE_SHIFT)))
6590 printk(KERN_WARNING
6591 "hda_codec: failed to override amp caps for NID 0x2\n");
6592}
6593
David Henningsson6cb3b702010-09-09 08:51:44 +02006594enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006595 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006596 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006597 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006598 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006599 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006600 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006601 ALC662_FIXUP_ASUS_MODE1,
6602 ALC662_FIXUP_ASUS_MODE2,
6603 ALC662_FIXUP_ASUS_MODE3,
6604 ALC662_FIXUP_ASUS_MODE4,
6605 ALC662_FIXUP_ASUS_MODE5,
6606 ALC662_FIXUP_ASUS_MODE6,
6607 ALC662_FIXUP_ASUS_MODE7,
6608 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006609 ALC662_FIXUP_NO_JACK_DETECT,
David Henningssonedfe3bf2012-06-12 13:15:12 +02006610 ALC662_FIXUP_ZOTAC_Z68,
Takashi Iwai125821a2012-06-22 14:30:29 +02006611 ALC662_FIXUP_INV_DMIC,
David Henningsson6cb3b702010-09-09 08:51:44 +02006612};
6613
6614static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006615 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006616 .type = ALC_FIXUP_PINS,
6617 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006618 { 0x15, 0x99130112 }, /* subwoofer */
6619 { }
6620 }
6621 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006622 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006623 .type = ALC_FIXUP_PINS,
6624 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006625 { 0x17, 0x99130112 }, /* subwoofer */
6626 { }
6627 }
6628 },
Todd Broch6be79482010-12-07 16:51:05 -08006629 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006630 .type = ALC_FIXUP_FUNC,
6631 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006632 },
6633 [ALC662_FIXUP_CZC_P10T] = {
6634 .type = ALC_FIXUP_VERBS,
6635 .v.verbs = (const struct hda_verb[]) {
6636 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6637 {}
6638 }
6639 },
David Henningsson94024cd2011-04-29 14:10:55 +02006640 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006641 .type = ALC_FIXUP_FUNC,
6642 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006643 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006644 [ALC662_FIXUP_HP_RP5800] = {
6645 .type = ALC_FIXUP_PINS,
6646 .v.pins = (const struct alc_pincfg[]) {
6647 { 0x14, 0x0221201f }, /* HP out */
6648 { }
6649 },
6650 .chained = true,
6651 .chain_id = ALC662_FIXUP_SKU_IGNORE
6652 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006653 [ALC662_FIXUP_ASUS_MODE1] = {
6654 .type = ALC_FIXUP_PINS,
6655 .v.pins = (const struct alc_pincfg[]) {
6656 { 0x14, 0x99130110 }, /* speaker */
6657 { 0x18, 0x01a19c20 }, /* mic */
6658 { 0x19, 0x99a3092f }, /* int-mic */
6659 { 0x21, 0x0121401f }, /* HP out */
6660 { }
6661 },
6662 .chained = true,
6663 .chain_id = ALC662_FIXUP_SKU_IGNORE
6664 },
6665 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006666 .type = ALC_FIXUP_PINS,
6667 .v.pins = (const struct alc_pincfg[]) {
6668 { 0x14, 0x99130110 }, /* speaker */
6669 { 0x18, 0x01a19820 }, /* mic */
6670 { 0x19, 0x99a3092f }, /* int-mic */
6671 { 0x1b, 0x0121401f }, /* HP out */
6672 { }
6673 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006674 .chained = true,
6675 .chain_id = ALC662_FIXUP_SKU_IGNORE
6676 },
6677 [ALC662_FIXUP_ASUS_MODE3] = {
6678 .type = ALC_FIXUP_PINS,
6679 .v.pins = (const struct alc_pincfg[]) {
6680 { 0x14, 0x99130110 }, /* speaker */
6681 { 0x15, 0x0121441f }, /* HP */
6682 { 0x18, 0x01a19840 }, /* mic */
6683 { 0x19, 0x99a3094f }, /* int-mic */
6684 { 0x21, 0x01211420 }, /* HP2 */
6685 { }
6686 },
6687 .chained = true,
6688 .chain_id = ALC662_FIXUP_SKU_IGNORE
6689 },
6690 [ALC662_FIXUP_ASUS_MODE4] = {
6691 .type = ALC_FIXUP_PINS,
6692 .v.pins = (const struct alc_pincfg[]) {
6693 { 0x14, 0x99130110 }, /* speaker */
6694 { 0x16, 0x99130111 }, /* speaker */
6695 { 0x18, 0x01a19840 }, /* mic */
6696 { 0x19, 0x99a3094f }, /* int-mic */
6697 { 0x21, 0x0121441f }, /* HP */
6698 { }
6699 },
6700 .chained = true,
6701 .chain_id = ALC662_FIXUP_SKU_IGNORE
6702 },
6703 [ALC662_FIXUP_ASUS_MODE5] = {
6704 .type = ALC_FIXUP_PINS,
6705 .v.pins = (const struct alc_pincfg[]) {
6706 { 0x14, 0x99130110 }, /* speaker */
6707 { 0x15, 0x0121441f }, /* HP */
6708 { 0x16, 0x99130111 }, /* speaker */
6709 { 0x18, 0x01a19840 }, /* mic */
6710 { 0x19, 0x99a3094f }, /* int-mic */
6711 { }
6712 },
6713 .chained = true,
6714 .chain_id = ALC662_FIXUP_SKU_IGNORE
6715 },
6716 [ALC662_FIXUP_ASUS_MODE6] = {
6717 .type = ALC_FIXUP_PINS,
6718 .v.pins = (const struct alc_pincfg[]) {
6719 { 0x14, 0x99130110 }, /* speaker */
6720 { 0x15, 0x01211420 }, /* HP2 */
6721 { 0x18, 0x01a19840 }, /* mic */
6722 { 0x19, 0x99a3094f }, /* int-mic */
6723 { 0x1b, 0x0121441f }, /* HP */
6724 { }
6725 },
6726 .chained = true,
6727 .chain_id = ALC662_FIXUP_SKU_IGNORE
6728 },
6729 [ALC662_FIXUP_ASUS_MODE7] = {
6730 .type = ALC_FIXUP_PINS,
6731 .v.pins = (const struct alc_pincfg[]) {
6732 { 0x14, 0x99130110 }, /* speaker */
6733 { 0x17, 0x99130111 }, /* speaker */
6734 { 0x18, 0x01a19840 }, /* mic */
6735 { 0x19, 0x99a3094f }, /* int-mic */
6736 { 0x1b, 0x01214020 }, /* HP */
6737 { 0x21, 0x0121401f }, /* HP */
6738 { }
6739 },
6740 .chained = true,
6741 .chain_id = ALC662_FIXUP_SKU_IGNORE
6742 },
6743 [ALC662_FIXUP_ASUS_MODE8] = {
6744 .type = ALC_FIXUP_PINS,
6745 .v.pins = (const struct alc_pincfg[]) {
6746 { 0x14, 0x99130110 }, /* speaker */
6747 { 0x12, 0x99a30970 }, /* int-mic */
6748 { 0x15, 0x01214020 }, /* HP */
6749 { 0x17, 0x99130111 }, /* speaker */
6750 { 0x18, 0x01a19840 }, /* mic */
6751 { 0x21, 0x0121401f }, /* HP */
6752 { }
6753 },
6754 .chained = true,
6755 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006756 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006757 [ALC662_FIXUP_NO_JACK_DETECT] = {
6758 .type = ALC_FIXUP_FUNC,
6759 .v.func = alc_fixup_no_jack_detect,
6760 },
David Henningssonedfe3bf2012-06-12 13:15:12 +02006761 [ALC662_FIXUP_ZOTAC_Z68] = {
6762 .type = ALC_FIXUP_PINS,
6763 .v.pins = (const struct alc_pincfg[]) {
6764 { 0x1b, 0x02214020 }, /* Front HP */
6765 { }
6766 }
6767 },
Takashi Iwai125821a2012-06-22 14:30:29 +02006768 [ALC662_FIXUP_INV_DMIC] = {
6769 .type = ALC_FIXUP_FUNC,
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006770 .v.func = alc_fixup_inv_dmic_0x12,
Takashi Iwai125821a2012-06-22 14:30:29 +02006771 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006772};
6773
Takashi Iwaia9111322011-05-02 11:30:18 +02006774static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006775 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006776 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006777 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Takashi Iwai125821a2012-06-22 14:30:29 +02006778 SND_PCI_QUIRK(0x1025, 0x0349, "eMachines eM250", ALC662_FIXUP_INV_DMIC),
Daniel T Chen2df03512010-10-10 22:39:28 -04006779 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006780 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006781 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006782 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006783 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006784 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006785 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
David Henningssonedfe3bf2012-06-12 13:15:12 +02006786 SND_PCI_QUIRK(0x19da, 0xa130, "Zotac Z68", ALC662_FIXUP_ZOTAC_Z68),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006787 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006788
6789#if 0
6790 /* Below is a quirk table taken from the old code.
6791 * Basically the device should work as is without the fixup table.
6792 * If BIOS doesn't give a proper info, enable the corresponding
6793 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006794 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006795 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6796 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6797 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6798 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6799 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6800 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6801 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6802 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6803 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6804 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6805 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6806 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6807 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6808 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6809 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6810 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6811 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6812 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6813 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6814 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6815 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6816 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6817 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6818 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6819 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6820 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6821 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6822 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6823 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6824 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6825 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6826 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6827 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6828 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6829 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6830 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6831 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6832 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6833 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6834 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6835 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6836 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6837 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6838 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6839 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6840 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6841 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6842 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6843 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6844 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6845#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006846 {}
6847};
6848
Todd Broch6be79482010-12-07 16:51:05 -08006849static const struct alc_model_fixup alc662_fixup_models[] = {
6850 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006851 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6852 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6853 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6854 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6855 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6856 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6857 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6858 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Takashi Iwai6e72aa52012-06-25 10:52:25 +02006859 {.id = ALC662_FIXUP_INV_DMIC, .name = "inv-dmic"},
Todd Broch6be79482010-12-07 16:51:05 -08006860 {}
6861};
David Henningsson6cb3b702010-09-09 08:51:44 +02006862
6863
Takashi Iwai1d045db2011-07-07 18:23:21 +02006864/*
6865 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006866static int patch_alc662(struct hda_codec *codec)
6867{
6868 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006869 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006870
Takashi Iwai3de95172012-05-07 18:03:15 +02006871 err = alc_alloc_spec(codec, 0x0b);
6872 if (err < 0)
6873 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006874
Takashi Iwai3de95172012-05-07 18:03:15 +02006875 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006876
Takashi Iwai53c334a2011-08-23 18:27:14 +02006877 /* handle multiple HPs as is */
6878 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6879
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006880 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6881
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006882 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006883 codec->bus->pci->subsystem_vendor == 0x1025 &&
6884 spec->cdefine.platform_type == 1) {
6885 if (alc_codec_rename(codec, "ALC272X") < 0)
6886 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006887 }
Kailang Yang274693f2009-12-03 10:07:50 +01006888
Takashi Iwaib9c51062011-08-24 18:08:07 +02006889 alc_pick_fixup(codec, alc662_fixup_models,
6890 alc662_fixup_tbl, alc662_fixups);
6891 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006892
6893 alc_auto_parse_customize_define(codec);
6894
Takashi Iwaib9c51062011-08-24 18:08:07 +02006895 /* automatic parse from the BIOS config */
6896 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006897 if (err < 0)
6898 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006899
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006900 if (!spec->no_analog && has_cdefine_beep(codec)) {
6901 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006902 if (err < 0)
6903 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006904 switch (codec->vendor_id) {
6905 case 0x10ec0662:
6906 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6907 break;
6908 case 0x10ec0272:
6909 case 0x10ec0663:
6910 case 0x10ec0665:
6911 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6912 break;
6913 case 0x10ec0273:
6914 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6915 break;
6916 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006917 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006918
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006919 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02006920 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006921
Takashi Iwai589876e2012-02-20 15:47:55 +01006922 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6923
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006924 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006925
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006926 error:
6927 alc_free(codec);
6928 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006929}
6930
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006931/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006932 * ALC680 support
6933 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006934
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006935static int alc680_parse_auto_config(struct hda_codec *codec)
6936{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006937 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006938}
6939
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006940/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006941 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006942static int patch_alc680(struct hda_codec *codec)
6943{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006944 int err;
6945
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006946 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006947 err = alc_alloc_spec(codec, 0);
6948 if (err < 0)
6949 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006950
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006951 /* automatic parse from the BIOS config */
6952 err = alc680_parse_auto_config(codec);
6953 if (err < 0) {
6954 alc_free(codec);
6955 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006956 }
6957
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006958 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006959
6960 return 0;
6961}
6962
6963/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006964 * patch entries
6965 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006966static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006967 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006968 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006969 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006970 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006971 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006972 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006973 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006974 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006975 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006976 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006977 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006978 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006979 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6980 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6981 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006982 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006983 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006984 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6985 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006986 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6987 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006988 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006989 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006990 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006991 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006992 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006993 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006994 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006995 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006996 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006997 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006998 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006999 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007000 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02007001 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02007002 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007003 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02007004 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01007005 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02007006 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07007007 {} /* terminator */
7008};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01007009
7010MODULE_ALIAS("snd-hda-codec-id:10ec*");
7011
7012MODULE_LICENSE("GPL");
7013MODULE_DESCRIPTION("Realtek HD-audio codec");
7014
7015static struct hda_codec_preset_list realtek_list = {
7016 .preset = snd_hda_preset_realtek,
7017 .owner = THIS_MODULE,
7018};
7019
7020static int __init patch_realtek_init(void)
7021{
7022 return snd_hda_add_codec_preset(&realtek_list);
7023}
7024
7025static void __exit patch_realtek_exit(void)
7026{
7027 snd_hda_delete_codec_preset(&realtek_list);
7028}
7029
7030module_init(patch_realtek_init)
7031module_exit(patch_realtek_exit)