blob: 0d68bb0ff376877d51270034eac1d85713ed6bff [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Universal Interface for Intel High Definition Audio Codec
3 *
Takashi Iwai1d045db2011-07-07 18:23:21 +02004 * HD audio interface patch for Realtek ALC codecs
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
Kailang Yangdf694da2005-12-05 19:42:22 +01006 * Copyright (c) 2004 Kailang Yang <kailang@realtek.com.tw>
7 * PeiSen Hou <pshou@realtek.com.tw>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 * Takashi Iwai <tiwai@suse.de>
Jonathan Woithe7cf51e42006-02-09 12:01:26 +01009 * Jonathan Woithe <jwoithe@physics.adelaide.edu.au>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This driver is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This driver is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include <linux/init.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/pci.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040030#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <sound/core.h>
Kailang Yang9ad0e492010-09-14 23:22:00 +020032#include <sound/jack.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include "hda_codec.h"
34#include "hda_local.h"
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 Iwai834be882006-03-01 14:16:17 +0100173
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100174 /* hooks */
175 void (*init_hook)(struct hda_codec *codec);
176 void (*unsol_event)(struct hda_codec *codec, unsigned int res);
Hector Martinf5de24b2009-12-20 22:51:31 +0100177#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -0500178 void (*power_hook)(struct hda_codec *codec);
Hector Martinf5de24b2009-12-20 22:51:31 +0100179#endif
Takashi Iwai1c716152011-04-07 10:37:16 +0200180 void (*shutup)(struct hda_codec *codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200181 void (*automute_hook)(struct hda_codec *codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +0100182
Takashi Iwai834be882006-03-01 14:16:17 +0100183 /* for pin sensing */
David Henningsson42cf0d02011-09-20 12:04:56 +0200184 unsigned int hp_jack_present:1;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200185 unsigned int line_jack_present:1;
Takashi Iwaie9427962011-04-28 15:46:07 +0200186 unsigned int master_mute:1;
Takashi Iwai6c819492009-08-10 18:47:44 +0200187 unsigned int auto_mic:1;
Takashi Iwai21268962011-07-07 15:01:13 +0200188 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
David Henningsson42cf0d02011-09-20 12:04:56 +0200189 unsigned int automute_speaker:1; /* automute speaker outputs */
190 unsigned int automute_lo:1; /* automute LO outputs */
191 unsigned int detect_hp:1; /* Headphone detection enabled */
192 unsigned int detect_lo:1; /* Line-out detection enabled */
193 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
194 unsigned int automute_lo_possible:1; /* there are line outs and HP */
Takashi Iwai31150f22012-01-30 10:54:08 +0100195 unsigned int keep_vref_in_automute:1; /* Don't clear VREF in automute */
Takashi Iwaicb53c622007-08-10 17:21:45 +0200196
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100197 /* other flags */
198 unsigned int no_analog :1; /* digital I/O only */
Takashi Iwai21268962011-07-07 15:01:13 +0200199 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
Takashi Iwai584c0c42011-03-10 12:51:11 +0100200 unsigned int single_input_src:1;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +0200201 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
Takashi Iwai53c334a2011-08-23 18:27:14 +0200202 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
Takashi Iwai24de1832011-11-07 17:13:39 +0100203 unsigned int shared_mic_hp:1; /* HP/Mic-in sharing */
Takashi Iwaid922b512011-04-28 12:18:53 +0200204
205 /* auto-mute control */
206 int automute_mode;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200207 hda_nid_t automute_mixer_nid[AUTO_CFG_MAX_OUTS];
Takashi Iwaid922b512011-04-28 12:18:53 +0200208
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200209 int init_amp;
Takashi Iwaid433a672010-09-20 15:11:54 +0200210 int codec_variant; /* flag for other variants */
Takashi Iwaie64f14f2009-01-20 18:32:55 +0100211
Takashi Iwai2134ea42008-01-10 16:53:55 +0100212 /* for virtual master */
213 hda_nid_t vmaster_nid;
Takashi Iwaid2f344b2012-03-12 16:59:58 +0100214 struct hda_vmaster_mute_hook vmaster_mute;
Takashi Iwaicb53c622007-08-10 17:21:45 +0200215#ifdef CONFIG_SND_HDA_POWER_SAVE
216 struct hda_loopback_check loopback;
Takashi Iwai164f73e2012-02-21 11:27:09 +0100217 int num_loopbacks;
218 struct hda_amp_list loopback_list[8];
Takashi Iwaicb53c622007-08-10 17:21:45 +0200219#endif
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200220
221 /* for PLL fix */
222 hda_nid_t pll_nid;
223 unsigned int pll_coef_idx, pll_coef_bit;
Takashi Iwai1bb7e432011-10-17 16:50:59 +0200224 unsigned int coef0;
Takashi Iwaib5bfbc62011-01-13 14:22:32 +0100225
Takashi Iwaice764ab2011-04-27 16:35:23 +0200226 /* multi-io */
227 int multi_ios;
228 struct alc_multi_io multi_io[4];
Takashi Iwai23c09b02011-08-19 09:05:35 +0200229
230 /* bind volumes */
231 struct snd_array bind_ctls;
Kailang Yangdf694da2005-12-05 19:42:22 +0100232};
233
Takashi Iwai44c02402011-07-08 15:14:19 +0200234static bool check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
235 int dir, unsigned int bits)
236{
237 if (!nid)
238 return false;
239 if (get_wcaps(codec, nid) & (1 << (dir + 1)))
240 if (query_amp_caps(codec, nid, dir) & bits)
241 return true;
242 return false;
243}
244
245#define nid_has_mute(codec, nid, dir) \
246 check_amp_caps(codec, nid, dir, AC_AMPCAP_MUTE)
247#define nid_has_volume(codec, nid, dir) \
248 check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
249
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250/*
251 * input MUX handling
252 */
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200253static int alc_mux_enum_info(struct snd_kcontrol *kcontrol,
254 struct snd_ctl_elem_info *uinfo)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
256 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
257 struct alc_spec *spec = codec->spec;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200258 unsigned int mux_idx = snd_ctl_get_ioffidx(kcontrol, &uinfo->id);
259 if (mux_idx >= spec->num_mux_defs)
260 mux_idx = 0;
Takashi Iwai53111142010-03-08 12:13:07 +0100261 if (!spec->input_mux[mux_idx].num_items && mux_idx > 0)
262 mux_idx = 0;
Jonathan Woithea1e8d2d2006-03-28 12:47:09 +0200263 return snd_hda_input_mux_info(&spec->input_mux[mux_idx], uinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264}
265
Takashi Iwai9c7f8522006-06-28 15:08:22 +0200266static int alc_mux_enum_get(struct snd_kcontrol *kcontrol,
267 struct snd_ctl_elem_value *ucontrol)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268{
269 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
270 struct alc_spec *spec = codec->spec;
271 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
272
273 ucontrol->value.enumerated.item[0] = spec->cur_mux[adc_idx];
274 return 0;
275}
276
Takashi Iwai21268962011-07-07 15:01:13 +0200277static bool alc_dyn_adc_pcm_resetup(struct hda_codec *codec, int cur)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278{
Takashi Iwai21268962011-07-07 15:01:13 +0200279 struct alc_spec *spec = codec->spec;
280 hda_nid_t new_adc = spec->adc_nids[spec->dyn_adc_idx[cur]];
281
282 if (spec->cur_adc && spec->cur_adc != new_adc) {
283 /* stream is running, let's swap the current ADC */
284 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
285 spec->cur_adc = new_adc;
286 snd_hda_codec_setup_stream(codec, new_adc,
287 spec->cur_adc_stream_tag, 0,
288 spec->cur_adc_format);
289 return true;
290 }
291 return false;
292}
293
Takashi Iwai61071592011-11-23 07:52:15 +0100294static inline hda_nid_t get_capsrc(struct alc_spec *spec, int idx)
295{
296 return spec->capsrc_nids ?
297 spec->capsrc_nids[idx] : spec->adc_nids[idx];
298}
299
Takashi Iwai24de1832011-11-07 17:13:39 +0100300static void call_update_outputs(struct hda_codec *codec);
301
Takashi Iwai21268962011-07-07 15:01:13 +0200302/* select the given imux item; either unmute exclusively or select the route */
303static int alc_mux_select(struct hda_codec *codec, unsigned int adc_idx,
304 unsigned int idx, bool force)
305{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 struct alc_spec *spec = codec->spec;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100307 const struct hda_input_mux *imux;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100308 unsigned int mux_idx;
Takashi Iwaidccc1812011-11-08 07:52:19 +0100309 int i, type, num_conns;
Takashi Iwai21268962011-07-07 15:01:13 +0200310 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Takashi Iwai5803a322012-02-21 11:59:45 +0100312 if (!spec->input_mux)
313 return 0;
314
Takashi Iwaicd896c32008-11-18 12:36:33 +0100315 mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
316 imux = &spec->input_mux[mux_idx];
Takashi Iwai53111142010-03-08 12:13:07 +0100317 if (!imux->num_items && mux_idx > 0)
318 imux = &spec->input_mux[0];
Takashi Iwaicce4aa32011-12-02 15:29:12 +0100319 if (!imux->num_items)
320 return 0;
Takashi Iwaicd896c32008-11-18 12:36:33 +0100321
Takashi Iwai21268962011-07-07 15:01:13 +0200322 if (idx >= imux->num_items)
323 idx = imux->num_items - 1;
324 if (spec->cur_mux[adc_idx] == idx && !force)
325 return 0;
326 spec->cur_mux[adc_idx] = idx;
327
Takashi Iwai24de1832011-11-07 17:13:39 +0100328 /* for shared I/O, change the pin-control accordingly */
329 if (spec->shared_mic_hp) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200330 unsigned int val;
331 hda_nid_t pin = spec->autocfg.inputs[1].pin;
Takashi Iwai24de1832011-11-07 17:13:39 +0100332 /* NOTE: this assumes that there are only two inputs, the
333 * first is the real internal mic and the second is HP jack.
334 */
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200335 if (spec->cur_mux[adc_idx])
Takashi Iwai47408602012-04-20 13:06:53 +0200336 val = snd_hda_get_default_vref(codec, pin) | PIN_IN;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200337 else
338 val = PIN_HP;
339 snd_hda_set_pin_ctl(codec, pin, val);
Takashi Iwai24de1832011-11-07 17:13:39 +0100340 spec->automute_speaker = !spec->cur_mux[adc_idx];
341 call_update_outputs(codec);
342 }
343
Takashi Iwai21268962011-07-07 15:01:13 +0200344 if (spec->dyn_adc_switch) {
345 alc_dyn_adc_pcm_resetup(codec, idx);
346 adc_idx = spec->dyn_adc_idx[idx];
347 }
348
Takashi Iwai61071592011-11-23 07:52:15 +0100349 nid = get_capsrc(spec, adc_idx);
Takashi Iwai21268962011-07-07 15:01:13 +0200350
351 /* no selection? */
Takashi Iwai09cf03b2012-05-19 17:21:25 +0200352 num_conns = snd_hda_get_num_conns(codec, nid);
Takashi Iwaidccc1812011-11-08 07:52:19 +0100353 if (num_conns <= 1)
Takashi Iwai21268962011-07-07 15:01:13 +0200354 return 1;
355
Takashi Iwaia22d5432009-07-27 12:54:26 +0200356 type = get_wcaps_type(get_wcaps(codec, nid));
Takashi Iwai0169b6b2009-06-22 10:50:19 +0200357 if (type == AC_WID_AUD_MIX) {
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100358 /* Matrix-mixer style (e.g. ALC882) */
Takashi Iwaidccc1812011-11-08 07:52:19 +0100359 int active = imux->items[idx].index;
360 for (i = 0; i < num_conns; i++) {
361 unsigned int v = (i == active) ? 0 : HDA_AMP_MUTE;
362 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, i,
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100363 HDA_AMP_MUTE, v);
364 }
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100365 } else {
366 /* MUX style (e.g. ALC880) */
Takashi Iwai21268962011-07-07 15:01:13 +0200367 snd_hda_codec_write_cache(codec, nid, 0,
368 AC_VERB_SET_CONNECT_SEL,
369 imux->items[idx].index);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100370 }
Takashi Iwai21268962011-07-07 15:01:13 +0200371 return 1;
372}
373
374static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
375 struct snd_ctl_elem_value *ucontrol)
376{
377 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
378 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
379 return alc_mux_select(codec, adc_idx,
380 ucontrol->value.enumerated.item[0], false);
Takashi Iwai54cbc9a2008-10-31 15:24:04 +0100381}
Takashi Iwaie9edcee2005-06-13 14:16:38 +0200382
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383/*
Takashi Iwai23f0c042009-02-26 13:03:58 +0100384 * set up the input pin config (depending on the given auto-pin type)
385 */
386static void alc_set_input_pin(struct hda_codec *codec, hda_nid_t nid,
387 int auto_pin_type)
388{
389 unsigned int val = PIN_IN;
Takashi Iwai47408602012-04-20 13:06:53 +0200390 if (auto_pin_type == AUTO_PIN_MIC)
391 val |= snd_hda_get_default_vref(codec, nid);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200392 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai23f0c042009-02-26 13:03:58 +0100393}
394
395/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200396 * Append the given mixer and verb elements for the later use
397 * The mixer array is referred in build_controls(), and init_verbs are
398 * called in init().
Takashi Iwaid88897e2008-10-31 15:01:37 +0100399 */
Takashi Iwaia9111322011-05-02 11:30:18 +0200400static void add_mixer(struct alc_spec *spec, const struct snd_kcontrol_new *mix)
Takashi Iwaid88897e2008-10-31 15:01:37 +0100401{
402 if (snd_BUG_ON(spec->num_mixers >= ARRAY_SIZE(spec->mixers)))
403 return;
404 spec->mixers[spec->num_mixers++] = mix;
405}
406
Takashi Iwaid88897e2008-10-31 15:01:37 +0100407/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200408 * GPIO setup tables, used in initialization
Kailang Yangdf694da2005-12-05 19:42:22 +0100409 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200410/* Enable GPIO mask and set output */
Takashi Iwaia9111322011-05-02 11:30:18 +0200411static const struct hda_verb alc_gpio1_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200412 {0x01, AC_VERB_SET_GPIO_MASK, 0x01},
413 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
414 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
415 { }
416};
417
Takashi Iwaia9111322011-05-02 11:30:18 +0200418static const struct hda_verb alc_gpio2_init_verbs[] = {
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200419 {0x01, AC_VERB_SET_GPIO_MASK, 0x02},
420 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x02},
421 {0x01, AC_VERB_SET_GPIO_DATA, 0x02},
422 { }
423};
424
Takashi Iwaia9111322011-05-02 11:30:18 +0200425static const struct hda_verb alc_gpio3_init_verbs[] = {
Kailang Yangbdd148a2007-05-08 15:19:08 +0200426 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
427 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x03},
428 {0x01, AC_VERB_SET_GPIO_DATA, 0x03},
429 { }
430};
431
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +0200432/*
433 * Fix hardware PLL issue
434 * On some codecs, the analog PLL gating control must be off while
435 * the default value is 1.
436 */
437static void alc_fix_pll(struct hda_codec *codec)
438{
439 struct alc_spec *spec = codec->spec;
440 unsigned int val;
441
442 if (!spec->pll_nid)
443 return;
444 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
445 spec->pll_coef_idx);
446 val = snd_hda_codec_read(codec, spec->pll_nid, 0,
447 AC_VERB_GET_PROC_COEF, 0);
448 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_COEF_INDEX,
449 spec->pll_coef_idx);
450 snd_hda_codec_write(codec, spec->pll_nid, 0, AC_VERB_SET_PROC_COEF,
451 val & ~(1 << spec->pll_coef_bit));
452}
453
454static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
455 unsigned int coef_idx, unsigned int coef_bit)
456{
457 struct alc_spec *spec = codec->spec;
458 spec->pll_nid = nid;
459 spec->pll_coef_idx = coef_idx;
460 spec->pll_coef_bit = coef_bit;
461 alc_fix_pll(codec);
462}
463
Takashi Iwai1d045db2011-07-07 18:23:21 +0200464/*
Takashi Iwai1d045db2011-07-07 18:23:21 +0200465 * Jack detections for HP auto-mute and mic-switch
466 */
467
468/* check each pin in the given array; returns true if any of them is plugged */
469static bool detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
Kailang Yangc9b58002007-10-16 14:30:01 +0200470{
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200471 int i, present = 0;
Kailang Yangc9b58002007-10-16 14:30:01 +0200472
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200473 for (i = 0; i < num_pins; i++) {
474 hda_nid_t nid = pins[i];
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200475 if (!nid)
476 break;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200477 present |= snd_hda_jack_detect(codec, nid);
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200478 }
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200479 return present;
480}
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200481
Takashi Iwai1d045db2011-07-07 18:23:21 +0200482/* standard HP/line-out auto-mute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200483static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
Takashi Iwaie9427962011-04-28 15:46:07 +0200484 bool mute, bool hp_out)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200485{
486 struct alc_spec *spec = codec->spec;
487 unsigned int mute_bits = mute ? HDA_AMP_MUTE : 0;
Takashi Iwaie9427962011-04-28 15:46:07 +0200488 unsigned int pin_bits = mute ? 0 : (hp_out ? PIN_HP : PIN_OUT);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200489 int i;
490
491 for (i = 0; i < num_pins; i++) {
492 hda_nid_t nid = pins[i];
Takashi Iwai31150f22012-01-30 10:54:08 +0100493 unsigned int val;
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200494 if (!nid)
495 break;
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200496 switch (spec->automute_mode) {
497 case ALC_AUTOMUTE_PIN:
Takashi Iwai31150f22012-01-30 10:54:08 +0100498 /* don't reset VREF value in case it's controlling
499 * the amp (see alc861_fixup_asus_amp_vref_0f())
500 */
501 if (spec->keep_vref_in_automute) {
502 val = snd_hda_codec_read(codec, nid, 0,
503 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
504 val &= ~PIN_HP;
505 } else
506 val = 0;
507 val |= pin_bits;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +0200508 snd_hda_set_pin_ctl(codec, nid, val);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200509 break;
510 case ALC_AUTOMUTE_AMP:
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200511 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200512 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200513 break;
514 case ALC_AUTOMUTE_MIXER:
515 nid = spec->automute_mixer_nid[i];
516 if (!nid)
517 break;
518 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 0,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200519 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200520 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT, 1,
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200521 HDA_AMP_MUTE, mute_bits);
Takashi Iwai3b8510c2011-04-28 14:03:24 +0200522 break;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200523 }
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200524 }
Kailang Yangc9b58002007-10-16 14:30:01 +0200525}
526
David Henningsson42cf0d02011-09-20 12:04:56 +0200527/* Toggle outputs muting */
528static void update_outputs(struct hda_codec *codec)
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200529{
530 struct alc_spec *spec = codec->spec;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200531 int on;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200532
Takashi Iwaic0a20262011-06-10 15:28:15 +0200533 /* Control HP pins/amps depending on master_mute state;
534 * in general, HP pins/amps control should be enabled in all cases,
535 * but currently set only for master_mute, just to be safe
536 */
Takashi Iwai24de1832011-11-07 17:13:39 +0100537 if (!spec->shared_mic_hp) /* don't change HP-pin when shared with mic */
538 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
Takashi Iwaic0a20262011-06-10 15:28:15 +0200539 spec->autocfg.hp_pins, spec->master_mute, true);
540
David Henningsson42cf0d02011-09-20 12:04:56 +0200541 if (!spec->automute_speaker)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200542 on = 0;
543 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200544 on = spec->hp_jack_present | spec->line_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200545 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200546 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200547 spec->autocfg.speaker_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200548
549 /* toggle line-out mutes if needed, too */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200550 /* if LO is a copy of either HP or Speaker, don't need to handle it */
551 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
552 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200553 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200554 if (!spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200555 on = 0;
556 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200557 on = spec->hp_jack_present;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200558 on |= spec->master_mute;
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200559 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200560 spec->autocfg.line_out_pins, on, false);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200561}
562
David Henningsson42cf0d02011-09-20 12:04:56 +0200563static void call_update_outputs(struct hda_codec *codec)
Takashi Iwai24519912011-08-16 15:08:49 +0200564{
565 struct alc_spec *spec = codec->spec;
566 if (spec->automute_hook)
567 spec->automute_hook(codec);
568 else
David Henningsson42cf0d02011-09-20 12:04:56 +0200569 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +0200570}
571
Takashi Iwai1d045db2011-07-07 18:23:21 +0200572/* standard HP-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200573static void alc_hp_automute(struct hda_codec *codec)
574{
575 struct alc_spec *spec = codec->spec;
576
David Henningsson42cf0d02011-09-20 12:04:56 +0200577 spec->hp_jack_present =
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200578 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
579 spec->autocfg.hp_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200580 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
Takashi Iwai3c715a92011-08-23 12:41:09 +0200581 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200582 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200583}
584
Takashi Iwai1d045db2011-07-07 18:23:21 +0200585/* standard line-out-automute helper */
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200586static void alc_line_automute(struct hda_codec *codec)
587{
588 struct alc_spec *spec = codec->spec;
589
Takashi Iwaie0d32e32011-09-26 15:19:55 +0200590 /* check LO jack only when it's different from HP */
591 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
592 return;
593
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200594 spec->line_jack_present =
595 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
596 spec->autocfg.line_out_pins);
David Henningsson42cf0d02011-09-20 12:04:56 +0200597 if (!spec->automute_speaker || !spec->detect_lo)
Takashi Iwai3c715a92011-08-23 12:41:09 +0200598 return;
David Henningsson42cf0d02011-09-20 12:04:56 +0200599 call_update_outputs(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200600}
601
Takashi Iwai8d087c72011-06-28 12:45:47 +0200602#define get_connection_index(codec, mux, nid) \
603 snd_hda_get_conn_index(codec, mux, nid, 0)
Takashi Iwai6c819492009-08-10 18:47:44 +0200604
Takashi Iwai1d045db2011-07-07 18:23:21 +0200605/* standard mic auto-switch helper */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200606static void alc_mic_automute(struct hda_codec *codec)
607{
608 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +0200609 hda_nid_t *pins = spec->imux_pins;
Kailang Yang7fb0d782008-10-15 11:12:35 +0200610
Takashi Iwai21268962011-07-07 15:01:13 +0200611 if (!spec->auto_mic || !spec->auto_mic_valid_imux)
Takashi Iwai6c819492009-08-10 18:47:44 +0200612 return;
613 if (snd_BUG_ON(!spec->adc_nids))
614 return;
Takashi Iwai21268962011-07-07 15:01:13 +0200615 if (snd_BUG_ON(spec->int_mic_idx < 0 || spec->ext_mic_idx < 0))
Takashi Iwai840b64c2010-07-13 22:49:01 +0200616 return;
Takashi Iwai840b64c2010-07-13 22:49:01 +0200617
Takashi Iwai21268962011-07-07 15:01:13 +0200618 if (snd_hda_jack_detect(codec, pins[spec->ext_mic_idx]))
619 alc_mux_select(codec, 0, spec->ext_mic_idx, false);
620 else if (spec->dock_mic_idx >= 0 &&
621 snd_hda_jack_detect(codec, pins[spec->dock_mic_idx]))
622 alc_mux_select(codec, 0, spec->dock_mic_idx, false);
623 else
624 alc_mux_select(codec, 0, spec->int_mic_idx, false);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200625}
626
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100627/* handle the specified unsol action (ALC_XXX_EVENT) */
628static void alc_exec_unsol_event(struct hda_codec *codec, int action)
Kailang Yangc9b58002007-10-16 14:30:01 +0200629{
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100630 switch (action) {
Takashi Iwai1d045db2011-07-07 18:23:21 +0200631 case ALC_HP_EVENT:
Takashi Iwaid922b512011-04-28 12:18:53 +0200632 alc_hp_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200633 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200634 case ALC_FRONT_EVENT:
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200635 alc_line_automute(codec);
636 break;
Takashi Iwai1d045db2011-07-07 18:23:21 +0200637 case ALC_MIC_EVENT:
Kailang Yang7fb0d782008-10-15 11:12:35 +0200638 alc_mic_automute(codec);
Takashi Iwaia9fd4f32009-05-08 15:57:59 +0200639 break;
640 }
Takashi Iwai01a61e12011-10-28 00:03:22 +0200641 snd_hda_jack_report_sync(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200642}
643
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100644/* update the master volume per volume-knob's unsol event */
645static void alc_update_knob_master(struct hda_codec *codec, hda_nid_t nid)
646{
647 unsigned int val;
648 struct snd_kcontrol *kctl;
649 struct snd_ctl_elem_value *uctl;
650
651 kctl = snd_hda_find_mixer_ctl(codec, "Master Playback Volume");
652 if (!kctl)
653 return;
654 uctl = kzalloc(sizeof(*uctl), GFP_KERNEL);
655 if (!uctl)
656 return;
657 val = snd_hda_codec_read(codec, nid, 0,
658 AC_VERB_GET_VOLUME_KNOB_CONTROL, 0);
659 val &= HDA_AMP_VOLMASK;
660 uctl->value.integer.value[0] = val;
661 uctl->value.integer.value[1] = val;
662 kctl->put(kctl, uctl);
663 kfree(uctl);
664}
665
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100666/* unsolicited event for HP jack sensing */
667static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
668{
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100669 int action;
670
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100671 if (codec->vendor_id == 0x10ec0880)
672 res >>= 28;
673 else
674 res >>= 26;
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100675 action = snd_hda_jack_get_action(codec, res);
David Henningssone21af482012-03-05 11:38:46 +0100676 if (action == ALC_DCVOL_EVENT) {
Takashi Iwaicf5a2272012-02-20 16:31:07 +0100677 /* Execute the dc-vol event here as it requires the NID
678 * but we don't pass NID to alc_exec_unsol_event().
679 * Once when we convert all static quirks to the auto-parser,
680 * this can be integerated into there.
681 */
682 struct hda_jack_tbl *jack;
683 jack = snd_hda_jack_tbl_get_from_tag(codec, res);
684 if (jack)
685 alc_update_knob_master(codec, jack->nid);
686 return;
687 }
688 alc_exec_unsol_event(codec, action);
Takashi Iwaif21d78e2012-01-19 12:10:29 +0100689}
690
Takashi Iwai1d045db2011-07-07 18:23:21 +0200691/* call init functions of standard auto-mute helpers */
Kailang Yang7fb0d782008-10-15 11:12:35 +0200692static void alc_inithook(struct hda_codec *codec)
693{
Takashi Iwaid922b512011-04-28 12:18:53 +0200694 alc_hp_automute(codec);
Takashi Iwaie6a5e1b2011-04-28 14:41:52 +0200695 alc_line_automute(codec);
Kailang Yang7fb0d782008-10-15 11:12:35 +0200696 alc_mic_automute(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200697}
698
Kailang Yangf9423e72008-05-27 12:32:25 +0200699/* additional initialization for ALC888 variants */
700static void alc888_coef_init(struct hda_codec *codec)
701{
702 unsigned int tmp;
703
704 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0);
705 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
706 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
Takashi Iwai37db6232009-03-05 09:40:16 +0100707 if ((tmp & 0xf0) == 0x20)
Kailang Yangf9423e72008-05-27 12:32:25 +0200708 /* alc888S-VC */
709 snd_hda_codec_read(codec, 0x20, 0,
710 AC_VERB_SET_PROC_COEF, 0x830);
711 else
712 /* alc888-VB */
713 snd_hda_codec_read(codec, 0x20, 0,
714 AC_VERB_SET_PROC_COEF, 0x3030);
715}
716
Takashi Iwai1d045db2011-07-07 18:23:21 +0200717/* additional initialization for ALC889 variants */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200718static void alc889_coef_init(struct hda_codec *codec)
719{
720 unsigned int tmp;
721
722 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
723 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
724 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 7);
725 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF, tmp|0x2010);
726}
727
Takashi Iwai3fb4a502010-01-19 15:46:37 +0100728/* turn on/off EAPD control (only if available) */
729static void set_eapd(struct hda_codec *codec, hda_nid_t nid, int on)
730{
731 if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
732 return;
733 if (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)
734 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_EAPD_BTLENABLE,
735 on ? 2 : 0);
736}
737
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200738/* turn on/off EAPD controls of the codec */
739static void alc_auto_setup_eapd(struct hda_codec *codec, bool on)
740{
741 /* We currently only handle front, HP */
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200742 static hda_nid_t pins[] = {
743 0x0f, 0x10, 0x14, 0x15, 0
744 };
745 hda_nid_t *p;
746 for (p = pins; *p; p++)
747 set_eapd(codec, *p, on);
Takashi Iwai691f1fc2011-04-07 10:31:43 +0200748}
749
Takashi Iwai1c716152011-04-07 10:37:16 +0200750/* generic shutup callback;
751 * just turning off EPAD and a little pause for avoiding pop-noise
752 */
753static void alc_eapd_shutup(struct hda_codec *codec)
754{
755 alc_auto_setup_eapd(codec, false);
756 msleep(200);
757}
758
Takashi Iwai1d045db2011-07-07 18:23:21 +0200759/* generic EAPD initialization */
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200760static void alc_auto_init_amp(struct hda_codec *codec, int type)
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200761{
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200762 unsigned int tmp;
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200763
Takashi Iwai39fa84e2011-06-27 15:28:57 +0200764 alc_auto_setup_eapd(codec, true);
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200765 switch (type) {
766 case ALC_INIT_GPIO1:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200767 snd_hda_sequence_write(codec, alc_gpio1_init_verbs);
768 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200769 case ALC_INIT_GPIO2:
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200770 snd_hda_sequence_write(codec, alc_gpio2_init_verbs);
771 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200772 case ALC_INIT_GPIO3:
Kailang Yangbdd148a2007-05-08 15:19:08 +0200773 snd_hda_sequence_write(codec, alc_gpio3_init_verbs);
774 break;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200775 case ALC_INIT_DEFAULT:
Kailang Yangc9b58002007-10-16 14:30:01 +0200776 switch (codec->vendor_id) {
777 case 0x10ec0260:
778 snd_hda_codec_write(codec, 0x1a, 0,
779 AC_VERB_SET_COEF_INDEX, 7);
780 tmp = snd_hda_codec_read(codec, 0x1a, 0,
781 AC_VERB_GET_PROC_COEF, 0);
782 snd_hda_codec_write(codec, 0x1a, 0,
783 AC_VERB_SET_COEF_INDEX, 7);
784 snd_hda_codec_write(codec, 0x1a, 0,
785 AC_VERB_SET_PROC_COEF,
786 tmp | 0x2010);
787 break;
788 case 0x10ec0262:
789 case 0x10ec0880:
790 case 0x10ec0882:
791 case 0x10ec0883:
792 case 0x10ec0885:
Takashi Iwai4a5a4c52009-02-06 12:46:59 +0100793 case 0x10ec0887:
Takashi Iwai20b67dd2011-03-23 22:54:32 +0100794 /*case 0x10ec0889:*/ /* this causes an SPDIF problem */
Jaroslav Kysela87a8c372009-07-23 10:58:29 +0200795 alc889_coef_init(codec);
Kailang Yangc9b58002007-10-16 14:30:01 +0200796 break;
Kailang Yangf9423e72008-05-27 12:32:25 +0200797 case 0x10ec0888:
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200798 alc888_coef_init(codec);
Kailang Yangf9423e72008-05-27 12:32:25 +0200799 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100800#if 0 /* XXX: This may cause the silent output on speaker on some machines */
Kailang Yangc9b58002007-10-16 14:30:01 +0200801 case 0x10ec0267:
802 case 0x10ec0268:
803 snd_hda_codec_write(codec, 0x20, 0,
804 AC_VERB_SET_COEF_INDEX, 7);
805 tmp = snd_hda_codec_read(codec, 0x20, 0,
806 AC_VERB_GET_PROC_COEF, 0);
807 snd_hda_codec_write(codec, 0x20, 0,
Kailang Yangea1fb292008-08-26 12:58:38 +0200808 AC_VERB_SET_COEF_INDEX, 7);
Kailang Yangc9b58002007-10-16 14:30:01 +0200809 snd_hda_codec_write(codec, 0x20, 0,
810 AC_VERB_SET_PROC_COEF,
811 tmp | 0x3000);
812 break;
Takashi Iwai0aea7782010-01-25 15:44:11 +0100813#endif /* XXX */
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200814 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +0200815 break;
816 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200817}
Kailang Yangea1fb292008-08-26 12:58:38 +0200818
Takashi Iwai1d045db2011-07-07 18:23:21 +0200819/*
820 * Auto-Mute mode mixer enum support
821 */
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200822static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
823 struct snd_ctl_elem_info *uinfo)
824{
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200825 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
826 struct alc_spec *spec = codec->spec;
827 static const char * const texts2[] = {
828 "Disabled", "Enabled"
829 };
830 static const char * const texts3[] = {
Takashi Iwaie49a3432012-03-01 18:14:41 +0100831 "Disabled", "Speaker Only", "Line Out+Speaker"
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200832 };
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200833 const char * const *texts;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200834
835 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
836 uinfo->count = 1;
David Henningsson42cf0d02011-09-20 12:04:56 +0200837 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200838 uinfo->value.enumerated.items = 3;
839 texts = texts3;
840 } else {
841 uinfo->value.enumerated.items = 2;
842 texts = texts2;
843 }
844 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
845 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200846 strcpy(uinfo->value.enumerated.name,
847 texts[uinfo->value.enumerated.item]);
848 return 0;
849}
850
851static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
852 struct snd_ctl_elem_value *ucontrol)
853{
854 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
855 struct alc_spec *spec = codec->spec;
David Henningsson42cf0d02011-09-20 12:04:56 +0200856 unsigned int val = 0;
857 if (spec->automute_speaker)
858 val++;
859 if (spec->automute_lo)
860 val++;
861
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200862 ucontrol->value.enumerated.item[0] = val;
863 return 0;
864}
865
866static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
867 struct snd_ctl_elem_value *ucontrol)
868{
869 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
870 struct alc_spec *spec = codec->spec;
871
872 switch (ucontrol->value.enumerated.item[0]) {
873 case 0:
David Henningsson42cf0d02011-09-20 12:04:56 +0200874 if (!spec->automute_speaker && !spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200875 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200876 spec->automute_speaker = 0;
877 spec->automute_lo = 0;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200878 break;
879 case 1:
David Henningsson42cf0d02011-09-20 12:04:56 +0200880 if (spec->automute_speaker_possible) {
881 if (!spec->automute_lo && spec->automute_speaker)
882 return 0;
883 spec->automute_speaker = 1;
884 spec->automute_lo = 0;
885 } else if (spec->automute_lo_possible) {
886 if (spec->automute_lo)
887 return 0;
888 spec->automute_lo = 1;
889 } else
890 return -EINVAL;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200891 break;
892 case 2:
David Henningsson42cf0d02011-09-20 12:04:56 +0200893 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200894 return -EINVAL;
David Henningsson42cf0d02011-09-20 12:04:56 +0200895 if (spec->automute_speaker && spec->automute_lo)
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200896 return 0;
David Henningsson42cf0d02011-09-20 12:04:56 +0200897 spec->automute_speaker = 1;
898 spec->automute_lo = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200899 break;
900 default:
901 return -EINVAL;
902 }
David Henningsson42cf0d02011-09-20 12:04:56 +0200903 call_update_outputs(codec);
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200904 return 1;
905}
906
Takashi Iwaia9111322011-05-02 11:30:18 +0200907static const struct snd_kcontrol_new alc_automute_mode_enum = {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200908 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
909 .name = "Auto-Mute Mode",
910 .info = alc_automute_mode_info,
911 .get = alc_automute_mode_get,
912 .put = alc_automute_mode_put,
913};
914
Takashi Iwai1d045db2011-07-07 18:23:21 +0200915static struct snd_kcontrol_new *alc_kcontrol_new(struct alc_spec *spec)
916{
917 snd_array_init(&spec->kctls, sizeof(struct snd_kcontrol_new), 32);
918 return snd_array_new(&spec->kctls);
919}
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200920
921static int alc_add_automute_mode_enum(struct hda_codec *codec)
922{
923 struct alc_spec *spec = codec->spec;
924 struct snd_kcontrol_new *knew;
925
926 knew = alc_kcontrol_new(spec);
927 if (!knew)
928 return -ENOMEM;
929 *knew = alc_automute_mode_enum;
930 knew->name = kstrdup("Auto-Mute Mode", GFP_KERNEL);
931 if (!knew->name)
932 return -ENOMEM;
933 return 0;
934}
935
Takashi Iwai1d045db2011-07-07 18:23:21 +0200936/*
937 * Check the availability of HP/line-out auto-mute;
938 * Set up appropriately if really supported
939 */
David Henningsson42cf0d02011-09-20 12:04:56 +0200940static void alc_init_automute(struct hda_codec *codec)
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200941{
942 struct alc_spec *spec = codec->spec;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200943 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200944 int present = 0;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200945 int i;
Takashi Iwai4a79ba32009-04-22 16:31:35 +0200946
Takashi Iwai1daf5f42011-04-28 17:57:46 +0200947 if (cfg->hp_pins[0])
948 present++;
949 if (cfg->line_out_pins[0])
950 present++;
951 if (cfg->speaker_pins[0])
952 present++;
953 if (present < 2) /* need two different output types */
954 return;
Kailang Yangc9b58002007-10-16 14:30:01 +0200955
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200956 if (!cfg->speaker_pins[0] &&
957 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200958 memcpy(cfg->speaker_pins, cfg->line_out_pins,
959 sizeof(cfg->speaker_pins));
960 cfg->speaker_outs = cfg->line_outs;
961 }
962
Takashi Iwaic48a8fb2011-07-27 16:41:57 +0200963 if (!cfg->hp_pins[0] &&
964 cfg->line_out_type == AUTO_PIN_HP_OUT) {
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200965 memcpy(cfg->hp_pins, cfg->line_out_pins,
966 sizeof(cfg->hp_pins));
967 cfg->hp_outs = cfg->line_outs;
968 }
969
David Henningsson42cf0d02011-09-20 12:04:56 +0200970 spec->automute_mode = ALC_AUTOMUTE_PIN;
971
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200972 for (i = 0; i < cfg->hp_outs; i++) {
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200973 hda_nid_t nid = cfg->hp_pins[i];
Takashi Iwai06dec222011-05-17 10:00:16 +0200974 if (!is_jack_detectable(codec, nid))
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200975 continue;
Takashi Iwaibb35feb2010-09-08 15:30:49 +0200976 snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200977 nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200978 snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200979 spec->detect_hp = 1;
Takashi Iwai1a1455d2011-04-28 17:36:18 +0200980 }
Takashi Iwaiae8a60a2011-04-28 18:09:52 +0200981
David Henningsson42cf0d02011-09-20 12:04:56 +0200982 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
983 if (cfg->speaker_outs)
984 for (i = 0; i < cfg->line_outs; i++) {
985 hda_nid_t nid = cfg->line_out_pins[i];
986 if (!is_jack_detectable(codec, nid))
987 continue;
988 snd_printdd("realtek: Enable Line-Out "
989 "auto-muting on NID 0x%x\n", nid);
Takashi Iwai1835a0f2011-10-27 22:12:46 +0200990 snd_hda_jack_detect_enable(codec, nid,
991 ALC_FRONT_EVENT);
David Henningsson42cf0d02011-09-20 12:04:56 +0200992 spec->detect_lo = 1;
993 }
994 spec->automute_lo_possible = spec->detect_hp;
995 }
996
997 spec->automute_speaker_possible = cfg->speaker_outs &&
998 (spec->detect_hp || spec->detect_lo);
999
1000 spec->automute_lo = spec->automute_lo_possible;
1001 spec->automute_speaker = spec->automute_speaker_possible;
1002
1003 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
Takashi Iwaiae8a60a2011-04-28 18:09:52 +02001004 /* create a control for automute mode */
1005 alc_add_automute_mode_enum(codec);
1006 spec->unsol_event = alc_sku_unsol_event;
1007 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001008}
1009
Takashi Iwai1d045db2011-07-07 18:23:21 +02001010/* return the position of NID in the list, or -1 if not found */
Takashi Iwai21268962011-07-07 15:01:13 +02001011static int find_idx_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1012{
1013 int i;
1014 for (i = 0; i < nums; i++)
1015 if (list[i] == nid)
1016 return i;
1017 return -1;
1018}
1019
Takashi Iwai1d045db2011-07-07 18:23:21 +02001020/* check whether dynamic ADC-switching is available */
1021static bool alc_check_dyn_adc_switch(struct hda_codec *codec)
1022{
1023 struct alc_spec *spec = codec->spec;
1024 struct hda_input_mux *imux = &spec->private_imux[0];
1025 int i, n, idx;
1026 hda_nid_t cap, pin;
1027
1028 if (imux != spec->input_mux) /* no dynamic imux? */
1029 return false;
1030
1031 for (n = 0; n < spec->num_adc_nids; n++) {
1032 cap = spec->private_capsrc_nids[n];
1033 for (i = 0; i < imux->num_items; i++) {
1034 pin = spec->imux_pins[i];
1035 if (!pin)
1036 return false;
1037 if (get_connection_index(codec, cap, pin) < 0)
1038 break;
1039 }
1040 if (i >= imux->num_items)
Takashi Iwai268ff6f2011-07-08 14:37:35 +02001041 return true; /* no ADC-switch is needed */
Takashi Iwai1d045db2011-07-07 18:23:21 +02001042 }
1043
1044 for (i = 0; i < imux->num_items; i++) {
1045 pin = spec->imux_pins[i];
1046 for (n = 0; n < spec->num_adc_nids; n++) {
1047 cap = spec->private_capsrc_nids[n];
1048 idx = get_connection_index(codec, cap, pin);
1049 if (idx >= 0) {
1050 imux->items[i].index = idx;
1051 spec->dyn_adc_idx[i] = n;
1052 break;
1053 }
1054 }
1055 }
1056
1057 snd_printdd("realtek: enabling ADC switching\n");
1058 spec->dyn_adc_switch = 1;
1059 return true;
1060}
Takashi Iwai21268962011-07-07 15:01:13 +02001061
Takashi Iwai21268962011-07-07 15:01:13 +02001062/* check whether all auto-mic pins are valid; setup indices if OK */
1063static bool alc_auto_mic_check_imux(struct hda_codec *codec)
1064{
1065 struct alc_spec *spec = codec->spec;
1066 const struct hda_input_mux *imux;
1067
1068 if (!spec->auto_mic)
1069 return false;
1070 if (spec->auto_mic_valid_imux)
1071 return true; /* already checked */
1072
1073 /* fill up imux indices */
1074 if (!alc_check_dyn_adc_switch(codec)) {
1075 spec->auto_mic = 0;
1076 return false;
1077 }
1078
1079 imux = spec->input_mux;
1080 spec->ext_mic_idx = find_idx_in_nid_list(spec->ext_mic_pin,
1081 spec->imux_pins, imux->num_items);
1082 spec->int_mic_idx = find_idx_in_nid_list(spec->int_mic_pin,
1083 spec->imux_pins, imux->num_items);
1084 spec->dock_mic_idx = find_idx_in_nid_list(spec->dock_mic_pin,
1085 spec->imux_pins, imux->num_items);
1086 if (spec->ext_mic_idx < 0 || spec->int_mic_idx < 0) {
1087 spec->auto_mic = 0;
1088 return false; /* no corresponding imux */
1089 }
1090
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001091 snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001092 if (spec->dock_mic_pin)
Takashi Iwai1835a0f2011-10-27 22:12:46 +02001093 snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
1094 ALC_MIC_EVENT);
Takashi Iwai21268962011-07-07 15:01:13 +02001095
1096 spec->auto_mic_valid_imux = 1;
1097 spec->auto_mic = 1;
1098 return true;
1099}
1100
Takashi Iwai1d045db2011-07-07 18:23:21 +02001101/*
1102 * Check the availability of auto-mic switch;
1103 * Set up if really supported
1104 */
Takashi Iwai6c819492009-08-10 18:47:44 +02001105static void alc_init_auto_mic(struct hda_codec *codec)
1106{
1107 struct alc_spec *spec = codec->spec;
1108 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001109 hda_nid_t fixed, ext, dock;
Takashi Iwai6c819492009-08-10 18:47:44 +02001110 int i;
1111
Takashi Iwai24de1832011-11-07 17:13:39 +01001112 if (spec->shared_mic_hp)
1113 return; /* no auto-mic for the shared I/O */
1114
Takashi Iwai21268962011-07-07 15:01:13 +02001115 spec->ext_mic_idx = spec->int_mic_idx = spec->dock_mic_idx = -1;
1116
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001117 fixed = ext = dock = 0;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02001118 for (i = 0; i < cfg->num_inputs; i++) {
1119 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai6c819492009-08-10 18:47:44 +02001120 unsigned int defcfg;
Takashi Iwai6c819492009-08-10 18:47:44 +02001121 defcfg = snd_hda_codec_get_pincfg(codec, nid);
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001122 switch (snd_hda_get_input_pin_attr(defcfg)) {
1123 case INPUT_PIN_ATTR_INT:
Takashi Iwai6c819492009-08-10 18:47:44 +02001124 if (fixed)
1125 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001126 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1127 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001128 fixed = nid;
1129 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001130 case INPUT_PIN_ATTR_UNUSED:
1131 return; /* invalid entry */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001132 case INPUT_PIN_ATTR_DOCK:
1133 if (dock)
1134 return; /* already occupied */
1135 if (cfg->inputs[i].type > AUTO_PIN_LINE_IN)
1136 return; /* invalid type */
1137 dock = nid;
1138 break;
Takashi Iwai99ae28b2010-09-17 14:42:34 +02001139 default:
Takashi Iwai6c819492009-08-10 18:47:44 +02001140 if (ext)
1141 return; /* already occupied */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001142 if (cfg->inputs[i].type != AUTO_PIN_MIC)
1143 return; /* invalid type */
Takashi Iwai6c819492009-08-10 18:47:44 +02001144 ext = nid;
1145 break;
Takashi Iwai6c819492009-08-10 18:47:44 +02001146 }
1147 }
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001148 if (!ext && dock) {
1149 ext = dock;
1150 dock = 0;
1151 }
Takashi Iwaieaa9b3a2010-01-17 13:09:33 +01001152 if (!ext || !fixed)
1153 return;
Takashi Iwaie35d9d62011-05-17 11:28:16 +02001154 if (!is_jack_detectable(codec, ext))
Takashi Iwai6c819492009-08-10 18:47:44 +02001155 return; /* no unsol support */
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001156 if (dock && !is_jack_detectable(codec, dock))
1157 return; /* no unsol support */
Takashi Iwai21268962011-07-07 15:01:13 +02001158
1159 /* check imux indices */
1160 spec->ext_mic_pin = ext;
1161 spec->int_mic_pin = fixed;
1162 spec->dock_mic_pin = dock;
1163
1164 spec->auto_mic = 1;
1165 if (!alc_auto_mic_check_imux(codec))
1166 return;
1167
Takashi Iwai8ed99d92011-05-17 12:05:02 +02001168 snd_printdd("realtek: Enable auto-mic switch on NID 0x%x/0x%x/0x%x\n",
1169 ext, fixed, dock);
Takashi Iwai6c819492009-08-10 18:47:44 +02001170 spec->unsol_event = alc_sku_unsol_event;
1171}
1172
Takashi Iwai1d045db2011-07-07 18:23:21 +02001173/* check the availabilities of auto-mute and auto-mic switches */
1174static void alc_auto_check_switches(struct hda_codec *codec)
1175{
David Henningsson42cf0d02011-09-20 12:04:56 +02001176 alc_init_automute(codec);
Takashi Iwai1d045db2011-07-07 18:23:21 +02001177 alc_init_auto_mic(codec);
1178}
1179
1180/*
1181 * Realtek SSID verification
1182 */
1183
David Henningsson90622912010-10-14 14:50:18 +02001184/* Could be any non-zero and even value. When used as fixup, tells
1185 * the driver to ignore any present sku defines.
1186 */
1187#define ALC_FIXUP_SKU_IGNORE (2)
1188
Takashi Iwai23d30f22012-05-07 17:17:32 +02001189static void alc_fixup_sku_ignore(struct hda_codec *codec,
1190 const struct hda_fixup *fix, int action)
1191{
1192 struct alc_spec *spec = codec->spec;
1193 if (action == HDA_FIXUP_ACT_PRE_PROBE) {
1194 spec->cdefine.fixup = 1;
1195 spec->cdefine.sku_cfg = ALC_FIXUP_SKU_IGNORE;
1196 }
1197}
1198
Kailang Yangda00c242010-03-19 11:23:45 +01001199static int alc_auto_parse_customize_define(struct hda_codec *codec)
1200{
1201 unsigned int ass, tmp, i;
Takashi Iwai7fb56222010-03-22 17:09:47 +01001202 unsigned nid = 0;
Kailang Yangda00c242010-03-19 11:23:45 +01001203 struct alc_spec *spec = codec->spec;
1204
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001205 spec->cdefine.enable_pcbeep = 1; /* assume always enabled */
1206
David Henningsson90622912010-10-14 14:50:18 +02001207 if (spec->cdefine.fixup) {
1208 ass = spec->cdefine.sku_cfg;
1209 if (ass == ALC_FIXUP_SKU_IGNORE)
1210 return -1;
1211 goto do_sku;
1212 }
1213
Kailang Yangda00c242010-03-19 11:23:45 +01001214 ass = codec->subsystem_id & 0xffff;
Takashi Iwaib6cbe512010-07-28 17:43:36 +02001215 if (ass != codec->bus->pci->subsystem_device && (ass & 1))
Kailang Yangda00c242010-03-19 11:23:45 +01001216 goto do_sku;
1217
1218 nid = 0x1d;
1219 if (codec->vendor_id == 0x10ec0260)
1220 nid = 0x17;
1221 ass = snd_hda_codec_get_pincfg(codec, nid);
1222
1223 if (!(ass & 1)) {
1224 printk(KERN_INFO "hda_codec: %s: SKU not ready 0x%08x\n",
1225 codec->chip_name, ass);
1226 return -1;
1227 }
1228
1229 /* check sum */
1230 tmp = 0;
1231 for (i = 1; i < 16; i++) {
1232 if ((ass >> i) & 1)
1233 tmp++;
1234 }
1235 if (((ass >> 16) & 0xf) != tmp)
1236 return -1;
1237
1238 spec->cdefine.port_connectivity = ass >> 30;
1239 spec->cdefine.enable_pcbeep = (ass & 0x100000) >> 20;
1240 spec->cdefine.check_sum = (ass >> 16) & 0xf;
1241 spec->cdefine.customization = ass >> 8;
1242do_sku:
1243 spec->cdefine.sku_cfg = ass;
1244 spec->cdefine.external_amp = (ass & 0x38) >> 3;
1245 spec->cdefine.platform_type = (ass & 0x4) >> 2;
1246 spec->cdefine.swap = (ass & 0x2) >> 1;
1247 spec->cdefine.override = ass & 0x1;
1248
1249 snd_printd("SKU: Nid=0x%x sku_cfg=0x%08x\n",
1250 nid, spec->cdefine.sku_cfg);
1251 snd_printd("SKU: port_connectivity=0x%x\n",
1252 spec->cdefine.port_connectivity);
1253 snd_printd("SKU: enable_pcbeep=0x%x\n", spec->cdefine.enable_pcbeep);
1254 snd_printd("SKU: check_sum=0x%08x\n", spec->cdefine.check_sum);
1255 snd_printd("SKU: customization=0x%08x\n", spec->cdefine.customization);
1256 snd_printd("SKU: external_amp=0x%x\n", spec->cdefine.external_amp);
1257 snd_printd("SKU: platform_type=0x%x\n", spec->cdefine.platform_type);
1258 snd_printd("SKU: swap=0x%x\n", spec->cdefine.swap);
1259 snd_printd("SKU: override=0x%x\n", spec->cdefine.override);
1260
1261 return 0;
1262}
1263
Takashi Iwai1d045db2011-07-07 18:23:21 +02001264/* return true if the given NID is found in the list */
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001265static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums)
1266{
Takashi Iwai21268962011-07-07 15:01:13 +02001267 return find_idx_in_nid_list(nid, list, nums) >= 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001268}
1269
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001270/* check subsystem ID and set up device-specific initialization;
1271 * return 1 if initialized, 0 if invalid SSID
1272 */
1273/* 32-bit subsystem ID for BIOS loading in HD Audio codec.
1274 * 31 ~ 16 : Manufacture ID
1275 * 15 ~ 8 : SKU ID
1276 * 7 ~ 0 : Assembly ID
1277 * port-A --> pin 39/41, port-E --> pin 14/15, port-D --> pin 35/36
1278 */
1279static int alc_subsystem_id(struct hda_codec *codec,
1280 hda_nid_t porta, hda_nid_t porte,
Kailang Yang6227cdc2010-02-25 08:36:52 +01001281 hda_nid_t portd, hda_nid_t porti)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001282{
1283 unsigned int ass, tmp, i;
1284 unsigned nid;
1285 struct alc_spec *spec = codec->spec;
1286
David Henningsson90622912010-10-14 14:50:18 +02001287 if (spec->cdefine.fixup) {
1288 ass = spec->cdefine.sku_cfg;
1289 if (ass == ALC_FIXUP_SKU_IGNORE)
1290 return 0;
1291 goto do_sku;
1292 }
1293
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001294 ass = codec->subsystem_id & 0xffff;
1295 if ((ass != codec->bus->pci->subsystem_device) && (ass & 1))
1296 goto do_sku;
1297
1298 /* invalid SSID, check the special NID pin defcfg instead */
1299 /*
Sasha Alexandrdef319f2009-06-16 16:00:15 -04001300 * 31~30 : port connectivity
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001301 * 29~21 : reserve
1302 * 20 : PCBEEP input
1303 * 19~16 : Check sum (15:1)
1304 * 15~1 : Custom
1305 * 0 : override
1306 */
1307 nid = 0x1d;
1308 if (codec->vendor_id == 0x10ec0260)
1309 nid = 0x17;
1310 ass = snd_hda_codec_get_pincfg(codec, nid);
1311 snd_printd("realtek: No valid SSID, "
1312 "checking pincfg 0x%08x for NID 0x%x\n",
Takashi Iwaicb6605c2009-04-28 13:03:19 +02001313 ass, nid);
Kailang Yang6227cdc2010-02-25 08:36:52 +01001314 if (!(ass & 1))
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001315 return 0;
1316 if ((ass >> 30) != 1) /* no physical connection */
1317 return 0;
1318
1319 /* check sum */
1320 tmp = 0;
1321 for (i = 1; i < 16; i++) {
1322 if ((ass >> i) & 1)
1323 tmp++;
1324 }
1325 if (((ass >> 16) & 0xf) != tmp)
1326 return 0;
1327do_sku:
1328 snd_printd("realtek: Enabling init ASM_ID=0x%04x CODEC_ID=%08x\n",
1329 ass & 0xffff, codec->vendor_id);
1330 /*
1331 * 0 : override
1332 * 1 : Swap Jack
1333 * 2 : 0 --> Desktop, 1 --> Laptop
1334 * 3~5 : External Amplifier control
1335 * 7~6 : Reserved
1336 */
1337 tmp = (ass & 0x38) >> 3; /* external Amp control */
1338 switch (tmp) {
1339 case 1:
1340 spec->init_amp = ALC_INIT_GPIO1;
1341 break;
1342 case 3:
1343 spec->init_amp = ALC_INIT_GPIO2;
1344 break;
1345 case 7:
1346 spec->init_amp = ALC_INIT_GPIO3;
1347 break;
1348 case 5:
Takashi Iwai5a8cfb42010-11-26 17:11:18 +01001349 default:
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001350 spec->init_amp = ALC_INIT_DEFAULT;
1351 break;
1352 }
1353
1354 /* is laptop or Desktop and enable the function "Mute internal speaker
1355 * when the external headphone out jack is plugged"
1356 */
1357 if (!(ass & 0x8000))
1358 return 1;
1359 /*
1360 * 10~8 : Jack location
1361 * 12~11: Headphone out -> 00: PortA, 01: PortE, 02: PortD, 03: Resvered
1362 * 14~13: Resvered
1363 * 15 : 1 --> enable the function "Mute internal speaker
1364 * when the external headphone out jack is plugged"
1365 */
Takashi Iwai5fe6e012011-09-26 10:41:21 +02001366 if (!spec->autocfg.hp_pins[0] &&
1367 !(spec->autocfg.line_out_pins[0] &&
1368 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
Takashi Iwai01d48252009-10-06 13:21:54 +02001369 hda_nid_t nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001370 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1371 if (tmp == 0)
Takashi Iwai01d48252009-10-06 13:21:54 +02001372 nid = porta;
Kailang Yangc9b58002007-10-16 14:30:01 +02001373 else if (tmp == 1)
Takashi Iwai01d48252009-10-06 13:21:54 +02001374 nid = porte;
Kailang Yangc9b58002007-10-16 14:30:01 +02001375 else if (tmp == 2)
Takashi Iwai01d48252009-10-06 13:21:54 +02001376 nid = portd;
Kailang Yang6227cdc2010-02-25 08:36:52 +01001377 else if (tmp == 3)
1378 nid = porti;
Kailang Yangc9b58002007-10-16 14:30:01 +02001379 else
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001380 return 1;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02001381 if (found_in_nid_list(nid, spec->autocfg.line_out_pins,
1382 spec->autocfg.line_outs))
1383 return 1;
Takashi Iwai01d48252009-10-06 13:21:54 +02001384 spec->autocfg.hp_pins[0] = nid;
Kailang Yangc9b58002007-10-16 14:30:01 +02001385 }
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001386 return 1;
1387}
Kailang Yangea1fb292008-08-26 12:58:38 +02001388
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001389/* Check the validity of ALC subsystem-id
1390 * ports contains an array of 4 pin NIDs for port-A, E, D and I */
1391static void alc_ssid_check(struct hda_codec *codec, const hda_nid_t *ports)
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001392{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02001393 if (!alc_subsystem_id(codec, ports[0], ports[1], ports[2], ports[3])) {
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001394 struct alc_spec *spec = codec->spec;
1395 snd_printd("realtek: "
1396 "Enable default setup for auto mode as fallback\n");
1397 spec->init_amp = ALC_INIT_DEFAULT;
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001398 }
Takashi Iwai21268962011-07-07 15:01:13 +02001399}
Takashi Iwai1a1455d2011-04-28 17:36:18 +02001400
Takashi Iwai41e41f12005-06-08 14:48:49 +02001401/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001402 * COEF access helper functions
1403 */
Kailang Yang274693f2009-12-03 10:07:50 +01001404static int alc_read_coef_idx(struct hda_codec *codec,
1405 unsigned int coef_idx)
1406{
1407 unsigned int val;
1408 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1409 coef_idx);
1410 val = snd_hda_codec_read(codec, 0x20, 0,
1411 AC_VERB_GET_PROC_COEF, 0);
1412 return val;
1413}
1414
Kailang Yang977ddd62010-09-15 10:02:29 +02001415static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1416 unsigned int coef_val)
1417{
1418 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX,
1419 coef_idx);
1420 snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_PROC_COEF,
1421 coef_val);
1422}
1423
Takashi Iwai1bb7e432011-10-17 16:50:59 +02001424/* a special bypass for COEF 0; read the cached value at the second time */
1425static unsigned int alc_get_coef0(struct hda_codec *codec)
1426{
1427 struct alc_spec *spec = codec->spec;
1428 if (!spec->coef0)
1429 spec->coef0 = alc_read_coef_idx(codec, 0);
1430 return spec->coef0;
1431}
1432
Takashi Iwai1d045db2011-07-07 18:23:21 +02001433/*
1434 * Digital I/O handling
1435 */
1436
Takashi Iwai757899a2010-07-30 10:48:14 +02001437/* set right pin controls for digital I/O */
1438static void alc_auto_init_digital(struct hda_codec *codec)
1439{
1440 struct alc_spec *spec = codec->spec;
1441 int i;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001442 hda_nid_t pin, dac;
Takashi Iwai757899a2010-07-30 10:48:14 +02001443
1444 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1445 pin = spec->autocfg.dig_out_pins[i];
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001446 if (!pin)
1447 continue;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001448 snd_hda_set_pin_ctl(codec, pin, PIN_OUT);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02001449 if (!i)
1450 dac = spec->multiout.dig_out_nid;
1451 else
1452 dac = spec->slave_dig_outs[i - 1];
1453 if (!dac || !(get_wcaps(codec, dac) & AC_WCAP_OUT_AMP))
1454 continue;
1455 snd_hda_codec_write(codec, dac, 0,
1456 AC_VERB_SET_AMP_GAIN_MUTE,
1457 AMP_OUT_UNMUTE);
Takashi Iwai757899a2010-07-30 10:48:14 +02001458 }
1459 pin = spec->autocfg.dig_in_pin;
1460 if (pin)
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02001461 snd_hda_set_pin_ctl(codec, pin, PIN_IN);
Takashi Iwai757899a2010-07-30 10:48:14 +02001462}
1463
1464/* parse digital I/Os and set up NIDs in BIOS auto-parse mode */
1465static void alc_auto_parse_digital(struct hda_codec *codec)
1466{
1467 struct alc_spec *spec = codec->spec;
Takashi Iwai51e41522011-11-03 16:54:06 +01001468 int i, err, nums;
Takashi Iwai757899a2010-07-30 10:48:14 +02001469 hda_nid_t dig_nid;
1470
1471 /* support multiple SPDIFs; the secondary is set up as a slave */
Takashi Iwai51e41522011-11-03 16:54:06 +01001472 nums = 0;
Takashi Iwai757899a2010-07-30 10:48:14 +02001473 for (i = 0; i < spec->autocfg.dig_outs; i++) {
Takashi Iwaia9267572011-07-07 15:12:55 +02001474 hda_nid_t conn[4];
Takashi Iwai757899a2010-07-30 10:48:14 +02001475 err = snd_hda_get_connections(codec,
1476 spec->autocfg.dig_out_pins[i],
Takashi Iwaia9267572011-07-07 15:12:55 +02001477 conn, ARRAY_SIZE(conn));
Takashi Iwai51e41522011-11-03 16:54:06 +01001478 if (err <= 0)
Takashi Iwai757899a2010-07-30 10:48:14 +02001479 continue;
Takashi Iwaia9267572011-07-07 15:12:55 +02001480 dig_nid = conn[0]; /* assume the first element is audio-out */
Takashi Iwai51e41522011-11-03 16:54:06 +01001481 if (!nums) {
Takashi Iwai757899a2010-07-30 10:48:14 +02001482 spec->multiout.dig_out_nid = dig_nid;
1483 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1484 } else {
1485 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
Takashi Iwai51e41522011-11-03 16:54:06 +01001486 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
Takashi Iwai757899a2010-07-30 10:48:14 +02001487 break;
Takashi Iwai51e41522011-11-03 16:54:06 +01001488 spec->slave_dig_outs[nums - 1] = dig_nid;
Takashi Iwai757899a2010-07-30 10:48:14 +02001489 }
Takashi Iwai51e41522011-11-03 16:54:06 +01001490 nums++;
Takashi Iwai757899a2010-07-30 10:48:14 +02001491 }
1492
1493 if (spec->autocfg.dig_in_pin) {
Takashi Iwai01fdf182010-09-24 09:09:42 +02001494 dig_nid = codec->start_nid;
1495 for (i = 0; i < codec->num_nodes; i++, dig_nid++) {
1496 unsigned int wcaps = get_wcaps(codec, dig_nid);
1497 if (get_wcaps_type(wcaps) != AC_WID_AUD_IN)
1498 continue;
1499 if (!(wcaps & AC_WCAP_DIGITAL))
1500 continue;
1501 if (!(wcaps & AC_WCAP_CONN_LIST))
1502 continue;
1503 err = get_connection_index(codec, dig_nid,
1504 spec->autocfg.dig_in_pin);
1505 if (err >= 0) {
1506 spec->dig_in_nid = dig_nid;
1507 break;
1508 }
1509 }
Takashi Iwai757899a2010-07-30 10:48:14 +02001510 }
1511}
1512
Takashi Iwaif95474e2007-07-10 00:47:43 +02001513/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02001514 * capture mixer elements
Vincent Petryef8ef5f2008-11-23 11:31:41 +08001515 */
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001516static int alc_cap_vol_info(struct snd_kcontrol *kcontrol,
1517 struct snd_ctl_elem_info *uinfo)
1518{
1519 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1520 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001521 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001522 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001523
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001524 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001525 if (spec->vol_in_capsrc)
1526 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1527 else
1528 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1529 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001530 err = snd_hda_mixer_amp_volume_info(kcontrol, uinfo);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001531 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001532 return err;
1533}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001535static int alc_cap_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag,
1536 unsigned int size, unsigned int __user *tlv)
1537{
1538 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1539 struct alc_spec *spec = codec->spec;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001540 unsigned long val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001541 int err;
1542
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001543 mutex_lock(&codec->control_mutex);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001544 if (spec->vol_in_capsrc)
1545 val = HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[0], 3, 0, HDA_OUTPUT);
1546 else
1547 val = HDA_COMPOSE_AMP_VAL(spec->adc_nids[0], 3, 0, HDA_INPUT);
1548 kcontrol->private_value = val;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001549 err = snd_hda_mixer_amp_tlv(kcontrol, op_flag, size, tlv);
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001550 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001551 return err;
1552}
1553
1554typedef int (*getput_call_t)(struct snd_kcontrol *kcontrol,
1555 struct snd_ctl_elem_value *ucontrol);
1556
1557static int alc_cap_getput_caller(struct snd_kcontrol *kcontrol,
1558 struct snd_ctl_elem_value *ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001559 getput_call_t func, bool check_adc_switch)
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001560{
1561 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
1562 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02001563 int i, err = 0;
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001564
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001565 mutex_lock(&codec->control_mutex);
Takashi Iwai21268962011-07-07 15:01:13 +02001566 if (check_adc_switch && spec->dyn_adc_switch) {
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001567 for (i = 0; i < spec->num_adc_nids; i++) {
1568 kcontrol->private_value =
1569 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1570 3, 0, HDA_INPUT);
1571 err = func(kcontrol, ucontrol);
1572 if (err < 0)
1573 goto error;
1574 }
1575 } else {
1576 i = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02001577 if (spec->vol_in_capsrc)
1578 kcontrol->private_value =
1579 HDA_COMPOSE_AMP_VAL(spec->capsrc_nids[i],
1580 3, 0, HDA_OUTPUT);
1581 else
1582 kcontrol->private_value =
Takashi Iwai21268962011-07-07 15:01:13 +02001583 HDA_COMPOSE_AMP_VAL(spec->adc_nids[i],
1584 3, 0, HDA_INPUT);
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001585 err = func(kcontrol, ucontrol);
1586 }
1587 error:
Wu Fengguang5a9e02e2009-01-09 16:45:24 +08001588 mutex_unlock(&codec->control_mutex);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001589 return err;
1590}
1591
1592static int alc_cap_vol_get(struct snd_kcontrol *kcontrol,
1593 struct snd_ctl_elem_value *ucontrol)
1594{
1595 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001596 snd_hda_mixer_amp_volume_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001597}
1598
1599static int alc_cap_vol_put(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_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001604}
1605
1606/* capture mixer elements */
1607#define alc_cap_sw_info snd_ctl_boolean_stereo_info
1608
1609static int alc_cap_sw_get(struct snd_kcontrol *kcontrol,
1610 struct snd_ctl_elem_value *ucontrol)
1611{
1612 return alc_cap_getput_caller(kcontrol, ucontrol,
Takashi Iwai9c7a0832011-07-07 09:25:54 +02001613 snd_hda_mixer_amp_switch_get, false);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001614}
1615
1616static int alc_cap_sw_put(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_put, true);
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001621}
1622
Takashi Iwaia23b6882009-03-23 15:21:36 +01001623#define _DEFINE_CAPMIX(num) \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001624 { \
1625 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1626 .name = "Capture Switch", \
1627 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, \
1628 .count = num, \
1629 .info = alc_cap_sw_info, \
1630 .get = alc_cap_sw_get, \
1631 .put = alc_cap_sw_put, \
1632 }, \
1633 { \
1634 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1635 .name = "Capture Volume", \
1636 .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1637 SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
1638 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK), \
1639 .count = num, \
1640 .info = alc_cap_vol_info, \
1641 .get = alc_cap_vol_get, \
1642 .put = alc_cap_vol_put, \
1643 .tlv = { .c = alc_cap_vol_tlv }, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001644 }
1645
1646#define _DEFINE_CAPSRC(num) \
Takashi Iwai3c3e9892008-10-31 17:48:56 +01001647 { \
1648 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1649 /* .name = "Capture Source", */ \
1650 .name = "Input Source", \
1651 .count = num, \
1652 .info = alc_mux_enum_info, \
1653 .get = alc_mux_enum_get, \
1654 .put = alc_mux_enum_put, \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001655 }
1656
1657#define DEFINE_CAPMIX(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001658static const struct snd_kcontrol_new alc_capture_mixer ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001659 _DEFINE_CAPMIX(num), \
1660 _DEFINE_CAPSRC(num), \
1661 { } /* end */ \
1662}
1663
1664#define DEFINE_CAPMIX_NOSRC(num) \
Takashi Iwaia9111322011-05-02 11:30:18 +02001665static const struct snd_kcontrol_new alc_capture_mixer_nosrc ## num[] = { \
Takashi Iwaia23b6882009-03-23 15:21:36 +01001666 _DEFINE_CAPMIX(num), \
1667 { } /* end */ \
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001668}
1669
1670/* up to three ADCs */
1671DEFINE_CAPMIX(1);
1672DEFINE_CAPMIX(2);
1673DEFINE_CAPMIX(3);
Takashi Iwaia23b6882009-03-23 15:21:36 +01001674DEFINE_CAPMIX_NOSRC(1);
1675DEFINE_CAPMIX_NOSRC(2);
1676DEFINE_CAPMIX_NOSRC(3);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001677
1678/*
Takashi Iwai2134ea42008-01-10 16:53:55 +01001679 * virtual master controls
1680 */
1681
1682/*
1683 * slave controls for virtual master
1684 */
Takashi Iwai9322ca52012-02-03 14:28:01 +01001685static const char * const alc_slave_pfxs[] = {
1686 "Front", "Surround", "Center", "LFE", "Side",
Takashi Iwai7c589752012-03-02 09:00:33 +01001687 "Headphone", "Speaker", "Mono", "Line Out",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001688 "CLFE", "Bass Speaker", "PCM",
Takashi Iwai2134ea42008-01-10 16:53:55 +01001689 NULL,
1690};
1691
1692/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001693 * build control elements
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 */
Takashi Iwai603c4012008-07-30 15:01:44 +02001695
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001696#define NID_MAPPING (-1)
1697
1698#define SUBDEV_SPEAKER_ (0 << 6)
1699#define SUBDEV_HP_ (1 << 6)
1700#define SUBDEV_LINE_ (2 << 6)
1701#define SUBDEV_SPEAKER(x) (SUBDEV_SPEAKER_ | ((x) & 0x3f))
1702#define SUBDEV_HP(x) (SUBDEV_HP_ | ((x) & 0x3f))
1703#define SUBDEV_LINE(x) (SUBDEV_LINE_ | ((x) & 0x3f))
1704
Takashi Iwai603c4012008-07-30 15:01:44 +02001705static void alc_free_kctls(struct hda_codec *codec);
1706
Takashi Iwai67d634c2009-11-16 15:35:59 +01001707#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001708/* additional beep mixers; the actual parameters are overwritten at build */
Takashi Iwaia9111322011-05-02 11:30:18 +02001709static const struct snd_kcontrol_new alc_beep_mixer[] = {
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001710 HDA_CODEC_VOLUME("Beep Playback Volume", 0, 0, HDA_INPUT),
Jaroslav Kysela123c07a2009-10-21 14:48:23 +02001711 HDA_CODEC_MUTE_BEEP("Beep Playback Switch", 0, 0, HDA_INPUT),
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001712 { } /* end */
1713};
Takashi Iwai67d634c2009-11-16 15:35:59 +01001714#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001715
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001716static int __alc_build_controls(struct hda_codec *codec)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
1718 struct alc_spec *spec = codec->spec;
Takashi Iwai2f44f842010-06-22 11:12:32 +02001719 struct snd_kcontrol *kctl = NULL;
Takashi Iwaia9111322011-05-02 11:30:18 +02001720 const struct snd_kcontrol_new *knew;
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001721 int i, j, err;
1722 unsigned int u;
1723 hda_nid_t nid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001724
1725 for (i = 0; i < spec->num_mixers; i++) {
1726 err = snd_hda_add_new_ctls(codec, spec->mixers[i]);
1727 if (err < 0)
1728 return err;
1729 }
Takashi Iwaif9e336f2008-10-31 16:37:07 +01001730 if (spec->cap_mixer) {
1731 err = snd_hda_add_new_ctls(codec, spec->cap_mixer);
1732 if (err < 0)
1733 return err;
1734 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 if (spec->multiout.dig_out_nid) {
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001736 err = snd_hda_create_spdif_out_ctls(codec,
Stephen Warren74b654c2011-06-01 11:14:18 -06001737 spec->multiout.dig_out_nid,
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001738 spec->multiout.dig_out_nid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 if (err < 0)
1740 return err;
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001741 if (!spec->no_analog) {
1742 err = snd_hda_create_spdif_share_sw(codec,
1743 &spec->multiout);
1744 if (err < 0)
1745 return err;
1746 spec->multiout.share_spdif = 1;
1747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 }
1749 if (spec->dig_in_nid) {
1750 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
1751 if (err < 0)
1752 return err;
1753 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01001754
Takashi Iwai67d634c2009-11-16 15:35:59 +01001755#ifdef CONFIG_SND_HDA_INPUT_BEEP
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001756 /* create beep controls if needed */
1757 if (spec->beep_amp) {
Takashi Iwaia9111322011-05-02 11:30:18 +02001758 const struct snd_kcontrol_new *knew;
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001759 for (knew = alc_beep_mixer; knew->name; knew++) {
1760 struct snd_kcontrol *kctl;
1761 kctl = snd_ctl_new1(knew, codec);
1762 if (!kctl)
1763 return -ENOMEM;
1764 kctl->private_value = spec->beep_amp;
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01001765 err = snd_hda_ctl_add(codec, 0, kctl);
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001766 if (err < 0)
1767 return err;
1768 }
1769 }
Takashi Iwai67d634c2009-11-16 15:35:59 +01001770#endif
Takashi Iwai45bdd1c2009-02-06 16:11:25 +01001771
Takashi Iwai2134ea42008-01-10 16:53:55 +01001772 /* if we have no master control, let's create it */
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001773 if (!spec->no_analog &&
1774 !snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001775 unsigned int vmaster_tlv[4];
Takashi Iwai2134ea42008-01-10 16:53:55 +01001776 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
Takashi Iwai1c82ed12008-02-18 13:05:50 +01001777 HDA_OUTPUT, vmaster_tlv);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001778 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
Takashi Iwai9322ca52012-02-03 14:28:01 +01001779 vmaster_tlv, alc_slave_pfxs,
1780 "Playback Volume");
Takashi Iwai2134ea42008-01-10 16:53:55 +01001781 if (err < 0)
1782 return err;
1783 }
Takashi Iwaie64f14f2009-01-20 18:32:55 +01001784 if (!spec->no_analog &&
1785 !snd_hda_find_mixer_ctl(codec, "Master Playback Switch")) {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001786 err = __snd_hda_add_vmaster(codec, "Master Playback Switch",
1787 NULL, alc_slave_pfxs,
1788 "Playback Switch",
Takashi Iwaid2f344b2012-03-12 16:59:58 +01001789 true, &spec->vmaster_mute.sw_kctl);
Takashi Iwai2134ea42008-01-10 16:53:55 +01001790 if (err < 0)
1791 return err;
1792 }
1793
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001794 /* assign Capture Source enums to NID */
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001795 if (spec->capsrc_nids || spec->adc_nids) {
1796 kctl = snd_hda_find_mixer_ctl(codec, "Capture Source");
1797 if (!kctl)
1798 kctl = snd_hda_find_mixer_ctl(codec, "Input Source");
1799 for (i = 0; kctl && i < kctl->count; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01001800 err = snd_hda_add_nid(codec, kctl, i,
1801 get_capsrc(spec, i));
Takashi Iwaifbe618f2010-06-11 11:24:58 +02001802 if (err < 0)
1803 return err;
1804 }
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001805 }
Takashi Iwai60a6a842011-07-27 14:01:24 +02001806 if (spec->cap_mixer && spec->adc_nids) {
Jaroslav Kysela5b0cb1d2009-12-08 16:13:32 +01001807 const char *kname = kctl ? kctl->id.name : NULL;
1808 for (knew = spec->cap_mixer; knew->name; knew++) {
1809 if (kname && strcmp(knew->name, kname) == 0)
1810 continue;
1811 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1812 for (i = 0; kctl && i < kctl->count; i++) {
1813 err = snd_hda_add_nid(codec, kctl, i,
1814 spec->adc_nids[i]);
1815 if (err < 0)
1816 return err;
1817 }
1818 }
1819 }
1820
1821 /* other nid->control mapping */
1822 for (i = 0; i < spec->num_mixers; i++) {
1823 for (knew = spec->mixers[i]; knew->name; knew++) {
1824 if (knew->iface != NID_MAPPING)
1825 continue;
1826 kctl = snd_hda_find_mixer_ctl(codec, knew->name);
1827 if (kctl == NULL)
1828 continue;
1829 u = knew->subdevice;
1830 for (j = 0; j < 4; j++, u >>= 8) {
1831 nid = u & 0x3f;
1832 if (nid == 0)
1833 continue;
1834 switch (u & 0xc0) {
1835 case SUBDEV_SPEAKER_:
1836 nid = spec->autocfg.speaker_pins[nid];
1837 break;
1838 case SUBDEV_LINE_:
1839 nid = spec->autocfg.line_out_pins[nid];
1840 break;
1841 case SUBDEV_HP_:
1842 nid = spec->autocfg.hp_pins[nid];
1843 break;
1844 default:
1845 continue;
1846 }
1847 err = snd_hda_add_nid(codec, kctl, 0, nid);
1848 if (err < 0)
1849 return err;
1850 }
1851 u = knew->private_value;
1852 for (j = 0; j < 4; j++, u >>= 8) {
1853 nid = u & 0xff;
1854 if (nid == 0)
1855 continue;
1856 err = snd_hda_add_nid(codec, kctl, 0, nid);
1857 if (err < 0)
1858 return err;
1859 }
1860 }
1861 }
Takashi Iwaibae84e72010-03-22 08:30:20 +01001862
1863 alc_free_kctls(codec); /* no longer needed */
1864
Takashi Iwaif21d78e2012-01-19 12:10:29 +01001865 return 0;
1866}
1867
1868static int alc_build_controls(struct hda_codec *codec)
1869{
1870 struct alc_spec *spec = codec->spec;
1871 int err = __alc_build_controls(codec);
Takashi Iwai01a61e12011-10-28 00:03:22 +02001872 if (err < 0)
1873 return err;
Takashi Iwai420b0fe2012-03-12 12:35:27 +01001874 err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
1875 if (err < 0)
1876 return err;
1877 alc_apply_fixup(codec, ALC_FIXUP_ACT_BUILD);
1878 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879}
1880
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001881
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882/*
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001883 * Common callbacks
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001884 */
Takashi Iwai16ded522005-06-10 19:58:24 +02001885
Takashi Iwai584c0c42011-03-10 12:51:11 +01001886static void alc_init_special_input_src(struct hda_codec *codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001887static void alc_auto_init_std(struct hda_codec *codec);
Takashi Iwai584c0c42011-03-10 12:51:11 +01001888
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889static int alc_init(struct hda_codec *codec)
1890{
1891 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02001892
Takashi Iwai546bb672012-03-07 08:37:19 +01001893 if (spec->init_hook)
1894 spec->init_hook(codec);
Kailang Yang526af6e2012-03-07 08:25:20 +01001895
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001896 alc_fix_pll(codec);
Takashi Iwai4a79ba32009-04-22 16:31:35 +02001897 alc_auto_init_amp(codec, spec->init_amp);
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02001898
Takashi Iwai584c0c42011-03-10 12:51:11 +01001899 alc_init_special_input_src(codec);
Takashi Iwai070cff42012-02-21 12:54:17 +01001900 alc_auto_init_std(codec);
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001901
Takashi Iwai58701122011-01-13 15:41:45 +01001902 alc_apply_fixup(codec, ALC_FIXUP_ACT_INIT);
1903
Takashi Iwai01a61e12011-10-28 00:03:22 +02001904 snd_hda_jack_report_sync(codec);
1905
Takashi Iwai9e5341b2010-09-21 09:57:06 +02001906 hda_call_check_power_status(codec, 0x01);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 return 0;
1908}
1909
Takashi Iwaiae6b8132006-03-03 16:47:17 +01001910static void alc_unsol_event(struct hda_codec *codec, unsigned int res)
1911{
1912 struct alc_spec *spec = codec->spec;
1913
1914 if (spec->unsol_event)
1915 spec->unsol_event(codec, res);
1916}
1917
Takashi Iwaicb53c622007-08-10 17:21:45 +02001918#ifdef CONFIG_SND_HDA_POWER_SAVE
1919static int alc_check_power_status(struct hda_codec *codec, hda_nid_t nid)
1920{
1921 struct alc_spec *spec = codec->spec;
1922 return snd_hda_check_amp_list_power(codec, &spec->loopback, nid);
1923}
1924#endif
1925
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926/*
1927 * Analog playback callbacks
1928 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001929static int alc_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001931 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932{
1933 struct alc_spec *spec = codec->spec;
Takashi Iwai9a081602008-02-12 18:37:26 +01001934 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1935 hinfo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936}
1937
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001938static int alc_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 struct hda_codec *codec,
1940 unsigned int stream_tag,
1941 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001942 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943{
1944 struct alc_spec *spec = codec->spec;
Takashi Iwai9c7f8522006-06-28 15:08:22 +02001945 return snd_hda_multi_out_analog_prepare(codec, &spec->multiout,
1946 stream_tag, format, substream);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947}
1948
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001949static int alc_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001951 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952{
1953 struct alc_spec *spec = codec->spec;
1954 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
1955}
1956
1957/*
1958 * Digital out
1959 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001960static int alc_dig_playback_pcm_open(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001962 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963{
1964 struct alc_spec *spec = codec->spec;
1965 return snd_hda_multi_out_dig_open(codec, &spec->multiout);
1966}
1967
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001968static int alc_dig_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai6b97eb42007-04-05 14:51:48 +02001969 struct hda_codec *codec,
1970 unsigned int stream_tag,
1971 unsigned int format,
1972 struct snd_pcm_substream *substream)
1973{
1974 struct alc_spec *spec = codec->spec;
1975 return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
1976 stream_tag, format, substream);
1977}
1978
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001979static int alc_dig_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai9b5f12e2009-02-13 11:47:37 +01001980 struct hda_codec *codec,
1981 struct snd_pcm_substream *substream)
1982{
1983 struct alc_spec *spec = codec->spec;
1984 return snd_hda_multi_out_dig_cleanup(codec, &spec->multiout);
1985}
1986
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001987static int alc_dig_playback_pcm_close(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01001989 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990{
1991 struct alc_spec *spec = codec->spec;
1992 return snd_hda_multi_out_dig_close(codec, &spec->multiout);
1993}
1994
1995/*
1996 * Analog capture
1997 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02001998static int alc_alt_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 struct hda_codec *codec,
2000 unsigned int stream_tag,
2001 unsigned int format,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002002 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003{
2004 struct alc_spec *spec = codec->spec;
2005
Takashi Iwai63300792008-01-24 15:31:36 +01002006 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1],
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 stream_tag, 0, format);
2008 return 0;
2009}
2010
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002011static int alc_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 struct hda_codec *codec,
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002013 struct snd_pcm_substream *substream)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014{
2015 struct alc_spec *spec = codec->spec;
2016
Takashi Iwai888afa12008-03-18 09:57:50 +01002017 snd_hda_codec_cleanup_stream(codec,
2018 spec->adc_nids[substream->number + 1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 return 0;
2020}
2021
Takashi Iwai840b64c2010-07-13 22:49:01 +02002022/* analog capture with dynamic dual-adc changes */
Takashi Iwai21268962011-07-07 15:01:13 +02002023static int dyn_adc_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002024 struct hda_codec *codec,
2025 unsigned int stream_tag,
2026 unsigned int format,
2027 struct snd_pcm_substream *substream)
2028{
2029 struct alc_spec *spec = codec->spec;
Takashi Iwai21268962011-07-07 15:01:13 +02002030 spec->cur_adc = spec->adc_nids[spec->dyn_adc_idx[spec->cur_mux[0]]];
Takashi Iwai840b64c2010-07-13 22:49:01 +02002031 spec->cur_adc_stream_tag = stream_tag;
2032 spec->cur_adc_format = format;
2033 snd_hda_codec_setup_stream(codec, spec->cur_adc, stream_tag, 0, format);
2034 return 0;
2035}
2036
Takashi Iwai21268962011-07-07 15:01:13 +02002037static int dyn_adc_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
Takashi Iwai840b64c2010-07-13 22:49:01 +02002038 struct hda_codec *codec,
2039 struct snd_pcm_substream *substream)
2040{
2041 struct alc_spec *spec = codec->spec;
2042 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
2043 spec->cur_adc = 0;
2044 return 0;
2045}
2046
Takashi Iwai21268962011-07-07 15:01:13 +02002047static const struct hda_pcm_stream dyn_adc_pcm_analog_capture = {
Takashi Iwai840b64c2010-07-13 22:49:01 +02002048 .substreams = 1,
2049 .channels_min = 2,
2050 .channels_max = 2,
2051 .nid = 0, /* fill later */
2052 .ops = {
Takashi Iwai21268962011-07-07 15:01:13 +02002053 .prepare = dyn_adc_capture_pcm_prepare,
2054 .cleanup = dyn_adc_capture_pcm_cleanup
Takashi Iwai840b64c2010-07-13 22:49:01 +02002055 },
2056};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057
2058/*
2059 */
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002060static const struct hda_pcm_stream alc_pcm_analog_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 .substreams = 1,
2062 .channels_min = 2,
2063 .channels_max = 8,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002064 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002066 .open = alc_playback_pcm_open,
2067 .prepare = alc_playback_pcm_prepare,
2068 .cleanup = alc_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 },
2070};
2071
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002072static const struct hda_pcm_stream alc_pcm_analog_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002073 .substreams = 1,
2074 .channels_min = 2,
2075 .channels_max = 2,
2076 /* NID is set in alc_build_pcms */
2077};
2078
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002079static const struct hda_pcm_stream alc_pcm_analog_alt_playback = {
Takashi Iwai63300792008-01-24 15:31:36 +01002080 .substreams = 1,
2081 .channels_min = 2,
2082 .channels_max = 2,
2083 /* NID is set in alc_build_pcms */
2084};
2085
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002086static const struct hda_pcm_stream alc_pcm_analog_alt_capture = {
Takashi Iwai63300792008-01-24 15:31:36 +01002087 .substreams = 2, /* can be overridden */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 .channels_min = 2,
2089 .channels_max = 2,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002090 /* NID is set in alc_build_pcms */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002092 .prepare = alc_alt_capture_pcm_prepare,
2093 .cleanup = alc_alt_capture_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 },
2095};
2096
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002097static const struct hda_pcm_stream alc_pcm_digital_playback = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 .substreams = 1,
2099 .channels_min = 2,
2100 .channels_max = 2,
2101 /* NID is set in alc_build_pcms */
2102 .ops = {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002103 .open = alc_dig_playback_pcm_open,
2104 .close = alc_dig_playback_pcm_close,
2105 .prepare = alc_dig_playback_pcm_prepare,
2106 .cleanup = alc_dig_playback_pcm_cleanup
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 },
2108};
2109
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002110static const struct hda_pcm_stream alc_pcm_digital_capture = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 .substreams = 1,
2112 .channels_min = 2,
2113 .channels_max = 2,
2114 /* NID is set in alc_build_pcms */
2115};
2116
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002117/* Used by alc_build_pcms to flag that a PCM has no playback stream */
Takashi Iwaia9111322011-05-02 11:30:18 +02002118static const struct hda_pcm_stream alc_pcm_null_stream = {
Jonathan Woithe4c5186e2006-02-09 11:53:48 +01002119 .substreams = 0,
2120 .channels_min = 0,
2121 .channels_max = 0,
2122};
2123
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124static int alc_build_pcms(struct hda_codec *codec)
2125{
2126 struct alc_spec *spec = codec->spec;
2127 struct hda_pcm *info = spec->pcm_rec;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002128 const struct hda_pcm_stream *p;
Takashi Iwai1fa17572011-11-02 21:30:51 +01002129 bool have_multi_adcs;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 int i;
2131
2132 codec->num_pcms = 1;
2133 codec->pcm_info = info;
2134
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002135 if (spec->no_analog)
2136 goto skip_analog;
2137
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002138 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog),
2139 "%s Analog", codec->chip_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 info->name = spec->stream_name_analog;
Kailang Yang274693f2009-12-03 10:07:50 +01002141
Takashi Iwaieedec3d2012-02-06 10:24:04 +01002142 if (spec->multiout.num_dacs > 0) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002143 p = spec->stream_analog_playback;
2144 if (!p)
2145 p = &alc_pcm_analog_playback;
2146 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002147 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dac_nids[0];
2148 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002149 if (spec->adc_nids) {
2150 p = spec->stream_analog_capture;
Takashi Iwai21268962011-07-07 15:01:13 +02002151 if (!p) {
2152 if (spec->dyn_adc_switch)
2153 p = &dyn_adc_pcm_analog_capture;
2154 else
2155 p = &alc_pcm_analog_capture;
2156 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002157 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai4a471b72005-12-07 13:56:29 +01002158 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
2159 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160
Takashi Iwai4a471b72005-12-07 13:56:29 +01002161 if (spec->channel_mode) {
2162 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 0;
2163 for (i = 0; i < spec->num_channel_mode; i++) {
2164 if (spec->channel_mode[i].channels > info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max) {
2165 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = spec->channel_mode[i].channels;
2166 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 }
2168 }
2169
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002170 skip_analog:
Takashi Iwaie08a0072006-09-07 17:52:14 +02002171 /* SPDIF for stream index #1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
Takashi Iwai812a2cc2009-05-16 10:00:49 +02002173 snprintf(spec->stream_name_digital,
2174 sizeof(spec->stream_name_digital),
2175 "%s Digital", codec->chip_name);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002176 codec->num_pcms = 2;
Wu Fengguangb25c9da2009-02-06 15:02:27 +08002177 codec->slave_dig_outs = spec->multiout.slave_dig_outs;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002178 info = spec->pcm_rec + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 info->name = spec->stream_name_digital;
Takashi Iwai8c441982009-01-20 18:30:20 +01002180 if (spec->dig_out_type)
2181 info->pcm_type = spec->dig_out_type;
2182 else
2183 info->pcm_type = HDA_PCM_TYPE_SPDIF;
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002184 if (spec->multiout.dig_out_nid) {
2185 p = spec->stream_digital_playback;
2186 if (!p)
2187 p = &alc_pcm_digital_playback;
2188 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
2190 }
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002191 if (spec->dig_in_nid) {
2192 p = spec->stream_digital_capture;
2193 if (!p)
2194 p = &alc_pcm_digital_capture;
2195 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->dig_in_nid;
2197 }
Takashi Iwai963f8032008-08-11 10:04:40 +02002198 /* FIXME: do we need this for all Realtek codec models? */
2199 codec->spdif_status_reset = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 }
2201
Takashi Iwaie64f14f2009-01-20 18:32:55 +01002202 if (spec->no_analog)
2203 return 0;
2204
Takashi Iwaie08a0072006-09-07 17:52:14 +02002205 /* If the use of more than one ADC is requested for the current
2206 * model, configure a second analog capture-only PCM.
2207 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002208 have_multi_adcs = (spec->num_adc_nids > 1) &&
2209 !spec->dyn_adc_switch && !spec->auto_mic &&
2210 (!spec->input_mux || spec->input_mux->num_items > 1);
Takashi Iwaie08a0072006-09-07 17:52:14 +02002211 /* Additional Analaog capture for index #2 */
Takashi Iwai1fa17572011-11-02 21:30:51 +01002212 if (spec->alt_dac_nid || have_multi_adcs) {
Takashi Iwaie08a0072006-09-07 17:52:14 +02002213 codec->num_pcms = 3;
Takashi Iwaic06134d2006-10-11 18:49:13 +02002214 info = spec->pcm_rec + 2;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002215 info->name = spec->stream_name_analog;
Takashi Iwai63300792008-01-24 15:31:36 +01002216 if (spec->alt_dac_nid) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002217 p = spec->stream_analog_alt_playback;
2218 if (!p)
2219 p = &alc_pcm_analog_alt_playback;
2220 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002221 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
2222 spec->alt_dac_nid;
2223 } else {
2224 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
2225 alc_pcm_null_stream;
2226 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2227 }
Takashi Iwai1fa17572011-11-02 21:30:51 +01002228 if (have_multi_adcs) {
Takashi Iwaic2d986b2011-07-06 18:30:08 +02002229 p = spec->stream_analog_alt_capture;
2230 if (!p)
2231 p = &alc_pcm_analog_alt_capture;
2232 info->stream[SNDRV_PCM_STREAM_CAPTURE] = *p;
Takashi Iwai63300792008-01-24 15:31:36 +01002233 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
2234 spec->adc_nids[1];
2235 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
2236 spec->num_adc_nids - 1;
2237 } else {
2238 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
2239 alc_pcm_null_stream;
2240 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 0;
Takashi Iwaie08a0072006-09-07 17:52:14 +02002241 }
2242 }
2243
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 return 0;
2245}
2246
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002247static inline void alc_shutup(struct hda_codec *codec)
2248{
Takashi Iwai1c716152011-04-07 10:37:16 +02002249 struct alc_spec *spec = codec->spec;
2250
2251 if (spec && spec->shutup)
2252 spec->shutup(codec);
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002253 snd_hda_shutup_pins(codec);
2254}
2255
Takashi Iwai603c4012008-07-30 15:01:44 +02002256static void alc_free_kctls(struct hda_codec *codec)
2257{
2258 struct alc_spec *spec = codec->spec;
2259
2260 if (spec->kctls.list) {
2261 struct snd_kcontrol_new *kctl = spec->kctls.list;
2262 int i;
2263 for (i = 0; i < spec->kctls.used; i++)
2264 kfree(kctl[i].name);
2265 }
2266 snd_array_free(&spec->kctls);
2267}
2268
Takashi Iwai23c09b02011-08-19 09:05:35 +02002269static void alc_free_bind_ctls(struct hda_codec *codec)
2270{
2271 struct alc_spec *spec = codec->spec;
2272 if (spec->bind_ctls.list) {
2273 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2274 int i;
2275 for (i = 0; i < spec->bind_ctls.used; i++)
2276 kfree(ctl[i]);
2277 }
2278 snd_array_free(&spec->bind_ctls);
2279}
2280
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281static void alc_free(struct hda_codec *codec)
2282{
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002283 struct alc_spec *spec = codec->spec;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002284
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002285 if (!spec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002286 return;
2287
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002288 alc_shutup(codec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002289 alc_free_kctls(codec);
Takashi Iwai23c09b02011-08-19 09:05:35 +02002290 alc_free_bind_ctls(codec);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002291 kfree(spec);
Kusanagi Kouichi680cd532009-02-05 00:00:58 +09002292 snd_hda_detach_beep_device(codec);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293}
2294
Hector Martinf5de24b2009-12-20 22:51:31 +01002295#ifdef CONFIG_SND_HDA_POWER_SAVE
Daniel T Chenc97259d2009-12-27 18:52:08 -05002296static void alc_power_eapd(struct hda_codec *codec)
2297{
Takashi Iwai691f1fc2011-04-07 10:31:43 +02002298 alc_auto_setup_eapd(codec, false);
Daniel T Chenc97259d2009-12-27 18:52:08 -05002299}
2300
Hector Martinf5de24b2009-12-20 22:51:31 +01002301static int alc_suspend(struct hda_codec *codec, pm_message_t state)
2302{
2303 struct alc_spec *spec = codec->spec;
Takashi Iwaia4e09aa2009-12-27 11:22:24 +01002304 alc_shutup(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002305 if (spec && spec->power_hook)
Daniel T Chenc97259d2009-12-27 18:52:08 -05002306 spec->power_hook(codec);
Hector Martinf5de24b2009-12-20 22:51:31 +01002307 return 0;
2308}
2309#endif
2310
Takashi Iwai2a439522011-07-26 09:52:50 +02002311#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002312static int alc_resume(struct hda_codec *codec)
2313{
Takashi Iwai1c716152011-04-07 10:37:16 +02002314 msleep(150); /* to avoid pop noise */
Takashi Iwaie044c392008-10-27 16:56:24 +01002315 codec->patch_ops.init(codec);
2316 snd_hda_codec_resume_amp(codec);
2317 snd_hda_codec_resume_cache(codec);
Takashi Iwai9e5341b2010-09-21 09:57:06 +02002318 hda_call_check_power_status(codec, 0x01);
Takashi Iwaie044c392008-10-27 16:56:24 +01002319 return 0;
2320}
Takashi Iwaie044c392008-10-27 16:56:24 +01002321#endif
2322
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323/*
2324 */
Takashi Iwaia9111322011-05-02 11:30:18 +02002325static const struct hda_codec_ops alc_patch_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 .build_controls = alc_build_controls,
2327 .build_pcms = alc_build_pcms,
2328 .init = alc_init,
2329 .free = alc_free,
Takashi Iwaiae6b8132006-03-03 16:47:17 +01002330 .unsol_event = alc_unsol_event,
Takashi Iwai2a439522011-07-26 09:52:50 +02002331#ifdef CONFIG_PM
Takashi Iwaie044c392008-10-27 16:56:24 +01002332 .resume = alc_resume,
2333#endif
Takashi Iwaicb53c622007-08-10 17:21:45 +02002334#ifdef CONFIG_SND_HDA_POWER_SAVE
Hector Martinf5de24b2009-12-20 22:51:31 +01002335 .suspend = alc_suspend,
Takashi Iwaicb53c622007-08-10 17:21:45 +02002336 .check_power_status = alc_check_power_status,
2337#endif
Daniel T Chenc97259d2009-12-27 18:52:08 -05002338 .reboot_notify = alc_shutup,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339};
2340
Kailang Yangc027ddc2010-03-19 11:33:06 +01002341/* replace the codec chip_name with the given string */
2342static int alc_codec_rename(struct hda_codec *codec, const char *name)
2343{
2344 kfree(codec->chip_name);
2345 codec->chip_name = kstrdup(name, GFP_KERNEL);
2346 if (!codec->chip_name) {
2347 alc_free(codec);
2348 return -ENOMEM;
2349 }
2350 return 0;
2351}
2352
Takashi Iwai2fa522b2005-05-12 14:51:12 +02002353/*
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002354 * Rename codecs appropriately from COEF value
2355 */
2356struct alc_codec_rename_table {
2357 unsigned int vendor_id;
2358 unsigned short coef_mask;
2359 unsigned short coef_bits;
2360 const char *name;
2361};
2362
2363static struct alc_codec_rename_table rename_tbl[] = {
2364 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2365 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2366 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2367 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2368 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2369 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2370 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2371 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2372 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2373 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2374 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2375 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2376 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2377 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2378 { } /* terminator */
2379};
2380
2381static int alc_codec_rename_from_preset(struct hda_codec *codec)
2382{
2383 const struct alc_codec_rename_table *p;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002384
2385 for (p = rename_tbl; p->vendor_id; p++) {
2386 if (p->vendor_id != codec->vendor_id)
2387 continue;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02002388 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02002389 return alc_codec_rename(codec, p->name);
2390 }
2391 return 0;
2392}
2393
2394/*
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002395 * Automatic parse of I/O pins from the BIOS configuration
2396 */
2397
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002398enum {
2399 ALC_CTL_WIDGET_VOL,
2400 ALC_CTL_WIDGET_MUTE,
2401 ALC_CTL_BIND_MUTE,
Takashi Iwai23c09b02011-08-19 09:05:35 +02002402 ALC_CTL_BIND_VOL,
2403 ALC_CTL_BIND_SW,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002404};
Takashi Iwai1d045db2011-07-07 18:23:21 +02002405static const struct snd_kcontrol_new alc_control_templates[] = {
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002406 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2407 HDA_CODEC_MUTE(NULL, 0, 0, 0),
Takashi Iwai985be542005-11-02 18:26:49 +01002408 HDA_BIND_MUTE(NULL, 0, 0, 0),
Takashi Iwai23c09b02011-08-19 09:05:35 +02002409 HDA_BIND_VOL(NULL, 0),
2410 HDA_BIND_SW(NULL, 0),
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002411};
2412
2413/* add dynamic controls */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002414static int add_control(struct alc_spec *spec, int type, const char *name,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002415 int cidx, unsigned long val)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002416{
Takashi Iwaic8b6bf92005-11-17 14:57:47 +01002417 struct snd_kcontrol_new *knew;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002418
Takashi Iwaice764ab2011-04-27 16:35:23 +02002419 knew = alc_kcontrol_new(spec);
Takashi Iwai603c4012008-07-30 15:01:44 +02002420 if (!knew)
2421 return -ENOMEM;
Takashi Iwai1d045db2011-07-07 18:23:21 +02002422 *knew = alc_control_templates[type];
Paulo Marques543537b2005-06-23 00:09:02 -07002423 knew->name = kstrdup(name, GFP_KERNEL);
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002424 if (!knew->name)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002425 return -ENOMEM;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002426 knew->index = cidx;
Jaroslav Kysela4d02d1b2009-11-12 10:15:48 +01002427 if (get_amp_nid_(val))
Jaroslav Kysela5e26dfd2009-12-10 13:57:01 +01002428 knew->subdevice = HDA_SUBDEV_AMP_FLAG;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002429 knew->private_value = val;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002430 return 0;
2431}
2432
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002433static int add_control_with_pfx(struct alc_spec *spec, int type,
2434 const char *pfx, const char *dir,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002435 const char *sfx, int cidx, unsigned long val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002436{
2437 char name[32];
2438 snprintf(name, sizeof(name), "%s %s %s", pfx, dir, sfx);
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002439 return add_control(spec, type, name, cidx, val);
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002440}
2441
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002442#define add_pb_vol_ctrl(spec, type, pfx, val) \
2443 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", 0, val)
2444#define add_pb_sw_ctrl(spec, type, pfx, val) \
2445 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", 0, val)
2446#define __add_pb_vol_ctrl(spec, type, pfx, cidx, val) \
2447 add_control_with_pfx(spec, type, pfx, "Playback", "Volume", cidx, val)
2448#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2449 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
Takashi Iwai0afe5f82009-10-02 09:20:00 +02002450
Takashi Iwai23c09b02011-08-19 09:05:35 +02002451static const char * const channel_name[4] = {
2452 "Front", "Surround", "CLFE", "Side"
2453};
2454
Takashi Iwai6843ca12011-06-24 11:03:58 +02002455static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2456 bool can_be_master, int *index)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002457{
Takashi Iwaice764ab2011-04-27 16:35:23 +02002458 struct auto_pin_cfg *cfg = &spec->autocfg;
2459
Takashi Iwai6843ca12011-06-24 11:03:58 +02002460 *index = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02002461 if (cfg->line_outs == 1 && !spec->multi_ios &&
2462 !cfg->hp_outs && !cfg->speaker_outs && can_be_master)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002463 return "Master";
2464
2465 switch (cfg->line_out_type) {
2466 case AUTO_PIN_SPEAKER_OUT:
David Henningssonebbeb3d2011-03-04 14:08:30 +01002467 if (cfg->line_outs == 1)
2468 return "Speaker";
Takashi Iwaifbabc242011-12-07 17:14:20 +01002469 if (cfg->line_outs == 2)
2470 return ch ? "Bass Speaker" : "Speaker";
David Henningssonebbeb3d2011-03-04 14:08:30 +01002471 break;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002472 case AUTO_PIN_HP_OUT:
Takashi Iwai6843ca12011-06-24 11:03:58 +02002473 /* for multi-io case, only the primary out */
2474 if (ch && spec->multi_ios)
2475 break;
2476 *index = ch;
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002477 return "Headphone";
2478 default:
Takashi Iwaice764ab2011-04-27 16:35:23 +02002479 if (cfg->line_outs == 1 && !spec->multi_ios)
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002480 return "PCM";
2481 break;
2482 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02002483 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2484 return "PCM";
2485
2486 return channel_name[ch];
Takashi Iwaibcb2f0f2011-01-10 15:45:23 +01002487}
2488
Takashi Iwai164f73e2012-02-21 11:27:09 +01002489#ifdef CONFIG_SND_HDA_POWER_SAVE
2490/* add the powersave loopback-list entry */
2491static void add_loopback_list(struct alc_spec *spec, hda_nid_t mix, int idx)
2492{
2493 struct hda_amp_list *list;
2494
2495 if (spec->num_loopbacks >= ARRAY_SIZE(spec->loopback_list) - 1)
2496 return;
2497 list = spec->loopback_list + spec->num_loopbacks;
2498 list->nid = mix;
2499 list->dir = HDA_INPUT;
2500 list->idx = idx;
2501 spec->num_loopbacks++;
2502 spec->loopback.amplist = spec->loopback_list;
2503}
2504#else
2505#define add_loopback_list(spec, mix, idx) /* NOP */
2506#endif
2507
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002508/* create input playback/capture controls for the given pin */
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002509static int new_analog_input(struct alc_spec *spec, hda_nid_t pin,
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002510 const char *ctlname, int ctlidx,
Kailang Yangdf694da2005-12-05 19:42:22 +01002511 int idx, hda_nid_t mix_nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002512{
Kailang Yangdf694da2005-12-05 19:42:22 +01002513 int err;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002514
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002515 err = __add_pb_vol_ctrl(spec, ALC_CTL_WIDGET_VOL, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002516 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2517 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002518 return err;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002519 err = __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, ctlname, ctlidx,
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002520 HDA_COMPOSE_AMP_VAL(mix_nid, 3, idx, HDA_INPUT));
2521 if (err < 0)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002522 return err;
Takashi Iwai164f73e2012-02-21 11:27:09 +01002523 add_loopback_list(spec, mix_nid, idx);
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002524 return 0;
2525}
2526
Takashi Iwai05f5f472009-08-25 13:10:18 +02002527static int alc_is_input_pin(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002528{
Takashi Iwai05f5f472009-08-25 13:10:18 +02002529 unsigned int pincap = snd_hda_query_pin_caps(codec, nid);
2530 return (pincap & AC_PINCAP_IN) != 0;
2531}
2532
Takashi Iwai1d045db2011-07-07 18:23:21 +02002533/* Parse the codec tree and retrieve ADCs and corresponding capsrc MUXs */
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002534static int alc_auto_fill_adc_caps(struct hda_codec *codec)
Takashi Iwaib7821702011-07-06 15:12:46 +02002535{
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002536 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002537 hda_nid_t nid;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002538 hda_nid_t *adc_nids = spec->private_adc_nids;
2539 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2540 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
Takashi Iwaib7821702011-07-06 15:12:46 +02002541 int i, nums = 0;
2542
2543 nid = codec->start_nid;
2544 for (i = 0; i < codec->num_nodes; i++, nid++) {
2545 hda_nid_t src;
Takashi Iwaib7821702011-07-06 15:12:46 +02002546 unsigned int caps = get_wcaps(codec, nid);
2547 int type = get_wcaps_type(caps);
2548
2549 if (type != AC_WID_AUD_IN || (caps & AC_WCAP_DIGITAL))
2550 continue;
2551 adc_nids[nums] = nid;
2552 cap_nids[nums] = nid;
2553 src = nid;
2554 for (;;) {
2555 int n;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002556 hda_nid_t conn_nid;
Takashi Iwaib7821702011-07-06 15:12:46 +02002557 type = get_wcaps_type(get_wcaps(codec, src));
2558 if (type == AC_WID_PIN)
2559 break;
2560 if (type == AC_WID_AUD_SEL) {
2561 cap_nids[nums] = src;
2562 break;
2563 }
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002564 n = snd_hda_get_num_conns(codec, src);
Takashi Iwaib7821702011-07-06 15:12:46 +02002565 if (n > 1) {
2566 cap_nids[nums] = src;
2567 break;
2568 } else if (n != 1)
2569 break;
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002570 if (snd_hda_get_connections(codec, src, &src, 1) != 1)
2571 break;
Takashi Iwaib7821702011-07-06 15:12:46 +02002572 }
2573 if (++nums >= max_nums)
2574 break;
2575 }
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002576 spec->adc_nids = spec->private_adc_nids;
Takashi Iwai21268962011-07-07 15:01:13 +02002577 spec->capsrc_nids = spec->private_capsrc_nids;
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002578 spec->num_adc_nids = nums;
Takashi Iwaib7821702011-07-06 15:12:46 +02002579 return nums;
2580}
2581
Takashi Iwai05f5f472009-08-25 13:10:18 +02002582/* create playback/capture controls for input pins */
Takashi Iwaib7821702011-07-06 15:12:46 +02002583static int alc_auto_create_input_ctls(struct hda_codec *codec)
Takashi Iwai05f5f472009-08-25 13:10:18 +02002584{
2585 struct alc_spec *spec = codec->spec;
Takashi Iwaib7821702011-07-06 15:12:46 +02002586 const struct auto_pin_cfg *cfg = &spec->autocfg;
2587 hda_nid_t mixer = spec->mixer_nid;
Herton Ronaldo Krzesinski61b9b9b2009-01-28 09:16:33 -02002588 struct hda_input_mux *imux = &spec->private_imux[0];
Takashi Iwaib7821702011-07-06 15:12:46 +02002589 int num_adcs;
Takashi Iwaib7821702011-07-06 15:12:46 +02002590 int i, c, err, idx, type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002591 const char *prev_label = NULL;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002592
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002593 num_adcs = alc_auto_fill_adc_caps(codec);
Takashi Iwaib7821702011-07-06 15:12:46 +02002594 if (num_adcs < 0)
2595 return 0;
2596
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002597 for (i = 0; i < cfg->num_inputs; i++) {
Takashi Iwai05f5f472009-08-25 13:10:18 +02002598 hda_nid_t pin;
Takashi Iwai10a20af2010-09-09 16:28:02 +02002599 const char *label;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002600
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002601 pin = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002602 if (!alc_is_input_pin(codec, pin))
2603 continue;
2604
David Henningsson5322bf22011-01-05 11:03:56 +01002605 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01002606 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
2607 label = "Headphone Mic";
David Henningsson5322bf22011-01-05 11:03:56 +01002608 if (prev_label && !strcmp(label, prev_label))
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002609 type_idx++;
2610 else
2611 type_idx = 0;
David Henningsson5322bf22011-01-05 11:03:56 +01002612 prev_label = label;
2613
Takashi Iwai05f5f472009-08-25 13:10:18 +02002614 if (mixer) {
2615 idx = get_connection_index(codec, mixer, pin);
2616 if (idx >= 0) {
2617 err = new_analog_input(spec, pin,
Takashi Iwai10a20af2010-09-09 16:28:02 +02002618 label, type_idx,
2619 idx, mixer);
Takashi Iwai05f5f472009-08-25 13:10:18 +02002620 if (err < 0)
2621 return err;
2622 }
2623 }
2624
Takashi Iwaib7821702011-07-06 15:12:46 +02002625 for (c = 0; c < num_adcs; c++) {
Takashi Iwai61071592011-11-23 07:52:15 +01002626 hda_nid_t cap = get_capsrc(spec, c);
Takashi Iwaid6cc9fab2011-07-06 16:38:42 +02002627 idx = get_connection_index(codec, cap, pin);
Takashi Iwaib7821702011-07-06 15:12:46 +02002628 if (idx >= 0) {
Takashi Iwai21268962011-07-07 15:01:13 +02002629 spec->imux_pins[imux->num_items] = pin;
Takashi Iwaib7821702011-07-06 15:12:46 +02002630 snd_hda_add_imux_item(imux, label, idx, NULL);
2631 break;
2632 }
2633 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002634 }
Takashi Iwai21268962011-07-07 15:01:13 +02002635
2636 spec->num_mux_defs = 1;
2637 spec->input_mux = imux;
2638
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002639 return 0;
2640}
2641
Takashi Iwai24de1832011-11-07 17:13:39 +01002642/* create a shared input with the headphone out */
2643static int alc_auto_create_shared_input(struct hda_codec *codec)
2644{
2645 struct alc_spec *spec = codec->spec;
2646 struct auto_pin_cfg *cfg = &spec->autocfg;
2647 unsigned int defcfg;
2648 hda_nid_t nid;
2649
2650 /* only one internal input pin? */
2651 if (cfg->num_inputs != 1)
2652 return 0;
2653 defcfg = snd_hda_codec_get_pincfg(codec, cfg->inputs[0].pin);
2654 if (snd_hda_get_input_pin_attr(defcfg) != INPUT_PIN_ATTR_INT)
2655 return 0;
2656
2657 if (cfg->hp_outs == 1 && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
2658 nid = cfg->hp_pins[0]; /* OK, we have a single HP-out */
2659 else if (cfg->line_outs == 1 && cfg->line_out_type == AUTO_PIN_HP_OUT)
2660 nid = cfg->line_out_pins[0]; /* OK, we have a single line-out */
2661 else
2662 return 0; /* both not available */
2663
2664 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_IN))
2665 return 0; /* no input */
2666
2667 cfg->inputs[1].pin = nid;
2668 cfg->inputs[1].type = AUTO_PIN_MIC;
2669 cfg->num_inputs = 2;
2670 spec->shared_mic_hp = 1;
2671 snd_printdd("realtek: Enable shared I/O jack on NID 0x%x\n", nid);
2672 return 0;
2673}
2674
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002675static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
2676 unsigned int pin_type)
2677{
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02002678 snd_hda_set_pin_ctl(codec, nid, pin_type);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002679 /* unmute pin */
Takashi Iwai44c02402011-07-08 15:14:19 +02002680 if (nid_has_mute(codec, nid, HDA_OUTPUT))
2681 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaid260cdf2008-02-13 17:19:35 +01002682 AMP_OUT_UNMUTE);
Takashi Iwaif6c7e542008-02-12 18:32:23 +01002683}
2684
Takashi Iwaibaba8ee2007-04-23 17:17:48 +02002685static int get_pin_type(int line_out_type)
2686{
2687 if (line_out_type == AUTO_PIN_HP_OUT)
2688 return PIN_HP;
2689 else
2690 return PIN_OUT;
2691}
2692
Takashi Iwai0a7f5322011-07-06 15:15:12 +02002693static void alc_auto_init_analog_input(struct hda_codec *codec)
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002694{
2695 struct alc_spec *spec = codec->spec;
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002696 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002697 int i;
2698
Takashi Iwai66ceeb62010-08-30 13:05:52 +02002699 for (i = 0; i < cfg->num_inputs; i++) {
2700 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai05f5f472009-08-25 13:10:18 +02002701 if (alc_is_input_pin(codec, nid)) {
Takashi Iwai30ea0982010-09-16 18:47:56 +02002702 alc_set_input_pin(codec, nid, cfg->inputs[i].type);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002703 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
Takashi Iwaif12ab1e2007-04-12 15:51:47 +02002704 snd_hda_codec_write(codec, nid, 0,
2705 AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002706 AMP_OUT_MUTE);
2707 }
2708 }
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002709
2710 /* mute all loopback inputs */
2711 if (spec->mixer_nid) {
Takashi Iwai09cf03b2012-05-19 17:21:25 +02002712 int nums = snd_hda_get_num_conns(codec, spec->mixer_nid);
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02002713 for (i = 0; i < nums; i++)
2714 snd_hda_codec_write(codec, spec->mixer_nid, 0,
2715 AC_VERB_SET_AMP_GAIN_MUTE,
2716 AMP_IN_MUTE(i));
2717 }
Takashi Iwaie9edcee2005-06-13 14:16:38 +02002718}
2719
Takashi Iwai7085ec12009-10-02 09:03:58 +02002720/* convert from MIX nid to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002721static hda_nid_t alc_auto_mix_to_dac(struct hda_codec *codec, hda_nid_t nid)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002722{
Takashi Iwai604401a2011-04-27 15:14:23 +02002723 hda_nid_t list[5];
Takashi Iwai1304ac82011-04-06 15:16:21 +02002724 int i, num;
2725
Takashi Iwaiafcd5512011-07-08 11:07:59 +02002726 if (get_wcaps_type(get_wcaps(codec, nid)) == AC_WID_AUD_OUT)
2727 return nid;
Takashi Iwai1304ac82011-04-06 15:16:21 +02002728 num = snd_hda_get_connections(codec, nid, list, ARRAY_SIZE(list));
2729 for (i = 0; i < num; i++) {
2730 if (get_wcaps_type(get_wcaps(codec, list[i])) == AC_WID_AUD_OUT)
2731 return list[i];
2732 }
2733 return 0;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002734}
2735
Takashi Iwai604401a2011-04-27 15:14:23 +02002736/* go down to the selector widget before the mixer */
2737static hda_nid_t alc_go_down_to_selector(struct hda_codec *codec, hda_nid_t pin)
2738{
2739 hda_nid_t srcs[5];
2740 int num = snd_hda_get_connections(codec, pin, srcs,
2741 ARRAY_SIZE(srcs));
2742 if (num != 1 ||
2743 get_wcaps_type(get_wcaps(codec, srcs[0])) != AC_WID_AUD_SEL)
2744 return pin;
2745 return srcs[0];
2746}
2747
Takashi Iwai7085ec12009-10-02 09:03:58 +02002748/* get MIX nid connected to the given pin targeted to DAC */
Takashi Iwai604401a2011-04-27 15:14:23 +02002749static hda_nid_t alc_auto_dac_to_mix(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai7085ec12009-10-02 09:03:58 +02002750 hda_nid_t dac)
2751{
David Henningssoncc1c4522010-11-24 14:17:47 +01002752 hda_nid_t mix[5];
Takashi Iwai7085ec12009-10-02 09:03:58 +02002753 int i, num;
2754
Takashi Iwai604401a2011-04-27 15:14:23 +02002755 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002756 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2757 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002758 if (alc_auto_mix_to_dac(codec, mix[i]) == dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002759 return mix[i];
2760 }
2761 return 0;
2762}
2763
Takashi Iwaice764ab2011-04-27 16:35:23 +02002764/* select the connection from pin to DAC if needed */
2765static int alc_auto_select_dac(struct hda_codec *codec, hda_nid_t pin,
2766 hda_nid_t dac)
2767{
2768 hda_nid_t mix[5];
2769 int i, num;
2770
2771 pin = alc_go_down_to_selector(codec, pin);
2772 num = snd_hda_get_connections(codec, pin, mix, ARRAY_SIZE(mix));
2773 if (num < 2)
2774 return 0;
2775 for (i = 0; i < num; i++) {
2776 if (alc_auto_mix_to_dac(codec, mix[i]) == dac) {
2777 snd_hda_codec_update_cache(codec, pin, 0,
2778 AC_VERB_SET_CONNECT_SEL, i);
2779 return 0;
2780 }
2781 }
2782 return 0;
2783}
2784
Takashi Iwai185d99f2012-02-16 18:39:45 +01002785static bool alc_is_dac_already_used(struct hda_codec *codec, hda_nid_t nid)
2786{
2787 struct alc_spec *spec = codec->spec;
Takashi Iwai276dd702012-02-17 16:17:03 +01002788 int i;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002789 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2790 ARRAY_SIZE(spec->private_dac_nids)) ||
2791 found_in_nid_list(nid, spec->multiout.hp_out_nid,
2792 ARRAY_SIZE(spec->multiout.hp_out_nid)) ||
2793 found_in_nid_list(nid, spec->multiout.extra_out_nid,
2794 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2795 return true;
Takashi Iwai276dd702012-02-17 16:17:03 +01002796 for (i = 0; i < spec->multi_ios; i++) {
2797 if (spec->multi_io[i].dac == nid)
2798 return true;
2799 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01002800 return false;
2801}
2802
Takashi Iwai7085ec12009-10-02 09:03:58 +02002803/* look for an empty DAC slot */
Takashi Iwai604401a2011-04-27 15:14:23 +02002804static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
Takashi Iwai7085ec12009-10-02 09:03:58 +02002805{
Takashi Iwai7085ec12009-10-02 09:03:58 +02002806 hda_nid_t srcs[5];
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002807 int i, num;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002808
Takashi Iwai604401a2011-04-27 15:14:23 +02002809 pin = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002810 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02002811 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02002812 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
Takashi Iwai7085ec12009-10-02 09:03:58 +02002813 if (!nid)
2814 continue;
Takashi Iwai185d99f2012-02-16 18:39:45 +01002815 if (!alc_is_dac_already_used(codec, nid))
2816 return nid;
Takashi Iwai7085ec12009-10-02 09:03:58 +02002817 }
2818 return 0;
2819}
2820
Takashi Iwai07b18f62011-11-10 15:42:54 +01002821/* check whether the DAC is reachable from the pin */
2822static bool alc_auto_is_dac_reachable(struct hda_codec *codec,
2823 hda_nid_t pin, hda_nid_t dac)
2824{
2825 hda_nid_t srcs[5];
2826 int i, num;
2827
Takashi Iwaidc31b582012-02-17 17:27:53 +01002828 if (!pin || !dac)
2829 return false;
Takashi Iwai07b18f62011-11-10 15:42:54 +01002830 pin = alc_go_down_to_selector(codec, pin);
2831 num = snd_hda_get_connections(codec, pin, srcs, ARRAY_SIZE(srcs));
2832 for (i = 0; i < num; i++) {
2833 hda_nid_t nid = alc_auto_mix_to_dac(codec, srcs[i]);
2834 if (nid == dac)
2835 return true;
2836 }
2837 return false;
2838}
2839
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002840static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2841{
Takashi Iwai140547e2012-02-16 17:23:46 +01002842 struct alc_spec *spec = codec->spec;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002843 hda_nid_t sel = alc_go_down_to_selector(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002844 hda_nid_t nid, nid_found, srcs[5];
2845 int i, num = snd_hda_get_connections(codec, sel, srcs,
Takashi Iwai140547e2012-02-16 17:23:46 +01002846 ARRAY_SIZE(srcs));
Takashi Iwai185d99f2012-02-16 18:39:45 +01002847 if (num == 1)
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002848 return alc_auto_look_for_dac(codec, pin);
Takashi Iwai185d99f2012-02-16 18:39:45 +01002849 nid_found = 0;
2850 for (i = 0; i < num; i++) {
2851 if (srcs[i] == spec->mixer_nid)
2852 continue;
2853 nid = alc_auto_mix_to_dac(codec, srcs[i]);
2854 if (nid && !alc_is_dac_already_used(codec, nid)) {
2855 if (nid_found)
2856 return 0;
2857 nid_found = nid;
2858 }
2859 }
2860 return nid_found;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02002861}
2862
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002863/* mark up volume and mute control NIDs: used during badness parsing and
2864 * at creating actual controls
2865 */
2866static inline unsigned int get_ctl_pos(unsigned int data)
2867{
2868 hda_nid_t nid = get_amp_nid_(data);
2869 unsigned int dir;
2870 if (snd_BUG_ON(nid >= MAX_VOL_NIDS))
2871 return 0;
2872 dir = get_amp_direction_(data);
2873 return (nid << 1) | dir;
2874}
2875
2876#define is_ctl_used(bits, data) \
2877 test_bit(get_ctl_pos(data), bits)
2878#define mark_ctl_usage(bits, data) \
2879 set_bit(get_ctl_pos(data), bits)
2880
2881static void clear_vol_marks(struct hda_codec *codec)
2882{
2883 struct alc_spec *spec = codec->spec;
2884 memset(spec->vol_ctls, 0, sizeof(spec->vol_ctls));
2885 memset(spec->sw_ctls, 0, sizeof(spec->sw_ctls));
2886}
2887
2888/* badness definition */
2889enum {
2890 /* No primary DAC is found for the main output */
2891 BAD_NO_PRIMARY_DAC = 0x10000,
2892 /* No DAC is found for the extra output */
2893 BAD_NO_DAC = 0x4000,
Takashi Iwai276dd702012-02-17 16:17:03 +01002894 /* No possible multi-ios */
2895 BAD_MULTI_IO = 0x103,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002896 /* No individual DAC for extra output */
Takashi Iwai276dd702012-02-17 16:17:03 +01002897 BAD_NO_EXTRA_DAC = 0x102,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002898 /* No individual DAC for extra surrounds */
Takashi Iwai276dd702012-02-17 16:17:03 +01002899 BAD_NO_EXTRA_SURR_DAC = 0x101,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002900 /* Primary DAC shared with main surrounds */
2901 BAD_SHARED_SURROUND = 0x100,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002902 /* Primary DAC shared with main CLFE */
2903 BAD_SHARED_CLFE = 0x10,
2904 /* Primary DAC shared with extra surrounds */
2905 BAD_SHARED_EXTRA_SURROUND = 0x10,
Takashi Iwai276dd702012-02-17 16:17:03 +01002906 /* Volume widget is shared */
2907 BAD_SHARED_VOL = 0x10,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002908};
2909
2910static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
2911 hda_nid_t pin, hda_nid_t dac);
2912static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
2913 hda_nid_t pin, hda_nid_t dac);
2914
2915static int eval_shared_vol_badness(struct hda_codec *codec, hda_nid_t pin,
2916 hda_nid_t dac)
2917{
2918 struct alc_spec *spec = codec->spec;
2919 hda_nid_t nid;
2920 unsigned int val;
2921 int badness = 0;
2922
2923 nid = alc_look_for_out_vol_nid(codec, pin, dac);
2924 if (nid) {
2925 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2926 if (is_ctl_used(spec->vol_ctls, nid))
2927 badness += BAD_SHARED_VOL;
2928 else
2929 mark_ctl_usage(spec->vol_ctls, val);
2930 } else
2931 badness += BAD_SHARED_VOL;
2932 nid = alc_look_for_out_mute_nid(codec, pin, dac);
2933 if (nid) {
2934 unsigned int wid_type = get_wcaps_type(get_wcaps(codec, nid));
2935 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT)
2936 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_OUTPUT);
2937 else
2938 val = HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT);
2939 if (is_ctl_used(spec->sw_ctls, val))
2940 badness += BAD_SHARED_VOL;
2941 else
2942 mark_ctl_usage(spec->sw_ctls, val);
2943 } else
2944 badness += BAD_SHARED_VOL;
2945 return badness;
2946}
2947
Takashi Iwaidc31b582012-02-17 17:27:53 +01002948struct badness_table {
2949 int no_primary_dac; /* no primary DAC */
2950 int no_dac; /* no secondary DACs */
2951 int shared_primary; /* primary DAC is shared with main output */
2952 int shared_surr; /* secondary DAC shared with main or primary */
2953 int shared_clfe; /* third DAC shared with main or primary */
2954 int shared_surr_main; /* secondary DAC sahred with main/DAC0 */
2955};
2956
2957static struct badness_table main_out_badness = {
2958 .no_primary_dac = BAD_NO_PRIMARY_DAC,
2959 .no_dac = BAD_NO_DAC,
2960 .shared_primary = BAD_NO_PRIMARY_DAC,
2961 .shared_surr = BAD_SHARED_SURROUND,
2962 .shared_clfe = BAD_SHARED_CLFE,
2963 .shared_surr_main = BAD_SHARED_SURROUND,
2964};
2965
2966static struct badness_table extra_out_badness = {
2967 .no_primary_dac = BAD_NO_DAC,
2968 .no_dac = BAD_NO_DAC,
2969 .shared_primary = BAD_NO_EXTRA_DAC,
2970 .shared_surr = BAD_SHARED_EXTRA_SURROUND,
2971 .shared_clfe = BAD_SHARED_EXTRA_SURROUND,
2972 .shared_surr_main = BAD_NO_EXTRA_SURR_DAC,
2973};
2974
2975/* try to assign DACs to pins and return the resultant badness */
2976static int alc_auto_fill_dacs(struct hda_codec *codec, int num_outs,
2977 const hda_nid_t *pins, hda_nid_t *dacs,
2978 const struct badness_table *bad)
Takashi Iwaic2674682011-08-24 17:57:44 +02002979{
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002980 struct alc_spec *spec = codec->spec;
Takashi Iwaidc31b582012-02-17 17:27:53 +01002981 struct auto_pin_cfg *cfg = &spec->autocfg;
2982 int i, j;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01002983 int badness = 0;
2984 hda_nid_t dac;
Takashi Iwaic2674682011-08-24 17:57:44 +02002985
Takashi Iwai185d99f2012-02-16 18:39:45 +01002986 if (!num_outs)
2987 return 0;
2988
Takashi Iwaidc31b582012-02-17 17:27:53 +01002989 for (i = 0; i < num_outs; i++) {
2990 hda_nid_t pin = pins[i];
2991 if (!dacs[i])
2992 dacs[i] = alc_auto_look_for_dac(codec, pin);
2993 if (!dacs[i] && !i) {
2994 for (j = 1; j < num_outs; j++) {
2995 if (alc_auto_is_dac_reachable(codec, pin, dacs[j])) {
2996 dacs[0] = dacs[j];
2997 dacs[j] = 0;
2998 break;
2999 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003000 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003001 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003002 dac = dacs[i];
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003003 if (!dac) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003004 if (alc_auto_is_dac_reachable(codec, pin, dacs[0]))
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003005 dac = dacs[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003006 else if (cfg->line_outs > i &&
3007 alc_auto_is_dac_reachable(codec, pin,
3008 spec->private_dac_nids[i]))
3009 dac = spec->private_dac_nids[i];
3010 if (dac) {
3011 if (!i)
3012 badness += bad->shared_primary;
3013 else if (i == 1)
3014 badness += bad->shared_surr;
3015 else
3016 badness += bad->shared_clfe;
3017 } else if (alc_auto_is_dac_reachable(codec, pin,
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003018 spec->private_dac_nids[0])) {
3019 dac = spec->private_dac_nids[0];
Takashi Iwaidc31b582012-02-17 17:27:53 +01003020 badness += bad->shared_surr_main;
3021 } else if (!i)
3022 badness += bad->no_primary_dac;
3023 else
3024 badness += bad->no_dac;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003025 }
3026 if (dac)
Takashi Iwaidc31b582012-02-17 17:27:53 +01003027 badness += eval_shared_vol_badness(codec, pin, dac);
Takashi Iwaic2674682011-08-24 17:57:44 +02003028 }
Takashi Iwaidc31b582012-02-17 17:27:53 +01003029
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003030 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003031}
3032
3033static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003034 hda_nid_t reference_pin,
3035 bool hardwired, int offset);
Takashi Iwaic2674682011-08-24 17:57:44 +02003036
Takashi Iwai185d99f2012-02-16 18:39:45 +01003037static bool alc_map_singles(struct hda_codec *codec, int outs,
3038 const hda_nid_t *pins, hda_nid_t *dacs)
3039{
3040 int i;
3041 bool found = false;
3042 for (i = 0; i < outs; i++) {
3043 if (dacs[i])
3044 continue;
3045 dacs[i] = get_dac_if_single(codec, pins[i]);
3046 if (dacs[i])
3047 found = true;
3048 }
3049 return found;
3050}
3051
Takashi Iwai7085ec12009-10-02 09:03:58 +02003052/* fill in the dac_nids table from the parsed pin configuration */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003053static int fill_and_eval_dacs(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003054 bool fill_hardwired,
3055 bool fill_mio_first)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003056{
3057 struct alc_spec *spec = codec->spec;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003058 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwaidc31b582012-02-17 17:27:53 +01003059 int i, err, badness;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003060
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003061 /* set num_dacs once to full for alc_auto_look_for_dac() */
3062 spec->multiout.num_dacs = cfg->line_outs;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003063 spec->multiout.dac_nids = spec->private_dac_nids;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003064 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
3065 memset(spec->multiout.hp_out_nid, 0, sizeof(spec->multiout.hp_out_nid));
3066 memset(spec->multiout.extra_out_nid, 0, sizeof(spec->multiout.extra_out_nid));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003067 spec->multi_ios = 0;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003068 clear_vol_marks(codec);
3069 badness = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003070
3071 /* fill hard-wired DACs first */
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003072 if (fill_hardwired) {
Takashi Iwai185d99f2012-02-16 18:39:45 +01003073 bool mapped;
3074 do {
3075 mapped = alc_map_singles(codec, cfg->line_outs,
Takashi Iwai276dd702012-02-17 16:17:03 +01003076 cfg->line_out_pins,
3077 spec->private_dac_nids);
Takashi Iwai185d99f2012-02-16 18:39:45 +01003078 mapped |= alc_map_singles(codec, cfg->hp_outs,
3079 cfg->hp_pins,
3080 spec->multiout.hp_out_nid);
3081 mapped |= alc_map_singles(codec, cfg->speaker_outs,
3082 cfg->speaker_pins,
3083 spec->multiout.extra_out_nid);
Takashi Iwai276dd702012-02-17 16:17:03 +01003084 if (fill_mio_first && cfg->line_outs == 1 &&
3085 cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3086 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], true, 0);
3087 if (!err)
3088 mapped = true;
3089 }
Takashi Iwai185d99f2012-02-16 18:39:45 +01003090 } while (mapped);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003091 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003092
Takashi Iwaidc31b582012-02-17 17:27:53 +01003093 badness += alc_auto_fill_dacs(codec, cfg->line_outs, cfg->line_out_pins,
3094 spec->private_dac_nids,
3095 &main_out_badness);
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003096
Takashi Iwai8f398ae2011-07-23 18:57:11 +02003097 /* re-count num_dacs and squash invalid entries */
3098 spec->multiout.num_dacs = 0;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003099 for (i = 0; i < cfg->line_outs; i++) {
3100 if (spec->private_dac_nids[i])
3101 spec->multiout.num_dacs++;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003102 else {
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003103 memmove(spec->private_dac_nids + i,
3104 spec->private_dac_nids + i + 1,
3105 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
Takashi Iwai0a34b422011-12-07 17:20:30 +01003106 spec->private_dac_nids[cfg->line_outs - 1] = 0;
3107 }
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003108 }
3109
Takashi Iwai276dd702012-02-17 16:17:03 +01003110 if (fill_mio_first &&
3111 cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaic2674682011-08-24 17:57:44 +02003112 /* try to fill multi-io first */
Takashi Iwai276dd702012-02-17 16:17:03 +01003113 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003114 if (err < 0)
3115 return err;
Takashi Iwai276dd702012-02-17 16:17:03 +01003116 /* we don't count badness at this stage yet */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003117 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003118
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003119 if (cfg->line_out_type != AUTO_PIN_HP_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003120 err = alc_auto_fill_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3121 spec->multiout.hp_out_nid,
3122 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003123 if (err < 0)
3124 return err;
3125 badness += err;
3126 }
Takashi Iwai0a34b422011-12-07 17:20:30 +01003127 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
Takashi Iwaidc31b582012-02-17 17:27:53 +01003128 err = alc_auto_fill_dacs(codec, cfg->speaker_outs,
3129 cfg->speaker_pins,
3130 spec->multiout.extra_out_nid,
3131 &extra_out_badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003132 if (err < 0)
3133 return err;
3134 badness += err;
3135 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003136 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
3137 err = alc_auto_fill_multi_ios(codec, cfg->line_out_pins[0], false, 0);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003138 if (err < 0)
3139 return err;
3140 badness += err;
3141 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003142 if (cfg->hp_outs && cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3143 /* try multi-ios with HP + inputs */
Takashi Iwaif5682912012-02-21 12:37:00 +01003144 int offset = 0;
3145 if (cfg->line_outs >= 3)
3146 offset = 1;
3147 err = alc_auto_fill_multi_ios(codec, cfg->hp_pins[0], false,
3148 offset);
Takashi Iwai276dd702012-02-17 16:17:03 +01003149 if (err < 0)
3150 return err;
3151 badness += err;
3152 }
3153
3154 if (spec->multi_ios == 2) {
3155 for (i = 0; i < 2; i++)
3156 spec->private_dac_nids[spec->multiout.num_dacs++] =
3157 spec->multi_io[i].dac;
3158 spec->ext_channel_count = 2;
3159 } else if (spec->multi_ios) {
3160 spec->multi_ios = 0;
3161 badness += BAD_MULTI_IO;
3162 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003163
3164 return badness;
3165}
3166
3167#define DEBUG_BADNESS
3168
3169#ifdef DEBUG_BADNESS
3170#define debug_badness snd_printdd
3171#else
3172#define debug_badness(...)
3173#endif
3174
3175static void debug_show_configs(struct alc_spec *spec, struct auto_pin_cfg *cfg)
3176{
3177 debug_badness("multi_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3178 cfg->line_out_pins[0], cfg->line_out_pins[1],
3179 cfg->line_out_pins[2], cfg->line_out_pins[2],
3180 spec->multiout.dac_nids[0],
3181 spec->multiout.dac_nids[1],
3182 spec->multiout.dac_nids[2],
3183 spec->multiout.dac_nids[3]);
Takashi Iwai6f453042012-02-17 14:09:20 +01003184 if (spec->multi_ios > 0)
3185 debug_badness("multi_ios(%d) = %x/%x : %x/%x\n",
3186 spec->multi_ios,
3187 spec->multi_io[0].pin, spec->multi_io[1].pin,
3188 spec->multi_io[0].dac, spec->multi_io[1].dac);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003189 debug_badness("hp_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3190 cfg->hp_pins[0], cfg->hp_pins[1],
3191 cfg->hp_pins[2], cfg->hp_pins[2],
3192 spec->multiout.hp_out_nid[0],
3193 spec->multiout.hp_out_nid[1],
3194 spec->multiout.hp_out_nid[2],
3195 spec->multiout.hp_out_nid[3]);
3196 debug_badness("spk_outs = %x/%x/%x/%x : %x/%x/%x/%x\n",
3197 cfg->speaker_pins[0], cfg->speaker_pins[1],
3198 cfg->speaker_pins[2], cfg->speaker_pins[3],
3199 spec->multiout.extra_out_nid[0],
3200 spec->multiout.extra_out_nid[1],
3201 spec->multiout.extra_out_nid[2],
3202 spec->multiout.extra_out_nid[3]);
3203}
3204
3205static int alc_auto_fill_dac_nids(struct hda_codec *codec)
3206{
3207 struct alc_spec *spec = codec->spec;
3208 struct auto_pin_cfg *cfg = &spec->autocfg;
3209 struct auto_pin_cfg *best_cfg;
3210 int best_badness = INT_MAX;
3211 int badness;
Takashi Iwai276dd702012-02-17 16:17:03 +01003212 bool fill_hardwired = true, fill_mio_first = true;
3213 bool best_wired = true, best_mio = true;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003214 bool hp_spk_swapped = false;
3215
3216 best_cfg = kmalloc(sizeof(*best_cfg), GFP_KERNEL);
3217 if (!best_cfg)
3218 return -ENOMEM;
3219 *best_cfg = *cfg;
3220
3221 for (;;) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003222 badness = fill_and_eval_dacs(codec, fill_hardwired,
3223 fill_mio_first);
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003224 if (badness < 0) {
3225 kfree(best_cfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003226 return badness;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003227 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003228 debug_badness("==> lo_type=%d, wired=%d, mio=%d, badness=0x%x\n",
3229 cfg->line_out_type, fill_hardwired, fill_mio_first,
3230 badness);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003231 debug_show_configs(spec, cfg);
3232 if (badness < best_badness) {
3233 best_badness = badness;
3234 *best_cfg = *cfg;
3235 best_wired = fill_hardwired;
Takashi Iwai276dd702012-02-17 16:17:03 +01003236 best_mio = fill_mio_first;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003237 }
3238 if (!badness)
3239 break;
Takashi Iwai276dd702012-02-17 16:17:03 +01003240 fill_mio_first = !fill_mio_first;
3241 if (!fill_mio_first)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003242 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003243 fill_hardwired = !fill_hardwired;
3244 if (!fill_hardwired)
3245 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003246 if (hp_spk_swapped)
3247 break;
3248 hp_spk_swapped = true;
3249 if (cfg->speaker_outs > 0 &&
Takashi Iwai0a34b422011-12-07 17:20:30 +01003250 cfg->line_out_type == AUTO_PIN_HP_OUT) {
3251 cfg->hp_outs = cfg->line_outs;
3252 memcpy(cfg->hp_pins, cfg->line_out_pins,
3253 sizeof(cfg->hp_pins));
3254 cfg->line_outs = cfg->speaker_outs;
3255 memcpy(cfg->line_out_pins, cfg->speaker_pins,
3256 sizeof(cfg->speaker_pins));
3257 cfg->speaker_outs = 0;
3258 memset(cfg->speaker_pins, 0, sizeof(cfg->speaker_pins));
3259 cfg->line_out_type = AUTO_PIN_SPEAKER_OUT;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003260 fill_hardwired = true;
3261 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003262 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003263 if (cfg->hp_outs > 0 &&
3264 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
3265 cfg->speaker_outs = cfg->line_outs;
3266 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3267 sizeof(cfg->speaker_pins));
3268 cfg->line_outs = cfg->hp_outs;
3269 memcpy(cfg->line_out_pins, cfg->hp_pins,
3270 sizeof(cfg->hp_pins));
3271 cfg->hp_outs = 0;
3272 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3273 cfg->line_out_type = AUTO_PIN_HP_OUT;
3274 fill_hardwired = true;
3275 continue;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02003276 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003277 break;
Takashi Iwai0a34b422011-12-07 17:20:30 +01003278 }
Takashi Iwaic2674682011-08-24 17:57:44 +02003279
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003280 if (badness) {
3281 *cfg = *best_cfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003282 fill_and_eval_dacs(codec, best_wired, best_mio);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003283 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003284 debug_badness("==> Best config: lo_type=%d, wired=%d, mio=%d\n",
3285 cfg->line_out_type, best_wired, best_mio);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003286 debug_show_configs(spec, cfg);
Takashi Iwai07b18f62011-11-10 15:42:54 +01003287
David Henningssonfde48a12011-12-09 18:27:42 +08003288 if (cfg->line_out_pins[0])
3289 spec->vmaster_nid =
3290 alc_look_for_out_vol_nid(codec, cfg->line_out_pins[0],
3291 spec->multiout.dac_nids[0]);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003292
3293 /* clear the bitmap flags for creating controls */
3294 clear_vol_marks(codec);
3295 kfree(best_cfg);
Takashi Iwai23c09b02011-08-19 09:05:35 +02003296 return 0;
3297}
3298
Takashi Iwai343a04b2011-07-06 14:28:39 +02003299static int alc_auto_add_vol_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003300 const char *pfx, int cidx,
3301 hda_nid_t nid, unsigned int chs)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003302{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003303 struct alc_spec *spec = codec->spec;
3304 unsigned int val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003305 if (!nid)
3306 return 0;
Takashi Iwai527e4d72011-10-27 16:33:27 +02003307 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3308 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3309 return 0;
3310 mark_ctl_usage(spec->vol_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003311 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
Takashi Iwai527e4d72011-10-27 16:33:27 +02003312 val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003313}
3314
Takashi Iwaie29d3772011-11-14 17:13:23 +01003315static int alc_auto_add_stereo_vol(struct hda_codec *codec,
3316 const char *pfx, int cidx,
3317 hda_nid_t nid)
3318{
3319 int chs = 1;
3320 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3321 chs = 3;
3322 return alc_auto_add_vol_ctl(codec, pfx, cidx, nid, chs);
3323}
Takashi Iwai97aaab72011-07-06 14:02:55 +02003324
3325/* create a mute-switch for the given mixer widget;
3326 * if it has multiple sources (e.g. DAC and loopback), create a bind-mute
3327 */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003328static int alc_auto_add_sw_ctl(struct hda_codec *codec,
Takashi Iwai97aaab72011-07-06 14:02:55 +02003329 const char *pfx, int cidx,
3330 hda_nid_t nid, unsigned int chs)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003331{
Takashi Iwai527e4d72011-10-27 16:33:27 +02003332 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003333 int wid_type;
Takashi Iwai97aaab72011-07-06 14:02:55 +02003334 int type;
3335 unsigned long val;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003336 if (!nid)
3337 return 0;
3338 wid_type = get_wcaps_type(get_wcaps(codec, nid));
3339 if (wid_type == AC_WID_PIN || wid_type == AC_WID_AUD_OUT) {
3340 type = ALC_CTL_WIDGET_MUTE;
3341 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003342 } else if (snd_hda_get_num_conns(codec, nid) == 1) {
Takashi Iwai97aaab72011-07-06 14:02:55 +02003343 type = ALC_CTL_WIDGET_MUTE;
3344 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_INPUT);
3345 } else {
3346 type = ALC_CTL_BIND_MUTE;
3347 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
3348 }
Takashi Iwai527e4d72011-10-27 16:33:27 +02003349 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3350 return 0;
3351 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai97aaab72011-07-06 14:02:55 +02003352 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003353}
3354
Takashi Iwaie29d3772011-11-14 17:13:23 +01003355static int alc_auto_add_stereo_sw(struct hda_codec *codec, const char *pfx,
3356 int cidx, hda_nid_t nid)
3357{
3358 int chs = 1;
3359 if (get_wcaps(codec, nid) & AC_WCAP_STEREO)
3360 chs = 3;
3361 return alc_auto_add_sw_ctl(codec, pfx, cidx, nid, chs);
3362}
Takashi Iwai7085ec12009-10-02 09:03:58 +02003363
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003364static hda_nid_t alc_look_for_out_mute_nid(struct hda_codec *codec,
3365 hda_nid_t pin, hda_nid_t dac)
3366{
3367 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3368 if (nid_has_mute(codec, pin, HDA_OUTPUT))
3369 return pin;
3370 else if (mix && nid_has_mute(codec, mix, HDA_INPUT))
3371 return mix;
3372 else if (nid_has_mute(codec, dac, HDA_OUTPUT))
3373 return dac;
3374 return 0;
3375}
3376
3377static hda_nid_t alc_look_for_out_vol_nid(struct hda_codec *codec,
3378 hda_nid_t pin, hda_nid_t dac)
3379{
3380 hda_nid_t mix = alc_auto_dac_to_mix(codec, pin, dac);
3381 if (nid_has_volume(codec, dac, HDA_OUTPUT))
3382 return dac;
3383 else if (nid_has_volume(codec, mix, HDA_OUTPUT))
3384 return mix;
3385 else if (nid_has_volume(codec, pin, HDA_OUTPUT))
3386 return pin;
3387 return 0;
3388}
3389
Takashi Iwai7085ec12009-10-02 09:03:58 +02003390/* add playback controls from the parsed DAC table */
Takashi Iwai343a04b2011-07-06 14:28:39 +02003391static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003392 const struct auto_pin_cfg *cfg)
3393{
3394 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003395 int i, err, noutputs;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003396
Takashi Iwaice764ab2011-04-27 16:35:23 +02003397 noutputs = cfg->line_outs;
Takashi Iwaib90bf1d2012-01-19 11:42:55 +01003398 if (spec->multi_ios > 0 && cfg->line_outs < 3)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003399 noutputs += spec->multi_ios;
3400
3401 for (i = 0; i < noutputs; i++) {
Takashi Iwai6843ca12011-06-24 11:03:58 +02003402 const char *name;
3403 int index;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003404 hda_nid_t dac, pin;
3405 hda_nid_t sw, vol;
3406
3407 dac = spec->multiout.dac_nids[i];
3408 if (!dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003409 continue;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003410 if (i >= cfg->line_outs) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003411 pin = spec->multi_io[i - 1].pin;
Takashi Iwai689cabf2012-02-21 12:35:27 +01003412 index = 0;
3413 name = channel_name[i];
3414 } else {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003415 pin = cfg->line_out_pins[i];
Takashi Iwai689cabf2012-02-21 12:35:27 +01003416 name = alc_get_line_out_pfx(spec, i, true, &index);
3417 }
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003418
3419 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3420 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai9c4e84d2011-08-24 17:27:52 +02003421 if (!name || !strcmp(name, "CLFE")) {
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003422 /* Center/LFE */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003423 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003424 if (err < 0)
3425 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003426 err = alc_auto_add_vol_ctl(codec, "LFE", 0, vol, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003427 if (err < 0)
3428 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003429 err = alc_auto_add_sw_ctl(codec, "Center", 0, sw, 1);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003430 if (err < 0)
3431 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003432 err = alc_auto_add_sw_ctl(codec, "LFE", 0, sw, 2);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003433 if (err < 0)
3434 return err;
3435 } else {
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003436 err = alc_auto_add_stereo_vol(codec, name, index, vol);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003437 if (err < 0)
3438 return err;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003439 err = alc_auto_add_stereo_sw(codec, name, index, sw);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003440 if (err < 0)
3441 return err;
3442 }
3443 }
3444 return 0;
3445}
3446
Takashi Iwai343a04b2011-07-06 14:28:39 +02003447static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
Takashi Iwai766ddee2011-12-07 16:55:19 +01003448 hda_nid_t dac, const char *pfx,
3449 int cidx)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003450{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003451 struct alc_spec *spec = codec->spec;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003452 hda_nid_t sw, vol;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003453 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003454
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003455 if (!dac) {
Takashi Iwai527e4d72011-10-27 16:33:27 +02003456 unsigned int val;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003457 /* the corresponding DAC is already occupied */
3458 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
3459 return 0; /* no way */
3460 /* create a switch only */
Takashi Iwai527e4d72011-10-27 16:33:27 +02003461 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3462 if (is_ctl_used(spec->sw_ctls, val))
3463 return 0; /* already created */
3464 mark_ctl_usage(spec->sw_ctls, val);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003465 return __add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, cidx, val);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003466 }
3467
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003468 sw = alc_look_for_out_mute_nid(codec, pin, dac);
3469 vol = alc_look_for_out_vol_nid(codec, pin, dac);
Takashi Iwai766ddee2011-12-07 16:55:19 +01003470 err = alc_auto_add_stereo_vol(codec, pfx, cidx, vol);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003471 if (err < 0)
Takashi Iwai24fb9172008-09-02 14:48:20 +02003472 return err;
Takashi Iwai766ddee2011-12-07 16:55:19 +01003473 err = alc_auto_add_stereo_sw(codec, pfx, cidx, sw);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003474 if (err < 0)
3475 return err;
Takashi Iwai3af9ee62011-06-27 12:34:01 +02003476 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003477}
3478
Takashi Iwai23c09b02011-08-19 09:05:35 +02003479static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3480 unsigned int nums,
3481 struct hda_ctl_ops *ops)
3482{
3483 struct alc_spec *spec = codec->spec;
3484 struct hda_bind_ctls **ctlp, *ctl;
3485 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3486 ctlp = snd_array_new(&spec->bind_ctls);
3487 if (!ctlp)
3488 return NULL;
3489 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3490 *ctlp = ctl;
3491 if (ctl)
3492 ctl->ops = ops;
3493 return ctl;
3494}
3495
3496/* add playback controls for speaker and HP outputs */
3497static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3498 const hda_nid_t *pins,
3499 const hda_nid_t *dacs,
3500 const char *pfx)
3501{
3502 struct alc_spec *spec = codec->spec;
3503 struct hda_bind_ctls *ctl;
3504 char name[32];
3505 int i, n, err;
3506
3507 if (!num_pins || !pins[0])
3508 return 0;
3509
Takashi Iwai527e4d72011-10-27 16:33:27 +02003510 if (num_pins == 1) {
3511 hda_nid_t dac = *dacs;
3512 if (!dac)
3513 dac = spec->multiout.dac_nids[0];
Takashi Iwai766ddee2011-12-07 16:55:19 +01003514 return alc_auto_create_extra_out(codec, *pins, dac, pfx, 0);
Takashi Iwai527e4d72011-10-27 16:33:27 +02003515 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003516
Takashi Iwai23c09b02011-08-19 09:05:35 +02003517 for (i = 0; i < num_pins; i++) {
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003518 hda_nid_t dac;
3519 if (dacs[num_pins - 1])
3520 dac = dacs[i]; /* with individual volumes */
3521 else
3522 dac = 0;
3523 if (num_pins == 2 && i == 1 && !strcmp(pfx, "Speaker")) {
3524 err = alc_auto_create_extra_out(codec, pins[i], dac,
3525 "Bass Speaker", 0);
3526 } else if (num_pins >= 3) {
3527 snprintf(name, sizeof(name), "%s %s",
3528 pfx, channel_name[i]);
3529 err = alc_auto_create_extra_out(codec, pins[i], dac,
3530 name, 0);
3531 } else {
3532 err = alc_auto_create_extra_out(codec, pins[i], dac,
3533 pfx, i);
3534 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02003535 if (err < 0)
3536 return err;
3537 }
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003538 if (dacs[num_pins - 1])
3539 return 0;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003540
Takashi Iwaic96f0bf2012-02-21 12:12:57 +01003541 /* Let's create a bind-controls for volumes */
Takashi Iwai23c09b02011-08-19 09:05:35 +02003542 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3543 if (!ctl)
3544 return -ENOMEM;
3545 n = 0;
3546 for (i = 0; i < num_pins; i++) {
3547 hda_nid_t vol;
3548 if (!pins[i] || !dacs[i])
3549 continue;
3550 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3551 if (vol)
3552 ctl->values[n++] =
3553 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3554 }
3555 if (n) {
3556 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3557 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3558 if (err < 0)
3559 return err;
3560 }
3561 return 0;
3562}
3563
Takashi Iwai343a04b2011-07-06 14:28:39 +02003564static int alc_auto_create_hp_out(struct hda_codec *codec)
3565{
3566 struct alc_spec *spec = codec->spec;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003567 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3568 spec->autocfg.hp_pins,
3569 spec->multiout.hp_out_nid,
3570 "Headphone");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003571}
3572
3573static int alc_auto_create_speaker_out(struct hda_codec *codec)
3574{
3575 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02003576 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3577 spec->autocfg.speaker_pins,
3578 spec->multiout.extra_out_nid,
3579 "Speaker");
Takashi Iwai343a04b2011-07-06 14:28:39 +02003580}
3581
Takashi Iwai343a04b2011-07-06 14:28:39 +02003582static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003583 hda_nid_t pin, int pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003584 hda_nid_t dac)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003585{
Takashi Iwai7085ec12009-10-02 09:03:58 +02003586 int i, num;
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003587 hda_nid_t nid, mix = 0;
Takashi Iwaice503f32010-07-30 10:37:29 +02003588 hda_nid_t srcs[HDA_MAX_CONNECTIONS];
Takashi Iwai7085ec12009-10-02 09:03:58 +02003589
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003590 alc_set_pin_output(codec, pin, pin_type);
3591 nid = alc_go_down_to_selector(codec, pin);
Takashi Iwai7085ec12009-10-02 09:03:58 +02003592 num = snd_hda_get_connections(codec, nid, srcs, ARRAY_SIZE(srcs));
Takashi Iwai7085ec12009-10-02 09:03:58 +02003593 for (i = 0; i < num; i++) {
Takashi Iwai604401a2011-04-27 15:14:23 +02003594 if (alc_auto_mix_to_dac(codec, srcs[i]) != dac)
Takashi Iwai7085ec12009-10-02 09:03:58 +02003595 continue;
Takashi Iwaicd511552011-07-06 13:10:42 +02003596 mix = srcs[i];
3597 break;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003598 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003599 if (!mix)
3600 return;
3601
3602 /* need the manual connection? */
3603 if (num > 1)
3604 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, i);
3605 /* unmute mixer widget inputs */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003606 if (nid_has_mute(codec, mix, HDA_INPUT)) {
3607 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003608 AMP_IN_UNMUTE(0));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003609 snd_hda_codec_write(codec, mix, 0, AC_VERB_SET_AMP_GAIN_MUTE,
Takashi Iwaicd511552011-07-06 13:10:42 +02003610 AMP_IN_UNMUTE(1));
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003611 }
Takashi Iwaicd511552011-07-06 13:10:42 +02003612 /* initialize volume */
Takashi Iwaiafcd5512011-07-08 11:07:59 +02003613 nid = alc_look_for_out_vol_nid(codec, pin, dac);
3614 if (nid)
3615 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3616 AMP_OUT_ZERO);
Takashi Iwai43dea222011-11-06 11:25:34 +01003617
3618 /* unmute DAC if it's not assigned to a mixer */
3619 nid = alc_look_for_out_mute_nid(codec, pin, dac);
3620 if (nid == mix && nid_has_mute(codec, dac, HDA_OUTPUT))
3621 snd_hda_codec_write(codec, dac, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3622 AMP_OUT_ZERO);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003623}
3624
Takashi Iwai343a04b2011-07-06 14:28:39 +02003625static void alc_auto_init_multi_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003626{
3627 struct alc_spec *spec = codec->spec;
Takashi Iwai7085ec12009-10-02 09:03:58 +02003628 int pin_type = get_pin_type(spec->autocfg.line_out_type);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003629 int i;
3630
3631 for (i = 0; i <= HDA_SIDE; i++) {
3632 hda_nid_t nid = spec->autocfg.line_out_pins[i];
3633 if (nid)
Takashi Iwai343a04b2011-07-06 14:28:39 +02003634 alc_auto_set_output_and_unmute(codec, nid, pin_type,
Takashi Iwai7085ec12009-10-02 09:03:58 +02003635 spec->multiout.dac_nids[i]);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003636 }
3637}
3638
Takashi Iwai343a04b2011-07-06 14:28:39 +02003639static void alc_auto_init_extra_out(struct hda_codec *codec)
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003640{
3641 struct alc_spec *spec = codec->spec;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003642 int i;
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003643 hda_nid_t pin, dac;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003644
David Henningsson636030e2011-10-12 19:26:03 +02003645 for (i = 0; i < spec->autocfg.hp_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003646 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3647 break;
Takashi Iwaie23832a2011-08-23 18:16:56 +02003648 pin = spec->autocfg.hp_pins[i];
3649 if (!pin)
3650 break;
3651 dac = spec->multiout.hp_out_nid[i];
3652 if (!dac) {
3653 if (i > 0 && spec->multiout.hp_out_nid[0])
3654 dac = spec->multiout.hp_out_nid[0];
3655 else
3656 dac = spec->multiout.dac_nids[0];
3657 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003658 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3659 }
Takashi Iwai8cd07752011-08-23 15:16:22 +02003660 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
Takashi Iwai716eef02011-10-21 15:07:42 +02003661 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3662 break;
Takashi Iwai8cd07752011-08-23 15:16:22 +02003663 pin = spec->autocfg.speaker_pins[i];
3664 if (!pin)
3665 break;
3666 dac = spec->multiout.extra_out_nid[i];
3667 if (!dac) {
3668 if (i > 0 && spec->multiout.extra_out_nid[0])
3669 dac = spec->multiout.extra_out_nid[0];
3670 else
3671 dac = spec->multiout.dac_nids[0];
3672 }
Takashi Iwai675c1aa2011-08-23 12:36:28 +02003673 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3674 }
Kailang Yangbc9f98a2007-04-12 13:06:07 +02003675}
3676
Takashi Iwai276dd702012-02-17 16:17:03 +01003677/* check whether the given pin can be a multi-io pin */
3678static bool can_be_multiio_pin(struct hda_codec *codec,
3679 unsigned int location, hda_nid_t nid)
3680{
3681 unsigned int defcfg, caps;
3682
3683 defcfg = snd_hda_codec_get_pincfg(codec, nid);
3684 if (get_defcfg_connect(defcfg) != AC_JACK_PORT_COMPLEX)
3685 return false;
3686 if (location && get_defcfg_location(defcfg) != location)
3687 return false;
3688 caps = snd_hda_query_pin_caps(codec, nid);
3689 if (!(caps & AC_PINCAP_OUT))
3690 return false;
3691 return true;
3692}
3693
Takashi Iwaice764ab2011-04-27 16:35:23 +02003694/*
3695 * multi-io helper
Takashi Iwai276dd702012-02-17 16:17:03 +01003696 *
3697 * When hardwired is set, try to fill ony hardwired pins, and returns
3698 * zero if any pins are filled, non-zero if nothing found.
3699 * When hardwired is off, try to fill possible input pins, and returns
3700 * the badness value.
Takashi Iwaice764ab2011-04-27 16:35:23 +02003701 */
3702static int alc_auto_fill_multi_ios(struct hda_codec *codec,
Takashi Iwai276dd702012-02-17 16:17:03 +01003703 hda_nid_t reference_pin,
3704 bool hardwired, int offset)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003705{
3706 struct alc_spec *spec = codec->spec;
3707 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai276dd702012-02-17 16:17:03 +01003708 int type, i, j, dacs, num_pins, old_pins;
3709 unsigned int defcfg = snd_hda_codec_get_pincfg(codec, reference_pin);
3710 unsigned int location = get_defcfg_location(defcfg);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003711 int badness = 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003712
Takashi Iwai276dd702012-02-17 16:17:03 +01003713 old_pins = spec->multi_ios;
3714 if (old_pins >= 2)
3715 goto end_fill;
3716
3717 num_pins = 0;
3718 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3719 for (i = 0; i < cfg->num_inputs; i++) {
3720 if (cfg->inputs[i].type != type)
3721 continue;
3722 if (can_be_multiio_pin(codec, location,
3723 cfg->inputs[i].pin))
3724 num_pins++;
3725 }
3726 }
3727 if (num_pins < 2)
3728 goto end_fill;
3729
Takashi Iwai07b18f62011-11-10 15:42:54 +01003730 dacs = spec->multiout.num_dacs;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003731 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
3732 for (i = 0; i < cfg->num_inputs; i++) {
3733 hda_nid_t nid = cfg->inputs[i].pin;
Takashi Iwai07b18f62011-11-10 15:42:54 +01003734 hda_nid_t dac = 0;
Takashi Iwai276dd702012-02-17 16:17:03 +01003735
Takashi Iwaice764ab2011-04-27 16:35:23 +02003736 if (cfg->inputs[i].type != type)
3737 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003738 if (!can_be_multiio_pin(codec, location, nid))
Takashi Iwaice764ab2011-04-27 16:35:23 +02003739 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003740 for (j = 0; j < spec->multi_ios; j++) {
3741 if (nid == spec->multi_io[j].pin)
3742 break;
3743 }
3744 if (j < spec->multi_ios)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003745 continue;
Takashi Iwai276dd702012-02-17 16:17:03 +01003746
3747 if (offset && offset + spec->multi_ios < dacs) {
3748 dac = spec->private_dac_nids[offset + spec->multi_ios];
Takashi Iwai07b18f62011-11-10 15:42:54 +01003749 if (!alc_auto_is_dac_reachable(codec, nid, dac))
3750 dac = 0;
3751 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003752 if (hardwired)
3753 dac = get_dac_if_single(codec, nid);
3754 else if (!dac)
Takashi Iwai07b18f62011-11-10 15:42:54 +01003755 dac = alc_auto_look_for_dac(codec, nid);
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003756 if (!dac) {
Takashi Iwai276dd702012-02-17 16:17:03 +01003757 badness++;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003758 continue;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003759 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003760 spec->multi_io[spec->multi_ios].pin = nid;
3761 spec->multi_io[spec->multi_ios].dac = dac;
3762 spec->multi_ios++;
3763 if (spec->multi_ios >= 2)
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003764 break;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003765 }
3766 }
Takashi Iwai276dd702012-02-17 16:17:03 +01003767 end_fill:
3768 if (badness)
3769 badness = BAD_MULTI_IO;
3770 if (old_pins == spec->multi_ios) {
3771 if (hardwired)
3772 return 1; /* nothing found */
3773 else
3774 return badness; /* no badness if nothing found */
3775 }
3776 if (!hardwired && spec->multi_ios < 2) {
3777 spec->multi_ios = old_pins;
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003778 return badness;
Takashi Iwaic2674682011-08-24 17:57:44 +02003779 }
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003780
Takashi Iwai1c4a54b2012-02-16 16:45:59 +01003781 return 0;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003782}
3783
3784static int alc_auto_ch_mode_info(struct snd_kcontrol *kcontrol,
3785 struct snd_ctl_elem_info *uinfo)
3786{
3787 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3788 struct alc_spec *spec = codec->spec;
3789
3790 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3791 uinfo->count = 1;
3792 uinfo->value.enumerated.items = spec->multi_ios + 1;
3793 if (uinfo->value.enumerated.item > spec->multi_ios)
3794 uinfo->value.enumerated.item = spec->multi_ios;
3795 sprintf(uinfo->value.enumerated.name, "%dch",
3796 (uinfo->value.enumerated.item + 1) * 2);
3797 return 0;
3798}
3799
3800static int alc_auto_ch_mode_get(struct snd_kcontrol *kcontrol,
3801 struct snd_ctl_elem_value *ucontrol)
3802{
3803 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3804 struct alc_spec *spec = codec->spec;
3805 ucontrol->value.enumerated.item[0] = (spec->ext_channel_count - 1) / 2;
3806 return 0;
3807}
3808
3809static int alc_set_multi_io(struct hda_codec *codec, int idx, bool output)
3810{
3811 struct alc_spec *spec = codec->spec;
3812 hda_nid_t nid = spec->multi_io[idx].pin;
3813
3814 if (!spec->multi_io[idx].ctl_in)
3815 spec->multi_io[idx].ctl_in =
3816 snd_hda_codec_read(codec, nid, 0,
3817 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3818 if (output) {
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003819 snd_hda_set_pin_ctl_cache(codec, nid, PIN_OUT);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003820 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3821 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3822 HDA_AMP_MUTE, 0);
3823 alc_auto_select_dac(codec, nid, spec->multi_io[idx].dac);
3824 } else {
3825 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
3826 snd_hda_codec_amp_stereo(codec, nid, HDA_OUTPUT, 0,
3827 HDA_AMP_MUTE, HDA_AMP_MUTE);
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02003828 snd_hda_set_pin_ctl_cache(codec, nid,
3829 spec->multi_io[idx].ctl_in);
Takashi Iwaice764ab2011-04-27 16:35:23 +02003830 }
3831 return 0;
3832}
3833
3834static int alc_auto_ch_mode_put(struct snd_kcontrol *kcontrol,
3835 struct snd_ctl_elem_value *ucontrol)
3836{
3837 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
3838 struct alc_spec *spec = codec->spec;
3839 int i, ch;
3840
3841 ch = ucontrol->value.enumerated.item[0];
3842 if (ch < 0 || ch > spec->multi_ios)
3843 return -EINVAL;
3844 if (ch == (spec->ext_channel_count - 1) / 2)
3845 return 0;
3846 spec->ext_channel_count = (ch + 1) * 2;
3847 for (i = 0; i < spec->multi_ios; i++)
3848 alc_set_multi_io(codec, i, i < ch);
3849 spec->multiout.max_channels = spec->ext_channel_count;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02003850 if (spec->need_dac_fix && !spec->const_channel_count)
3851 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003852 return 1;
3853}
3854
Takashi Iwaia9111322011-05-02 11:30:18 +02003855static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003856 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3857 .name = "Channel Mode",
3858 .info = alc_auto_ch_mode_info,
3859 .get = alc_auto_ch_mode_get,
3860 .put = alc_auto_ch_mode_put,
3861};
3862
Takashi Iwai23c09b02011-08-19 09:05:35 +02003863static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
Takashi Iwaice764ab2011-04-27 16:35:23 +02003864{
3865 struct alc_spec *spec = codec->spec;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003866
Takashi Iwaic2674682011-08-24 17:57:44 +02003867 if (spec->multi_ios > 0) {
Takashi Iwaice764ab2011-04-27 16:35:23 +02003868 struct snd_kcontrol_new *knew;
3869
3870 knew = alc_kcontrol_new(spec);
3871 if (!knew)
3872 return -ENOMEM;
3873 *knew = alc_auto_channel_mode_enum;
3874 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3875 if (!knew->name)
3876 return -ENOMEM;
Takashi Iwaice764ab2011-04-27 16:35:23 +02003877 }
3878 return 0;
3879}
3880
Takashi Iwai1d045db2011-07-07 18:23:21 +02003881/* filter out invalid adc_nids (and capsrc_nids) that don't give all
3882 * active input pins
3883 */
3884static void alc_remove_invalid_adc_nids(struct hda_codec *codec)
3885{
3886 struct alc_spec *spec = codec->spec;
3887 const struct hda_input_mux *imux;
3888 hda_nid_t adc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3889 hda_nid_t capsrc_nids[ARRAY_SIZE(spec->private_adc_nids)];
3890 int i, n, nums;
3891
3892 imux = spec->input_mux;
3893 if (!imux)
3894 return;
3895 if (spec->dyn_adc_switch)
3896 return;
3897
Takashi Iwai26acaf02012-03-22 14:36:50 +01003898 again:
Takashi Iwai1d045db2011-07-07 18:23:21 +02003899 nums = 0;
3900 for (n = 0; n < spec->num_adc_nids; n++) {
3901 hda_nid_t cap = spec->private_capsrc_nids[n];
Takashi Iwai09cf03b2012-05-19 17:21:25 +02003902 int num_conns = snd_hda_get_num_conns(codec, cap);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003903 for (i = 0; i < imux->num_items; i++) {
3904 hda_nid_t pin = spec->imux_pins[i];
3905 if (pin) {
3906 if (get_connection_index(codec, cap, pin) < 0)
3907 break;
3908 } else if (num_conns <= imux->items[i].index)
3909 break;
3910 }
3911 if (i >= imux->num_items) {
3912 adc_nids[nums] = spec->private_adc_nids[n];
3913 capsrc_nids[nums++] = cap;
3914 }
3915 }
3916 if (!nums) {
3917 /* check whether ADC-switch is possible */
3918 if (!alc_check_dyn_adc_switch(codec)) {
Takashi Iwai26acaf02012-03-22 14:36:50 +01003919 if (spec->shared_mic_hp) {
3920 spec->shared_mic_hp = 0;
3921 spec->private_imux[0].num_items = 1;
3922 goto again;
3923 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02003924 printk(KERN_WARNING "hda_codec: %s: no valid ADC found;"
3925 " using fallback 0x%x\n",
3926 codec->chip_name, spec->private_adc_nids[0]);
3927 spec->num_adc_nids = 1;
3928 spec->auto_mic = 0;
3929 return;
3930 }
3931 } else if (nums != spec->num_adc_nids) {
3932 memcpy(spec->private_adc_nids, adc_nids,
3933 nums * sizeof(hda_nid_t));
3934 memcpy(spec->private_capsrc_nids, capsrc_nids,
3935 nums * sizeof(hda_nid_t));
3936 spec->num_adc_nids = nums;
3937 }
3938
3939 if (spec->auto_mic)
3940 alc_auto_mic_check_imux(codec); /* check auto-mic setups */
Takashi Iwai26acaf02012-03-22 14:36:50 +01003941 else if (spec->input_mux->num_items == 1 || spec->shared_mic_hp)
Takashi Iwai1d045db2011-07-07 18:23:21 +02003942 spec->num_adc_nids = 1; /* reduce to a single ADC */
3943}
3944
3945/*
3946 * initialize ADC paths
3947 */
3948static void alc_auto_init_adc(struct hda_codec *codec, int adc_idx)
3949{
3950 struct alc_spec *spec = codec->spec;
3951 hda_nid_t nid;
3952
3953 nid = spec->adc_nids[adc_idx];
3954 /* mute ADC */
Takashi Iwai44c02402011-07-08 15:14:19 +02003955 if (nid_has_mute(codec, nid, HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02003956 snd_hda_codec_write(codec, nid, 0,
3957 AC_VERB_SET_AMP_GAIN_MUTE,
3958 AMP_IN_MUTE(0));
3959 return;
3960 }
3961 if (!spec->capsrc_nids)
3962 return;
3963 nid = spec->capsrc_nids[adc_idx];
Takashi Iwai44c02402011-07-08 15:14:19 +02003964 if (nid_has_mute(codec, nid, HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02003965 snd_hda_codec_write(codec, nid, 0,
3966 AC_VERB_SET_AMP_GAIN_MUTE,
3967 AMP_OUT_MUTE);
3968}
3969
3970static void alc_auto_init_input_src(struct hda_codec *codec)
3971{
3972 struct alc_spec *spec = codec->spec;
3973 int c, nums;
3974
3975 for (c = 0; c < spec->num_adc_nids; c++)
3976 alc_auto_init_adc(codec, c);
3977 if (spec->dyn_adc_switch)
3978 nums = 1;
3979 else
3980 nums = spec->num_adc_nids;
3981 for (c = 0; c < nums; c++)
Takashi Iwai068b9392012-02-25 11:13:16 +01003982 alc_mux_select(codec, c, spec->cur_mux[c], true);
Takashi Iwai1d045db2011-07-07 18:23:21 +02003983}
3984
3985/* add mic boosts if needed */
3986static int alc_auto_add_mic_boost(struct hda_codec *codec)
3987{
3988 struct alc_spec *spec = codec->spec;
3989 struct auto_pin_cfg *cfg = &spec->autocfg;
3990 int i, err;
3991 int type_idx = 0;
3992 hda_nid_t nid;
3993 const char *prev_label = NULL;
3994
3995 for (i = 0; i < cfg->num_inputs; i++) {
3996 if (cfg->inputs[i].type > AUTO_PIN_MIC)
3997 break;
3998 nid = cfg->inputs[i].pin;
3999 if (get_wcaps(codec, nid) & AC_WCAP_IN_AMP) {
4000 const char *label;
4001 char boost_label[32];
4002
4003 label = hda_get_autocfg_input_label(codec, cfg, i);
Takashi Iwai24de1832011-11-07 17:13:39 +01004004 if (spec->shared_mic_hp && !strcmp(label, "Misc"))
4005 label = "Headphone Mic";
Takashi Iwai1d045db2011-07-07 18:23:21 +02004006 if (prev_label && !strcmp(label, prev_label))
4007 type_idx++;
4008 else
4009 type_idx = 0;
4010 prev_label = label;
4011
4012 snprintf(boost_label, sizeof(boost_label),
4013 "%s Boost Volume", label);
4014 err = add_control(spec, ALC_CTL_WIDGET_VOL,
4015 boost_label, type_idx,
4016 HDA_COMPOSE_AMP_VAL(nid, 3, 0, HDA_INPUT));
4017 if (err < 0)
4018 return err;
4019 }
4020 }
4021 return 0;
4022}
4023
4024/* select or unmute the given capsrc route */
4025static void select_or_unmute_capsrc(struct hda_codec *codec, hda_nid_t cap,
4026 int idx)
4027{
4028 if (get_wcaps_type(get_wcaps(codec, cap)) == AC_WID_AUD_MIX) {
4029 snd_hda_codec_amp_stereo(codec, cap, HDA_INPUT, idx,
4030 HDA_AMP_MUTE, 0);
Takashi Iwai09cf03b2012-05-19 17:21:25 +02004031 } else if (snd_hda_get_num_conns(codec, cap) > 1) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004032 snd_hda_codec_write_cache(codec, cap, 0,
4033 AC_VERB_SET_CONNECT_SEL, idx);
4034 }
4035}
4036
4037/* set the default connection to that pin */
4038static int init_capsrc_for_pin(struct hda_codec *codec, hda_nid_t pin)
4039{
4040 struct alc_spec *spec = codec->spec;
4041 int i;
4042
4043 if (!pin)
4044 return 0;
4045 for (i = 0; i < spec->num_adc_nids; i++) {
Takashi Iwai61071592011-11-23 07:52:15 +01004046 hda_nid_t cap = get_capsrc(spec, i);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004047 int idx;
4048
4049 idx = get_connection_index(codec, cap, pin);
4050 if (idx < 0)
4051 continue;
4052 select_or_unmute_capsrc(codec, cap, idx);
4053 return i; /* return the found index */
4054 }
4055 return -1; /* not found */
4056}
4057
4058/* initialize some special cases for input sources */
4059static void alc_init_special_input_src(struct hda_codec *codec)
4060{
4061 struct alc_spec *spec = codec->spec;
4062 int i;
4063
4064 for (i = 0; i < spec->autocfg.num_inputs; i++)
4065 init_capsrc_for_pin(codec, spec->autocfg.inputs[i].pin);
4066}
4067
4068/* assign appropriate capture mixers */
4069static void set_capture_mixer(struct hda_codec *codec)
4070{
4071 struct alc_spec *spec = codec->spec;
4072 static const struct snd_kcontrol_new *caps[2][3] = {
4073 { alc_capture_mixer_nosrc1,
4074 alc_capture_mixer_nosrc2,
4075 alc_capture_mixer_nosrc3 },
4076 { alc_capture_mixer1,
4077 alc_capture_mixer2,
4078 alc_capture_mixer3 },
4079 };
4080
4081 /* check whether either of ADC or MUX has a volume control */
Takashi Iwai44c02402011-07-08 15:14:19 +02004082 if (!nid_has_volume(codec, spec->adc_nids[0], HDA_INPUT)) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004083 if (!spec->capsrc_nids)
4084 return; /* no volume */
Takashi Iwai44c02402011-07-08 15:14:19 +02004085 if (!nid_has_volume(codec, spec->capsrc_nids[0], HDA_OUTPUT))
Takashi Iwai1d045db2011-07-07 18:23:21 +02004086 return; /* no volume in capsrc, too */
4087 spec->vol_in_capsrc = 1;
4088 }
4089
4090 if (spec->num_adc_nids > 0) {
4091 int mux = 0;
4092 int num_adcs = 0;
4093
4094 if (spec->input_mux && spec->input_mux->num_items > 1)
4095 mux = 1;
4096 if (spec->auto_mic) {
4097 num_adcs = 1;
4098 mux = 0;
4099 } else if (spec->dyn_adc_switch)
4100 num_adcs = 1;
4101 if (!num_adcs) {
4102 if (spec->num_adc_nids > 3)
4103 spec->num_adc_nids = 3;
4104 else if (!spec->num_adc_nids)
4105 return;
4106 num_adcs = spec->num_adc_nids;
4107 }
4108 spec->cap_mixer = caps[mux][num_adcs - 1];
4109 }
4110}
4111
4112/*
Takashi Iwaie4770622011-07-08 11:11:35 +02004113 * standard auto-parser initializations
4114 */
4115static void alc_auto_init_std(struct hda_codec *codec)
4116{
4117 struct alc_spec *spec = codec->spec;
4118 alc_auto_init_multi_out(codec);
4119 alc_auto_init_extra_out(codec);
4120 alc_auto_init_analog_input(codec);
4121 alc_auto_init_input_src(codec);
4122 alc_auto_init_digital(codec);
4123 if (spec->unsol_event)
4124 alc_inithook(codec);
4125}
4126
4127/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004128 * Digital-beep handlers
4129 */
4130#ifdef CONFIG_SND_HDA_INPUT_BEEP
4131#define set_beep_amp(spec, nid, idx, dir) \
4132 ((spec)->beep_amp = HDA_COMPOSE_AMP_VAL(nid, 3, idx, dir))
4133
4134static const struct snd_pci_quirk beep_white_list[] = {
4135 SND_PCI_QUIRK(0x1043, 0x829f, "ASUS", 1),
4136 SND_PCI_QUIRK(0x1043, 0x83ce, "EeePC", 1),
4137 SND_PCI_QUIRK(0x1043, 0x831a, "EeePC", 1),
4138 SND_PCI_QUIRK(0x1043, 0x834a, "EeePC", 1),
Takashi Iwai78f8baf2012-03-06 14:02:32 +01004139 SND_PCI_QUIRK(0x1458, 0xa002, "GA-MA790X", 1),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004140 SND_PCI_QUIRK(0x8086, 0xd613, "Intel", 1),
4141 {}
4142};
4143
4144static inline int has_cdefine_beep(struct hda_codec *codec)
4145{
4146 struct alc_spec *spec = codec->spec;
4147 const struct snd_pci_quirk *q;
4148 q = snd_pci_quirk_lookup(codec->bus->pci, beep_white_list);
4149 if (q)
4150 return q->value;
4151 return spec->cdefine.enable_pcbeep;
4152}
4153#else
4154#define set_beep_amp(spec, nid, idx, dir) /* NOP */
4155#define has_cdefine_beep(codec) 0
4156#endif
4157
4158/* parse the BIOS configuration and set up the alc_spec */
4159/* return 1 if successful, 0 if the proper config is not found,
4160 * or a negative error code
4161 */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004162static int alc_parse_auto_config(struct hda_codec *codec,
4163 const hda_nid_t *ignore_nids,
4164 const hda_nid_t *ssid_nids)
Takashi Iwai1d045db2011-07-07 18:23:21 +02004165{
4166 struct alc_spec *spec = codec->spec;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004167 struct auto_pin_cfg *cfg = &spec->autocfg;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004168 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004169
Takashi Iwai53c334a2011-08-23 18:27:14 +02004170 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
4171 spec->parse_flags);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004172 if (err < 0)
4173 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004174 if (!cfg->line_outs) {
4175 if (cfg->dig_outs || cfg->dig_in_pin) {
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004176 spec->multiout.max_channels = 2;
4177 spec->no_analog = 1;
4178 goto dig_only;
4179 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004180 return 0; /* can't find valid BIOS pin config */
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004181 }
Takashi Iwai23c09b02011-08-19 09:05:35 +02004182
Takashi Iwai06503672011-10-06 08:27:19 +02004183 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
4184 cfg->line_outs <= cfg->hp_outs) {
Takashi Iwai23c09b02011-08-19 09:05:35 +02004185 /* use HP as primary out */
4186 cfg->speaker_outs = cfg->line_outs;
4187 memcpy(cfg->speaker_pins, cfg->line_out_pins,
4188 sizeof(cfg->speaker_pins));
4189 cfg->line_outs = cfg->hp_outs;
4190 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
4191 cfg->hp_outs = 0;
4192 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
4193 cfg->line_out_type = AUTO_PIN_HP_OUT;
4194 }
4195
Takashi Iwai1d045db2011-07-07 18:23:21 +02004196 err = alc_auto_fill_dac_nids(codec);
4197 if (err < 0)
4198 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004199 err = alc_auto_add_multi_channel_mode(codec);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004200 if (err < 0)
4201 return err;
Takashi Iwai23c09b02011-08-19 09:05:35 +02004202 err = alc_auto_create_multi_out_ctls(codec, cfg);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004203 if (err < 0)
4204 return err;
4205 err = alc_auto_create_hp_out(codec);
4206 if (err < 0)
4207 return err;
4208 err = alc_auto_create_speaker_out(codec);
4209 if (err < 0)
4210 return err;
Takashi Iwai24de1832011-11-07 17:13:39 +01004211 err = alc_auto_create_shared_input(codec);
4212 if (err < 0)
4213 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004214 err = alc_auto_create_input_ctls(codec);
4215 if (err < 0)
4216 return err;
4217
4218 spec->multiout.max_channels = spec->multiout.num_dacs * 2;
4219
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004220 dig_only:
Takashi Iwai1d045db2011-07-07 18:23:21 +02004221 alc_auto_parse_digital(codec);
4222
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004223 if (!spec->no_analog)
4224 alc_remove_invalid_adc_nids(codec);
4225
4226 if (ssid_nids)
4227 alc_ssid_check(codec, ssid_nids);
4228
4229 if (!spec->no_analog) {
4230 alc_auto_check_switches(codec);
4231 err = alc_auto_add_mic_boost(codec);
4232 if (err < 0)
4233 return err;
4234 }
4235
Takashi Iwai1d045db2011-07-07 18:23:21 +02004236 if (spec->kctls.list)
4237 add_mixer(spec, spec->kctls.list);
4238
Takashi Iwai070cff42012-02-21 12:54:17 +01004239 if (!spec->no_analog && !spec->cap_mixer)
4240 set_capture_mixer(codec);
4241
Takashi Iwai1d045db2011-07-07 18:23:21 +02004242 return 1;
4243}
4244
Takashi Iwai3de95172012-05-07 18:03:15 +02004245/* common preparation job for alc_spec */
4246static int alc_alloc_spec(struct hda_codec *codec, hda_nid_t mixer_nid)
4247{
4248 struct alc_spec *spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4249 int err;
4250
4251 if (!spec)
4252 return -ENOMEM;
4253 codec->spec = spec;
4254 spec->mixer_nid = mixer_nid;
4255
4256 err = alc_codec_rename_from_preset(codec);
4257 if (err < 0) {
4258 kfree(spec);
4259 return err;
4260 }
4261 return 0;
4262}
4263
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004264static int alc880_parse_auto_config(struct hda_codec *codec)
4265{
4266 static const hda_nid_t alc880_ignore[] = { 0x1d, 0 };
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02004267 static const hda_nid_t alc880_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004268 return alc_parse_auto_config(codec, alc880_ignore, alc880_ssids);
4269}
4270
Takashi Iwai1d045db2011-07-07 18:23:21 +02004271/*
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004272 * ALC880 fix-ups
4273 */
4274enum {
Takashi Iwai411225a2012-02-20 17:48:19 +01004275 ALC880_FIXUP_GPIO1,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004276 ALC880_FIXUP_GPIO2,
4277 ALC880_FIXUP_MEDION_RIM,
Takashi Iwaidc6af522012-02-17 16:18:59 +01004278 ALC880_FIXUP_LG,
Takashi Iwaif02aab52012-02-17 16:33:56 +01004279 ALC880_FIXUP_W810,
Takashi Iwai27e917f2012-02-17 17:49:54 +01004280 ALC880_FIXUP_EAPD_COEF,
Takashi Iwaib9368f52012-02-17 17:54:44 +01004281 ALC880_FIXUP_TCL_S700,
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004282 ALC880_FIXUP_VOL_KNOB,
4283 ALC880_FIXUP_FUJITSU,
Takashi Iwaiba533812012-02-20 16:36:52 +01004284 ALC880_FIXUP_F1734,
Takashi Iwai817de922012-02-20 17:20:48 +01004285 ALC880_FIXUP_UNIWILL,
Takashi Iwai967b88c2012-02-20 17:31:02 +01004286 ALC880_FIXUP_UNIWILL_DIG,
Takashi Iwai96e225f2012-02-20 17:41:51 +01004287 ALC880_FIXUP_Z71V,
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004288 ALC880_FIXUP_3ST_BASE,
4289 ALC880_FIXUP_3ST,
4290 ALC880_FIXUP_3ST_DIG,
4291 ALC880_FIXUP_5ST_BASE,
4292 ALC880_FIXUP_5ST,
4293 ALC880_FIXUP_5ST_DIG,
4294 ALC880_FIXUP_6ST_BASE,
4295 ALC880_FIXUP_6ST,
4296 ALC880_FIXUP_6ST_DIG,
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004297};
4298
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004299/* enable the volume-knob widget support on NID 0x21 */
4300static void alc880_fixup_vol_knob(struct hda_codec *codec,
4301 const struct alc_fixup *fix, int action)
4302{
4303 if (action == ALC_FIXUP_ACT_PROBE)
4304 snd_hda_jack_detect_enable(codec, 0x21, ALC_DCVOL_EVENT);
4305}
4306
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004307static const struct alc_fixup alc880_fixups[] = {
Takashi Iwai411225a2012-02-20 17:48:19 +01004308 [ALC880_FIXUP_GPIO1] = {
4309 .type = ALC_FIXUP_VERBS,
4310 .v.verbs = alc_gpio1_init_verbs,
4311 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004312 [ALC880_FIXUP_GPIO2] = {
4313 .type = ALC_FIXUP_VERBS,
4314 .v.verbs = alc_gpio2_init_verbs,
4315 },
4316 [ALC880_FIXUP_MEDION_RIM] = {
4317 .type = ALC_FIXUP_VERBS,
4318 .v.verbs = (const struct hda_verb[]) {
4319 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4320 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4321 { }
4322 },
4323 .chained = true,
4324 .chain_id = ALC880_FIXUP_GPIO2,
4325 },
Takashi Iwaidc6af522012-02-17 16:18:59 +01004326 [ALC880_FIXUP_LG] = {
4327 .type = ALC_FIXUP_PINS,
4328 .v.pins = (const struct alc_pincfg[]) {
4329 /* disable bogus unused pins */
4330 { 0x16, 0x411111f0 },
4331 { 0x18, 0x411111f0 },
4332 { 0x1a, 0x411111f0 },
4333 { }
4334 }
4335 },
Takashi Iwaif02aab52012-02-17 16:33:56 +01004336 [ALC880_FIXUP_W810] = {
4337 .type = ALC_FIXUP_PINS,
4338 .v.pins = (const struct alc_pincfg[]) {
4339 /* disable bogus unused pins */
4340 { 0x17, 0x411111f0 },
4341 { }
4342 },
4343 .chained = true,
4344 .chain_id = ALC880_FIXUP_GPIO2,
4345 },
Takashi Iwai27e917f2012-02-17 17:49:54 +01004346 [ALC880_FIXUP_EAPD_COEF] = {
4347 .type = ALC_FIXUP_VERBS,
4348 .v.verbs = (const struct hda_verb[]) {
4349 /* change to EAPD mode */
4350 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4351 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
4352 {}
4353 },
4354 },
Takashi Iwaib9368f52012-02-17 17:54:44 +01004355 [ALC880_FIXUP_TCL_S700] = {
4356 .type = ALC_FIXUP_VERBS,
4357 .v.verbs = (const struct hda_verb[]) {
4358 /* change to EAPD mode */
4359 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4360 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
4361 {}
4362 },
4363 .chained = true,
4364 .chain_id = ALC880_FIXUP_GPIO2,
4365 },
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004366 [ALC880_FIXUP_VOL_KNOB] = {
4367 .type = ALC_FIXUP_FUNC,
4368 .v.func = alc880_fixup_vol_knob,
4369 },
4370 [ALC880_FIXUP_FUJITSU] = {
4371 /* override all pins as BIOS on old Amilo is broken */
4372 .type = ALC_FIXUP_PINS,
4373 .v.pins = (const struct alc_pincfg[]) {
4374 { 0x14, 0x0121411f }, /* HP */
4375 { 0x15, 0x99030120 }, /* speaker */
4376 { 0x16, 0x99030130 }, /* bass speaker */
4377 { 0x17, 0x411111f0 }, /* N/A */
4378 { 0x18, 0x411111f0 }, /* N/A */
4379 { 0x19, 0x01a19950 }, /* mic-in */
4380 { 0x1a, 0x411111f0 }, /* N/A */
4381 { 0x1b, 0x411111f0 }, /* N/A */
4382 { 0x1c, 0x411111f0 }, /* N/A */
4383 { 0x1d, 0x411111f0 }, /* N/A */
4384 { 0x1e, 0x01454140 }, /* SPDIF out */
4385 { }
4386 },
4387 .chained = true,
4388 .chain_id = ALC880_FIXUP_VOL_KNOB,
4389 },
Takashi Iwaiba533812012-02-20 16:36:52 +01004390 [ALC880_FIXUP_F1734] = {
4391 /* almost compatible with FUJITSU, but no bass and SPDIF */
4392 .type = ALC_FIXUP_PINS,
4393 .v.pins = (const struct alc_pincfg[]) {
4394 { 0x14, 0x0121411f }, /* HP */
4395 { 0x15, 0x99030120 }, /* speaker */
4396 { 0x16, 0x411111f0 }, /* N/A */
4397 { 0x17, 0x411111f0 }, /* N/A */
4398 { 0x18, 0x411111f0 }, /* N/A */
4399 { 0x19, 0x01a19950 }, /* mic-in */
4400 { 0x1a, 0x411111f0 }, /* N/A */
4401 { 0x1b, 0x411111f0 }, /* N/A */
4402 { 0x1c, 0x411111f0 }, /* N/A */
4403 { 0x1d, 0x411111f0 }, /* N/A */
4404 { 0x1e, 0x411111f0 }, /* N/A */
4405 { }
4406 },
4407 .chained = true,
4408 .chain_id = ALC880_FIXUP_VOL_KNOB,
4409 },
Takashi Iwai817de922012-02-20 17:20:48 +01004410 [ALC880_FIXUP_UNIWILL] = {
4411 /* need to fix HP and speaker pins to be parsed correctly */
4412 .type = ALC_FIXUP_PINS,
4413 .v.pins = (const struct alc_pincfg[]) {
4414 { 0x14, 0x0121411f }, /* HP */
4415 { 0x15, 0x99030120 }, /* speaker */
4416 { 0x16, 0x99030130 }, /* bass speaker */
4417 { }
4418 },
4419 },
Takashi Iwai967b88c2012-02-20 17:31:02 +01004420 [ALC880_FIXUP_UNIWILL_DIG] = {
4421 .type = ALC_FIXUP_PINS,
4422 .v.pins = (const struct alc_pincfg[]) {
4423 /* disable bogus unused pins */
4424 { 0x17, 0x411111f0 },
4425 { 0x19, 0x411111f0 },
4426 { 0x1b, 0x411111f0 },
4427 { 0x1f, 0x411111f0 },
4428 { }
4429 }
4430 },
Takashi Iwai96e225f2012-02-20 17:41:51 +01004431 [ALC880_FIXUP_Z71V] = {
4432 .type = ALC_FIXUP_PINS,
4433 .v.pins = (const struct alc_pincfg[]) {
4434 /* set up the whole pins as BIOS is utterly broken */
4435 { 0x14, 0x99030120 }, /* speaker */
4436 { 0x15, 0x0121411f }, /* HP */
4437 { 0x16, 0x411111f0 }, /* N/A */
4438 { 0x17, 0x411111f0 }, /* N/A */
4439 { 0x18, 0x01a19950 }, /* mic-in */
4440 { 0x19, 0x411111f0 }, /* N/A */
4441 { 0x1a, 0x01813031 }, /* line-in */
4442 { 0x1b, 0x411111f0 }, /* N/A */
4443 { 0x1c, 0x411111f0 }, /* N/A */
4444 { 0x1d, 0x411111f0 }, /* N/A */
4445 { 0x1e, 0x0144111e }, /* SPDIF */
4446 { }
4447 }
4448 },
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004449 [ALC880_FIXUP_3ST_BASE] = {
4450 .type = ALC_FIXUP_PINS,
4451 .v.pins = (const struct alc_pincfg[]) {
4452 { 0x14, 0x01014010 }, /* line-out */
4453 { 0x15, 0x411111f0 }, /* N/A */
4454 { 0x16, 0x411111f0 }, /* N/A */
4455 { 0x17, 0x411111f0 }, /* N/A */
4456 { 0x18, 0x01a19c30 }, /* mic-in */
4457 { 0x19, 0x0121411f }, /* HP */
4458 { 0x1a, 0x01813031 }, /* line-in */
4459 { 0x1b, 0x02a19c40 }, /* front-mic */
4460 { 0x1c, 0x411111f0 }, /* N/A */
4461 { 0x1d, 0x411111f0 }, /* N/A */
4462 /* 0x1e is filled in below */
4463 { 0x1f, 0x411111f0 }, /* N/A */
4464 { }
4465 }
4466 },
4467 [ALC880_FIXUP_3ST] = {
4468 .type = ALC_FIXUP_PINS,
4469 .v.pins = (const struct alc_pincfg[]) {
4470 { 0x1e, 0x411111f0 }, /* N/A */
4471 { }
4472 },
4473 .chained = true,
4474 .chain_id = ALC880_FIXUP_3ST_BASE,
4475 },
4476 [ALC880_FIXUP_3ST_DIG] = {
4477 .type = ALC_FIXUP_PINS,
4478 .v.pins = (const struct alc_pincfg[]) {
4479 { 0x1e, 0x0144111e }, /* SPDIF */
4480 { }
4481 },
4482 .chained = true,
4483 .chain_id = ALC880_FIXUP_3ST_BASE,
4484 },
4485 [ALC880_FIXUP_5ST_BASE] = {
4486 .type = ALC_FIXUP_PINS,
4487 .v.pins = (const struct alc_pincfg[]) {
4488 { 0x14, 0x01014010 }, /* front */
4489 { 0x15, 0x411111f0 }, /* N/A */
4490 { 0x16, 0x01011411 }, /* CLFE */
4491 { 0x17, 0x01016412 }, /* surr */
4492 { 0x18, 0x01a19c30 }, /* mic-in */
4493 { 0x19, 0x0121411f }, /* HP */
4494 { 0x1a, 0x01813031 }, /* line-in */
4495 { 0x1b, 0x02a19c40 }, /* front-mic */
4496 { 0x1c, 0x411111f0 }, /* N/A */
4497 { 0x1d, 0x411111f0 }, /* N/A */
4498 /* 0x1e is filled in below */
4499 { 0x1f, 0x411111f0 }, /* N/A */
4500 { }
4501 }
4502 },
4503 [ALC880_FIXUP_5ST] = {
4504 .type = ALC_FIXUP_PINS,
4505 .v.pins = (const struct alc_pincfg[]) {
4506 { 0x1e, 0x411111f0 }, /* N/A */
4507 { }
4508 },
4509 .chained = true,
4510 .chain_id = ALC880_FIXUP_5ST_BASE,
4511 },
4512 [ALC880_FIXUP_5ST_DIG] = {
4513 .type = ALC_FIXUP_PINS,
4514 .v.pins = (const struct alc_pincfg[]) {
4515 { 0x1e, 0x0144111e }, /* SPDIF */
4516 { }
4517 },
4518 .chained = true,
4519 .chain_id = ALC880_FIXUP_5ST_BASE,
4520 },
4521 [ALC880_FIXUP_6ST_BASE] = {
4522 .type = ALC_FIXUP_PINS,
4523 .v.pins = (const struct alc_pincfg[]) {
4524 { 0x14, 0x01014010 }, /* front */
4525 { 0x15, 0x01016412 }, /* surr */
4526 { 0x16, 0x01011411 }, /* CLFE */
4527 { 0x17, 0x01012414 }, /* side */
4528 { 0x18, 0x01a19c30 }, /* mic-in */
4529 { 0x19, 0x02a19c40 }, /* front-mic */
4530 { 0x1a, 0x01813031 }, /* line-in */
4531 { 0x1b, 0x0121411f }, /* HP */
4532 { 0x1c, 0x411111f0 }, /* N/A */
4533 { 0x1d, 0x411111f0 }, /* N/A */
4534 /* 0x1e is filled in below */
4535 { 0x1f, 0x411111f0 }, /* N/A */
4536 { }
4537 }
4538 },
4539 [ALC880_FIXUP_6ST] = {
4540 .type = ALC_FIXUP_PINS,
4541 .v.pins = (const struct alc_pincfg[]) {
4542 { 0x1e, 0x411111f0 }, /* N/A */
4543 { }
4544 },
4545 .chained = true,
4546 .chain_id = ALC880_FIXUP_6ST_BASE,
4547 },
4548 [ALC880_FIXUP_6ST_DIG] = {
4549 .type = ALC_FIXUP_PINS,
4550 .v.pins = (const struct alc_pincfg[]) {
4551 { 0x1e, 0x0144111e }, /* SPDIF */
4552 { }
4553 },
4554 .chained = true,
4555 .chain_id = ALC880_FIXUP_6ST_BASE,
4556 },
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004557};
4558
4559static const struct snd_pci_quirk alc880_fixup_tbl[] = {
Takashi Iwaif02aab52012-02-17 16:33:56 +01004560 SND_PCI_QUIRK(0x1019, 0x0f69, "Coeus G610P", ALC880_FIXUP_W810),
Takashi Iwai96e225f2012-02-20 17:41:51 +01004561 SND_PCI_QUIRK(0x1043, 0x1964, "ASUS Z71V", ALC880_FIXUP_Z71V),
Takashi Iwai29e3fdc2012-02-20 17:56:57 +01004562 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS", ALC880_FIXUP_GPIO1),
4563 SND_PCI_QUIRK(0x1558, 0x5401, "Clevo GPIO2", ALC880_FIXUP_GPIO2),
Takashi Iwai27e917f2012-02-17 17:49:54 +01004564 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo", ALC880_FIXUP_EAPD_COEF),
Takashi Iwai967b88c2012-02-20 17:31:02 +01004565 SND_PCI_QUIRK(0x1584, 0x9050, "Uniwill", ALC880_FIXUP_UNIWILL_DIG),
Takashi Iwaiba533812012-02-20 16:36:52 +01004566 SND_PCI_QUIRK(0x1584, 0x9054, "Uniwill", ALC880_FIXUP_F1734),
Takashi Iwai817de922012-02-20 17:20:48 +01004567 SND_PCI_QUIRK(0x1584, 0x9070, "Uniwill", ALC880_FIXUP_UNIWILL),
Takashi Iwai7833c7e2012-02-20 17:11:38 +01004568 SND_PCI_QUIRK(0x1584, 0x9077, "Uniwill P53", ALC880_FIXUP_VOL_KNOB),
Takashi Iwaif02aab52012-02-17 16:33:56 +01004569 SND_PCI_QUIRK(0x161f, 0x203d, "W810", ALC880_FIXUP_W810),
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004570 SND_PCI_QUIRK(0x161f, 0x205d, "Medion Rim 2150", ALC880_FIXUP_MEDION_RIM),
Takashi Iwaiba533812012-02-20 16:36:52 +01004571 SND_PCI_QUIRK(0x1734, 0x107c, "FSC F1734", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004572 SND_PCI_QUIRK(0x1734, 0x1094, "FSC Amilo M1451G", ALC880_FIXUP_FUJITSU),
Takashi Iwaiba533812012-02-20 16:36:52 +01004573 SND_PCI_QUIRK(0x1734, 0x10ac, "FSC AMILO Xi 1526", ALC880_FIXUP_F1734),
Takashi Iwaicf5a2272012-02-20 16:31:07 +01004574 SND_PCI_QUIRK(0x1734, 0x10b0, "FSC Amilo Pi1556", ALC880_FIXUP_FUJITSU),
Takashi Iwaidc6af522012-02-17 16:18:59 +01004575 SND_PCI_QUIRK(0x1854, 0x003b, "LG", ALC880_FIXUP_LG),
4576 SND_PCI_QUIRK(0x1854, 0x005f, "LG P1 Express", ALC880_FIXUP_LG),
4577 SND_PCI_QUIRK(0x1854, 0x0068, "LG w1", ALC880_FIXUP_LG),
Takashi Iwaib9368f52012-02-17 17:54:44 +01004578 SND_PCI_QUIRK(0x19db, 0x4188, "TCL S700", ALC880_FIXUP_TCL_S700),
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004579
4580 /* Below is the copied entries from alc880_quirks.c.
4581 * It's not quite sure whether BIOS sets the correct pin-config table
4582 * on these machines, thus they are kept to be compatible with
4583 * the old static quirks. Once when it's confirmed to work without
4584 * these overrides, it'd be better to remove.
4585 */
4586 SND_PCI_QUIRK(0x1019, 0xa880, "ECS", ALC880_FIXUP_5ST_DIG),
4587 SND_PCI_QUIRK(0x1019, 0xa884, "Acer APFV", ALC880_FIXUP_6ST),
4588 SND_PCI_QUIRK(0x1025, 0x0070, "ULI", ALC880_FIXUP_3ST_DIG),
4589 SND_PCI_QUIRK(0x1025, 0x0077, "ULI", ALC880_FIXUP_6ST_DIG),
4590 SND_PCI_QUIRK(0x1025, 0x0078, "ULI", ALC880_FIXUP_6ST_DIG),
4591 SND_PCI_QUIRK(0x1025, 0x0087, "ULI", ALC880_FIXUP_6ST_DIG),
4592 SND_PCI_QUIRK(0x1025, 0xe309, "ULI", ALC880_FIXUP_3ST_DIG),
4593 SND_PCI_QUIRK(0x1025, 0xe310, "ULI", ALC880_FIXUP_3ST),
4594 SND_PCI_QUIRK(0x1039, 0x1234, NULL, ALC880_FIXUP_6ST_DIG),
4595 SND_PCI_QUIRK(0x104d, 0x81a0, "Sony", ALC880_FIXUP_3ST),
4596 SND_PCI_QUIRK(0x104d, 0x81d6, "Sony", ALC880_FIXUP_3ST),
4597 SND_PCI_QUIRK(0x107b, 0x3032, "Gateway", ALC880_FIXUP_5ST),
4598 SND_PCI_QUIRK(0x107b, 0x3033, "Gateway", ALC880_FIXUP_5ST),
4599 SND_PCI_QUIRK(0x107b, 0x4039, "Gateway", ALC880_FIXUP_5ST),
4600 SND_PCI_QUIRK(0x1297, 0xc790, "Shuttle ST20G5", ALC880_FIXUP_6ST_DIG),
4601 SND_PCI_QUIRK(0x1458, 0xa102, "Gigabyte K8", ALC880_FIXUP_6ST_DIG),
4602 SND_PCI_QUIRK(0x1462, 0x1150, "MSI", ALC880_FIXUP_6ST_DIG),
4603 SND_PCI_QUIRK(0x1509, 0x925d, "FIC P4M", ALC880_FIXUP_6ST_DIG),
4604 SND_PCI_QUIRK(0x1565, 0x8202, "Biostar", ALC880_FIXUP_5ST_DIG),
4605 SND_PCI_QUIRK(0x1695, 0x400d, "EPoX", ALC880_FIXUP_5ST_DIG),
4606 SND_PCI_QUIRK(0x1695, 0x4012, "EPox EP-5LDA", ALC880_FIXUP_5ST_DIG),
4607 SND_PCI_QUIRK(0x2668, 0x8086, NULL, ALC880_FIXUP_6ST_DIG), /* broken BIOS */
4608 SND_PCI_QUIRK(0x8086, 0x2668, NULL, ALC880_FIXUP_6ST_DIG),
4609 SND_PCI_QUIRK(0x8086, 0xa100, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4610 SND_PCI_QUIRK(0x8086, 0xd400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4611 SND_PCI_QUIRK(0x8086, 0xd401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4612 SND_PCI_QUIRK(0x8086, 0xd402, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4613 SND_PCI_QUIRK(0x8086, 0xe224, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4614 SND_PCI_QUIRK(0x8086, 0xe305, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4615 SND_PCI_QUIRK(0x8086, 0xe308, "Intel mobo", ALC880_FIXUP_3ST_DIG),
4616 SND_PCI_QUIRK(0x8086, 0xe400, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4617 SND_PCI_QUIRK(0x8086, 0xe401, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4618 SND_PCI_QUIRK(0x8086, 0xe402, "Intel mobo", ALC880_FIXUP_5ST_DIG),
4619 /* default Intel */
4620 SND_PCI_QUIRK_VENDOR(0x8086, "Intel mobo", ALC880_FIXUP_3ST),
4621 SND_PCI_QUIRK(0xa0a0, 0x0560, "AOpen i915GMm-HFS", ALC880_FIXUP_5ST_DIG),
4622 SND_PCI_QUIRK(0xe803, 0x1019, NULL, ALC880_FIXUP_6ST_DIG),
4623 {}
4624};
4625
4626static const struct alc_model_fixup alc880_fixup_models[] = {
4627 {.id = ALC880_FIXUP_3ST, .name = "3stack"},
4628 {.id = ALC880_FIXUP_3ST_DIG, .name = "3stack-digout"},
4629 {.id = ALC880_FIXUP_5ST, .name = "5stack"},
4630 {.id = ALC880_FIXUP_5ST_DIG, .name = "5stack-digout"},
4631 {.id = ALC880_FIXUP_6ST, .name = "6stack"},
4632 {.id = ALC880_FIXUP_6ST_DIG, .name = "6stack-digout"},
Takashi Iwaiee3b2962011-11-15 14:26:54 +01004633 {}
4634};
4635
4636
4637/*
Takashi Iwai1d045db2011-07-07 18:23:21 +02004638 * OK, here we have finally the patch for ALC880
4639 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004640static int patch_alc880(struct hda_codec *codec)
4641{
4642 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004643 int err;
4644
Takashi Iwai3de95172012-05-07 18:03:15 +02004645 err = alc_alloc_spec(codec, 0x0b);
4646 if (err < 0)
4647 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004648
Takashi Iwai3de95172012-05-07 18:03:15 +02004649 spec = codec->spec;
Takashi Iwai7b1655f2011-07-14 15:31:21 +02004650 spec->need_dac_fix = 1;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004651
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004652 alc_pick_fixup(codec, alc880_fixup_models, alc880_fixup_tbl,
4653 alc880_fixups);
4654 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004655
Takashi Iwai67b6ec32012-02-20 18:20:42 +01004656 /* automatic parse from the BIOS config */
4657 err = alc880_parse_auto_config(codec);
4658 if (err < 0)
4659 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004660
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004661 if (!spec->no_analog) {
4662 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004663 if (err < 0)
4664 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004665 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4666 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004667
Takashi Iwai1d045db2011-07-07 18:23:21 +02004668 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004669
Takashi Iwai589876e2012-02-20 15:47:55 +01004670 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4671
Takashi Iwai1d045db2011-07-07 18:23:21 +02004672 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004673
4674 error:
4675 alc_free(codec);
4676 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004677}
4678
4679
4680/*
4681 * ALC260 support
4682 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004683static int alc260_parse_auto_config(struct hda_codec *codec)
4684{
Takashi Iwai1d045db2011-07-07 18:23:21 +02004685 static const hda_nid_t alc260_ignore[] = { 0x17, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004686 static const hda_nid_t alc260_ssids[] = { 0x10, 0x15, 0x0f, 0 };
4687 return alc_parse_auto_config(codec, alc260_ignore, alc260_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004688}
4689
Takashi Iwai1d045db2011-07-07 18:23:21 +02004690/*
4691 * Pin config fixes
4692 */
4693enum {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004694 ALC260_FIXUP_HP_DC5750,
4695 ALC260_FIXUP_HP_PIN_0F,
4696 ALC260_FIXUP_COEF,
Takashi Iwai15317ab2012-02-16 12:02:53 +01004697 ALC260_FIXUP_GPIO1,
Takashi Iwai20f7d922012-02-16 12:35:16 +01004698 ALC260_FIXUP_GPIO1_TOGGLE,
4699 ALC260_FIXUP_REPLACER,
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004700 ALC260_FIXUP_HP_B1900,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004701 ALC260_FIXUP_KN1,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004702};
4703
Takashi Iwai20f7d922012-02-16 12:35:16 +01004704static void alc260_gpio1_automute(struct hda_codec *codec)
4705{
4706 struct alc_spec *spec = codec->spec;
4707 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA,
4708 spec->hp_jack_present);
4709}
4710
4711static void alc260_fixup_gpio1_toggle(struct hda_codec *codec,
4712 const struct alc_fixup *fix, int action)
4713{
4714 struct alc_spec *spec = codec->spec;
4715 if (action == ALC_FIXUP_ACT_PROBE) {
4716 /* although the machine has only one output pin, we need to
4717 * toggle GPIO1 according to the jack state
4718 */
4719 spec->automute_hook = alc260_gpio1_automute;
4720 spec->detect_hp = 1;
4721 spec->automute_speaker = 1;
4722 spec->autocfg.hp_pins[0] = 0x0f; /* copy it for automute */
4723 snd_hda_jack_detect_enable(codec, 0x0f, ALC_HP_EVENT);
4724 spec->unsol_event = alc_sku_unsol_event;
Takashi Iwai23d30f22012-05-07 17:17:32 +02004725 snd_hda_gen_add_verbs(&spec->gen, alc_gpio1_init_verbs);
Takashi Iwai20f7d922012-02-16 12:35:16 +01004726 }
4727}
4728
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004729static void alc260_fixup_kn1(struct hda_codec *codec,
4730 const struct alc_fixup *fix, int action)
4731{
4732 struct alc_spec *spec = codec->spec;
4733 static const struct alc_pincfg pincfgs[] = {
4734 { 0x0f, 0x02214000 }, /* HP/speaker */
4735 { 0x12, 0x90a60160 }, /* int mic */
4736 { 0x13, 0x02a19000 }, /* ext mic */
4737 { 0x18, 0x01446000 }, /* SPDIF out */
4738 /* disable bogus I/O pins */
4739 { 0x10, 0x411111f0 },
4740 { 0x11, 0x411111f0 },
4741 { 0x14, 0x411111f0 },
4742 { 0x15, 0x411111f0 },
4743 { 0x16, 0x411111f0 },
4744 { 0x17, 0x411111f0 },
4745 { 0x19, 0x411111f0 },
4746 { }
4747 };
4748
4749 switch (action) {
4750 case ALC_FIXUP_ACT_PRE_PROBE:
4751 alc_apply_pincfgs(codec, pincfgs);
4752 break;
4753 case ALC_FIXUP_ACT_PROBE:
4754 spec->init_amp = ALC_INIT_NONE;
4755 break;
4756 }
4757}
4758
Takashi Iwai1d045db2011-07-07 18:23:21 +02004759static const struct alc_fixup alc260_fixups[] = {
Takashi Iwaica8f0422012-02-16 11:51:19 +01004760 [ALC260_FIXUP_HP_DC5750] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02004761 .type = ALC_FIXUP_PINS,
4762 .v.pins = (const struct alc_pincfg[]) {
4763 { 0x11, 0x90130110 }, /* speaker */
4764 { }
4765 }
4766 },
Takashi Iwaica8f0422012-02-16 11:51:19 +01004767 [ALC260_FIXUP_HP_PIN_0F] = {
4768 .type = ALC_FIXUP_PINS,
4769 .v.pins = (const struct alc_pincfg[]) {
4770 { 0x0f, 0x01214000 }, /* HP */
4771 { }
4772 }
4773 },
4774 [ALC260_FIXUP_COEF] = {
4775 .type = ALC_FIXUP_VERBS,
4776 .v.verbs = (const struct hda_verb[]) {
4777 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4778 { 0x20, AC_VERB_SET_PROC_COEF, 0x3040 },
4779 { }
4780 },
4781 .chained = true,
4782 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4783 },
Takashi Iwai15317ab2012-02-16 12:02:53 +01004784 [ALC260_FIXUP_GPIO1] = {
4785 .type = ALC_FIXUP_VERBS,
4786 .v.verbs = alc_gpio1_init_verbs,
4787 },
Takashi Iwai20f7d922012-02-16 12:35:16 +01004788 [ALC260_FIXUP_GPIO1_TOGGLE] = {
4789 .type = ALC_FIXUP_FUNC,
4790 .v.func = alc260_fixup_gpio1_toggle,
4791 .chained = true,
4792 .chain_id = ALC260_FIXUP_HP_PIN_0F,
4793 },
4794 [ALC260_FIXUP_REPLACER] = {
4795 .type = ALC_FIXUP_VERBS,
4796 .v.verbs = (const struct hda_verb[]) {
4797 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
4798 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
4799 { }
4800 },
4801 .chained = true,
4802 .chain_id = ALC260_FIXUP_GPIO1_TOGGLE,
4803 },
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004804 [ALC260_FIXUP_HP_B1900] = {
4805 .type = ALC_FIXUP_FUNC,
4806 .v.func = alc260_fixup_gpio1_toggle,
4807 .chained = true,
4808 .chain_id = ALC260_FIXUP_COEF,
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004809 },
4810 [ALC260_FIXUP_KN1] = {
4811 .type = ALC_FIXUP_FUNC,
4812 .v.func = alc260_fixup_kn1,
4813 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02004814};
4815
4816static const struct snd_pci_quirk alc260_fixup_tbl[] = {
Takashi Iwai15317ab2012-02-16 12:02:53 +01004817 SND_PCI_QUIRK(0x1025, 0x007b, "Acer C20x", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004818 SND_PCI_QUIRK(0x1025, 0x007f, "Acer Aspire 9500", ALC260_FIXUP_COEF),
Takashi Iwai15317ab2012-02-16 12:02:53 +01004819 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_FIXUP_GPIO1),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004820 SND_PCI_QUIRK(0x103c, 0x280a, "HP dc5750", ALC260_FIXUP_HP_DC5750),
Takashi Iwai0a1c4fa2012-02-16 12:42:30 +01004821 SND_PCI_QUIRK(0x103c, 0x30ba, "HP Presario B1900", ALC260_FIXUP_HP_B1900),
Takashi Iwaib1f58082012-02-16 12:45:03 +01004822 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FIXUP_GPIO1),
Takashi Iwai118cb4a2012-04-19 07:33:27 +02004823 SND_PCI_QUIRK(0x152d, 0x0729, "Quanta KN1", ALC260_FIXUP_KN1),
Takashi Iwai20f7d922012-02-16 12:35:16 +01004824 SND_PCI_QUIRK(0x161f, 0x2057, "Replacer 672V", ALC260_FIXUP_REPLACER),
Takashi Iwaica8f0422012-02-16 11:51:19 +01004825 SND_PCI_QUIRK(0x1631, 0xc017, "PB V7900", ALC260_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02004826 {}
4827};
4828
4829/*
4830 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004831static int patch_alc260(struct hda_codec *codec)
4832{
4833 struct alc_spec *spec;
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004834 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004835
Takashi Iwai3de95172012-05-07 18:03:15 +02004836 err = alc_alloc_spec(codec, 0x07);
4837 if (err < 0)
4838 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004839
Takashi Iwai3de95172012-05-07 18:03:15 +02004840 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004841
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004842 alc_pick_fixup(codec, NULL, alc260_fixup_tbl, alc260_fixups);
4843 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02004844
Takashi Iwaic3c2c9e2012-02-16 12:59:55 +01004845 /* automatic parse from the BIOS config */
4846 err = alc260_parse_auto_config(codec);
4847 if (err < 0)
4848 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004849
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004850 if (!spec->no_analog) {
4851 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004852 if (err < 0)
4853 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02004854 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
4855 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02004856
Takashi Iwai1d045db2011-07-07 18:23:21 +02004857 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004858 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004859
Takashi Iwai589876e2012-02-20 15:47:55 +01004860 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4861
Takashi Iwai1d045db2011-07-07 18:23:21 +02004862 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02004863
4864 error:
4865 alc_free(codec);
4866 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02004867}
4868
4869
4870/*
4871 * ALC882/883/885/888/889 support
4872 *
4873 * ALC882 is almost identical with ALC880 but has cleaner and more flexible
4874 * configuration. Each pin widget can choose any input DACs and a mixer.
4875 * Each ADC is connected from a mixer of all inputs. This makes possible
4876 * 6-channel independent captures.
4877 *
4878 * In addition, an independent DAC for the multi-playback (not used in this
4879 * driver yet).
4880 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02004881
4882/*
4883 * Pin config fixes
4884 */
4885enum {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004886 ALC882_FIXUP_ABIT_AW9D_MAX,
4887 ALC882_FIXUP_LENOVO_Y530,
4888 ALC882_FIXUP_PB_M5210,
4889 ALC882_FIXUP_ACER_ASPIRE_7736,
4890 ALC882_FIXUP_ASUS_W90V,
Marton Balint8f239212012-03-05 21:33:23 +01004891 ALC889_FIXUP_CD,
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01004892 ALC889_FIXUP_VAIO_TT,
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01004893 ALC888_FIXUP_EEE1601,
Takashi Iwai177943a2011-11-09 12:55:18 +01004894 ALC882_FIXUP_EAPD,
Takashi Iwai7a6069b2011-11-09 15:22:01 +01004895 ALC883_FIXUP_EAPD,
Takashi Iwai8812c4f2011-11-09 17:39:15 +01004896 ALC883_FIXUP_ACER_EAPD,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01004897 ALC882_FIXUP_GPIO1,
4898 ALC882_FIXUP_GPIO2,
Takashi Iwaieb844d52011-11-09 18:03:07 +01004899 ALC882_FIXUP_GPIO3,
Takashi Iwai68ef0562011-11-09 18:24:44 +01004900 ALC889_FIXUP_COEF,
4901 ALC882_FIXUP_ASUS_W2JC,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01004902 ALC882_FIXUP_ACER_ASPIRE_4930G,
4903 ALC882_FIXUP_ACER_ASPIRE_8930G,
4904 ALC882_FIXUP_ASPIRE_8930G_VERBS,
Takashi Iwai56710872011-11-14 17:42:11 +01004905 ALC885_FIXUP_MACPRO_GPIO,
Takashi Iwai02a237b2012-02-13 15:25:07 +01004906 ALC889_FIXUP_DAC_ROUTE,
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01004907 ALC889_FIXUP_MBP_VREF,
4908 ALC889_FIXUP_IMAC91_VREF,
Takashi Iwai1d045db2011-07-07 18:23:21 +02004909};
4910
Takashi Iwai68ef0562011-11-09 18:24:44 +01004911static void alc889_fixup_coef(struct hda_codec *codec,
4912 const struct alc_fixup *fix, int action)
4913{
4914 if (action != ALC_FIXUP_ACT_INIT)
4915 return;
4916 alc889_coef_init(codec);
4917}
4918
Takashi Iwai56710872011-11-14 17:42:11 +01004919/* toggle speaker-output according to the hp-jack state */
4920static void alc882_gpio_mute(struct hda_codec *codec, int pin, int muted)
4921{
4922 unsigned int gpiostate, gpiomask, gpiodir;
4923
4924 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4925 AC_VERB_GET_GPIO_DATA, 0);
4926
4927 if (!muted)
4928 gpiostate |= (1 << pin);
4929 else
4930 gpiostate &= ~(1 << pin);
4931
4932 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
4933 AC_VERB_GET_GPIO_MASK, 0);
4934 gpiomask |= (1 << pin);
4935
4936 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
4937 AC_VERB_GET_GPIO_DIRECTION, 0);
4938 gpiodir |= (1 << pin);
4939
4940
4941 snd_hda_codec_write(codec, codec->afg, 0,
4942 AC_VERB_SET_GPIO_MASK, gpiomask);
4943 snd_hda_codec_write(codec, codec->afg, 0,
4944 AC_VERB_SET_GPIO_DIRECTION, gpiodir);
4945
4946 msleep(1);
4947
4948 snd_hda_codec_write(codec, codec->afg, 0,
4949 AC_VERB_SET_GPIO_DATA, gpiostate);
4950}
4951
4952/* set up GPIO at initialization */
4953static void alc885_fixup_macpro_gpio(struct hda_codec *codec,
4954 const struct alc_fixup *fix, int action)
4955{
4956 if (action != ALC_FIXUP_ACT_INIT)
4957 return;
4958 alc882_gpio_mute(codec, 0, 0);
4959 alc882_gpio_mute(codec, 1, 0);
4960}
4961
Takashi Iwai02a237b2012-02-13 15:25:07 +01004962/* Fix the connection of some pins for ALC889:
4963 * At least, Acer Aspire 5935 shows the connections to DAC3/4 don't
4964 * work correctly (bko#42740)
4965 */
4966static void alc889_fixup_dac_route(struct hda_codec *codec,
4967 const struct alc_fixup *fix, int action)
4968{
4969 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
Takashi Iwaief8d60f2012-02-17 10:12:38 +01004970 /* fake the connections during parsing the tree */
Takashi Iwai02a237b2012-02-13 15:25:07 +01004971 hda_nid_t conn1[2] = { 0x0c, 0x0d };
4972 hda_nid_t conn2[2] = { 0x0e, 0x0f };
4973 snd_hda_override_conn_list(codec, 0x14, 2, conn1);
4974 snd_hda_override_conn_list(codec, 0x15, 2, conn1);
4975 snd_hda_override_conn_list(codec, 0x18, 2, conn2);
4976 snd_hda_override_conn_list(codec, 0x1a, 2, conn2);
Takashi Iwaief8d60f2012-02-17 10:12:38 +01004977 } else if (action == ALC_FIXUP_ACT_PROBE) {
4978 /* restore the connections */
4979 hda_nid_t conn[5] = { 0x0c, 0x0d, 0x0e, 0x0f, 0x26 };
4980 snd_hda_override_conn_list(codec, 0x14, 5, conn);
4981 snd_hda_override_conn_list(codec, 0x15, 5, conn);
4982 snd_hda_override_conn_list(codec, 0x18, 5, conn);
4983 snd_hda_override_conn_list(codec, 0x1a, 5, conn);
Takashi Iwai02a237b2012-02-13 15:25:07 +01004984 }
4985}
4986
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01004987/* Set VREF on HP pin */
4988static void alc889_fixup_mbp_vref(struct hda_codec *codec,
4989 const struct alc_fixup *fix, int action)
4990{
4991 struct alc_spec *spec = codec->spec;
4992 static hda_nid_t nids[2] = { 0x14, 0x15 };
4993 int i;
4994
4995 if (action != ALC_FIXUP_ACT_INIT)
4996 return;
4997 for (i = 0; i < ARRAY_SIZE(nids); i++) {
4998 unsigned int val = snd_hda_codec_get_pincfg(codec, nids[i]);
4999 if (get_defcfg_device(val) != AC_JACK_HP_OUT)
5000 continue;
5001 val = snd_hda_codec_read(codec, nids[i], 0,
5002 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5003 val |= AC_PINCTL_VREF_80;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005004 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005005 spec->keep_vref_in_automute = 1;
5006 break;
5007 }
5008}
5009
5010/* Set VREF on speaker pins on imac91 */
5011static void alc889_fixup_imac91_vref(struct hda_codec *codec,
5012 const struct alc_fixup *fix, int action)
5013{
5014 struct alc_spec *spec = codec->spec;
5015 static hda_nid_t nids[2] = { 0x18, 0x1a };
5016 int i;
5017
5018 if (action != ALC_FIXUP_ACT_INIT)
5019 return;
5020 for (i = 0; i < ARRAY_SIZE(nids); i++) {
5021 unsigned int val;
5022 val = snd_hda_codec_read(codec, nids[i], 0,
5023 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5024 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005025 snd_hda_set_pin_ctl(codec, nids[i], val);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005026 }
5027 spec->keep_vref_in_automute = 1;
5028}
5029
Takashi Iwai1d045db2011-07-07 18:23:21 +02005030static const struct alc_fixup alc882_fixups[] = {
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005031 [ALC882_FIXUP_ABIT_AW9D_MAX] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005032 .type = ALC_FIXUP_PINS,
5033 .v.pins = (const struct alc_pincfg[]) {
5034 { 0x15, 0x01080104 }, /* side */
5035 { 0x16, 0x01011012 }, /* rear */
5036 { 0x17, 0x01016011 }, /* clfe */
5037 { }
5038 }
5039 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005040 [ALC882_FIXUP_LENOVO_Y530] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005041 .type = ALC_FIXUP_PINS,
5042 .v.pins = (const struct alc_pincfg[]) {
5043 { 0x15, 0x99130112 }, /* rear int speakers */
5044 { 0x16, 0x99130111 }, /* subwoofer */
5045 { }
5046 }
5047 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005048 [ALC882_FIXUP_PB_M5210] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005049 .type = ALC_FIXUP_VERBS,
5050 .v.verbs = (const struct hda_verb[]) {
5051 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
5052 {}
5053 }
5054 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005055 [ALC882_FIXUP_ACER_ASPIRE_7736] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005056 .type = ALC_FIXUP_FUNC,
5057 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005058 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005059 [ALC882_FIXUP_ASUS_W90V] = {
Takashi Iwai5cdf7452011-10-26 23:04:08 +02005060 .type = ALC_FIXUP_PINS,
5061 .v.pins = (const struct alc_pincfg[]) {
5062 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
5063 { }
5064 }
5065 },
Marton Balint8f239212012-03-05 21:33:23 +01005066 [ALC889_FIXUP_CD] = {
5067 .type = ALC_FIXUP_PINS,
5068 .v.pins = (const struct alc_pincfg[]) {
5069 { 0x1c, 0x993301f0 }, /* CD */
5070 { }
5071 }
5072 },
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005073 [ALC889_FIXUP_VAIO_TT] = {
5074 .type = ALC_FIXUP_PINS,
5075 .v.pins = (const struct alc_pincfg[]) {
5076 { 0x17, 0x90170111 }, /* hidden surround speaker */
5077 { }
5078 }
5079 },
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005080 [ALC888_FIXUP_EEE1601] = {
5081 .type = ALC_FIXUP_VERBS,
5082 .v.verbs = (const struct hda_verb[]) {
5083 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5084 { 0x20, AC_VERB_SET_PROC_COEF, 0x0838 },
5085 { }
5086 }
Takashi Iwai177943a2011-11-09 12:55:18 +01005087 },
5088 [ALC882_FIXUP_EAPD] = {
5089 .type = ALC_FIXUP_VERBS,
5090 .v.verbs = (const struct hda_verb[]) {
5091 /* change to EAPD mode */
5092 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5093 { 0x20, AC_VERB_SET_PROC_COEF, 0x3060 },
5094 { }
5095 }
5096 },
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005097 [ALC883_FIXUP_EAPD] = {
5098 .type = ALC_FIXUP_VERBS,
5099 .v.verbs = (const struct hda_verb[]) {
5100 /* change to EAPD mode */
5101 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5102 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5103 { }
5104 }
5105 },
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005106 [ALC883_FIXUP_ACER_EAPD] = {
5107 .type = ALC_FIXUP_VERBS,
5108 .v.verbs = (const struct hda_verb[]) {
5109 /* eanable EAPD on Acer laptops */
5110 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5111 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5112 { }
5113 }
5114 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005115 [ALC882_FIXUP_GPIO1] = {
5116 .type = ALC_FIXUP_VERBS,
5117 .v.verbs = alc_gpio1_init_verbs,
5118 },
5119 [ALC882_FIXUP_GPIO2] = {
5120 .type = ALC_FIXUP_VERBS,
5121 .v.verbs = alc_gpio2_init_verbs,
5122 },
Takashi Iwaieb844d52011-11-09 18:03:07 +01005123 [ALC882_FIXUP_GPIO3] = {
5124 .type = ALC_FIXUP_VERBS,
5125 .v.verbs = alc_gpio3_init_verbs,
5126 },
Takashi Iwai68ef0562011-11-09 18:24:44 +01005127 [ALC882_FIXUP_ASUS_W2JC] = {
5128 .type = ALC_FIXUP_VERBS,
5129 .v.verbs = alc_gpio1_init_verbs,
5130 .chained = true,
5131 .chain_id = ALC882_FIXUP_EAPD,
5132 },
5133 [ALC889_FIXUP_COEF] = {
5134 .type = ALC_FIXUP_FUNC,
5135 .v.func = alc889_fixup_coef,
5136 },
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005137 [ALC882_FIXUP_ACER_ASPIRE_4930G] = {
5138 .type = ALC_FIXUP_PINS,
5139 .v.pins = (const struct alc_pincfg[]) {
5140 { 0x16, 0x99130111 }, /* CLFE speaker */
5141 { 0x17, 0x99130112 }, /* surround speaker */
5142 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005143 },
5144 .chained = true,
5145 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005146 },
5147 [ALC882_FIXUP_ACER_ASPIRE_8930G] = {
5148 .type = ALC_FIXUP_PINS,
5149 .v.pins = (const struct alc_pincfg[]) {
5150 { 0x16, 0x99130111 }, /* CLFE speaker */
5151 { 0x1b, 0x99130112 }, /* surround speaker */
5152 { }
5153 },
5154 .chained = true,
5155 .chain_id = ALC882_FIXUP_ASPIRE_8930G_VERBS,
5156 },
5157 [ALC882_FIXUP_ASPIRE_8930G_VERBS] = {
5158 /* additional init verbs for Acer Aspire 8930G */
5159 .type = ALC_FIXUP_VERBS,
5160 .v.verbs = (const struct hda_verb[]) {
5161 /* Enable all DACs */
5162 /* DAC DISABLE/MUTE 1? */
5163 /* setting bits 1-5 disables DAC nids 0x02-0x06
5164 * apparently. Init=0x38 */
5165 { 0x20, AC_VERB_SET_COEF_INDEX, 0x03 },
5166 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5167 /* DAC DISABLE/MUTE 2? */
5168 /* some bit here disables the other DACs.
5169 * Init=0x4900 */
5170 { 0x20, AC_VERB_SET_COEF_INDEX, 0x08 },
5171 { 0x20, AC_VERB_SET_PROC_COEF, 0x0000 },
5172 /* DMIC fix
5173 * This laptop has a stereo digital microphone.
5174 * The mics are only 1cm apart which makes the stereo
5175 * useless. However, either the mic or the ALC889
5176 * makes the signal become a difference/sum signal
5177 * instead of standard stereo, which is annoying.
5178 * So instead we flip this bit which makes the
5179 * codec replicate the sum signal to both channels,
5180 * turning it into a normal mono mic.
5181 */
5182 /* DMIC_CONTROL? Init value = 0x0001 */
5183 { 0x20, AC_VERB_SET_COEF_INDEX, 0x0b },
5184 { 0x20, AC_VERB_SET_PROC_COEF, 0x0003 },
5185 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5186 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5187 { }
Takashi Iwai038d4fe2012-04-11 17:18:12 +02005188 },
5189 .chained = true,
5190 .chain_id = ALC882_FIXUP_GPIO1,
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005191 },
Takashi Iwai56710872011-11-14 17:42:11 +01005192 [ALC885_FIXUP_MACPRO_GPIO] = {
5193 .type = ALC_FIXUP_FUNC,
5194 .v.func = alc885_fixup_macpro_gpio,
5195 },
Takashi Iwai02a237b2012-02-13 15:25:07 +01005196 [ALC889_FIXUP_DAC_ROUTE] = {
5197 .type = ALC_FIXUP_FUNC,
5198 .v.func = alc889_fixup_dac_route,
5199 },
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005200 [ALC889_FIXUP_MBP_VREF] = {
5201 .type = ALC_FIXUP_FUNC,
5202 .v.func = alc889_fixup_mbp_vref,
5203 .chained = true,
5204 .chain_id = ALC882_FIXUP_GPIO1,
5205 },
5206 [ALC889_FIXUP_IMAC91_VREF] = {
5207 .type = ALC_FIXUP_FUNC,
5208 .v.func = alc889_fixup_imac91_vref,
5209 .chained = true,
5210 .chain_id = ALC882_FIXUP_GPIO1,
5211 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005212};
5213
5214static const struct snd_pci_quirk alc882_fixup_tbl[] = {
Takashi Iwai8812c4f2011-11-09 17:39:15 +01005215 SND_PCI_QUIRK(0x1025, 0x006c, "Acer Aspire 9810", ALC883_FIXUP_ACER_EAPD),
5216 SND_PCI_QUIRK(0x1025, 0x0090, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5217 SND_PCI_QUIRK(0x1025, 0x010a, "Acer Ferrari 5000", ALC883_FIXUP_ACER_EAPD),
5218 SND_PCI_QUIRK(0x1025, 0x0110, "Acer Aspire", ALC883_FIXUP_ACER_EAPD),
5219 SND_PCI_QUIRK(0x1025, 0x0112, "Acer Aspire 9303", ALC883_FIXUP_ACER_EAPD),
5220 SND_PCI_QUIRK(0x1025, 0x0121, "Acer Aspire 5920G", ALC883_FIXUP_ACER_EAPD),
Takashi Iwaic3e837b2011-11-10 16:01:47 +01005221 SND_PCI_QUIRK(0x1025, 0x013e, "Acer Aspire 4930G",
5222 ALC882_FIXUP_ACER_ASPIRE_4930G),
5223 SND_PCI_QUIRK(0x1025, 0x013f, "Acer Aspire 5930G",
5224 ALC882_FIXUP_ACER_ASPIRE_4930G),
5225 SND_PCI_QUIRK(0x1025, 0x0145, "Acer Aspire 8930G",
5226 ALC882_FIXUP_ACER_ASPIRE_8930G),
5227 SND_PCI_QUIRK(0x1025, 0x0146, "Acer Aspire 6935G",
5228 ALC882_FIXUP_ACER_ASPIRE_8930G),
5229 SND_PCI_QUIRK(0x1025, 0x015e, "Acer Aspire 6930G",
5230 ALC882_FIXUP_ACER_ASPIRE_4930G),
5231 SND_PCI_QUIRK(0x1025, 0x0166, "Acer Aspire 6530G",
5232 ALC882_FIXUP_ACER_ASPIRE_4930G),
5233 SND_PCI_QUIRK(0x1025, 0x0142, "Acer Aspire 7730G",
5234 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005235 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", ALC882_FIXUP_PB_M5210),
Takashi Iwaif5c53d82012-05-07 10:07:33 +02005236 SND_PCI_QUIRK(0x1025, 0x021e, "Acer Aspire 5739G",
5237 ALC882_FIXUP_ACER_ASPIRE_4930G),
Takashi Iwai02a237b2012-02-13 15:25:07 +01005238 SND_PCI_QUIRK(0x1025, 0x0259, "Acer Aspire 5935", ALC889_FIXUP_DAC_ROUTE),
Takashi Iwaife97da12012-04-12 08:00:19 +02005239 SND_PCI_QUIRK(0x1025, 0x026b, "Acer Aspire 8940G", ALC882_FIXUP_ACER_ASPIRE_8930G),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005240 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", ALC882_FIXUP_ACER_ASPIRE_7736),
Takashi Iwai177943a2011-11-09 12:55:18 +01005241 SND_PCI_QUIRK(0x1043, 0x13c2, "Asus A7M", ALC882_FIXUP_EAPD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005242 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", ALC882_FIXUP_ASUS_W90V),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005243 SND_PCI_QUIRK(0x1043, 0x1971, "Asus W2JC", ALC882_FIXUP_ASUS_W2JC),
Takashi Iwai0e7cc2e2011-11-09 12:42:48 +01005244 SND_PCI_QUIRK(0x1043, 0x835f, "Asus Eee 1601", ALC888_FIXUP_EEE1601),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005245 SND_PCI_QUIRK(0x104d, 0x9047, "Sony Vaio TT", ALC889_FIXUP_VAIO_TT),
Takashi Iwai56710872011-11-14 17:42:11 +01005246
5247 /* All Apple entries are in codec SSIDs */
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005248 SND_PCI_QUIRK(0x106b, 0x00a0, "MacBookPro 3,1", ALC889_FIXUP_MBP_VREF),
5249 SND_PCI_QUIRK(0x106b, 0x00a1, "Macbook", ALC889_FIXUP_MBP_VREF),
5250 SND_PCI_QUIRK(0x106b, 0x00a4, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005251 SND_PCI_QUIRK(0x106b, 0x0c00, "Mac Pro", ALC885_FIXUP_MACPRO_GPIO),
5252 SND_PCI_QUIRK(0x106b, 0x1000, "iMac 24", ALC885_FIXUP_MACPRO_GPIO),
5253 SND_PCI_QUIRK(0x106b, 0x2800, "AppleTV", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005254 SND_PCI_QUIRK(0x106b, 0x2c00, "MacbookPro rev3", ALC889_FIXUP_MBP_VREF),
5255 SND_PCI_QUIRK(0x106b, 0x3000, "iMac", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005256 SND_PCI_QUIRK(0x106b, 0x3200, "iMac 7,1 Aluminum", ALC882_FIXUP_EAPD),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005257 SND_PCI_QUIRK(0x106b, 0x3400, "MacBookAir 1,1", ALC889_FIXUP_MBP_VREF),
5258 SND_PCI_QUIRK(0x106b, 0x3500, "MacBookAir 2,1", ALC889_FIXUP_MBP_VREF),
5259 SND_PCI_QUIRK(0x106b, 0x3600, "Macbook 3,1", ALC889_FIXUP_MBP_VREF),
5260 SND_PCI_QUIRK(0x106b, 0x3800, "MacbookPro 4,1", ALC889_FIXUP_MBP_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005261 SND_PCI_QUIRK(0x106b, 0x3e00, "iMac 24 Aluminum", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005262 SND_PCI_QUIRK(0x106b, 0x3f00, "Macbook 5,1", ALC889_FIXUP_IMAC91_VREF),
5263 SND_PCI_QUIRK(0x106b, 0x4000, "MacbookPro 5,1", ALC889_FIXUP_IMAC91_VREF),
5264 SND_PCI_QUIRK(0x106b, 0x4100, "Macmini 3,1", ALC889_FIXUP_IMAC91_VREF),
Josh Boyer29ebe402012-04-12 13:55:36 -04005265 SND_PCI_QUIRK(0x106b, 0x4200, "Mac Pro 5,1", ALC885_FIXUP_MACPRO_GPIO),
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005266 SND_PCI_QUIRK(0x106b, 0x4600, "MacbookPro 5,2", ALC889_FIXUP_IMAC91_VREF),
5267 SND_PCI_QUIRK(0x106b, 0x4900, "iMac 9,1 Aluminum", ALC889_FIXUP_IMAC91_VREF),
5268 SND_PCI_QUIRK(0x106b, 0x4a00, "Macbook 5,2", ALC889_FIXUP_IMAC91_VREF),
Takashi Iwai56710872011-11-14 17:42:11 +01005269
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005270 SND_PCI_QUIRK(0x1071, 0x8258, "Evesham Voyaeger", ALC882_FIXUP_EAPD),
Takashi Iwaibca40132012-05-07 11:13:14 +02005271 SND_PCI_QUIRK(0x1462, 0x7350, "MSI-7350", ALC889_FIXUP_CD),
Takashi Iwaieb844d52011-11-09 18:03:07 +01005272 SND_PCI_QUIRK_VENDOR(0x1462, "MSI", ALC882_FIXUP_GPIO3),
Marton Balint8f239212012-03-05 21:33:23 +01005273 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte EP45-DS3", ALC889_FIXUP_CD),
Takashi Iwai5c0ebfb2011-11-07 17:59:13 +01005274 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", ALC882_FIXUP_ABIT_AW9D_MAX),
Takashi Iwai7a6069b2011-11-09 15:22:01 +01005275 SND_PCI_QUIRK_VENDOR(0x1558, "Clevo laptop", ALC882_FIXUP_EAPD),
5276 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_FIXUP_EAPD),
Takashi Iwaiac9b1cd2011-11-09 17:45:55 +01005277 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", ALC882_FIXUP_LENOVO_Y530),
Takashi Iwai68ef0562011-11-09 18:24:44 +01005278 SND_PCI_QUIRK(0x8086, 0x0022, "DX58SO", ALC889_FIXUP_COEF),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005279 {}
5280};
5281
Takashi Iwai912093b2012-04-11 14:03:41 +02005282static const struct alc_model_fixup alc882_fixup_models[] = {
5283 {.id = ALC882_FIXUP_ACER_ASPIRE_4930G, .name = "acer-aspire-4930g"},
5284 {.id = ALC882_FIXUP_ACER_ASPIRE_8930G, .name = "acer-aspire-8930g"},
5285 {.id = ALC883_FIXUP_ACER_EAPD, .name = "acer-aspire"},
5286 {}
5287};
5288
Takashi Iwai1d045db2011-07-07 18:23:21 +02005289/*
5290 * BIOS auto configuration
5291 */
5292/* almost identical with ALC880 parser... */
5293static int alc882_parse_auto_config(struct hda_codec *codec)
5294{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005295 static const hda_nid_t alc882_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005296 static const hda_nid_t alc882_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5297 return alc_parse_auto_config(codec, alc882_ignore, alc882_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005298}
5299
Takashi Iwai1d045db2011-07-07 18:23:21 +02005300/*
5301 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005302static int patch_alc882(struct hda_codec *codec)
5303{
5304 struct alc_spec *spec;
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005305 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005306
Takashi Iwai3de95172012-05-07 18:03:15 +02005307 err = alc_alloc_spec(codec, 0x0b);
5308 if (err < 0)
5309 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005310
Takashi Iwai3de95172012-05-07 18:03:15 +02005311 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005312
5313 switch (codec->vendor_id) {
5314 case 0x10ec0882:
5315 case 0x10ec0885:
5316 break;
5317 default:
5318 /* ALC883 and variants */
5319 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5320 break;
5321 }
5322
Takashi Iwai912093b2012-04-11 14:03:41 +02005323 alc_pick_fixup(codec, alc882_fixup_models, alc882_fixup_tbl,
5324 alc882_fixups);
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005325 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005326
5327 alc_auto_parse_customize_define(codec);
5328
Takashi Iwai1a97b7f2012-02-21 11:11:48 +01005329 /* automatic parse from the BIOS config */
5330 err = alc882_parse_auto_config(codec);
5331 if (err < 0)
5332 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005333
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005334 if (!spec->no_analog && has_cdefine_beep(codec)) {
5335 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005336 if (err < 0)
5337 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005338 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005339 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005340
Takashi Iwai1d045db2011-07-07 18:23:21 +02005341 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005342
Takashi Iwai589876e2012-02-20 15:47:55 +01005343 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5344
Takashi Iwai1d045db2011-07-07 18:23:21 +02005345 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005346
5347 error:
5348 alc_free(codec);
5349 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005350}
5351
5352
5353/*
5354 * ALC262 support
5355 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005356static int alc262_parse_auto_config(struct hda_codec *codec)
5357{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005358 static const hda_nid_t alc262_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005359 static const hda_nid_t alc262_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5360 return alc_parse_auto_config(codec, alc262_ignore, alc262_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005361}
5362
5363/*
5364 * Pin config fixes
5365 */
5366enum {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005367 ALC262_FIXUP_FSC_H270,
5368 ALC262_FIXUP_HP_Z200,
5369 ALC262_FIXUP_TYAN,
Takashi Iwaic4701502011-11-07 14:20:07 +01005370 ALC262_FIXUP_LENOVO_3000,
Takashi Iwaib42590b2011-11-07 14:41:01 +01005371 ALC262_FIXUP_BENQ,
5372 ALC262_FIXUP_BENQ_T31,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005373};
5374
5375static const struct alc_fixup alc262_fixups[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005376 [ALC262_FIXUP_FSC_H270] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005377 .type = ALC_FIXUP_PINS,
5378 .v.pins = (const struct alc_pincfg[]) {
5379 { 0x14, 0x99130110 }, /* speaker */
5380 { 0x15, 0x0221142f }, /* front HP */
5381 { 0x1b, 0x0121141f }, /* rear HP */
5382 { }
5383 }
5384 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005385 [ALC262_FIXUP_HP_Z200] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005386 .type = ALC_FIXUP_PINS,
5387 .v.pins = (const struct alc_pincfg[]) {
5388 { 0x16, 0x99130120 }, /* internal speaker */
5389 { }
5390 }
5391 },
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005392 [ALC262_FIXUP_TYAN] = {
5393 .type = ALC_FIXUP_PINS,
5394 .v.pins = (const struct alc_pincfg[]) {
5395 { 0x14, 0x1993e1f0 }, /* int AUX */
5396 { }
5397 }
5398 },
Takashi Iwaic4701502011-11-07 14:20:07 +01005399 [ALC262_FIXUP_LENOVO_3000] = {
5400 .type = ALC_FIXUP_VERBS,
5401 .v.verbs = (const struct hda_verb[]) {
5402 { 0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005403 {}
5404 },
5405 .chained = true,
5406 .chain_id = ALC262_FIXUP_BENQ,
5407 },
5408 [ALC262_FIXUP_BENQ] = {
5409 .type = ALC_FIXUP_VERBS,
5410 .v.verbs = (const struct hda_verb[]) {
Takashi Iwaic4701502011-11-07 14:20:07 +01005411 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5412 { 0x20, AC_VERB_SET_PROC_COEF, 0x3070 },
5413 {}
5414 }
5415 },
Takashi Iwaib42590b2011-11-07 14:41:01 +01005416 [ALC262_FIXUP_BENQ_T31] = {
5417 .type = ALC_FIXUP_VERBS,
5418 .v.verbs = (const struct hda_verb[]) {
5419 { 0x20, AC_VERB_SET_COEF_INDEX, 0x07 },
5420 { 0x20, AC_VERB_SET_PROC_COEF, 0x3050 },
5421 {}
5422 }
5423 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005424};
5425
5426static const struct snd_pci_quirk alc262_fixup_tbl[] = {
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005427 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200", ALC262_FIXUP_HP_Z200),
Takashi Iwai3dcd3be2011-11-07 14:59:40 +01005428 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FIXUP_BENQ),
5429 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FIXUP_BENQ),
Takashi Iwaiea4e7af2011-11-07 12:23:55 +01005430 SND_PCI_QUIRK(0x10f1, 0x2915, "Tyan Thunder n6650W", ALC262_FIXUP_TYAN),
5431 SND_PCI_QUIRK(0x1734, 0x1147, "FSC Celsius H270", ALC262_FIXUP_FSC_H270),
Takashi Iwaic4701502011-11-07 14:20:07 +01005432 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000", ALC262_FIXUP_LENOVO_3000),
Takashi Iwaib42590b2011-11-07 14:41:01 +01005433 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_FIXUP_BENQ),
5434 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_FIXUP_BENQ_T31),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005435 {}
5436};
5437
5438
Takashi Iwai1d045db2011-07-07 18:23:21 +02005439/*
5440 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005441static int patch_alc262(struct hda_codec *codec)
5442{
5443 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005444 int err;
5445
Takashi Iwai3de95172012-05-07 18:03:15 +02005446 err = alc_alloc_spec(codec, 0x0b);
5447 if (err < 0)
5448 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005449
Takashi Iwai3de95172012-05-07 18:03:15 +02005450 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005451
5452#if 0
5453 /* pshou 07/11/05 set a zero PCM sample to DAC when FIFO is
5454 * under-run
5455 */
5456 {
5457 int tmp;
5458 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5459 tmp = snd_hda_codec_read(codec, 0x20, 0, AC_VERB_GET_PROC_COEF, 0);
5460 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_COEF_INDEX, 7);
5461 snd_hda_codec_write(codec, 0x1a, 0, AC_VERB_SET_PROC_COEF, tmp | 0x80);
5462 }
5463#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02005464 alc_fix_pll_init(codec, 0x20, 0x0a, 10);
5465
Takashi Iwai42399f72011-11-07 17:18:44 +01005466 alc_pick_fixup(codec, NULL, alc262_fixup_tbl, alc262_fixups);
5467 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005468
Takashi Iwaiaf741c12012-05-07 18:09:48 +02005469 alc_auto_parse_customize_define(codec);
5470
Takashi Iwai42399f72011-11-07 17:18:44 +01005471 /* automatic parse from the BIOS config */
5472 err = alc262_parse_auto_config(codec);
5473 if (err < 0)
5474 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005475
Takashi Iwai1d045db2011-07-07 18:23:21 +02005476 if (!spec->no_analog && has_cdefine_beep(codec)) {
5477 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005478 if (err < 0)
5479 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005480 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005481 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005482
Takashi Iwai1d045db2011-07-07 18:23:21 +02005483 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005484 spec->shutup = alc_eapd_shutup;
5485
Takashi Iwai589876e2012-02-20 15:47:55 +01005486 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5487
Takashi Iwai1d045db2011-07-07 18:23:21 +02005488 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005489
5490 error:
5491 alc_free(codec);
5492 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005493}
5494
5495/*
5496 * ALC268
5497 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005498/* bind Beep switches of both NID 0x0f and 0x10 */
5499static const struct hda_bind_ctls alc268_bind_beep_sw = {
5500 .ops = &snd_hda_bind_sw,
5501 .values = {
5502 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
5503 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
5504 0
5505 },
5506};
5507
5508static const struct snd_kcontrol_new alc268_beep_mixer[] = {
5509 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
5510 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
5511 { }
5512};
5513
5514/* set PCBEEP vol = 0, mute connections */
5515static const struct hda_verb alc268_beep_init_verbs[] = {
5516 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
5517 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5518 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
5519 { }
5520};
5521
5522/*
5523 * BIOS auto configuration
5524 */
5525static int alc268_parse_auto_config(struct hda_codec *codec)
5526{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005527 static const hda_nid_t alc268_ssids[] = { 0x15, 0x1b, 0x14, 0 };
Takashi Iwai1d045db2011-07-07 18:23:21 +02005528 struct alc_spec *spec = codec->spec;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005529 int err = alc_parse_auto_config(codec, NULL, alc268_ssids);
5530 if (err > 0) {
5531 if (!spec->no_analog && spec->autocfg.speaker_pins[0] != 0x1d) {
5532 add_mixer(spec, alc268_beep_mixer);
Takashi Iwai23d30f22012-05-07 17:17:32 +02005533 snd_hda_gen_add_verbs(&spec->gen, alc268_beep_init_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005534 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02005535 }
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005536 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005537}
5538
Takashi Iwai1d045db2011-07-07 18:23:21 +02005539/*
5540 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005541static int patch_alc268(struct hda_codec *codec)
5542{
5543 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005544 int i, has_beep, err;
5545
Takashi Iwai1d045db2011-07-07 18:23:21 +02005546 /* ALC268 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02005547 err = alc_alloc_spec(codec, 0);
5548 if (err < 0)
5549 return err;
5550
5551 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005552
Takashi Iwai6ebb8052011-08-16 15:15:40 +02005553 /* automatic parse from the BIOS config */
5554 err = alc268_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005555 if (err < 0)
5556 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005557
Takashi Iwai1d045db2011-07-07 18:23:21 +02005558 has_beep = 0;
5559 for (i = 0; i < spec->num_mixers; i++) {
5560 if (spec->mixers[i] == alc268_beep_mixer) {
5561 has_beep = 1;
5562 break;
5563 }
5564 }
5565
5566 if (has_beep) {
5567 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005568 if (err < 0)
5569 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005570 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
5571 /* override the amp caps for beep generator */
5572 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
5573 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
5574 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
5575 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
5576 (0 << AC_AMPCAP_MUTE_SHIFT));
5577 }
5578
Takashi Iwai1d045db2011-07-07 18:23:21 +02005579 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005580 spec->shutup = alc_eapd_shutup;
5581
Takashi Iwai1d045db2011-07-07 18:23:21 +02005582 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02005583
5584 error:
5585 alc_free(codec);
5586 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005587}
5588
5589/*
5590 * ALC269
5591 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005592static const struct hda_pcm_stream alc269_44k_pcm_analog_playback = {
5593 .substreams = 1,
5594 .channels_min = 2,
5595 .channels_max = 8,
5596 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5597 /* NID is set in alc_build_pcms */
5598 .ops = {
5599 .open = alc_playback_pcm_open,
5600 .prepare = alc_playback_pcm_prepare,
5601 .cleanup = alc_playback_pcm_cleanup
5602 },
5603};
5604
5605static const struct hda_pcm_stream alc269_44k_pcm_analog_capture = {
5606 .substreams = 1,
5607 .channels_min = 2,
5608 .channels_max = 2,
5609 .rates = SNDRV_PCM_RATE_44100, /* fixed rate */
5610 /* NID is set in alc_build_pcms */
5611};
5612
Takashi Iwai1d045db2011-07-07 18:23:21 +02005613/* different alc269-variants */
5614enum {
5615 ALC269_TYPE_ALC269VA,
5616 ALC269_TYPE_ALC269VB,
5617 ALC269_TYPE_ALC269VC,
5618};
5619
5620/*
5621 * BIOS auto configuration
5622 */
5623static int alc269_parse_auto_config(struct hda_codec *codec)
5624{
Takashi Iwai1d045db2011-07-07 18:23:21 +02005625 static const hda_nid_t alc269_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005626 static const hda_nid_t alc269_ssids[] = { 0, 0x1b, 0x14, 0x21 };
5627 static const hda_nid_t alc269va_ssids[] = { 0x15, 0x1b, 0x14, 0 };
5628 struct alc_spec *spec = codec->spec;
5629 const hda_nid_t *ssids = spec->codec_variant == ALC269_TYPE_ALC269VA ?
5630 alc269va_ssids : alc269_ssids;
Takashi Iwai1d045db2011-07-07 18:23:21 +02005631
Takashi Iwai3e6179b2011-07-08 16:55:13 +02005632 return alc_parse_auto_config(codec, alc269_ignore, ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02005633}
5634
Takashi Iwai1d045db2011-07-07 18:23:21 +02005635static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
5636{
5637 int val = alc_read_coef_idx(codec, 0x04);
5638 if (power_up)
5639 val |= 1 << 11;
5640 else
5641 val &= ~(1 << 11);
5642 alc_write_coef_idx(codec, 0x04, val);
5643}
5644
5645static void alc269_shutup(struct hda_codec *codec)
5646{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005647 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005648 alc269_toggle_power_output(codec, 0);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005649 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005650 alc269_toggle_power_output(codec, 0);
5651 msleep(150);
5652 }
5653}
5654
Takashi Iwai2a439522011-07-26 09:52:50 +02005655#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02005656static int alc269_resume(struct hda_codec *codec)
5657{
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005658 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005659 alc269_toggle_power_output(codec, 0);
5660 msleep(150);
5661 }
5662
5663 codec->patch_ops.init(codec);
5664
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005665 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02005666 alc269_toggle_power_output(codec, 1);
5667 msleep(200);
5668 }
5669
Takashi Iwai1bb7e432011-10-17 16:50:59 +02005670 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
Takashi Iwai1d045db2011-07-07 18:23:21 +02005671 alc269_toggle_power_output(codec, 1);
5672
5673 snd_hda_codec_resume_amp(codec);
5674 snd_hda_codec_resume_cache(codec);
5675 hda_call_check_power_status(codec, 0x01);
5676 return 0;
5677}
Takashi Iwai2a439522011-07-26 09:52:50 +02005678#endif /* CONFIG_PM */
Takashi Iwai1d045db2011-07-07 18:23:21 +02005679
5680static void alc269_fixup_hweq(struct hda_codec *codec,
5681 const struct alc_fixup *fix, int action)
5682{
5683 int coef;
5684
5685 if (action != ALC_FIXUP_ACT_INIT)
5686 return;
5687 coef = alc_read_coef_idx(codec, 0x1e);
5688 alc_write_coef_idx(codec, 0x1e, coef | 0x80);
5689}
5690
5691static void alc271_fixup_dmic(struct hda_codec *codec,
5692 const struct alc_fixup *fix, int action)
5693{
5694 static const struct hda_verb verbs[] = {
5695 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
5696 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
5697 {}
5698 };
5699 unsigned int cfg;
5700
5701 if (strcmp(codec->chip_name, "ALC271X"))
5702 return;
5703 cfg = snd_hda_codec_get_pincfg(codec, 0x12);
5704 if (get_defcfg_connect(cfg) == AC_JACK_PORT_FIXED)
5705 snd_hda_sequence_write(codec, verbs);
5706}
5707
Takashi Iwai017f2a12011-07-09 14:42:25 +02005708static void alc269_fixup_pcm_44k(struct hda_codec *codec,
5709 const struct alc_fixup *fix, int action)
5710{
5711 struct alc_spec *spec = codec->spec;
5712
5713 if (action != ALC_FIXUP_ACT_PROBE)
5714 return;
5715
5716 /* Due to a hardware problem on Lenovo Ideadpad, we need to
5717 * fix the sample rate of analog I/O to 44.1kHz
5718 */
5719 spec->stream_analog_playback = &alc269_44k_pcm_analog_playback;
5720 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
5721}
5722
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005723static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
5724 const struct alc_fixup *fix, int action)
5725{
5726 int coef;
5727
5728 if (action != ALC_FIXUP_ACT_INIT)
5729 return;
5730 /* The digital-mic unit sends PDM (differential signal) instead of
5731 * the standard PCM, thus you can't record a valid mono stream as is.
5732 * Below is a workaround specific to ALC269 to control the dmic
5733 * signal source as mono.
5734 */
5735 coef = alc_read_coef_idx(codec, 0x07);
5736 alc_write_coef_idx(codec, 0x07, coef | 0x80);
5737}
5738
Takashi Iwai24519912011-08-16 15:08:49 +02005739static void alc269_quanta_automute(struct hda_codec *codec)
5740{
David Henningsson42cf0d02011-09-20 12:04:56 +02005741 update_outputs(codec);
Takashi Iwai24519912011-08-16 15:08:49 +02005742
5743 snd_hda_codec_write(codec, 0x20, 0,
5744 AC_VERB_SET_COEF_INDEX, 0x0c);
5745 snd_hda_codec_write(codec, 0x20, 0,
5746 AC_VERB_SET_PROC_COEF, 0x680);
5747
5748 snd_hda_codec_write(codec, 0x20, 0,
5749 AC_VERB_SET_COEF_INDEX, 0x0c);
5750 snd_hda_codec_write(codec, 0x20, 0,
5751 AC_VERB_SET_PROC_COEF, 0x480);
5752}
5753
5754static void alc269_fixup_quanta_mute(struct hda_codec *codec,
5755 const struct alc_fixup *fix, int action)
5756{
5757 struct alc_spec *spec = codec->spec;
5758 if (action != ALC_FIXUP_ACT_PROBE)
5759 return;
5760 spec->automute_hook = alc269_quanta_automute;
5761}
5762
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005763/* update mute-LED according to the speaker mute state via mic2 VREF pin */
5764static void alc269_fixup_mic2_mute_hook(void *private_data, int enabled)
5765{
5766 struct hda_codec *codec = private_data;
5767 unsigned int pinval = enabled ? 0x20 : 0x24;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02005768 snd_hda_set_pin_ctl_cache(codec, 0x19, pinval);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005769}
5770
5771static void alc269_fixup_mic2_mute(struct hda_codec *codec,
5772 const struct alc_fixup *fix, int action)
5773{
5774 struct alc_spec *spec = codec->spec;
5775 switch (action) {
5776 case ALC_FIXUP_ACT_BUILD:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005777 spec->vmaster_mute.hook = alc269_fixup_mic2_mute_hook;
Takashi Iwaif29735c2012-03-13 07:55:10 +01005778 snd_hda_add_vmaster_hook(codec, &spec->vmaster_mute, true);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005779 /* fallthru */
5780 case ALC_FIXUP_ACT_INIT:
Takashi Iwaid2f344b2012-03-12 16:59:58 +01005781 snd_hda_sync_vmaster_hook(&spec->vmaster_mute);
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005782 break;
5783 }
5784}
5785
Takashi Iwai1d045db2011-07-07 18:23:21 +02005786enum {
5787 ALC269_FIXUP_SONY_VAIO,
5788 ALC275_FIXUP_SONY_VAIO_GPIO2,
5789 ALC269_FIXUP_DELL_M101Z,
5790 ALC269_FIXUP_SKU_IGNORE,
5791 ALC269_FIXUP_ASUS_G73JW,
5792 ALC269_FIXUP_LENOVO_EAPD,
5793 ALC275_FIXUP_SONY_HWEQ,
5794 ALC271_FIXUP_DMIC,
Takashi Iwai017f2a12011-07-09 14:42:25 +02005795 ALC269_FIXUP_PCM_44K,
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005796 ALC269_FIXUP_STEREO_DMIC,
Takashi Iwai24519912011-08-16 15:08:49 +02005797 ALC269_FIXUP_QUANTA_MUTE,
5798 ALC269_FIXUP_LIFEBOOK,
Takashi Iwaia4297b52011-08-23 18:40:12 +02005799 ALC269_FIXUP_AMIC,
5800 ALC269_FIXUP_DMIC,
5801 ALC269VB_FIXUP_AMIC,
5802 ALC269VB_FIXUP_DMIC,
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005803 ALC269_FIXUP_MIC2_MUTE_LED,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005804};
5805
5806static const struct alc_fixup alc269_fixups[] = {
5807 [ALC269_FIXUP_SONY_VAIO] = {
5808 .type = ALC_FIXUP_VERBS,
5809 .v.verbs = (const struct hda_verb[]) {
5810 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREFGRD},
5811 {}
5812 }
5813 },
5814 [ALC275_FIXUP_SONY_VAIO_GPIO2] = {
5815 .type = ALC_FIXUP_VERBS,
5816 .v.verbs = (const struct hda_verb[]) {
5817 {0x01, AC_VERB_SET_GPIO_MASK, 0x04},
5818 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x04},
5819 {0x01, AC_VERB_SET_GPIO_DATA, 0x00},
5820 { }
5821 },
5822 .chained = true,
5823 .chain_id = ALC269_FIXUP_SONY_VAIO
5824 },
5825 [ALC269_FIXUP_DELL_M101Z] = {
5826 .type = ALC_FIXUP_VERBS,
5827 .v.verbs = (const struct hda_verb[]) {
5828 /* Enables internal speaker */
5829 {0x20, AC_VERB_SET_COEF_INDEX, 13},
5830 {0x20, AC_VERB_SET_PROC_COEF, 0x4040},
5831 {}
5832 }
5833 },
5834 [ALC269_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02005835 .type = ALC_FIXUP_FUNC,
5836 .v.func = alc_fixup_sku_ignore,
Takashi Iwai1d045db2011-07-07 18:23:21 +02005837 },
5838 [ALC269_FIXUP_ASUS_G73JW] = {
5839 .type = ALC_FIXUP_PINS,
5840 .v.pins = (const struct alc_pincfg[]) {
5841 { 0x17, 0x99130111 }, /* subwoofer */
5842 { }
5843 }
5844 },
5845 [ALC269_FIXUP_LENOVO_EAPD] = {
5846 .type = ALC_FIXUP_VERBS,
5847 .v.verbs = (const struct hda_verb[]) {
5848 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
5849 {}
5850 }
5851 },
5852 [ALC275_FIXUP_SONY_HWEQ] = {
5853 .type = ALC_FIXUP_FUNC,
5854 .v.func = alc269_fixup_hweq,
5855 .chained = true,
5856 .chain_id = ALC275_FIXUP_SONY_VAIO_GPIO2
5857 },
5858 [ALC271_FIXUP_DMIC] = {
5859 .type = ALC_FIXUP_FUNC,
5860 .v.func = alc271_fixup_dmic,
5861 },
Takashi Iwai017f2a12011-07-09 14:42:25 +02005862 [ALC269_FIXUP_PCM_44K] = {
5863 .type = ALC_FIXUP_FUNC,
5864 .v.func = alc269_fixup_pcm_44k,
5865 },
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005866 [ALC269_FIXUP_STEREO_DMIC] = {
5867 .type = ALC_FIXUP_FUNC,
5868 .v.func = alc269_fixup_stereo_dmic,
5869 },
Takashi Iwai24519912011-08-16 15:08:49 +02005870 [ALC269_FIXUP_QUANTA_MUTE] = {
5871 .type = ALC_FIXUP_FUNC,
5872 .v.func = alc269_fixup_quanta_mute,
5873 },
5874 [ALC269_FIXUP_LIFEBOOK] = {
5875 .type = ALC_FIXUP_PINS,
5876 .v.pins = (const struct alc_pincfg[]) {
5877 { 0x1a, 0x2101103f }, /* dock line-out */
5878 { 0x1b, 0x23a11040 }, /* dock mic-in */
5879 { }
5880 },
5881 .chained = true,
5882 .chain_id = ALC269_FIXUP_QUANTA_MUTE
5883 },
Takashi Iwaia4297b52011-08-23 18:40:12 +02005884 [ALC269_FIXUP_AMIC] = {
5885 .type = ALC_FIXUP_PINS,
5886 .v.pins = (const struct alc_pincfg[]) {
5887 { 0x14, 0x99130110 }, /* speaker */
5888 { 0x15, 0x0121401f }, /* HP out */
5889 { 0x18, 0x01a19c20 }, /* mic */
5890 { 0x19, 0x99a3092f }, /* int-mic */
5891 { }
5892 },
5893 },
5894 [ALC269_FIXUP_DMIC] = {
5895 .type = ALC_FIXUP_PINS,
5896 .v.pins = (const struct alc_pincfg[]) {
5897 { 0x12, 0x99a3092f }, /* int-mic */
5898 { 0x14, 0x99130110 }, /* speaker */
5899 { 0x15, 0x0121401f }, /* HP out */
5900 { 0x18, 0x01a19c20 }, /* mic */
5901 { }
5902 },
5903 },
5904 [ALC269VB_FIXUP_AMIC] = {
5905 .type = ALC_FIXUP_PINS,
5906 .v.pins = (const struct alc_pincfg[]) {
5907 { 0x14, 0x99130110 }, /* speaker */
5908 { 0x18, 0x01a19c20 }, /* mic */
5909 { 0x19, 0x99a3092f }, /* int-mic */
5910 { 0x21, 0x0121401f }, /* HP out */
5911 { }
5912 },
5913 },
David Henningsson2267ea92012-01-03 08:45:56 +01005914 [ALC269VB_FIXUP_DMIC] = {
Takashi Iwaia4297b52011-08-23 18:40:12 +02005915 .type = ALC_FIXUP_PINS,
5916 .v.pins = (const struct alc_pincfg[]) {
5917 { 0x12, 0x99a3092f }, /* int-mic */
5918 { 0x14, 0x99130110 }, /* speaker */
5919 { 0x18, 0x01a19c20 }, /* mic */
5920 { 0x21, 0x0121401f }, /* HP out */
5921 { }
5922 },
5923 },
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005924 [ALC269_FIXUP_MIC2_MUTE_LED] = {
5925 .type = ALC_FIXUP_FUNC,
5926 .v.func = alc269_fixup_mic2_mute,
5927 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02005928};
5929
5930static const struct snd_pci_quirk alc269_fixup_tbl[] = {
Takashi Iwai420b0fe2012-03-12 12:35:27 +01005931 SND_PCI_QUIRK(0x103c, 0x1586, "HP", ALC269_FIXUP_MIC2_MUTE_LED),
David Henningsson5ac57552012-04-20 10:01:46 +02005932 SND_PCI_QUIRK(0x1043, 0x1427, "Asus Zenbook UX31E", ALC269VB_FIXUP_DMIC),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005933 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
Takashi Iwaiadabb3e2011-08-03 07:48:37 +02005934 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
5935 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
5936 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
5937 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
5938 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005939 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
5940 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5941 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
5942 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
5943 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
5944 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
Takashi Iwai24519912011-08-16 15:08:49 +02005945 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005946 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
5947 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
5948 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
5949 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
5950 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
Takashi Iwai24519912011-08-16 15:08:49 +02005951 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
Takashi Iwai017f2a12011-07-09 14:42:25 +02005952 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
Takashi Iwai1d045db2011-07-07 18:23:21 +02005953 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005954
Takashi Iwaia7f3eed2012-02-16 13:03:18 +01005955#if 0
Takashi Iwaia4297b52011-08-23 18:40:12 +02005956 /* Below is a quirk table taken from the old code.
5957 * Basically the device should work as is without the fixup table.
5958 * If BIOS doesn't give a proper info, enable the corresponding
5959 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02005960 */
Takashi Iwaia4297b52011-08-23 18:40:12 +02005961 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
5962 ALC269_FIXUP_AMIC),
5963 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
Takashi Iwaia4297b52011-08-23 18:40:12 +02005964 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
5965 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
5966 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
5967 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
5968 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
5969 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
5970 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
5971 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
5972 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
5973 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
5974 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
5975 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
5976 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
5977 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
5978 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
5979 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
5980 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
5981 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
5982 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
5983 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
5984 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
5985 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
5986 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
5987 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
5988 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
5989 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
5990 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
5991 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
5992 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
5993 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
5994 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
5995 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
5996 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
5997 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
5998 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
5999 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
6000 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
6001 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
6002#endif
6003 {}
6004};
6005
6006static const struct alc_model_fixup alc269_fixup_models[] = {
6007 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
6008 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
Takashi Iwai1d045db2011-07-07 18:23:21 +02006009 {}
6010};
6011
6012
Takashi Iwai546bb672012-03-07 08:37:19 +01006013static void alc269_fill_coef(struct hda_codec *codec)
Takashi Iwai1d045db2011-07-07 18:23:21 +02006014{
Kailang Yang526af6e2012-03-07 08:25:20 +01006015 struct alc_spec *spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006016 int val;
6017
Kailang Yang526af6e2012-03-07 08:25:20 +01006018 if (spec->codec_variant != ALC269_TYPE_ALC269VB)
Takashi Iwai546bb672012-03-07 08:37:19 +01006019 return;
Kailang Yang526af6e2012-03-07 08:25:20 +01006020
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006021 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006022 alc_write_coef_idx(codec, 0xf, 0x960b);
6023 alc_write_coef_idx(codec, 0xe, 0x8817);
6024 }
6025
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006026 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006027 alc_write_coef_idx(codec, 0xf, 0x960b);
6028 alc_write_coef_idx(codec, 0xe, 0x8814);
6029 }
6030
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006031 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006032 val = alc_read_coef_idx(codec, 0x04);
6033 /* Power up output pin */
6034 alc_write_coef_idx(codec, 0x04, val | (1<<11));
6035 }
6036
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006037 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006038 val = alc_read_coef_idx(codec, 0xd);
6039 if ((val & 0x0c00) >> 10 != 0x1) {
6040 /* Capless ramp up clock control */
6041 alc_write_coef_idx(codec, 0xd, val | (1<<10));
6042 }
6043 val = alc_read_coef_idx(codec, 0x17);
6044 if ((val & 0x01c0) >> 6 != 0x4) {
6045 /* Class D power on reset */
6046 alc_write_coef_idx(codec, 0x17, val | (1<<7));
6047 }
6048 }
6049
6050 val = alc_read_coef_idx(codec, 0xd); /* Class D */
6051 alc_write_coef_idx(codec, 0xd, val | (1<<14));
6052
6053 val = alc_read_coef_idx(codec, 0x4); /* HP */
6054 alc_write_coef_idx(codec, 0x4, val | (1<<11));
Takashi Iwai1d045db2011-07-07 18:23:21 +02006055}
6056
6057/*
6058 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006059static int patch_alc269(struct hda_codec *codec)
6060{
6061 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006062 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006063
Takashi Iwai3de95172012-05-07 18:03:15 +02006064 err = alc_alloc_spec(codec, 0x0b);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006065 if (err < 0)
Takashi Iwai3de95172012-05-07 18:03:15 +02006066 return err;
6067
6068 spec = codec->spec;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006069
Takashi Iwai1d045db2011-07-07 18:23:21 +02006070 if (codec->vendor_id == 0x10ec0269) {
6071 spec->codec_variant = ALC269_TYPE_ALC269VA;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006072 switch (alc_get_coef0(codec) & 0x00f0) {
6073 case 0x0010:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006074 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006075 spec->cdefine.platform_type == 1)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006076 err = alc_codec_rename(codec, "ALC271X");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006077 spec->codec_variant = ALC269_TYPE_ALC269VB;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006078 break;
6079 case 0x0020:
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006080 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
6081 codec->bus->pci->subsystem_device == 0x21f3)
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006082 err = alc_codec_rename(codec, "ALC3202");
Takashi Iwai1d045db2011-07-07 18:23:21 +02006083 spec->codec_variant = ALC269_TYPE_ALC269VC;
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006084 break;
6085 default:
Takashi Iwai1d045db2011-07-07 18:23:21 +02006086 alc_fix_pll_init(codec, 0x20, 0x04, 15);
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006087 }
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006088 if (err < 0)
6089 goto error;
Takashi Iwai546bb672012-03-07 08:37:19 +01006090 spec->init_hook = alc269_fill_coef;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006091 alc269_fill_coef(codec);
6092 }
6093
Takashi Iwaia4297b52011-08-23 18:40:12 +02006094 alc_pick_fixup(codec, alc269_fixup_models,
6095 alc269_fixup_tbl, alc269_fixups);
6096 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006097
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006098 alc_auto_parse_customize_define(codec);
6099
Takashi Iwaia4297b52011-08-23 18:40:12 +02006100 /* automatic parse from the BIOS config */
6101 err = alc269_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006102 if (err < 0)
6103 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006104
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006105 if (!spec->no_analog && has_cdefine_beep(codec)) {
6106 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006107 if (err < 0)
6108 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006109 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006110 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006111
Takashi Iwai1d045db2011-07-07 18:23:21 +02006112 codec->patch_ops = alc_patch_ops;
Takashi Iwai2a439522011-07-26 09:52:50 +02006113#ifdef CONFIG_PM
Takashi Iwai1d045db2011-07-07 18:23:21 +02006114 codec->patch_ops.resume = alc269_resume;
6115#endif
Takashi Iwai1d045db2011-07-07 18:23:21 +02006116 spec->shutup = alc269_shutup;
6117
Takashi Iwai589876e2012-02-20 15:47:55 +01006118 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6119
Takashi Iwai1d045db2011-07-07 18:23:21 +02006120 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006121
6122 error:
6123 alc_free(codec);
6124 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006125}
6126
6127/*
6128 * ALC861
6129 */
6130
Takashi Iwai1d045db2011-07-07 18:23:21 +02006131static int alc861_parse_auto_config(struct hda_codec *codec)
6132{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006133 static const hda_nid_t alc861_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006134 static const hda_nid_t alc861_ssids[] = { 0x0e, 0x0f, 0x0b, 0 };
6135 return alc_parse_auto_config(codec, alc861_ignore, alc861_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006136}
6137
Takashi Iwai1d045db2011-07-07 18:23:21 +02006138/* Pin config fixes */
6139enum {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006140 ALC861_FIXUP_FSC_AMILO_PI1505,
6141 ALC861_FIXUP_AMP_VREF_0F,
6142 ALC861_FIXUP_NO_JACK_DETECT,
6143 ALC861_FIXUP_ASUS_A6RP,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006144};
6145
Takashi Iwai31150f22012-01-30 10:54:08 +01006146/* On some laptops, VREF of pin 0x0f is abused for controlling the main amp */
6147static void alc861_fixup_asus_amp_vref_0f(struct hda_codec *codec,
6148 const struct alc_fixup *fix, int action)
6149{
6150 struct alc_spec *spec = codec->spec;
6151 unsigned int val;
6152
6153 if (action != ALC_FIXUP_ACT_INIT)
6154 return;
6155 val = snd_hda_codec_read(codec, 0x0f, 0,
6156 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
6157 if (!(val & (AC_PINCTL_IN_EN | AC_PINCTL_OUT_EN)))
6158 val |= AC_PINCTL_IN_EN;
6159 val |= AC_PINCTL_VREF_50;
Takashi Iwaicdd03ce2012-04-20 12:34:50 +02006160 snd_hda_set_pin_ctl(codec, 0x0f, val);
Takashi Iwai31150f22012-01-30 10:54:08 +01006161 spec->keep_vref_in_automute = 1;
6162}
6163
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006164/* suppress the jack-detection */
6165static void alc_fixup_no_jack_detect(struct hda_codec *codec,
6166 const struct alc_fixup *fix, int action)
6167{
6168 if (action == ALC_FIXUP_ACT_PRE_PROBE)
6169 codec->no_jack_detect = 1;
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006170}
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006171
Takashi Iwai1d045db2011-07-07 18:23:21 +02006172static const struct alc_fixup alc861_fixups[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006173 [ALC861_FIXUP_FSC_AMILO_PI1505] = {
Takashi Iwai1d045db2011-07-07 18:23:21 +02006174 .type = ALC_FIXUP_PINS,
6175 .v.pins = (const struct alc_pincfg[]) {
6176 { 0x0b, 0x0221101f }, /* HP */
6177 { 0x0f, 0x90170310 }, /* speaker */
6178 { }
6179 }
6180 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006181 [ALC861_FIXUP_AMP_VREF_0F] = {
Takashi Iwai31150f22012-01-30 10:54:08 +01006182 .type = ALC_FIXUP_FUNC,
6183 .v.func = alc861_fixup_asus_amp_vref_0f,
Takashi Iwai3b25eb62012-01-25 09:55:46 +01006184 },
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006185 [ALC861_FIXUP_NO_JACK_DETECT] = {
6186 .type = ALC_FIXUP_FUNC,
6187 .v.func = alc_fixup_no_jack_detect,
6188 },
6189 [ALC861_FIXUP_ASUS_A6RP] = {
6190 .type = ALC_FIXUP_FUNC,
6191 .v.func = alc861_fixup_asus_amp_vref_0f,
6192 .chained = true,
6193 .chain_id = ALC861_FIXUP_NO_JACK_DETECT,
6194 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006195};
6196
6197static const struct snd_pci_quirk alc861_fixup_tbl[] = {
Takashi Iwaie652f4c2012-02-13 11:56:25 +01006198 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS A6Rp", ALC861_FIXUP_ASUS_A6RP),
6199 SND_PCI_QUIRK_VENDOR(0x1043, "ASUS laptop", ALC861_FIXUP_AMP_VREF_0F),
6200 SND_PCI_QUIRK(0x1462, 0x7254, "HP DX2200", ALC861_FIXUP_NO_JACK_DETECT),
6201 SND_PCI_QUIRK(0x1584, 0x2b01, "Haier W18", ALC861_FIXUP_AMP_VREF_0F),
6202 SND_PCI_QUIRK(0x1584, 0x0000, "Uniwill ECS M31EI", ALC861_FIXUP_AMP_VREF_0F),
6203 SND_PCI_QUIRK(0x1734, 0x10c7, "FSC Amilo Pi1505", ALC861_FIXUP_FSC_AMILO_PI1505),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006204 {}
6205};
6206
6207/*
6208 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006209static int patch_alc861(struct hda_codec *codec)
6210{
6211 struct alc_spec *spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006212 int err;
6213
Takashi Iwai3de95172012-05-07 18:03:15 +02006214 err = alc_alloc_spec(codec, 0x15);
6215 if (err < 0)
6216 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006217
Takashi Iwai3de95172012-05-07 18:03:15 +02006218 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006219
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006220 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
6221 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006222
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006223 /* automatic parse from the BIOS config */
6224 err = alc861_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006225 if (err < 0)
6226 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006227
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006228 if (!spec->no_analog) {
6229 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006230 if (err < 0)
6231 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006232 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
6233 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006234
Takashi Iwai1d045db2011-07-07 18:23:21 +02006235 codec->patch_ops = alc_patch_ops;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006236#ifdef CONFIG_SND_HDA_POWER_SAVE
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006237 spec->power_hook = alc_power_eapd;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006238#endif
6239
Takashi Iwai589876e2012-02-20 15:47:55 +01006240 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6241
Takashi Iwai1d045db2011-07-07 18:23:21 +02006242 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006243
6244 error:
6245 alc_free(codec);
6246 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006247}
6248
6249/*
6250 * ALC861-VD support
6251 *
6252 * Based on ALC882
6253 *
6254 * In addition, an independent DAC
6255 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006256static int alc861vd_parse_auto_config(struct hda_codec *codec)
6257{
Takashi Iwai1d045db2011-07-07 18:23:21 +02006258 static const hda_nid_t alc861vd_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006259 static const hda_nid_t alc861vd_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6260 return alc_parse_auto_config(codec, alc861vd_ignore, alc861vd_ssids);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006261}
6262
Takashi Iwai1d045db2011-07-07 18:23:21 +02006263enum {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006264 ALC660VD_FIX_ASUS_GPIO1,
6265 ALC861VD_FIX_DALLAS,
Takashi Iwai1d045db2011-07-07 18:23:21 +02006266};
6267
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006268/* exclude VREF80 */
6269static void alc861vd_fixup_dallas(struct hda_codec *codec,
6270 const struct alc_fixup *fix, int action)
6271{
6272 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
6273 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
6274 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
6275 }
6276}
6277
Takashi Iwai1d045db2011-07-07 18:23:21 +02006278static const struct alc_fixup alc861vd_fixups[] = {
6279 [ALC660VD_FIX_ASUS_GPIO1] = {
6280 .type = ALC_FIXUP_VERBS,
6281 .v.verbs = (const struct hda_verb[]) {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006282 /* reset GPIO1 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006283 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
6284 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
6285 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
6286 { }
6287 }
6288 },
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006289 [ALC861VD_FIX_DALLAS] = {
6290 .type = ALC_FIXUP_FUNC,
6291 .v.func = alc861vd_fixup_dallas,
6292 },
Takashi Iwai1d045db2011-07-07 18:23:21 +02006293};
6294
6295static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006296 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006297 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
Takashi Iwai8fdcb6f2011-08-23 17:28:55 +02006298 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
Takashi Iwai1d045db2011-07-07 18:23:21 +02006299 {}
6300};
6301
6302static const struct hda_verb alc660vd_eapd_verbs[] = {
6303 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
6304 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
6305 { }
6306};
6307
6308/*
6309 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006310static int patch_alc861vd(struct hda_codec *codec)
6311{
6312 struct alc_spec *spec;
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006313 int err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006314
Takashi Iwai3de95172012-05-07 18:03:15 +02006315 err = alc_alloc_spec(codec, 0x0b);
6316 if (err < 0)
6317 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006318
Takashi Iwai3de95172012-05-07 18:03:15 +02006319 spec = codec->spec;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006320
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006321 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
6322 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006323
Takashi Iwaicb4e4822011-08-23 17:34:25 +02006324 /* automatic parse from the BIOS config */
6325 err = alc861vd_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006326 if (err < 0)
6327 goto error;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006328
Takashi Iwai1d045db2011-07-07 18:23:21 +02006329 if (codec->vendor_id == 0x10ec0660) {
6330 /* always turn on EAPD */
Takashi Iwai23d30f22012-05-07 17:17:32 +02006331 snd_hda_gen_add_verbs(&spec->gen, alc660vd_eapd_verbs);
Takashi Iwai1d045db2011-07-07 18:23:21 +02006332 }
6333
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006334 if (!spec->no_analog) {
6335 err = snd_hda_attach_beep_device(codec, 0x23);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006336 if (err < 0)
6337 goto error;
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006338 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6339 }
Takashi Iwai1d045db2011-07-07 18:23:21 +02006340
Takashi Iwai1d045db2011-07-07 18:23:21 +02006341 codec->patch_ops = alc_patch_ops;
6342
Takashi Iwai1d045db2011-07-07 18:23:21 +02006343 spec->shutup = alc_eapd_shutup;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006344
Takashi Iwai589876e2012-02-20 15:47:55 +01006345 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6346
Takashi Iwai1d045db2011-07-07 18:23:21 +02006347 return 0;
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006348
6349 error:
6350 alc_free(codec);
6351 return err;
Takashi Iwai1d045db2011-07-07 18:23:21 +02006352}
6353
6354/*
6355 * ALC662 support
6356 *
6357 * ALC662 is almost identical with ALC880 but has cleaner and more flexible
6358 * configuration. Each pin widget can choose any input DACs and a mixer.
6359 * Each ADC is connected from a mixer of all inputs. This makes possible
6360 * 6-channel independent captures.
6361 *
6362 * In addition, an independent DAC for the multi-playback (not used in this
6363 * driver yet).
6364 */
Takashi Iwai1d045db2011-07-07 18:23:21 +02006365
6366/*
6367 * BIOS auto configuration
6368 */
6369
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006370static int alc662_parse_auto_config(struct hda_codec *codec)
6371{
Takashi Iwai4c6d72d2011-05-02 11:30:18 +02006372 static const hda_nid_t alc662_ignore[] = { 0x1d, 0 };
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006373 static const hda_nid_t alc663_ssids[] = { 0x15, 0x1b, 0x14, 0x21 };
6374 static const hda_nid_t alc662_ssids[] = { 0x15, 0x1b, 0x14, 0 };
6375 const hda_nid_t *ssids;
Takashi Iwaiee979a142008-09-02 15:42:20 +02006376
Kailang Yang6227cdc2010-02-25 08:36:52 +01006377 if (codec->vendor_id == 0x10ec0272 || codec->vendor_id == 0x10ec0663 ||
6378 codec->vendor_id == 0x10ec0665 || codec->vendor_id == 0x10ec0670)
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006379 ssids = alc663_ssids;
Kailang Yang6227cdc2010-02-25 08:36:52 +01006380 else
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006381 ssids = alc662_ssids;
6382 return alc_parse_auto_config(codec, alc662_ignore, ssids);
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006383}
6384
Todd Broch6be79482010-12-07 16:51:05 -08006385static void alc272_fixup_mario(struct hda_codec *codec,
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006386 const struct alc_fixup *fix, int action)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006387{
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006388 if (action != ALC_FIXUP_ACT_PROBE)
Takashi Iwai6fc398c2011-01-13 14:36:37 +01006389 return;
Todd Broch6be79482010-12-07 16:51:05 -08006390 if (snd_hda_override_amp_caps(codec, 0x2, HDA_OUTPUT,
6391 (0x3b << AC_AMPCAP_OFFSET_SHIFT) |
6392 (0x3b << AC_AMPCAP_NUM_STEPS_SHIFT) |
6393 (0x03 << AC_AMPCAP_STEP_SIZE_SHIFT) |
6394 (0 << AC_AMPCAP_MUTE_SHIFT)))
6395 printk(KERN_WARNING
6396 "hda_codec: failed to override amp caps for NID 0x2\n");
6397}
6398
David Henningsson6cb3b702010-09-09 08:51:44 +02006399enum {
Daniel T Chen2df03512010-10-10 22:39:28 -04006400 ALC662_FIXUP_ASPIRE,
David Henningsson6cb3b702010-09-09 08:51:44 +02006401 ALC662_FIXUP_IDEAPAD,
Todd Broch6be79482010-12-07 16:51:05 -08006402 ALC272_FIXUP_MARIO,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006403 ALC662_FIXUP_CZC_P10T,
David Henningsson94024cd2011-04-29 14:10:55 +02006404 ALC662_FIXUP_SKU_IGNORE,
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006405 ALC662_FIXUP_HP_RP5800,
Takashi Iwai53c334a2011-08-23 18:27:14 +02006406 ALC662_FIXUP_ASUS_MODE1,
6407 ALC662_FIXUP_ASUS_MODE2,
6408 ALC662_FIXUP_ASUS_MODE3,
6409 ALC662_FIXUP_ASUS_MODE4,
6410 ALC662_FIXUP_ASUS_MODE5,
6411 ALC662_FIXUP_ASUS_MODE6,
6412 ALC662_FIXUP_ASUS_MODE7,
6413 ALC662_FIXUP_ASUS_MODE8,
Takashi Iwai1565cc32012-02-13 12:03:25 +01006414 ALC662_FIXUP_NO_JACK_DETECT,
David Henningsson6cb3b702010-09-09 08:51:44 +02006415};
6416
6417static const struct alc_fixup alc662_fixups[] = {
Daniel T Chen2df03512010-10-10 22:39:28 -04006418 [ALC662_FIXUP_ASPIRE] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006419 .type = ALC_FIXUP_PINS,
6420 .v.pins = (const struct alc_pincfg[]) {
Daniel T Chen2df03512010-10-10 22:39:28 -04006421 { 0x15, 0x99130112 }, /* subwoofer */
6422 { }
6423 }
6424 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006425 [ALC662_FIXUP_IDEAPAD] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006426 .type = ALC_FIXUP_PINS,
6427 .v.pins = (const struct alc_pincfg[]) {
David Henningsson6cb3b702010-09-09 08:51:44 +02006428 { 0x17, 0x99130112 }, /* subwoofer */
6429 { }
6430 }
6431 },
Todd Broch6be79482010-12-07 16:51:05 -08006432 [ALC272_FIXUP_MARIO] = {
Takashi Iwaib5bfbc62011-01-13 14:22:32 +01006433 .type = ALC_FIXUP_FUNC,
6434 .v.func = alc272_fixup_mario,
Anisse Astierd2ebd472011-01-20 12:36:21 +01006435 },
6436 [ALC662_FIXUP_CZC_P10T] = {
6437 .type = ALC_FIXUP_VERBS,
6438 .v.verbs = (const struct hda_verb[]) {
6439 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 0},
6440 {}
6441 }
6442 },
David Henningsson94024cd2011-04-29 14:10:55 +02006443 [ALC662_FIXUP_SKU_IGNORE] = {
Takashi Iwai23d30f22012-05-07 17:17:32 +02006444 .type = ALC_FIXUP_FUNC,
6445 .v.func = alc_fixup_sku_ignore,
Takashi Iwaic6b35872011-03-28 12:05:31 +02006446 },
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006447 [ALC662_FIXUP_HP_RP5800] = {
6448 .type = ALC_FIXUP_PINS,
6449 .v.pins = (const struct alc_pincfg[]) {
6450 { 0x14, 0x0221201f }, /* HP out */
6451 { }
6452 },
6453 .chained = true,
6454 .chain_id = ALC662_FIXUP_SKU_IGNORE
6455 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006456 [ALC662_FIXUP_ASUS_MODE1] = {
6457 .type = ALC_FIXUP_PINS,
6458 .v.pins = (const struct alc_pincfg[]) {
6459 { 0x14, 0x99130110 }, /* speaker */
6460 { 0x18, 0x01a19c20 }, /* mic */
6461 { 0x19, 0x99a3092f }, /* int-mic */
6462 { 0x21, 0x0121401f }, /* HP out */
6463 { }
6464 },
6465 .chained = true,
6466 .chain_id = ALC662_FIXUP_SKU_IGNORE
6467 },
6468 [ALC662_FIXUP_ASUS_MODE2] = {
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006469 .type = ALC_FIXUP_PINS,
6470 .v.pins = (const struct alc_pincfg[]) {
6471 { 0x14, 0x99130110 }, /* speaker */
6472 { 0x18, 0x01a19820 }, /* mic */
6473 { 0x19, 0x99a3092f }, /* int-mic */
6474 { 0x1b, 0x0121401f }, /* HP out */
6475 { }
6476 },
Takashi Iwai53c334a2011-08-23 18:27:14 +02006477 .chained = true,
6478 .chain_id = ALC662_FIXUP_SKU_IGNORE
6479 },
6480 [ALC662_FIXUP_ASUS_MODE3] = {
6481 .type = ALC_FIXUP_PINS,
6482 .v.pins = (const struct alc_pincfg[]) {
6483 { 0x14, 0x99130110 }, /* speaker */
6484 { 0x15, 0x0121441f }, /* HP */
6485 { 0x18, 0x01a19840 }, /* mic */
6486 { 0x19, 0x99a3094f }, /* int-mic */
6487 { 0x21, 0x01211420 }, /* HP2 */
6488 { }
6489 },
6490 .chained = true,
6491 .chain_id = ALC662_FIXUP_SKU_IGNORE
6492 },
6493 [ALC662_FIXUP_ASUS_MODE4] = {
6494 .type = ALC_FIXUP_PINS,
6495 .v.pins = (const struct alc_pincfg[]) {
6496 { 0x14, 0x99130110 }, /* speaker */
6497 { 0x16, 0x99130111 }, /* speaker */
6498 { 0x18, 0x01a19840 }, /* mic */
6499 { 0x19, 0x99a3094f }, /* int-mic */
6500 { 0x21, 0x0121441f }, /* HP */
6501 { }
6502 },
6503 .chained = true,
6504 .chain_id = ALC662_FIXUP_SKU_IGNORE
6505 },
6506 [ALC662_FIXUP_ASUS_MODE5] = {
6507 .type = ALC_FIXUP_PINS,
6508 .v.pins = (const struct alc_pincfg[]) {
6509 { 0x14, 0x99130110 }, /* speaker */
6510 { 0x15, 0x0121441f }, /* HP */
6511 { 0x16, 0x99130111 }, /* speaker */
6512 { 0x18, 0x01a19840 }, /* mic */
6513 { 0x19, 0x99a3094f }, /* int-mic */
6514 { }
6515 },
6516 .chained = true,
6517 .chain_id = ALC662_FIXUP_SKU_IGNORE
6518 },
6519 [ALC662_FIXUP_ASUS_MODE6] = {
6520 .type = ALC_FIXUP_PINS,
6521 .v.pins = (const struct alc_pincfg[]) {
6522 { 0x14, 0x99130110 }, /* speaker */
6523 { 0x15, 0x01211420 }, /* HP2 */
6524 { 0x18, 0x01a19840 }, /* mic */
6525 { 0x19, 0x99a3094f }, /* int-mic */
6526 { 0x1b, 0x0121441f }, /* HP */
6527 { }
6528 },
6529 .chained = true,
6530 .chain_id = ALC662_FIXUP_SKU_IGNORE
6531 },
6532 [ALC662_FIXUP_ASUS_MODE7] = {
6533 .type = ALC_FIXUP_PINS,
6534 .v.pins = (const struct alc_pincfg[]) {
6535 { 0x14, 0x99130110 }, /* speaker */
6536 { 0x17, 0x99130111 }, /* speaker */
6537 { 0x18, 0x01a19840 }, /* mic */
6538 { 0x19, 0x99a3094f }, /* int-mic */
6539 { 0x1b, 0x01214020 }, /* HP */
6540 { 0x21, 0x0121401f }, /* HP */
6541 { }
6542 },
6543 .chained = true,
6544 .chain_id = ALC662_FIXUP_SKU_IGNORE
6545 },
6546 [ALC662_FIXUP_ASUS_MODE8] = {
6547 .type = ALC_FIXUP_PINS,
6548 .v.pins = (const struct alc_pincfg[]) {
6549 { 0x14, 0x99130110 }, /* speaker */
6550 { 0x12, 0x99a30970 }, /* int-mic */
6551 { 0x15, 0x01214020 }, /* HP */
6552 { 0x17, 0x99130111 }, /* speaker */
6553 { 0x18, 0x01a19840 }, /* mic */
6554 { 0x21, 0x0121401f }, /* HP */
6555 { }
6556 },
6557 .chained = true,
6558 .chain_id = ALC662_FIXUP_SKU_IGNORE
Takashi Iwai2996bdb2011-08-18 16:02:24 +02006559 },
Takashi Iwai1565cc32012-02-13 12:03:25 +01006560 [ALC662_FIXUP_NO_JACK_DETECT] = {
6561 .type = ALC_FIXUP_FUNC,
6562 .v.func = alc_fixup_no_jack_detect,
6563 },
David Henningsson6cb3b702010-09-09 08:51:44 +02006564};
6565
Takashi Iwaia9111322011-05-02 11:30:18 +02006566static const struct snd_pci_quirk alc662_fixup_tbl[] = {
Takashi Iwai53c334a2011-08-23 18:27:14 +02006567 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
David Henningssona6c47a82011-02-10 15:39:19 +01006568 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
David Henningsson94024cd2011-04-29 14:10:55 +02006569 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
Daniel T Chen2df03512010-10-10 22:39:28 -04006570 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
Takashi Iwaie59ea3e2011-06-29 17:21:00 +02006571 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
Takashi Iwai1565cc32012-02-13 12:03:25 +01006572 SND_PCI_QUIRK(0x1043, 0x8469, "ASUS mobo", ALC662_FIXUP_NO_JACK_DETECT),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006573 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
Daniel T Chena0e90ac2010-11-20 10:20:35 -05006574 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
Valentine Sinitsynd4118582010-10-01 22:24:08 +06006575 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
David Henningsson6cb3b702010-09-09 08:51:44 +02006576 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
Anisse Astierd2ebd472011-01-20 12:36:21 +01006577 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
Takashi Iwai53c334a2011-08-23 18:27:14 +02006578
6579#if 0
6580 /* Below is a quirk table taken from the old code.
6581 * Basically the device should work as is without the fixup table.
6582 * If BIOS doesn't give a proper info, enable the corresponding
6583 * fixup entry.
Jesper Juhl7d7eb9e2012-04-12 22:11:25 +02006584 */
Takashi Iwai53c334a2011-08-23 18:27:14 +02006585 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
6586 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
6587 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
6588 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
6589 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6590 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6591 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6592 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
6593 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
6594 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6595 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
6596 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
6597 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
6598 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
6599 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
6600 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6601 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
6602 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
6603 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6604 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6605 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6606 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6607 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
6608 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
6609 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
6610 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6611 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
6612 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
6613 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6614 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
6615 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6616 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6617 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
6618 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
6619 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
6620 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
6621 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
6622 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
6623 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
6624 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
6625 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
6626 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
6627 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6628 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
6629 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
6630 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
6631 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
6632 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
6633 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
6634 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
6635#endif
David Henningsson6cb3b702010-09-09 08:51:44 +02006636 {}
6637};
6638
Todd Broch6be79482010-12-07 16:51:05 -08006639static const struct alc_model_fixup alc662_fixup_models[] = {
6640 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
Takashi Iwai53c334a2011-08-23 18:27:14 +02006641 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
6642 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
6643 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
6644 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
6645 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
6646 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
6647 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
6648 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
Todd Broch6be79482010-12-07 16:51:05 -08006649 {}
6650};
David Henningsson6cb3b702010-09-09 08:51:44 +02006651
6652
Takashi Iwai1d045db2011-07-07 18:23:21 +02006653/*
6654 */
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006655static int patch_alc662(struct hda_codec *codec)
6656{
6657 struct alc_spec *spec;
Takashi Iwai3de95172012-05-07 18:03:15 +02006658 int err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006659
Takashi Iwai3de95172012-05-07 18:03:15 +02006660 err = alc_alloc_spec(codec, 0x0b);
6661 if (err < 0)
6662 return err;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006663
Takashi Iwai3de95172012-05-07 18:03:15 +02006664 spec = codec->spec;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006665
Takashi Iwai53c334a2011-08-23 18:27:14 +02006666 /* handle multiple HPs as is */
6667 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
6668
Takashi Iwai2c3bf9a2008-06-04 12:39:38 +02006669 alc_fix_pll_init(codec, 0x20, 0x04, 15);
6670
Takashi Iwai1bb7e432011-10-17 16:50:59 +02006671 if ((alc_get_coef0(codec) & (1 << 14)) &&
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006672 codec->bus->pci->subsystem_vendor == 0x1025 &&
6673 spec->cdefine.platform_type == 1) {
6674 if (alc_codec_rename(codec, "ALC272X") < 0)
6675 goto error;
Takashi Iwai20ca0c32011-10-17 16:00:35 +02006676 }
Kailang Yang274693f2009-12-03 10:07:50 +01006677
Takashi Iwaib9c51062011-08-24 18:08:07 +02006678 alc_pick_fixup(codec, alc662_fixup_models,
6679 alc662_fixup_tbl, alc662_fixups);
6680 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
Takashi Iwaiaf741c12012-05-07 18:09:48 +02006681
6682 alc_auto_parse_customize_define(codec);
6683
Takashi Iwaib9c51062011-08-24 18:08:07 +02006684 /* automatic parse from the BIOS config */
6685 err = alc662_parse_auto_config(codec);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006686 if (err < 0)
6687 goto error;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006688
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006689 if (!spec->no_analog && has_cdefine_beep(codec)) {
6690 err = snd_hda_attach_beep_device(codec, 0x1);
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006691 if (err < 0)
6692 goto error;
Kailang Yangda00c242010-03-19 11:23:45 +01006693 switch (codec->vendor_id) {
6694 case 0x10ec0662:
6695 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
6696 break;
6697 case 0x10ec0272:
6698 case 0x10ec0663:
6699 case 0x10ec0665:
6700 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
6701 break;
6702 case 0x10ec0273:
6703 set_beep_amp(spec, 0x0b, 0x03, HDA_INPUT);
6704 break;
6705 }
Kailang Yangcec27c82010-02-04 14:18:18 +01006706 }
Takashi Iwai2134ea42008-01-10 16:53:55 +01006707
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006708 codec->patch_ops = alc_patch_ops;
Takashi Iwai1c716152011-04-07 10:37:16 +02006709 spec->shutup = alc_eapd_shutup;
David Henningsson6cb3b702010-09-09 08:51:44 +02006710
Takashi Iwai589876e2012-02-20 15:47:55 +01006711 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
6712
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006713 return 0;
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006714
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006715 error:
6716 alc_free(codec);
6717 return err;
Kailang Yangb478b992011-05-18 11:51:15 +02006718}
6719
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006720/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006721 * ALC680 support
6722 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006723
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006724static int alc680_parse_auto_config(struct hda_codec *codec)
6725{
Takashi Iwai3e6179b2011-07-08 16:55:13 +02006726 return alc_parse_auto_config(codec, NULL, NULL);
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006727}
6728
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006729/*
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006730 */
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006731static int patch_alc680(struct hda_codec *codec)
6732{
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006733 int err;
6734
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006735 /* ALC680 has no aa-loopback mixer */
Takashi Iwai3de95172012-05-07 18:03:15 +02006736 err = alc_alloc_spec(codec, 0);
6737 if (err < 0)
6738 return err;
Takashi Iwai1f0f4b82011-06-27 10:52:59 +02006739
Takashi Iwai1ebec5f2011-08-15 13:21:48 +02006740 /* automatic parse from the BIOS config */
6741 err = alc680_parse_auto_config(codec);
6742 if (err < 0) {
6743 alc_free(codec);
6744 return err;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006745 }
6746
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006747 codec->patch_ops = alc_patch_ops;
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006748
6749 return 0;
6750}
6751
6752/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07006753 * patch entries
6754 */
Takashi Iwaia9111322011-05-02 11:30:18 +02006755static const struct hda_codec_preset snd_hda_preset_realtek[] = {
Kailang Yang296f0332011-05-18 11:52:36 +02006756 { .id = 0x10ec0221, .name = "ALC221", .patch = patch_alc269 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006757 { .id = 0x10ec0260, .name = "ALC260", .patch = patch_alc260 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006758 { .id = 0x10ec0262, .name = "ALC262", .patch = patch_alc262 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006759 { .id = 0x10ec0267, .name = "ALC267", .patch = patch_alc268 },
Kailang Yanga361d842007-06-05 12:30:55 +02006760 { .id = 0x10ec0268, .name = "ALC268", .patch = patch_alc268 },
Kailang Yangf6a92242007-12-13 16:52:54 +01006761 { .id = 0x10ec0269, .name = "ALC269", .patch = patch_alc269 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006762 { .id = 0x10ec0270, .name = "ALC270", .patch = patch_alc269 },
Kailang Yang01afd412008-10-15 11:22:09 +02006763 { .id = 0x10ec0272, .name = "ALC272", .patch = patch_alc662 },
Kailang Yangebb83ee2009-12-17 12:23:00 +01006764 { .id = 0x10ec0275, .name = "ALC275", .patch = patch_alc269 },
Kailang Yang296f0332011-05-18 11:52:36 +02006765 { .id = 0x10ec0276, .name = "ALC276", .patch = patch_alc269 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006766 { .id = 0x10ec0861, .rev = 0x100340, .name = "ALC660",
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006767 .patch = patch_alc861 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006768 { .id = 0x10ec0660, .name = "ALC660-VD", .patch = patch_alc861vd },
6769 { .id = 0x10ec0861, .name = "ALC861", .patch = patch_alc861 },
6770 { .id = 0x10ec0862, .name = "ALC861-VD", .patch = patch_alc861vd },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006771 { .id = 0x10ec0662, .rev = 0x100002, .name = "ALC662 rev2",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006772 .patch = patch_alc882 },
Kailang Yangbc9f98a2007-04-12 13:06:07 +02006773 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
6774 .patch = patch_alc662 },
David Henningssoncc667a72011-10-18 14:07:51 +02006775 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
6776 .patch = patch_alc662 },
Kailang Yang6dda9f42008-05-27 12:05:31 +02006777 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
Kailang Yangcec27c82010-02-04 14:18:18 +01006778 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
Kailang Yang6227cdc2010-02-25 08:36:52 +01006779 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
Kailang Yangd1eb57f2010-06-23 16:25:26 +02006780 { .id = 0x10ec0680, .name = "ALC680", .patch = patch_alc680 },
Jakub Schmidtkef32610e2007-02-02 18:17:27 +01006781 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006782 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006783 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc882 },
Clive Messer669faba2008-09-30 15:49:13 +02006784 { .id = 0x10ec0885, .rev = 0x100101, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006785 .patch = patch_alc882 },
Takashi Iwaicb308f92008-04-16 14:13:29 +02006786 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006787 .patch = patch_alc882 },
Kailang Yangdf694da2005-12-05 19:42:22 +01006788 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006789 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
Kailang Yang44426082008-10-15 11:18:05 +02006790 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
Takashi Iwai4953550a2009-06-30 15:28:30 +02006791 .patch = patch_alc882 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006792 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
Takashi Iwai4953550a2009-06-30 15:28:30 +02006793 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
Kailang Yang274693f2009-12-03 10:07:50 +01006794 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
Takashi Iwaie16fb6d2011-10-17 16:39:09 +02006795 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006796 {} /* terminator */
6797};
Takashi Iwai1289e9e2008-11-27 15:47:11 +01006798
6799MODULE_ALIAS("snd-hda-codec-id:10ec*");
6800
6801MODULE_LICENSE("GPL");
6802MODULE_DESCRIPTION("Realtek HD-audio codec");
6803
6804static struct hda_codec_preset_list realtek_list = {
6805 .preset = snd_hda_preset_realtek,
6806 .owner = THIS_MODULE,
6807};
6808
6809static int __init patch_realtek_init(void)
6810{
6811 return snd_hda_add_codec_preset(&realtek_list);
6812}
6813
6814static void __exit patch_realtek_exit(void)
6815{
6816 snd_hda_delete_codec_preset(&realtek_list);
6817}
6818
6819module_init(patch_realtek_init)
6820module_exit(patch_realtek_exit)